Deal with user[;auth][:pass] correctly.
authormo@ilaven.net <mo@ilaven.net@68b1170a-6346-0410-b79c-01ab32b2924b>
Wed, 19 Nov 2008 16:25:22 +0000 (16:25 +0000)
committermo@ilaven.net <mo@ilaven.net@68b1170a-6346-0410-b79c-01ab32b2924b>
Wed, 19 Nov 2008 16:25:22 +0000 (16:25 +0000)
git-svn-id: http://libiri.googlecode.com/svn/trunk@5 68b1170a-6346-0410-b79c-01ab32b2924b

include/iri.h
libiri/parse.c
tests/iridump.c

index cb7df6c..2adefab 100644 (file)
@@ -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_
index 3b2b2f2..d96a350 100644 (file)
@@ -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 != '#')
index e812ab1..e22c50f 100644 (file)
@@ -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;
 }