summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Neumann <neumann@teufel.de>2014-11-14 15:31:50 +0100
committerJens Georg <mail@jensge.org>2015-01-03 10:50:46 +0100
commit62eb328449e956fb146f1fe024ff798e5191e4f4 (patch)
treeaf51b3b262307ad77f031ccfe871c72e342c0ff5
parent20eed980f64a0042e6bfc340c80d982ddf04ff1c (diff)
downloadgupnp-62eb328449e956fb146f1fe024ff798e5191e4f4.tar.gz
gupnp-context: port to new libsoup API (requires libsoup 2.48)
Signed-off-by: Sven Neumann <neumann@teufel.de> https://bugzilla.gnome.org/show_bug.cgi?id=740267
-rw-r--r--configure.ac2
-rw-r--r--libgupnp/gupnp-context-private.h4
-rw-r--r--libgupnp/gupnp-context.c92
-rw-r--r--libgupnp/gupnp-root-device.c10
-rw-r--r--libgupnp/gupnp-service-proxy.c14
5 files changed, 61 insertions, 61 deletions
diff --git a/configure.ac b/configure.ac
index 6e4b75e..5aeef31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,7 +51,7 @@ PKG_CHECK_MODULES(LIBGUPNP, glib-2.0 >= 2.28.0 \
gio-2.0 \
gmodule-2.0 \
gssdp-1.0 >= 0.13.0 \
- libsoup-2.4 >= 2.28.2 \
+ libsoup-2.4 >= 2.48.0 \
libxml-2.0 \
$UUID_LIBS)
PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
diff --git a/libgupnp/gupnp-context-private.h b/libgupnp/gupnp-context-private.h
index 212d5e0..c088563 100644
--- a/libgupnp/gupnp-context-private.h
+++ b/libgupnp/gupnp-context-private.h
@@ -28,8 +28,8 @@
G_BEGIN_DECLS
-G_GNUC_INTERNAL const char *
-_gupnp_context_get_server_url (GUPnPContext *context);
+G_GNUC_INTERNAL SoupURI *
+_gupnp_context_get_server_uri (GUPnPContext *context);
G_GNUC_INTERNAL void
_gupnp_context_add_server_handler_with_data (GUPnPContext *context,
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 935feb5..e145c69 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -92,7 +92,7 @@ struct _GUPnPContextPrivate {
SoupSession *session;
SoupServer *server; /* Started on demand */
- char *server_url;
+ SoupURI *server_uri;
char *default_language;
GList *host_path_datas;
@@ -361,7 +361,9 @@ gupnp_context_finalize (GObject *object)
context = GUPNP_CONTEXT (object);
g_free (context->priv->default_language);
- g_free (context->priv->server_url);
+
+ if (context->priv->server_uri)
+ soup_uri_free (context->priv->server_uri);
/* Call super */
object_class = G_OBJECT_CLASS (gupnp_context_parent_class);
@@ -581,63 +583,55 @@ gupnp_context_get_server (GUPnPContext *context)
g_return_val_if_fail (GUPNP_IS_CONTEXT (context), NULL);
if (context->priv->server == NULL) {
- const char *ip;
-
- ip = gssdp_client_get_host_ip (GSSDP_CLIENT (context));
- SoupAddress *addr = soup_address_new (ip, context->priv->port);
- soup_address_resolve_sync (addr, NULL);
-
- context->priv->server = soup_server_new
- (SOUP_SERVER_PORT,
- context->priv->port,
- SOUP_SERVER_ASYNC_CONTEXT,
- g_main_context_get_thread_default (),
- SOUP_SERVER_INTERFACE,
- addr,
- NULL);
- g_object_unref (addr);
-
- if (context->priv->server) {
- soup_server_add_handler (context->priv->server,
- NULL,
- default_server_handler,
- context,
- NULL);
+ context->priv->server = soup_server_new (NULL, NULL);
- soup_server_run_async (context->priv->server);
+ soup_server_add_handler (context->priv->server,
+ NULL,
+ default_server_handler,
+ context,
+ NULL);
+
+ const char *ip = gssdp_client_get_host_ip (GSSDP_CLIENT (context));
+ const guint port = context->priv->port;
+ GSocketAddress *addr = g_inet_socket_address_new_from_string (ip, port);
+ GError *error = NULL;
+
+ if (! soup_server_listen (context->priv->server,
+ addr, (SoupServerListenOptions) 0, &error)) {
+ g_warning ("GUPnPContext: Unable to listen on %s:%u %s", ip, port, error->message);
+ g_error_free (error);
}
+
+ g_object_unref (addr);
}
return context->priv->server;
}
/*
- * Makes an URL that refers to our server.
+ * Makes a SoupURI that refers to our server.
**/
-static char *
-make_server_url (GUPnPContext *context)
+static SoupURI *
+make_server_uri (GUPnPContext *context)
{
- SoupServer *server;
- guint port;
-
- /* What port are we running on? */
- server = gupnp_context_get_server (context);
- port = soup_server_get_port (server);
-
- /* Put it all together */
- return g_strdup_printf
- ("http://%s:%u",
- gssdp_client_get_host_ip (GSSDP_CLIENT (context)),
- port);
+ SoupServer *server = gupnp_context_get_server (context);
+ GSList *uris = soup_server_get_uris (server);
+ if (uris)
+ {
+ SoupURI *uri = soup_uri_copy (uris->data);
+ g_slist_free_full (uris, (GDestroyNotify) soup_uri_free);
+ return uri;
+ }
+ return NULL;
}
-const char *
-_gupnp_context_get_server_url (GUPnPContext *context)
+SoupURI *
+_gupnp_context_get_server_uri (GUPnPContext *context)
{
- if (context->priv->server_url == NULL)
- context->priv->server_url = make_server_url (context);
+ if (context->priv->server_uri == NULL)
+ context->priv->server_uri = make_server_uri (context);
- return (const char *) context->priv->server_url;
+ return soup_uri_copy (context->priv->server_uri);
}
/**
@@ -702,12 +696,12 @@ gupnp_context_get_host_ip (GUPnPContext *context)
guint
gupnp_context_get_port (GUPnPContext *context)
{
- SoupServer *server;
-
g_return_val_if_fail (GUPNP_IS_CONTEXT (context), 0);
- server = gupnp_context_get_server (context);
- return soup_server_get_port (server);
+ if (context->priv->server_uri == NULL)
+ context->priv->server_uri = make_server_uri (context);
+
+ return soup_uri_get_port (context->priv->server_uri);
}
/**
diff --git a/libgupnp/gupnp-root-device.c b/libgupnp/gupnp-root-device.c
index fe6affc..cf207fc 100644
--- a/libgupnp/gupnp-root-device.c
+++ b/libgupnp/gupnp-root-device.c
@@ -272,6 +272,7 @@ gupnp_root_device_constructor (GType type,
GUPnPRootDevice *device;
GUPnPContext *context;
const char *description_path, *description_dir, *udn;
+ SoupURI *uri;
char *desc_path, *location, *usn, *relative_location;
unsigned int i;
GUPnPXMLDoc *description_doc;
@@ -420,10 +421,11 @@ gupnp_root_device_constructor (GType type,
gupnp_context_host_path (context, device->priv->description_dir, "");
/* Generate full location */
- location = g_strjoin (NULL,
- _gupnp_context_get_server_url (context),
- relative_location,
- NULL);
+ uri = _gupnp_context_get_server_uri (context);
+ soup_uri_set_path (uri, relative_location);
+ location = soup_uri_to_string (uri, FALSE);
+ soup_uri_free (uri);
+
g_free (relative_location);
/* Save the URL base, if any */
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index 015e926..2b363e1 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -2275,7 +2275,8 @@ subscribe (GUPnPServiceProxy *proxy)
SoupMessage *msg;
SoupSession *session;
SoupServer *server;
- const char *server_url;
+ SoupURI *uri;
+ char *uri_string;
char *sub_url, *delivery_url, *timeout;
/* Remove subscription timeout */
@@ -2321,10 +2322,13 @@ subscribe (GUPnPServiceProxy *proxy)
}
/* Add headers */
- server_url = _gupnp_context_get_server_url (context);
- delivery_url = g_strdup_printf ("<%s%s>",
- server_url,
- proxy->priv->path);
+ uri = _gupnp_context_get_server_uri (context);
+ soup_uri_set_path (uri, proxy->priv->path);
+ uri_string = soup_uri_to_string (uri, FALSE);
+ soup_uri_free (uri);
+ delivery_url = g_strdup_printf ("<%s>", uri_string);
+ g_free (uri_string);
+
soup_message_headers_append (msg->request_headers,
"Callback",
delivery_url);