Don't try to parse authority if it's not there.

Signed-off-by: Piotr Jaroszyński <[email protected]>
---
 src/core/uri.c |   44 ++++++++++++++++++++++----------------------
 1 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/core/uri.c b/src/core/uri.c
index 6a1f2e5..1a43206 100644
--- a/src/core/uri.c
+++ b/src/core/uri.c
@@ -129,7 +129,10 @@ struct uri * parse_uri ( const char *uri_string ) {
        }
 
        /* Identify net/absolute/relative path */
-       if ( strncmp ( path, "//", 2 ) == 0 ) {
+       if ( strncmp ( path, "//", 2 ) != 0 ) {
+               /* Absolute/relative path */
+               uri->path = path;
+       } else {
                /* Net path.  If this is terminated by the first '/'
                 * of an absolute path, then we have no space for a
                 * terminator after the authority field, so shuffle
@@ -145,31 +148,28 @@ struct uri * parse_uri ( const char *uri_string ) {
                        authority--;
                        *(--tmp) = '\0';
                }
-       } else {
-               /* Absolute/relative path */
-               uri->path = path;
-       }
 
-       /* Split authority into user[:password] and host[:port] portions */
-       if ( ( tmp = strchr ( authority, '@' ) ) ) {
-               /* Has user[:password] */
-               *(tmp++) = '\0';
-               uri->host = tmp;
-               uri->user = authority;
-               if ( ( tmp = strchr ( authority, ':' ) ) ) {
-                       /* Has password */
+               /* Split authority into user[:password] and host[:port] 
portions */
+               if ( ( tmp = strchr ( authority, '@' ) ) ) {
+                       /* Has user[:password] */
                        *(tmp++) = '\0';
-                       uri->password = tmp;
+                       uri->host = tmp;
+                       uri->user = authority;
+                       if ( ( tmp = strchr ( authority, ':' ) ) ) {
+                               /* Has password */
+                               *(tmp++) = '\0';
+                               uri->password = tmp;
+                       }
+               } else {
+                       /* No user:password */
+                       uri->host = authority;
                }
-       } else {
-               /* No user:password */
-               uri->host = authority;
-       }
 
-       /* Split host into host[:port] */
-       if ( ( tmp = strchr ( uri->host, ':' ) ) ) {
-               *(tmp++) = '\0';
-               uri->port = tmp;
+               /* Split host into host[:port] */
+               if ( ( tmp = strchr ( uri->host, ':' ) ) ) {
+                       *(tmp++) = '\0';
+                       uri->port = tmp;
+               }
        }
 
        /* Decode fields that should be decoded */
-- 
1.7.0.4

_______________________________________________
gPXE-devel mailing list
[email protected]
http://etherboot.org/mailman/listinfo/gpxe-devel

Reply via email to