cups: Use non-deprecated API

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.
This commit is contained in:
Emmanuele Bassi 2019-04-12 18:00:02 +01:00 committed by Marek Kasik
parent feddf5a694
commit ed31ea3773
3 changed files with 70 additions and 2 deletions

View File

@ -169,9 +169,16 @@ gtk_cups_request_new_with_username (http_t *connection,
else else
{ {
request->http = NULL; 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, request->http = httpConnectEncrypt (request->server,
ippPort (), ippPort (),
cupsEncryption ()); cupsEncryption ());
#endif
if (request->http) if (request->http)
httpBlocking (request->http, 0); httpBlocking (request->http, 0);
@ -686,9 +693,16 @@ _connect (GtkCupsRequest *request)
if (request->http == NULL) 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, request->http = httpConnectEncrypt (request->server,
ippPort (), ippPort (),
cupsEncryption ()); cupsEncryption ());
#endif
if (request->http == NULL) if (request->http == NULL)
request->attempts++; request->attempts++;
@ -741,7 +755,15 @@ _post_send (GtkCupsRequest *request)
if (httpPost (request->http, request->resource)) 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->state = GTK_CUPS_POST_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE; request->poll_state = GTK_CUPS_HTTP_IDLE;
@ -1039,7 +1061,11 @@ _post_check (GtkCupsRequest *request)
} }
if (auth_result || if (auth_result ||
#ifdef HAVE_CUPS_API_2_0
httpReconnect2 (request->http, 30000, NULL))
#else
httpReconnect (request->http)) httpReconnect (request->http))
#endif
{ {
/* if the password has been used, reset password_state /* if the password has been used, reset password_state
* so that we ask for a new one next time around * 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; request->state = GTK_CUPS_POST_CONNECT;
/* Reconnect... */ /* Reconnect... */
#ifdef HAVE_CUPS_API_2_0
httpReconnect2 (request->http, 30000, NULL);
#else
httpReconnect (request->http); httpReconnect (request->http);
#endif
/* Upgrade with encryption... */ /* Upgrade with encryption... */
httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED); httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
@ -1226,7 +1256,14 @@ _get_send (GtkCupsRequest *request)
if (httpGet (request->http, request->resource)) 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->state = GTK_CUPS_GET_DONE;
request->poll_state = GTK_CUPS_HTTP_IDLE; request->poll_state = GTK_CUPS_HTTP_IDLE;
@ -1335,7 +1372,11 @@ _get_check (GtkCupsRequest *request)
} }
if (auth_result || if (auth_result ||
#ifdef HAVE_CUPS_API_2_0
httpReconnect2 (request->http, 30000, NULL))
#else
httpReconnect (request->http)) httpReconnect (request->http))
#endif
{ {
/* if the password has been used, reset password_state /* if the password has been used, reset password_state
* so that we ask for a new one next time around * 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; request->state = GTK_CUPS_GET_CONNECT;
/* Reconnect... */ /* Reconnect... */
#ifdef HAVE_CUPS_API_2_0
httpReconnect2 (request->http, 30000, NULL);
#else
httpReconnect (request->http); httpReconnect (request->http);
#endif
/* Upgrade with encryption... */ /* Upgrade with encryption... */
httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED); httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);

View File

@ -740,7 +740,15 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
#ifdef HAVE_CUPS_API_1_6 #ifdef HAVE_CUPS_API_1_6
if (cups_printer->avahi_browsed) 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); http = httpConnect (cups_printer->hostname, cups_printer->port);
#endif
if (http) if (http)
{ {
request = gtk_cups_request_new_with_username (http, request = gtk_cups_request_new_with_username (http,
@ -2850,7 +2858,11 @@ cups_request_printer_info (const gchar *printer_uri,
GtkCupsRequest *request; GtkCupsRequest *request;
http_t *http; 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); http = httpConnect (host, port);
#endif
if (http) if (http)
{ {
request = gtk_cups_request_new_with_username (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, http = httpConnectEncrypt (cups_printer->hostname,
cups_printer->port, cups_printer->port,
cupsEncryption ()); cupsEncryption ());
#endif
data = g_new0 (GetPPDData, 1); data = g_new0 (GetPPDData, 1);

View File

@ -184,9 +184,13 @@ gtk_printer_cups_finalize (GObject *object)
g_strfreev (printer->covers); g_strfreev (printer->covers);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (printer->ppd_file) if (printer->ppd_file)
ppdClose (printer->ppd_file); ppdClose (printer->ppd_file);
G_GNUC_END_IGNORE_DEPRECATIONS
g_free (printer->media_default); g_free (printer->media_default);
g_list_free_full (printer->media_supported, g_free); g_list_free_full (printer->media_supported, g_free);
g_list_free_full (printer->media_size_supported, g_free); g_list_free_full (printer->media_size_supported, g_free);