[gssdp/wip/ipv6: 3/3] wip: Rewrite link-local locations



commit 4ff54949e8a279ebbb29c64c9b4397db9af2d6e8
Author: Jens Georg <mail jensge org>
Date:   Thu Feb 18 15:10:17 2016 +0100

    wip: Rewrite link-local locations
    
    Signed-off-by: Jens Georg <mail jensge org>

 libgssdp/gssdp-client.c           | 36 ++++++++++++++++++++++++++++++++++++
 libgssdp/gssdp-client.h           | 10 ++++++++++
 libgssdp/gssdp-resource-browser.c | 36 ++++++++++++++++++++++++++++++++++--
 3 files changed, 80 insertions(+), 2 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index aa54d55..211d934 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -1048,6 +1048,42 @@ gssdp_client_clear_headers (GSSDPClient *client)
                           (GDestroyNotify) header_field_free);
 }
 
+/**
+ * gssdp_client_get_address:
+ * @client: A #GSSDPClient
+ *
+ * Returns: (transfer full): The #GInetAddress this client works on
+ **/
+GInetAddress *
+gssdp_client_get_address (GSSDPClient *client)
+{
+        g_return_val_if_fail (GSSDP_IS_CLIENT (client), NULL);
+
+        return g_object_ref (client->priv->device.host_addr);
+}
+
+/**
+ * gssdp_client_get_index:
+ * @client: A #GSSDPClient
+ *
+ * Returns: The interface index of this client
+ **/
+guint
+gssdp_client_get_index (GSSDPClient *client)
+{
+        g_return_val_if_fail (GSSDP_IS_CLIENT (client), 0);
+
+        return client->priv->device.index;
+}
+
+GSocketFamily
+gssdp_client_get_family (GSSDPClient *client)
+{
+        g_return_val_if_fail (GSSDP_IS_CLIENT (client), G_SOCKET_FAMILY_INVALID);
+
+        return g_inet_address_get_family (client->priv->device.host_addr);
+}
+
 /**
  * _gssdp_client_send_message:
  * @client: A #GSSDPClient
diff --git a/libgssdp/gssdp-client.h b/libgssdp/gssdp-client.h
index 03a1866..46cf4b3 100644
--- a/libgssdp/gssdp-client.h
+++ b/libgssdp/gssdp-client.h
@@ -23,6 +23,7 @@
 #define __GSSDP_CLIENT_H__
 
 #include <glib-object.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -108,6 +109,15 @@ gssdp_client_get_network      (GSSDPClient  *client);
 gboolean
 gssdp_client_get_active       (GSSDPClient  *client);
 
+GInetAddress *
+gssdp_client_get_address      (GSSDPClient *client);
+
+guint
+gssdp_client_get_index        (GSSDPClient *client);
+
+GSocketFamily
+gssdp_client_get_family       (GSSDPClient *client);
+
 void
 gssdp_client_append_header    (GSSDPClient *client,
                                const char  *name,
diff --git a/libgssdp/gssdp-resource-browser.c b/libgssdp/gssdp-resource-browser.c
index 67e0856..b3ccd76 100644
--- a/libgssdp/gssdp-resource-browser.c
+++ b/libgssdp/gssdp-resource-browser.c
@@ -696,8 +696,40 @@ resource_available (GSSDPResourceBrowser *resource_browser,
         destroyLocations = TRUE;
 
         header = soup_message_headers_get_one (headers, "Location");
-        if (header)
-                locations = g_list_append (locations, g_strdup (header));
+        if (header) {
+                GSocketFamily family;
+                GSSDPClient *client;
+
+                client = resource_browser->priv->client;
+                family = gssdp_client_get_family (client);
+
+                if (family == G_SOCKET_FAMILY_IPV6) {
+                        SoupURI *uri = soup_uri_new (header);
+                        const char *host = NULL;
+                        GInetAddress *addr = NULL;
+
+                        host = soup_uri_get_host (uri);
+                        addr = g_inet_address_new_from_string (host);
+                        if (g_inet_address_get_is_link_local (addr)) {
+                                char *new_host;
+                                int index = 0;
+
+                                index = gssdp_client_get_index (client);
+
+                                new_host = g_strdup_printf ("%s%%%d",
+                                                            host,
+                                                            index);
+                                soup_uri_set_host (uri, new_host);
+                        }
+                        g_object_unref (addr);
+                        locations = g_list_append (locations,
+                                                   soup_uri_to_string (uri,
+                                                                       FALSE));
+                        soup_uri_free (uri);
+                } else {
+                        locations = g_list_append (locations, g_strdup (header));
+                }
+        }
 
         header = soup_message_headers_get_one (headers, "AL");
         if (header) {


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