You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gupnp/SOURCES/0001-context-Use-SoupURI-in...

64 lines
2.1 KiB

From 8ed9a525a97091c2a416c82f05e8311837cc7600 Mon Sep 17 00:00:00 2001
From: Jens Georg <mail@jensge.org>
Date: Wed, 2 Jun 2021 12:43:45 +0200
Subject: [PATCH] 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 ec88b93..dda565e 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -1595,26 +1595,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;
}
@@ -1635,8 +1631,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