[gupnp] [PATCH 1/2] Factor duplicated code into a utility function



Signed-off-by: Sven Neumann <s neumann raumfeld com>
---
 libgupnp/gupnp-service.c |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index d6b7d2c..40c6964 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -1357,6 +1357,19 @@ got_introspection (GUPnPServiceInfo          *info,
         g_object_unref (service);
 }
 
+static char *
+path_from_url (const char *url)
+{
+        SoupURI *uri;
+        gchar   *path;
+
+        uri = soup_uri_new (url);
+        path = soup_uri_to_string (uri, TRUE);
+        soup_uri_free (uri);
+
+        return path;
+}
+
 static GObject *
 gupnp_service_constructor (GType                  type,
                            guint                  n_construct_params,
@@ -1368,8 +1381,8 @@ gupnp_service_constructor (GType                  type,
         GUPnPServiceInfo *info;
         GUPnPContext *context;
         SoupServer *server;
-        SoupURI *uri;
         char *url;
+        char *path;
 
         object_class = G_OBJECT_CLASS (gupnp_service_parent_class);
 
@@ -1393,26 +1406,18 @@ gupnp_service_constructor (GType                  type,
 
         /* Run listener on controlURL */
         url = gupnp_service_info_get_control_url (info);
-        uri = soup_uri_new (url);
-        g_free (url);
-
-        url = soup_uri_to_string (uri, TRUE);
-        soup_uri_free (uri);
-
-        soup_server_add_handler (server, url,
+        path = path_from_url (url);
+        soup_server_add_handler (server, path,
                                  control_server_handler, object, NULL);
+        g_free (path);
         g_free (url);
 
         /* Run listener on eventSubscriptionURL */
         url = gupnp_service_info_get_event_subscription_url (info);
-        uri = soup_uri_new (url);
-        g_free (url);
-
-        url = soup_uri_to_string (uri, TRUE);
-        soup_uri_free (uri);
-
-        soup_server_add_handler (server, url,
+        path = path_from_url (url);
+        soup_server_add_handler (server, path,
                                  subscription_server_handler, object, NULL);
+        g_free (path);
         g_free (url);
 
         return object;
-- 
1.7.0.4

--
To unsubscribe send a mail to gupnp+unsubscribe\@o-hand.com



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