[glib: 8/13] gio: use g_uri_split_network() in g_network_address_parse_uri()




commit 6f419e7e2f1c00e297384688569e47ff09dc7de5
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Tue Jul 7 12:58:33 2020 +0400

    gio: use g_uri_split_network() in g_network_address_parse_uri()
    
    _g_uri_parse_authority() can be replaced with g_uri_split_network() &
    PARSE_STRICT. Keep the original error code, for compatibility reasons.
    
    Notice that GUri uses gint for the port, and value -1 if the port value
    is missing. However, GNetworkAddress::port is a guint.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 gio/gnetworkaddress.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gio/gnetworkaddress.c b/gio/gnetworkaddress.c
index 9693fc125..2fa10733e 100644
--- a/gio/gnetworkaddress.c
+++ b/gio/gnetworkaddress.c
@@ -787,25 +787,27 @@ g_network_address_parse_uri (const gchar  *uri,
                             guint16       default_port,
                             GError      **error)
 {
-  GSocketConnectable *conn;
-  gchar *scheme;
-  gchar *hostname;
-  guint16 port;
+  GSocketConnectable *conn = NULL;
+  gchar *scheme = NULL;
+  gchar *hostname = NULL;
+  gint port;
 
-  if (!_g_uri_parse_authority (uri, &hostname, &port, NULL, error))
-    return NULL;
+  if (!g_uri_split_network (uri, G_URI_FLAGS_PARSE_STRICT,
+                            &scheme, &hostname, &port, NULL))
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+                   "Invalid URI ‘%s’", uri);
+      return NULL;
+    }
 
-  if (port == 0)
+  if (port <= 0)
     port = default_port;
 
-  scheme = g_uri_parse_scheme (uri);
-
   conn = g_object_new (G_TYPE_NETWORK_ADDRESS,
                        "hostname", hostname,
-                       "port", port,
+                       "port", (guint) port,
                        "scheme", scheme,
                        NULL);
-
   g_free (scheme);
   g_free (hostname);
 


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