[gvfs/wip/oholy/davs-sd-ipv6: 1/2] common: Add interface property for GVfsDnsSdResolver



commit 7dee1c7fc9cac31bd6fbf67e340a3420e74d473b
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Oct 10 17:26:12 2019 +0200

    common: Add interface property for GVfsDnsSdResolver
    
    GVfsDnsSdResolver doesn't store interface for the resolved service,
    however, we need this for link-local address support. Let's add the
    missing bits for it.

 common/gvfsdnssdresolver.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 common/gvfsdnssdresolver.h |  1 +
 2 files changed, 53 insertions(+)
---
diff --git a/common/gvfsdnssdresolver.c b/common/gvfsdnssdresolver.c
index 8782f5fc..7db7ef5f 100644
--- a/common/gvfsdnssdresolver.c
+++ b/common/gvfsdnssdresolver.c
@@ -37,6 +37,8 @@
 #include <avahi-glib/glib-watch.h>
 #include <avahi-glib/glib-malloc.h>
 
+#include <net/if.h>
+
 #include "gvfsdnssdutils.h"
 #include "gvfsdnssdresolver.h"
 
@@ -52,6 +54,7 @@ enum
 
   PROP_IS_RESOLVED,
   PROP_ADDRESS,
+  PROP_INTERFACE,
   PROP_PORT,
   PROP_TXT_RECORDS,
 };
@@ -77,6 +80,7 @@ struct _GVfsDnsSdResolver
 
   gboolean is_resolved;
   char *address;
+  gchar *interface;
   guint port;
   char **txt_records;
 
@@ -293,6 +297,10 @@ g_vfs_dns_sd_resolver_get_property (GObject    *object,
       g_value_set_string (value, resolver->address);
       break;
 
+    case PROP_INTERFACE:
+      g_value_set_string (value, resolver->interface);
+      break;
+
     case PROP_PORT:
       g_value_set_uint (value, resolver->port);
       break;
@@ -365,6 +373,7 @@ g_vfs_dns_sd_resolver_finalize (GObject *object)
   g_strfreev (resolver->required_txt_keys_broken_out);
 
   g_free (resolver->address);
+  g_free (resolver->interface);
   g_strfreev (resolver->txt_records);
 
   if (resolver->avahi_resolver != NULL)
@@ -633,6 +642,22 @@ g_vfs_dns_sd_resolver_class_init (GVfsDnsSdResolverClass *klass)
                                                         G_PARAM_STATIC_BLURB |
                                                         G_PARAM_STATIC_NICK));
 
+  /**
+   * GVfsDnsSdResolver:interface:
+   *
+   * The resolved interface.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_INTERFACE,
+                                   g_param_spec_string ("interface",
+                                                        "Interface",
+                                                        "Interface",
+                                                        NULL,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_STATIC_NICK));
+
   /**
    * GVfsDnsSdResolver:port:
    *
@@ -722,6 +747,13 @@ g_vfs_dns_sd_resolver_get_address (GVfsDnsSdResolver *resolver)
   return g_strdup (resolver->address);
 }
 
+gchar *
+g_vfs_dns_sd_resolver_get_interface (GVfsDnsSdResolver *resolver)
+{
+  g_return_val_if_fail (G_VFS_IS_DNS_SD_RESOLVER (resolver), NULL);
+  return g_strdup (resolver->interface);
+}
+
 guint
 g_vfs_dns_sd_resolver_get_port (GVfsDnsSdResolver *resolver)
 {
@@ -883,10 +915,12 @@ set_avahi_data (GVfsDnsSdResolver    *resolver,
                 const char           *host_name,
                 AvahiProtocol         protocol,
                 const AvahiAddress   *a,
+                AvahiIfIndex          interface,
                 uint16_t              port,
                 AvahiStringList      *txt)
 {
   char *address;
+  gchar ifname[IF_NAMESIZE] = {0};
   gboolean changed;
   AvahiStringList *l;
   GPtrArray *p;
@@ -925,6 +959,15 @@ set_avahi_data (GVfsDnsSdResolver    *resolver,
 
   g_free (address);
 
+  if_indextoname (interface, ifname);
+  if (safe_strcmp (resolver->interface, ifname) != 0)
+    {
+      g_free (resolver->interface);
+      resolver->interface = g_strdup (ifname);
+      g_object_notify (G_OBJECT (resolver), "interface");
+      changed = TRUE;
+    }
+
   if (resolver->port != port)
     {
       resolver->port = port;
@@ -987,6 +1030,14 @@ clear_avahi_data (GVfsDnsSdResolver *resolver)
       changed = TRUE;
     }
 
+  if (resolver->interface != NULL)
+    {
+      g_free (resolver->interface);
+      resolver->interface = NULL;
+      g_object_notify (G_OBJECT (resolver), "interface");
+      changed = TRUE;
+    }
+
   if (resolver->port != 0)
     {
       resolver->port = 0;
@@ -1029,6 +1080,7 @@ service_resolver_cb (AvahiServiceResolver   *avahi_resolver,
                       host_name,
                       protocol,
                       a,
+                      interface,
                       port,
                       txt);
       break;
diff --git a/common/gvfsdnssdresolver.h b/common/gvfsdnssdresolver.h
index 425a4603..00a8976c 100644
--- a/common/gvfsdnssdresolver.h
+++ b/common/gvfsdnssdresolver.h
@@ -70,6 +70,7 @@ gboolean             g_vfs_dns_sd_resolver_resolve_sync           (GVfsDnsSdReso
 
 gboolean             g_vfs_dns_sd_resolver_is_resolved            (GVfsDnsSdResolver  *resolver);
 gchar               *g_vfs_dns_sd_resolver_get_address            (GVfsDnsSdResolver  *resolver);
+gchar               *g_vfs_dns_sd_resolver_get_interface          (GVfsDnsSdResolver  *resolver);
 guint                g_vfs_dns_sd_resolver_get_port               (GVfsDnsSdResolver  *resolver);
 gchar              **g_vfs_dns_sd_resolver_get_txt_records        (GVfsDnsSdResolver  *resolver);
 gchar               *g_vfs_dns_sd_resolver_lookup_txt_record      (GVfsDnsSdResolver  *resolver,


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