[gnome-control-center/gnome-3-34] printers: Provide a scheme to address parser



commit 8f169336e681a4dc5e7f9ded5e5ac46aaa001157
Author: Marek Kasik <mkasik redhat com>
Date:   Tue Oct 8 18:04:30 2019 +0200

    printers: Provide a scheme to address parser
    
    Add a scheme to the address which we test for correctness
    by g_network_address_parse_uri(). It does not work without it.
    Use "none" scheme if user did not entered one.
    Use port number 0 if user did not specify any.
    
    Fixes #679

 panels/printers/pp-new-printer-dialog.c | 66 ++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 26 deletions(-)
---
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index 651c0d8f3..81a4cc1f6 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -1607,43 +1607,57 @@ search_address (const gchar        *text,
 
       if (text && text[0] != '\0')
         {
-          g_autoptr(GSocketConnectable) conn;
+          g_autoptr(GSocketConnectable) conn = NULL;
+          g_autofree gchar *test_uri = NULL;
+          g_autofree gchar *test_port = NULL;
           gchar *scheme = NULL;
           gchar *host = NULL;
           gint   port;
 
           parse_uri (text, &scheme, &host, &port);
 
-          conn = g_network_address_parse_uri (host, port, NULL);
-
-          if (host != NULL && conn != NULL)
+          if (host != NULL)
             {
-              THostSearchData *search_data;
+              if (port >= 0)
+                test_port = g_strdup_printf (":%d", port);
+              else
+                test_port = g_strdup ("");
 
-              search_data = g_new (THostSearchData, 1);
-              search_data->host_scheme = scheme;
-              search_data->host_name = host;
-              search_data->host_port = port;
-              search_data->dialog = self;
+              test_uri = g_strdup_printf ("%s://%s%s",
+                                          scheme != NULL && scheme[0] != '\0' ? scheme : "none",
+                                          host,
+                                          test_port);
 
-              if (self->host_search_timeout_id != 0)
+              conn = g_network_address_parse_uri (test_uri, 0, NULL);
+              if (conn != NULL)
                 {
-                  g_source_remove (self->host_search_timeout_id);
-                  self->host_search_timeout_id = 0;
-                }
+                  THostSearchData *search_data;
 
-              if (delay_search)
-                {
-                  self->host_search_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
-                                                                     HOST_SEARCH_DELAY,
-                                                                     (GSourceFunc) 
search_for_remote_printers,
-                                                                     search_data,
-                                                                     (GDestroyNotify) 
search_for_remote_printers_free);
-                }
-              else
-                {
-                  search_for_remote_printers (search_data);
-                  search_for_remote_printers_free (search_data);
+                  search_data = g_new (THostSearchData, 1);
+                  search_data->host_scheme = scheme;
+                  search_data->host_name = host;
+                  search_data->host_port = port;
+                  search_data->dialog = self;
+
+                  if (self->host_search_timeout_id != 0)
+                    {
+                      g_source_remove (self->host_search_timeout_id);
+                      self->host_search_timeout_id = 0;
+                    }
+
+                  if (delay_search)
+                    {
+                      self->host_search_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
+                                                                         HOST_SEARCH_DELAY,
+                                                                         (GSourceFunc) 
search_for_remote_printers,
+                                                                         search_data,
+                                                                         (GDestroyNotify) 
search_for_remote_printers_free);
+                    }
+                  else
+                    {
+                      search_for_remote_printers (search_data);
+                      search_for_remote_printers_free (search_data);
+                    }
                 }
             }
         }


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