Blame SOURCES/0013-chooser-filter-out-duplicate-hostnames.patch

2fc437
From d32365ddb729e94f7ebf650ef526f7f5319dfe4c Mon Sep 17 00:00:00 2001
2fc437
From: Ray Strode <rstrode@redhat.com>
2fc437
Date: Fri, 31 Mar 2017 15:40:21 -0400
2fc437
Subject: [PATCH 13/13] chooser: filter out duplicate hostnames
2fc437
2fc437
One host may report itself on multiple interfaces.
2fc437
GDM only supports based on hostname not interface,
2fc437
so that leads duplicate entries in the list.
2fc437
2fc437
This commit filters out the dupes.
2fc437
---
2fc437
 chooser/gdm-host-chooser-widget.c | 34 +++++++++++++++++++++++++++++++++-
2fc437
 1 file changed, 33 insertions(+), 1 deletion(-)
2fc437
2fc437
diff --git a/chooser/gdm-host-chooser-widget.c b/chooser/gdm-host-chooser-widget.c
2fc437
index f8aabf3e..e2507900 100644
2fc437
--- a/chooser/gdm-host-chooser-widget.c
2fc437
+++ b/chooser/gdm-host-chooser-widget.c
2fc437
@@ -92,70 +92,102 @@ static void     gdm_host_chooser_widget_finalize    (GObject                   *
2fc437
 
2fc437
 G_DEFINE_TYPE (GdmHostChooserWidget, gdm_host_chooser_widget, GTK_TYPE_VBOX)
2fc437
 
2fc437
 #define GDM_XDMCP_PROTOCOL_VERSION 1001
2fc437
 #define SCAN_TIMEOUT 30
2fc437
 #define PING_TIMEOUT 2
2fc437
 #define PING_TRIES 3
2fc437
 
2fc437
 enum {
2fc437
         CHOOSER_LIST_ICON_COLUMN = 0,
2fc437
         CHOOSER_LIST_LABEL_COLUMN,
2fc437
         CHOOSER_LIST_HOST_COLUMN
2fc437
 };
2fc437
 
2fc437
 static void
2fc437
 chooser_host_add (GdmHostChooserWidget *widget,
2fc437
                   GdmChooserHost       *host)
2fc437
 {
2fc437
         widget->priv->chooser_hosts = g_slist_prepend (widget->priv->chooser_hosts, host);
2fc437
 }
2fc437
 
2fc437
 #if 0
2fc437
 static void
2fc437
 chooser_host_remove (GdmHostChooserWidget *widget,
2fc437
                      GdmChooserHost       *host)
2fc437
 {
2fc437
         widget->priv->chooser_hosts = g_slist_remove (widget->priv->chooser_hosts, host);
2fc437
 }
2fc437
 #endif
2fc437
 
2fc437
+static gboolean
2fc437
+address_hostnames_equal (GdmAddress *address,
2fc437
+                         GdmAddress *other_address)
2fc437
+{
2fc437
+        char *hostname, *other_hostname;
2fc437
+        gboolean are_equal;
2fc437
+
2fc437
+        if (gdm_address_equal (address, other_address)) {
2fc437
+                return TRUE;
2fc437
+        }
2fc437
+
2fc437
+        if (!gdm_address_get_hostname (address, &hostname)) {
2fc437
+                gdm_address_get_numeric_info (address, &hostname, NULL);
2fc437
+        }
2fc437
+
2fc437
+        if (!gdm_address_get_hostname (other_address, &other_hostname)) {
2fc437
+                gdm_address_get_numeric_info (other_address, &other_hostname, NULL);
2fc437
+        }
2fc437
+
2fc437
+        are_equal = g_strcmp0 (hostname, other_hostname) == 0;
2fc437
+
2fc437
+        g_free (hostname);
2fc437
+        g_free (other_hostname);
2fc437
+
2fc437
+        return are_equal;
2fc437
+}
2fc437
+
2fc437
 static GdmChooserHost *
2fc437
 find_known_host (GdmHostChooserWidget *widget,
2fc437
                  GdmAddress           *address)
2fc437
 {
2fc437
         GSList         *li;
2fc437
         GdmChooserHost *host;
2fc437
 
2fc437
         for (li = widget->priv->chooser_hosts; li != NULL; li = li->next) {
2fc437
+                GdmAddress *other_address;
2fc437
+
2fc437
                 host = li->data;
2fc437
-                if (gdm_address_equal (gdm_chooser_host_get_address (host), address)) {
2fc437
+
2fc437
+                other_address = gdm_chooser_host_get_address (host);
2fc437
+                        
2fc437
+                if (address_hostnames_equal (address, other_address)) {
2fc437
                         goto out;
2fc437
                 }
2fc437
         }
2fc437
 
2fc437
         host = NULL;
2fc437
  out:
2fc437
 
2fc437
         return host;
2fc437
 }
2fc437
 
2fc437
 static void
2fc437
 browser_add_host (GdmHostChooserWidget *widget,
2fc437
                   GdmChooserHost       *host)
2fc437
 {
2fc437
         char         *hostname;
2fc437
         char         *name;
2fc437
         char         *desc;
2fc437
         char         *label;
2fc437
         GtkTreeModel *model;
2fc437
         GtkTreeIter   iter;
2fc437
         gboolean      res;
2fc437
 
2fc437
         GtkTreeSelection  *selection;
2fc437
 
2fc437
         g_assert (host != NULL);
2fc437
 
2fc437
         if (! gdm_chooser_host_get_willing (host)) {
2fc437
                 gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
2fc437
                 return;
2fc437
         }
2fc437
-- 
2fc437
2.12.0
2fc437