From: mo@ilaven.net Date: Wed, 19 Nov 2008 16:25:22 +0000 (+0000) Subject: Deal with user[;auth][:pass] correctly. X-Git-Tag: upstream/1.1~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c7f383c5d826310ad7e872880d677592bbac6a49;p=platform%2Fupstream%2Flibiri.git Deal with user[;auth][:pass] correctly. git-svn-id: http://libiri.googlecode.com/svn/trunk@5 68b1170a-6346-0410-b79c-01ab32b2924b --- diff --git a/include/iri.h b/include/iri.h index cb7df6c..2adefab 100644 --- a/include/iri.h +++ b/include/iri.h @@ -38,15 +38,17 @@ typedef struct iri_struct iri_t; struct iri_struct { void *_private; + const char *display; const char *scheme; const char *user; const char *auth; + const char *password; const char *host; int port; const char *path; const char *query; const char *anchor; - const char **params; + const char **qparams; }; # undef EXTERNC_ diff --git a/libiri/parse.c b/libiri/parse.c index 3b2b2f2..d96a350 100644 --- a/libiri/parse.c +++ b/libiri/parse.c @@ -147,7 +147,7 @@ iri_parse(const char *src) } else if(colon && at && colon < at) { - /* This could be scheme://user[:auth]@host or [scheme:]user[:auth]@host (urgh) */ + /* This could be scheme://user[;auth][:password]@host or [scheme:]user[;auth][:password]@host (urgh) */ if(colon[1] == '/') { p->scheme = bufp; @@ -166,19 +166,32 @@ iri_parse(const char *src) { p->scheme = bufp; } - while(*src && *src != ':' && *src != '@') + while(*src && *src != ':' && *src != '@' && *src != ';') { src = iri__copychar_decode(&bufp, src, 0); } *bufp = 0; bufp++; - if(*src == ':') + if(*src == ';') { - /* Following auth data */ + /* Following authentication parameters */ src++; p->auth = bufp; while(*src && *src != ':' && *src != '@') { + /* Don't decode, so it can be extracted properly */ + src = iri__copychar(&bufp, src); + } + *bufp = 0; + bufp++; + } + if(*src == ':') + { + /* Following password data */ + src++; + p->password = bufp; + while(*src && *src != ':' && *src != '@') + { src = iri__copychar_decode(&bufp, src, 0); } *bufp = 0; @@ -188,7 +201,7 @@ iri_parse(const char *src) src++; /* It was actually scheme:user:auth@host */ p->user = p->auth; - p->auth = bufp; + p->password = bufp; while(*src && *src != '@') { src = iri__copychar_decode(&bufp, src, 0); @@ -209,15 +222,30 @@ iri_parse(const char *src) } else if(at) { - /* user@host[/path...] */ + /* user[;auth]@host[/path...] */ p->user = bufp; - while(*src != '@') + while(*src != '@' && *src != ';') { src = iri__copychar_decode(&bufp, src, 0); } *bufp = 0; bufp++; - src++; + if(*src == ';') + { + src++; + p->auth = bufp; + while(*src && *src != '@') + { + /* Don't decode, so it can be extracted properly */ + src = iri__copychar(&bufp, src); + } + *bufp = 0; + bufp++; + } + else + { + src++; + } } p->host = bufp; while(*src && *src != ':' && *src != '/' && *src != '?' && *src != '#') diff --git a/tests/iridump.c b/tests/iridump.c index e812ab1..e22c50f 100644 --- a/tests/iridump.c +++ b/tests/iridump.c @@ -51,13 +51,14 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } iri = iri_parse(argv[1]); - printf("scheme: %s\n", iri->scheme); - printf(" user: %s\n", iri->user); - printf(" auth: %s\n", iri->auth); - printf(" host: %s\n", iri->host); - printf(" port: %d\n", iri->port); - printf(" path: %s\n", iri->path); - printf(" query: %s\n", iri->query); - printf("anchor: %s\n", iri->anchor); + printf(" scheme: %s\n", iri->scheme); + printf(" user: %s\n", iri->user); + printf(" auth: %s\n", iri->auth); + printf("password: %s\n", iri->password); + printf(" host: %s\n", iri->host); + printf(" port: %d\n", iri->port); + printf(" path: %s\n", iri->path); + printf(" query: %s\n", iri->query); + printf(" anchor: %s\n", iri->anchor); return 0; }