[glib] networkaddress: Return an error from _g_uri_parse_authority()



commit 5f2c20e88bf474fd58e23c46c89d448f1fc00a55
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Jan 3 16:19:56 2017 +0100

    networkaddress: Return an error from _g_uri_parse_authority()
    
    So that errors can be propagated if necessary.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772989

 gio/gnetworkaddress.c         |   31 +++++++++++++++----------------
 gio/gnetworkingprivate.h      |    3 ++-
 gio/gproxyaddressenumerator.c |    2 +-
 gio/gsimpleproxyresolver.c    |    2 +-
 4 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/gio/gnetworkaddress.c b/gio/gnetworkaddress.c
index 07f923a..1cb4a2b 100644
--- a/gio/gnetworkaddress.c
+++ b/gio/gnetworkaddress.c
@@ -489,7 +489,8 @@ gboolean
 _g_uri_parse_authority (const char  *uri,
                        char       **host,
                        guint16     *port,
-                       char       **userinfo)
+                       char       **userinfo,
+                       GError     **error)
 {
   char *tmp_str;
   const char *start, *p, *at, *delim;
@@ -517,7 +518,7 @@ _g_uri_parse_authority (const char  *uri,
   tmp_str = g_uri_parse_scheme (uri);
 
   if (tmp_str == NULL)
-    return FALSE;
+    goto error;
 
   g_free (tmp_str);
 
@@ -528,7 +529,7 @@ _g_uri_parse_authority (const char  *uri,
   start = strstr (p, "//");
 
   if (start == NULL)
-    return FALSE;
+    goto error;
 
   start += 2;
 
@@ -559,7 +560,7 @@ _g_uri_parse_authority (const char  *uri,
            {
              if (!(g_ascii_isxdigit (p[0]) ||
                    g_ascii_isxdigit (p[1])))
-               return FALSE;
+          goto error;
 
              p++;
 
@@ -571,7 +572,7 @@ _g_uri_parse_authority (const char  *uri,
                strchr (G_URI_OTHER_UNRESERVED, c) ||
                strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
                c == ':'))
-           return FALSE;
+      goto error;
        }
 
       if (userinfo)
@@ -618,7 +619,7 @@ _g_uri_parse_authority (const char  *uri,
                strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
                c == ':' ||
                c == '.'))
-           goto error;
+      goto error;
        }
 
       if (host)
@@ -649,7 +650,7 @@ _g_uri_parse_authority (const char  *uri,
            {
              if (!(g_ascii_isxdigit (p[0]) ||
                    g_ascii_isxdigit (p[1])))
-               goto error;
+          goto error;
 
              p++;
 
@@ -660,7 +661,7 @@ _g_uri_parse_authority (const char  *uri,
          if (!(g_ascii_isalnum (c) ||
                strchr (G_URI_OTHER_UNRESERVED, c) ||
                strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c)))
-           goto error;
+      goto error;
        }
 
       if (host)
@@ -685,7 +686,7 @@ _g_uri_parse_authority (const char  *uri,
            break;
 
          if (!g_ascii_isdigit (c))
-           goto error;
+      goto error;
 
          tmp = (tmp * 10) + (c - '0');
 
@@ -699,6 +700,9 @@ _g_uri_parse_authority (const char  *uri,
   return TRUE;
 
 error:
+  g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+               "Invalid URI ā€˜%sā€™", uri);
+
   if (host && *host)
     {
       g_free (*host);
@@ -782,13 +786,8 @@ g_network_address_parse_uri (const gchar  *uri,
   gchar *hostname;
   guint16 port;
 
-  if (!_g_uri_parse_authority (uri, &hostname, &port, NULL))
-    {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
-                  "Invalid URI '%s'",
-                  uri);
-      return NULL;
-    }
+  if (!_g_uri_parse_authority (uri, &hostname, &port, NULL, error))
+    return NULL;
 
   if (port == 0)
     port = default_port;
diff --git a/gio/gnetworkingprivate.h b/gio/gnetworkingprivate.h
index fe126d6..ed0feb8 100644
--- a/gio/gnetworkingprivate.h
+++ b/gio/gnetworkingprivate.h
@@ -26,7 +26,8 @@ G_BEGIN_DECLS
 gboolean _g_uri_parse_authority            (const char       *uri,
                                            char            **host,
                                            guint16          *port,
-                                           char            **userinfo);
+                                           char            **userinfo,
+                                           GError          **error);
 gchar *  _g_uri_from_authority             (const gchar      *protocol,
                                            const gchar      *host,
                                            guint             port,
diff --git a/gio/gproxyaddressenumerator.c b/gio/gproxyaddressenumerator.c
index 698df3e..74a486e 100644
--- a/gio/gproxyaddressenumerator.c
+++ b/gio/gproxyaddressenumerator.c
@@ -93,7 +93,7 @@ save_userinfo (GProxyAddressEnumeratorPrivate *priv,
       priv->proxy_password = NULL;
     }
   
-  if (_g_uri_parse_authority (proxy, NULL, NULL, &userinfo))
+  if (_g_uri_parse_authority (proxy, NULL, NULL, &userinfo, NULL))
     {
       if (userinfo)
        {
diff --git a/gio/gsimpleproxyresolver.c b/gio/gsimpleproxyresolver.c
index 8a6fb38..f33d49f 100644
--- a/gio/gsimpleproxyresolver.c
+++ b/gio/gsimpleproxyresolver.c
@@ -329,7 +329,7 @@ g_simple_proxy_resolver_lookup (GProxyResolver  *proxy_resolver,
       gchar *host = NULL;
       gushort port;
 
-      if (_g_uri_parse_authority (uri, &host, &port, NULL) &&
+      if (_g_uri_parse_authority (uri, &host, &port, NULL, NULL) &&
           ignore_host (resolver, host, port))
         proxy = "direct://";
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]