]> git.proxmox.com Git - mirror_qemu.git/blobdiff - util/uri.c
all: Remove unnecessary glib.h includes
[mirror_qemu.git] / util / uri.c
index aa3969471aca1161fd0ad8954742462daedac370..70a9cbcbd2f12b694ece103779b9b2f6eb0a1f78 100644 (file)
@@ -51,9 +51,7 @@
  *
  */
 
-#include <glib.h>
-#include <string.h>
-#include <stdio.h>
+#include "qemu/osdep.h"
 
 #include "qemu/uri.h"
 
@@ -320,19 +318,23 @@ static int
 rfc3986_parse_port(URI *uri, const char **str)
 {
     const char *cur = *str;
+    int port = 0;
 
     if (ISA_DIGIT(cur)) {
-       if (uri != NULL)
-           uri->port = 0;
-       while (ISA_DIGIT(cur)) {
-           if (uri != NULL)
-               uri->port = uri->port * 10 + (*cur - '0');
-           cur++;
-       }
-       *str = cur;
-       return(0);
+        while (ISA_DIGIT(cur)) {
+            port = port * 10 + (*cur - '0');
+            if (port > 65535) {
+                return 1;
+            }
+            cur++;
+        }
+        if (uri) {
+            uri->port = port;
+        }
+        *str = cur;
+        return 0;
     }
-    return(1);
+    return 1;
 }
 
 /**
@@ -1049,14 +1051,12 @@ uri_to_string(URI *uri) {
        while (*p != 0) {
            if (len >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                ret = temp;
            }
            ret[len++] = *p++;
        }
        if (len >= max) {
             temp = realloc2n(ret, &max);
-            if (temp == NULL) goto mem_error;
             ret = temp;
        }
        ret[len++] = ':';
@@ -1066,7 +1066,6 @@ uri_to_string(URI *uri) {
        while (*p != 0) {
            if (len + 3 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
@@ -1083,7 +1082,6 @@ uri_to_string(URI *uri) {
        if (uri->server != NULL) {
            if (len + 3 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            ret[len++] = '/';
@@ -1093,7 +1091,6 @@ uri_to_string(URI *uri) {
                while (*p != 0) {
                    if (len + 3 >= max) {
                         temp = realloc2n(ret, &max);
-                        if (temp == NULL) goto mem_error;
                         ret = temp;
                    }
                    if ((IS_UNRESERVED(*(p))) ||
@@ -1112,7 +1109,6 @@ uri_to_string(URI *uri) {
                }
                if (len + 3 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                ret[len++] = '@';
@@ -1121,7 +1117,6 @@ uri_to_string(URI *uri) {
            while (*p != 0) {
                if (len >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                ret[len++] = *p++;
@@ -1129,7 +1124,6 @@ uri_to_string(URI *uri) {
            if (uri->port > 0) {
                if (len + 10 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                len += snprintf(&ret[len], max - len, ":%d", uri->port);
@@ -1137,7 +1131,6 @@ uri_to_string(URI *uri) {
        } else if (uri->authority != NULL) {
            if (len + 3 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            ret[len++] = '/';
@@ -1146,7 +1139,6 @@ uri_to_string(URI *uri) {
            while (*p != 0) {
                if (len + 3 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                if ((IS_UNRESERVED(*(p))) ||
@@ -1165,7 +1157,6 @@ uri_to_string(URI *uri) {
        } else if (uri->scheme != NULL) {
            if (len + 3 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            ret[len++] = '/';
@@ -1185,7 +1176,6 @@ uri_to_string(URI *uri) {
                (!strcmp(uri->scheme, "file"))) {
                if (len + 3 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                ret[len++] = *p++;
@@ -1195,7 +1185,6 @@ uri_to_string(URI *uri) {
            while (*p != 0) {
                if (len + 3 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
@@ -1215,7 +1204,6 @@ uri_to_string(URI *uri) {
        if (uri->query != NULL) {
            if (len + 1 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            ret[len++] = '?';
@@ -1223,7 +1211,6 @@ uri_to_string(URI *uri) {
            while (*p != 0) {
                if (len + 1 >= max) {
                     temp = realloc2n(ret, &max);
-                    if (temp == NULL) goto mem_error;
                     ret = temp;
                }
                ret[len++] = *p++;
@@ -1233,7 +1220,6 @@ uri_to_string(URI *uri) {
     if (uri->fragment != NULL) {
        if (len + 3 >= max) {
             temp = realloc2n(ret, &max);
-            if (temp == NULL) goto mem_error;
             ret = temp;
        }
        ret[len++] = '#';
@@ -1241,7 +1227,6 @@ uri_to_string(URI *uri) {
        while (*p != 0) {
            if (len + 3 >= max) {
                 temp = realloc2n(ret, &max);
-                if (temp == NULL) goto mem_error;
                 ret = temp;
            }
            if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
@@ -1257,15 +1242,10 @@ uri_to_string(URI *uri) {
     }
     if (len >= max) {
         temp = realloc2n(ret, &max);
-        if (temp == NULL) goto mem_error;
         ret = temp;
     }
     ret[len] = 0;
     return(ret);
-
-mem_error:
-    g_free(ret);
-    return(NULL);
 }
 
 /**
@@ -1957,7 +1937,8 @@ uri_resolve_relative (const char *uri, const char * base)
        val = g_strdup (uri);
        goto done;
     }
-    if (!strcmp(bas->path, ref->path)) {
+    if (bas->path == ref->path ||
+        (bas->path && ref->path && !strcmp(bas->path, ref->path))) {
        val = g_strdup("");
        goto done;
     }