[gnome-control-center] printers: Use CUPS httpConnect2() if available



commit 389ee0dfe5f8002cd266b9f53ee03015ae08821b
Author: Philip Chimento <philip endlessm com>
Date:   Fri Sep 13 18:26:54 2019 -0700

    printers: Use CUPS httpConnect2() if available
    
    In CUPS 1.7 httpConnect() and httpConnectEncrypt() were deprecated and
    replaced with httpConnect2(). This checks if httpConnect2() is available
    and if so, replaces the uses of the deprecated functions.
    
    In the CUPS source code, httpConnect() and httpConnectEncrypt() are now
    wrappers around httpConnect2(), so we make sure to use the same
    arguments as in the CUPS source code so the two code paths are sure to
    be identical:
    https://github.com/apple/cups/blob/2c030c7a06e0c2b8227c7e85f5c58dfb339731d0/cups/http.c#L412
    https://github.com/apple/cups/blob/2c030c7a06e0c2b8227c7e85f5c58dfb339731d0/cups/http.c#L477

 meson.build                |  4 ++++
 panels/printers/pp-cups.c  |  7 +++++++
 panels/printers/pp-host.c  |  7 +++++++
 panels/printers/pp-utils.c | 14 ++++++++++++--
 4 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/meson.build b/meson.build
index 5c879a4a2..7d2db5c94 100644
--- a/meson.build
+++ b/meson.build
@@ -165,6 +165,10 @@ foreach header: check_headers
   assert(cc.has_header(header[1], args: cups_cflags), 'CUPS headers not found: ' + header[1])
 endforeach
 
+config_h.set10('HAVE_CUPS_HTTPCONNECT2',
+               cc.has_function('httpConnect2', dependencies: cups_dep),
+               description: 'Define if httpConnect2() is available in CUPS')
+
 # Optional dependency for the user accounts panel
 enable_cheese = get_option('cheese')
 if enable_cheese
diff --git a/panels/printers/pp-cups.c b/panels/printers/pp-cups.c
index 32525f860..708690834 100644
--- a/panels/printers/pp-cups.c
+++ b/panels/printers/pp-cups.c
@@ -18,6 +18,8 @@
  * Author: Marek Kasik <mkasik redhat com>
  */
 
+#include "config.h"
+
 #include "pp-cups.h"
 
 #if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
@@ -120,7 +122,12 @@ connection_test_thread (GTask        *task,
 {
   http_t *http;
 
+#ifdef HAVE_CUPS_HTTPCONNECT2
+  http = httpConnect2 (cupsServer (), ippPort (), NULL, AF_UNSPEC,
+                       cupsEncryption (), 1, 30000, NULL);
+#else
   http = httpConnectEncrypt (cupsServer (), ippPort (), cupsEncryption ());
+#endif
   httpClose (http);
 
   if (g_task_set_return_on_cancel (task, FALSE))
diff --git a/panels/printers/pp-host.c b/panels/printers/pp-host.c
index f53ba217e..37c700918 100644
--- a/panels/printers/pp-host.c
+++ b/panels/printers/pp-host.c
@@ -18,6 +18,8 @@
  * Author: Marek Kasik <mkasik redhat com>
  */
 
+#include "config.h"
+
 #include "pp-host.h"
 
 #include <glib/gi18n.h>
@@ -356,7 +358,12 @@ _pp_host_get_remote_cups_devices_thread (GTask        *task,
     port = priv->port;
 
   /* Connect to remote CUPS server and get its devices */
+#ifdef HAVE_CUPS_HTTPCONNECT2
+  http = httpConnect2 (priv->hostname, port, NULL, AF_UNSPEC,
+                       HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+#else
   http = httpConnect (priv->hostname, port);
+#endif
   if (http)
     {
       num_of_devices = cupsGetDests2 (http, &dests);
diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c
index fbeb3c67e..5320903e6 100644
--- a/panels/printers/pp-utils.c
+++ b/panels/printers/pp-utils.c
@@ -367,8 +367,13 @@ printer_rename (const gchar *old_name,
   /*
    * Gather additional informations about the original printer
    */
-  if ((http = httpConnectEncrypt (cupsServer (), ippPort (),
-                                  cupsEncryption ())) != NULL)
+#ifdef HAVE_CUPS_HTTPCONNECT2
+  http = httpConnect2 (cupsServer (), ippPort (), NULL, AF_UNSPEC,
+                       cupsEncryption (), 1, 30000, NULL);
+#else
+  http = httpConnectEncrypt (cupsServer (), ippPort (), cupsEncryption ());
+#endif
+  if (http != NULL)
     {
       request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
       ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
@@ -3005,7 +3010,12 @@ printer_get_ppd_func (gpointer user_data)
     {
       http_t *http;
 
+#ifdef HAVE_CUPS_HTTPCONNECT2
+      http = httpConnect2 (data->host_name, data->port, NULL, AF_UNSPEC,
+                           HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+#else
       http = httpConnect (data->host_name, data->port);
+#endif
       if (http)
         {
           data->result = g_strdup (cupsGetPPD2 (http, data->printer_name));


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