Blob Blame History Raw
From c58c1b0ffa7d26ad0bc016a874744ffdce9d9d5b Mon Sep 17 00:00:00 2001
From: Jens Georg <mail@jensge.org>
Date: Wed, 2 Jun 2021 12:43:45 +0200
Subject: [PATCH 3/3] context: Use SoupURI instead of GUri

Do not bump the implicit requirement to GLib 2.66 for this version
---
 libgupnp/gupnp-context.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 878acf3..af8207f 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -1570,26 +1570,22 @@ validate_host_header (const char *host_header,
         // [] from v6 addresses, splitting of the port etc.
         char *uri_from_host = g_strconcat ("http://", host_header, NULL);
 
-        char *host = NULL;
+        const char *host = NULL;
         int port = 0;
-        GError *error = NULL;
-
-        g_uri_split_network (uri_from_host,
-                             G_URI_FLAGS_NONE,
-                             NULL,
-                             &host,
-                             &port,
-                             &error);
 
-        if (error != NULL) {
-                g_debug ("Failed to parse HOST header from request: %s",
-                         error->message);
+        SoupURI *uri = soup_uri_new (uri_from_host);
+        if (uri == NULL) {
+                g_debug ("Failed to parse HOST header %s from request",
+                         host_header);
                 goto out;
         }
+        host = soup_uri_get_host (uri);
+        port = soup_uri_get_port (uri);
+
 
         // -1 means there was no :port; according to UDA this is allowed and
         // defaults to 80, the HTTP port then
-        if (port == -1) {
+        if (soup_uri_uses_default_port (uri)) {
                 port = 80;
         }
 
@@ -1610,8 +1606,7 @@ validate_host_header (const char *host_header,
         retval = g_str_equal (host, host_ip) && port == context_port;
 
 out:
-        g_clear_error (&error);
-        g_free (host);
+        g_clear_pointer (&uri, soup_uri_free);
         g_free (uri_from_host);
 
         return retval;
-- 
2.31.1