Blob Blame History Raw
From d32365ddb729e94f7ebf650ef526f7f5319dfe4c Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 31 Mar 2017 15:40:21 -0400
Subject: [PATCH 13/13] chooser: filter out duplicate hostnames

One host may report itself on multiple interfaces.
GDM only supports based on hostname not interface,
so that leads duplicate entries in the list.

This commit filters out the dupes.
---
 chooser/gdm-host-chooser-widget.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/chooser/gdm-host-chooser-widget.c b/chooser/gdm-host-chooser-widget.c
index f8aabf3e..e2507900 100644
--- a/chooser/gdm-host-chooser-widget.c
+++ b/chooser/gdm-host-chooser-widget.c
@@ -92,70 +92,102 @@ static void     gdm_host_chooser_widget_finalize    (GObject                   *
 
 G_DEFINE_TYPE (GdmHostChooserWidget, gdm_host_chooser_widget, GTK_TYPE_VBOX)
 
 #define GDM_XDMCP_PROTOCOL_VERSION 1001
 #define SCAN_TIMEOUT 30
 #define PING_TIMEOUT 2
 #define PING_TRIES 3
 
 enum {
         CHOOSER_LIST_ICON_COLUMN = 0,
         CHOOSER_LIST_LABEL_COLUMN,
         CHOOSER_LIST_HOST_COLUMN
 };
 
 static void
 chooser_host_add (GdmHostChooserWidget *widget,
                   GdmChooserHost       *host)
 {
         widget->priv->chooser_hosts = g_slist_prepend (widget->priv->chooser_hosts, host);
 }
 
 #if 0
 static void
 chooser_host_remove (GdmHostChooserWidget *widget,
                      GdmChooserHost       *host)
 {
         widget->priv->chooser_hosts = g_slist_remove (widget->priv->chooser_hosts, host);
 }
 #endif
 
+static gboolean
+address_hostnames_equal (GdmAddress *address,
+                         GdmAddress *other_address)
+{
+        char *hostname, *other_hostname;
+        gboolean are_equal;
+
+        if (gdm_address_equal (address, other_address)) {
+                return TRUE;
+        }
+
+        if (!gdm_address_get_hostname (address, &hostname)) {
+                gdm_address_get_numeric_info (address, &hostname, NULL);
+        }
+
+        if (!gdm_address_get_hostname (other_address, &other_hostname)) {
+                gdm_address_get_numeric_info (other_address, &other_hostname, NULL);
+        }
+
+        are_equal = g_strcmp0 (hostname, other_hostname) == 0;
+
+        g_free (hostname);
+        g_free (other_hostname);
+
+        return are_equal;
+}
+
 static GdmChooserHost *
 find_known_host (GdmHostChooserWidget *widget,
                  GdmAddress           *address)
 {
         GSList         *li;
         GdmChooserHost *host;
 
         for (li = widget->priv->chooser_hosts; li != NULL; li = li->next) {
+                GdmAddress *other_address;
+
                 host = li->data;
-                if (gdm_address_equal (gdm_chooser_host_get_address (host), address)) {
+
+                other_address = gdm_chooser_host_get_address (host);
+                        
+                if (address_hostnames_equal (address, other_address)) {
                         goto out;
                 }
         }
 
         host = NULL;
  out:
 
         return host;
 }
 
 static void
 browser_add_host (GdmHostChooserWidget *widget,
                   GdmChooserHost       *host)
 {
         char         *hostname;
         char         *name;
         char         *desc;
         char         *label;
         GtkTreeModel *model;
         GtkTreeIter   iter;
         gboolean      res;
 
         GtkTreeSelection  *selection;
 
         g_assert (host != NULL);
 
         if (! gdm_chooser_host_get_willing (host)) {
                 gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
                 return;
         }
-- 
2.12.0