cups: Use non-deprecated API
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 12 Apr 2019 17:00:02 +0000 (18:00 +0100)
committerMarek Kasik <mkasik@redhat.com>
Tue, 7 May 2019 16:30:47 +0000 (18:30 +0200)
The http* family of functions was deprecated after CUPS 1.7. We can
conditionally use it when built against a newer version of CUPS. The
additional parameters are taken directly from the fallback values
inside CUPS itself.

modules/printbackends/gtkcupsutils.c
modules/printbackends/gtkprintbackendcups.c
modules/printbackends/gtkprintercups.c

index 54239cad07bdff236f5142d7b7d5fdca3c661def..d2916f6110ffecf8234a67b08336d6908122e41f 100644 (file)
@@ -169,9 +169,16 @@ gtk_cups_request_new_with_username (http_t             *connection,
   else
     {
       request->http = NULL;
+#ifdef HAVE_CUPS_API_2_0
+      request->http = httpConnect2 (request->server, ippPort (),
+                                    NULL, AF_UNSPEC,
+                                    cupsEncryption (),
+                                    1, 30000, NULL);
+#else
       request->http = httpConnectEncrypt (request->server, 
                                           ippPort (), 
                                           cupsEncryption ());
+#endif
 
       if (request->http)
         httpBlocking (request->http, 0);
@@ -686,9 +693,16 @@ _connect (GtkCupsRequest *request)
 
   if (request->http == NULL)
     {
+#ifdef HAVE_CUPS_API_2_0
+      request->http = httpConnect2 (request->server, ippPort (),
+                                    NULL, AF_UNSPEC,
+                                    cupsEncryption (),
+                                    1, 30000, NULL);
+#else
       request->http = httpConnectEncrypt (request->server, 
                                           ippPort (), 
                                           cupsEncryption ());
+#endif
 
       if (request->http == NULL)
         request->attempts++;
@@ -741,7 +755,15 @@ _post_send (GtkCupsRequest *request)
 
   if (httpPost (request->http, request->resource))
     {
-      if (httpReconnect (request->http))
+      int res;
+
+#ifdef HAVE_CUPS_API_2_0
+      res = httpReconnect2 (request->http, 30000, NULL);
+#else
+      res = httpReconnect (request->http);
+#endif
+
+      if (res)
         {
           request->state = GTK_CUPS_POST_DONE;
           request->poll_state = GTK_CUPS_HTTP_IDLE;
@@ -1039,7 +1061,11 @@ _post_check (GtkCupsRequest *request)
         }
 
       if (auth_result ||
+#ifdef HAVE_CUPS_API_2_0
+          httpReconnect2 (request->http, 30000, NULL))
+#else
           httpReconnect (request->http))
+#endif
         {
           /* if the password has been used, reset password_state
            * so that we ask for a new one next time around
@@ -1098,7 +1124,11 @@ _post_check (GtkCupsRequest *request)
       request->state = GTK_CUPS_POST_CONNECT;
 
       /* Reconnect... */
+#ifdef HAVE_CUPS_API_2_0
+      httpReconnect2 (request->http, 30000, NULL);
+#else
       httpReconnect (request->http);
+#endif
 
       /* Upgrade with encryption... */
       httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
@@ -1226,7 +1256,14 @@ _get_send (GtkCupsRequest *request)
 
   if (httpGet (request->http, request->resource))
     {
-      if (httpReconnect (request->http))
+      int reconnect;
+
+#ifdef HAVE_CUPS_API_2_0
+      reconnect = httpReconnect2 (request->http, 30000, NULL);
+#else
+      reconnect = httpReconnect (request->http);
+#endif
+      if (reconnect)
         {
           request->state = GTK_CUPS_GET_DONE;
           request->poll_state = GTK_CUPS_HTTP_IDLE;
@@ -1335,7 +1372,11 @@ _get_check (GtkCupsRequest *request)
         }
 
       if (auth_result ||
+#ifdef HAVE_CUPS_API_2_0
+          httpReconnect2 (request->http, 30000, NULL))
+#else
           httpReconnect (request->http))
+#endif
         {
           /* if the password has been used, reset password_state
            * so that we ask for a new one next time around
@@ -1367,7 +1408,11 @@ _get_check (GtkCupsRequest *request)
       request->state = GTK_CUPS_GET_CONNECT;
 
       /* Reconnect... */
+#ifdef HAVE_CUPS_API_2_0
+      httpReconnect2 (request->http, 30000, NULL);
+#else
       httpReconnect (request->http);
+#endif
 
       /* Upgrade with encryption... */
       httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
index bc0d3eec0d368f4d913b073a5de53737046bca36..48b4eb84611926286138db7cebcc609f9ad61824 100644 (file)
@@ -740,7 +740,15 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend         *print_backend,
 #ifdef HAVE_CUPS_API_1_6
   if (cups_printer->avahi_browsed)
     {
+#ifdef HAVE_CUPS_API_2_0
+      http = httpConnect2 (cups_printer->hostname, cups_printer->port,
+                           NULL, AF_UNSPEC,
+                           HTTP_ENCRYPTION_IF_REQUESTED,
+                           1, 30000,
+                           NULL);
+#else
       http = httpConnect (cups_printer->hostname, cups_printer->port);
+#endif
       if (http)
         {
           request = gtk_cups_request_new_with_username (http,
@@ -2850,7 +2858,11 @@ cups_request_printer_info (const gchar         *printer_uri,
   GtkCupsRequest *request;
   http_t         *http;
 
+#ifdef HAVE_CUPS_API_2_0
+  http = httpConnect2 (host, port, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+#else
   http = httpConnect (host, port);
+#endif
   if (http)
     {
       request = gtk_cups_request_new_with_username (http,
@@ -3960,9 +3972,16 @@ cups_request_ppd (GtkPrinter *printer)
         }
     }
 
+#ifdef HAVE_CUPS_API_2_0
+  http = httpConnect2 (cups_printer->hostname, cups_printer->port,
+                       NULL, AF_UNSPEC,
+                       cupsEncryption (),
+                       1, 30000, NULL);
+#else
   http = httpConnectEncrypt (cups_printer->hostname,
                             cups_printer->port,
                             cupsEncryption ());
+#endif
 
   data = g_new0 (GetPPDData, 1);
 
index b97da6180500675eb1abb06ff6893e3720f031d4..9d260cb9c3860fe3aadef123461acc76bdba69c8 100644 (file)
@@ -184,9 +184,13 @@ gtk_printer_cups_finalize (GObject *object)
 
   g_strfreev (printer->covers);
 
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
   if (printer->ppd_file)
     ppdClose (printer->ppd_file);
 
+  G_GNUC_END_IGNORE_DEPRECATIONS
+
   g_free (printer->media_default);
   g_list_free_full (printer->media_supported, g_free);
   g_list_free_full (printer->media_size_supported, g_free);