cups: use modern HTTP connection helpers when available
Detect httpConnect2 and httpReconnect2 at configure time. Preserve blocking, encryption, timeout and reconnect semantics while retaining the legacy CUPS APIs as compile-time fallbacks.
This commit is contained in:
parent
4c3c551359
commit
20ec5e6a6a
3 changed files with 80 additions and 11 deletions
|
|
@ -1594,6 +1594,7 @@ else
|
|||
gtk_save_libs="$LIBS"
|
||||
LIBS="$CUPS_LIBS"
|
||||
AC_CHECK_FUNCS(httpGetAuthString)
|
||||
AC_CHECK_FUNCS(httpConnect2 httpReconnect2)
|
||||
LIBS="$gtk_save_libs"
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@
|
|||
|
||||
typedef void (*GtkCupsRequestStateFunc) (GtkCupsRequest *request);
|
||||
|
||||
static http_t *gtk_cups_http_connect (const char *host,
|
||||
int port,
|
||||
http_encryption_t encryption);
|
||||
static int gtk_cups_http_reconnect (http_t *http);
|
||||
|
||||
static void _connect (GtkCupsRequest *request);
|
||||
static void _post_send (GtkCupsRequest *request);
|
||||
static void _post_write_request (GtkCupsRequest *request);
|
||||
|
|
@ -171,7 +176,7 @@ gtk_cups_request_new_with_username (http_t *connection,
|
|||
else
|
||||
{
|
||||
request->http = NULL;
|
||||
request->http = httpConnectEncrypt (request->server,
|
||||
request->http = gtk_cups_http_connect (request->server,
|
||||
ippPort (),
|
||||
cupsEncryption ());
|
||||
|
||||
|
|
@ -681,6 +686,29 @@ gtk_cups_request_set_ipp_version (GtkCupsRequest *request,
|
|||
ippSetVersion (request->ipp_request, major, minor);
|
||||
}
|
||||
|
||||
|
||||
static http_t *
|
||||
gtk_cups_http_connect (const char *host,
|
||||
int port,
|
||||
http_encryption_t encryption)
|
||||
{
|
||||
#ifdef HAVE_HTTPCONNECT2
|
||||
return httpConnect2 (host, port, NULL, AF_UNSPEC, encryption, 1, 30000, NULL);
|
||||
#else
|
||||
return httpConnectEncrypt (host, port, encryption);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
gtk_cups_http_reconnect (http_t *http)
|
||||
{
|
||||
#ifdef HAVE_HTTPRECONNECT2
|
||||
return httpReconnect2 (http, 30000, NULL);
|
||||
#else
|
||||
return httpReconnect (http);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
_connect (GtkCupsRequest *request)
|
||||
{
|
||||
|
|
@ -689,7 +717,7 @@ _connect (GtkCupsRequest *request)
|
|||
|
||||
if (request->http == NULL)
|
||||
{
|
||||
request->http = httpConnectEncrypt (request->server,
|
||||
request->http = gtk_cups_http_connect (request->server,
|
||||
ippPort (),
|
||||
cupsEncryption ());
|
||||
|
||||
|
|
@ -744,7 +772,7 @@ _post_send (GtkCupsRequest *request)
|
|||
|
||||
if (httpPost (request->http, request->resource))
|
||||
{
|
||||
if (httpReconnect (request->http))
|
||||
if (gtk_cups_http_reconnect (request->http))
|
||||
{
|
||||
request->state = GTK_CUPS_POST_DONE;
|
||||
request->poll_state = GTK_CUPS_HTTP_IDLE;
|
||||
|
|
@ -1046,7 +1074,7 @@ _post_check (GtkCupsRequest *request)
|
|||
}
|
||||
|
||||
if (auth_result ||
|
||||
httpReconnect (request->http))
|
||||
gtk_cups_http_reconnect (request->http))
|
||||
{
|
||||
/* if the password has been used, reset password_state
|
||||
* so that we ask for a new one next time around
|
||||
|
|
@ -1105,7 +1133,7 @@ _post_check (GtkCupsRequest *request)
|
|||
request->state = GTK_CUPS_POST_CONNECT;
|
||||
|
||||
/* Reconnect... */
|
||||
httpReconnect (request->http);
|
||||
gtk_cups_http_reconnect (request->http);
|
||||
|
||||
/* Upgrade with encryption... */
|
||||
httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
|
||||
|
|
@ -1232,7 +1260,7 @@ _get_send (GtkCupsRequest *request)
|
|||
|
||||
if (httpGet (request->http, request->resource))
|
||||
{
|
||||
if (httpReconnect (request->http))
|
||||
if (gtk_cups_http_reconnect (request->http))
|
||||
{
|
||||
request->state = GTK_CUPS_GET_DONE;
|
||||
request->poll_state = GTK_CUPS_HTTP_IDLE;
|
||||
|
|
@ -1341,7 +1369,7 @@ _get_check (GtkCupsRequest *request)
|
|||
}
|
||||
|
||||
if (auth_result ||
|
||||
httpReconnect (request->http))
|
||||
gtk_cups_http_reconnect (request->http))
|
||||
{
|
||||
/* if the password has been used, reset password_state
|
||||
* so that we ask for a new one next time around
|
||||
|
|
@ -1373,7 +1401,7 @@ _get_check (GtkCupsRequest *request)
|
|||
request->state = GTK_CUPS_GET_CONNECT;
|
||||
|
||||
/* Reconnect... */
|
||||
httpReconnect (request->http);
|
||||
gtk_cups_http_reconnect (request->http);
|
||||
|
||||
/* Upgrade with encryption... */
|
||||
httpEncryption (request->http, HTTP_ENCRYPT_REQUIRED);
|
||||
|
|
|
|||
|
|
@ -489,6 +489,44 @@ cups_free_print_stream_data (CupsPrintStreamData *data)
|
|||
g_free (data);
|
||||
}
|
||||
|
||||
|
||||
static http_t *
|
||||
gtk_cups_backend_http_connect (const char *host,
|
||||
int port)
|
||||
{
|
||||
#ifdef HAVE_HTTPCONNECT2
|
||||
return httpConnect2 (host,
|
||||
port,
|
||||
NULL,
|
||||
AF_UNSPEC,
|
||||
HTTP_ENCRYPT_IF_REQUESTED,
|
||||
1,
|
||||
30000,
|
||||
NULL);
|
||||
#else
|
||||
return httpConnect (host, port);
|
||||
#endif
|
||||
}
|
||||
|
||||
static http_t *
|
||||
gtk_cups_backend_http_connect_encrypt (const char *host,
|
||||
int port,
|
||||
http_encryption_t encryption)
|
||||
{
|
||||
#ifdef HAVE_HTTPCONNECT2
|
||||
return httpConnect2 (host,
|
||||
port,
|
||||
NULL,
|
||||
AF_UNSPEC,
|
||||
encryption,
|
||||
1,
|
||||
30000,
|
||||
NULL);
|
||||
#else
|
||||
return httpConnectEncrypt (host, port, encryption);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
cups_print_cb (GtkPrintBackendCups *print_backend,
|
||||
GtkCupsResult *result,
|
||||
|
|
@ -636,7 +674,9 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
|
|||
{
|
||||
http_t *http;
|
||||
|
||||
http = httpConnect (cups_printer->hostname, cups_printer->port);
|
||||
http = gtk_cups_backend_http_connect (
|
||||
cups_printer->hostname,
|
||||
cups_printer->port);
|
||||
if (http)
|
||||
{
|
||||
request = gtk_cups_request_new_with_username (http,
|
||||
|
|
@ -2555,7 +2595,7 @@ cups_request_avahi_printer_info (const gchar *printer_uri,
|
|||
AvahiService *service;
|
||||
http_t *http;
|
||||
|
||||
http = httpConnect (host, port);
|
||||
http = gtk_cups_backend_http_connect (host, port);
|
||||
if (http)
|
||||
{
|
||||
service = (AvahiService *) g_new0 (AvahiService, 1);
|
||||
|
|
@ -3438,7 +3478,7 @@ cups_request_ppd (GtkPrinter *printer)
|
|||
}
|
||||
}
|
||||
|
||||
http = httpConnectEncrypt (cups_printer->hostname,
|
||||
http = gtk_cups_backend_http_connect_encrypt (cups_printer->hostname,
|
||||
cups_printer->port,
|
||||
cupsEncryption ());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue