On Thu, May 7, 2009 at 11:30 AM, Viktor Kojouharov<vkojouha...@gmail.com> wrote:
> Hi,
>
> This patch adds a bunch of tests related to efreet_uri, and enabled
> parsing of usernames/passwords/ports along with the rest of the uri
> scheme. the encode itself has also been updated to support all of this.
>
> I wasn't exactly sure why efreet_uri_encode didn't even return the
> hostname. if a program can't handle such a valid uri, it's a program
> bug, thus it shouldn't be a limit of the library.

Hi Viktor, just now I had the time to review the patch and it could be improved:

   - instead of memset() the whole buffers, set the initial value of
it to "" (empty string) and gcc will do a better work. And really you
do not need to zero the whole array. You should change the previous
code to follow it as well. char username[_POSIX_HOST_NAME_MAX] = ""
   - avoid useless walks and copies of arrays/strings. For instance
the old code already did strstr() to find out "://" then there is a
loop to copy it, either you do copying (remove strstr) or you use the
pointer and copy in a batch with memcpy() since you know the size.
   - watch out memcpy()! Unlike strcpy() it will not stop on first \0
and will copy useless bytes all around

all in all, I'd say you can do it all in one step just by copying
full_uri and replacing markers with "\0", then set pointers. For
example:

if full_uri == "http://u:p...@server.com:123/a/b/c":

base = strdup(full_uri);
protocol = base [http://....]
protocol[protocol_lenth] = '\0'
username = protocol + protocol_length + 3  [u:p...@server...]
username[username_length] = '\0'
password = username + username_length + 1 [...@server...]
password[password_length] = '\0'
server = password + password_length + 1
...

and so on, then the free function just need to release the memory
pointed by protocol. less fragmentation, less complexity, much easier!
:-)

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbi...@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to