summaryrefslogtreecommitdiff
path: root/modules/printbackends/gtkprintbackendcups.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/printbackends/gtkprintbackendcups.c')
-rw-r--r--modules/printbackends/gtkprintbackendcups.c209
1 files changed, 27 insertions, 182 deletions
diff --git a/modules/printbackends/gtkprintbackendcups.c b/modules/printbackends/gtkprintbackendcups.c
index 48b4eb8461..68396c46c9 100644
--- a/modules/printbackends/gtkprintbackendcups.c
+++ b/modules/printbackends/gtkprintbackendcups.c
@@ -24,13 +24,12 @@
#include <sys/stat.h>
#include <stdlib.h>
#include <time.h>
+
/* Cups 1.6 deprecates ppdFindAttr(), ppdFindCustomOption(),
* ppdFirstCustomParam(), and ppdNextCustomParam() among others. This
* turns off the warning so that it will compile.
*/
-#ifdef HAVE_CUPS_API_1_6
-# define _PPD_DEPRECATED
-#endif
+#define _PPD_DEPRECATED
#include <cups/cups.h>
#include <cups/language.h>
@@ -71,7 +70,6 @@ typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
#define _CUPS_MAX_ATTEMPTS 10
#define _CUPS_MAX_CHUNK_SIZE 8192
-#ifdef HAVE_CUPS_API_1_6
#define AVAHI_IF_UNSPEC -1
#define AVAHI_PROTO_INET 0
#define AVAHI_PROTO_INET6 1
@@ -81,7 +79,6 @@ typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
#define AVAHI_SERVER_IFACE "org.freedesktop.Avahi.Server"
#define AVAHI_SERVICE_BROWSER_IFACE "org.freedesktop.Avahi.ServiceBrowser"
#define AVAHI_SERVICE_RESOLVER_IFACE "org.freedesktop.Avahi.ServiceResolver"
-#endif
/* define this to see warnings about ignored ppd options */
#undef PRINT_IGNORED_OPTIONS
@@ -143,14 +140,14 @@ struct _GtkPrintBackendCups
#ifdef HAVE_COLORD
CdClient *colord_client;
#endif
-#ifdef HAVE_CUPS_API_1_6
+
GDBusConnection *dbus_connection;
- gchar *avahi_default_printer;
- guint avahi_service_browser_subscription_id;
- guint avahi_service_browser_subscription_ids[2];
- gchar *avahi_service_browser_paths[2];
- GCancellable *avahi_cancellable;
-#endif
+ char *avahi_default_printer;
+ guint avahi_service_browser_subscription_id;
+ guint avahi_service_browser_subscription_ids[2];
+ char *avahi_service_browser_paths[2];
+ GCancellable *avahi_cancellable;
+
gboolean secrets_service_available;
guint secrets_service_watch_id;
GCancellable *secrets_service_cancellable;
@@ -228,9 +225,7 @@ static gboolean is_address_local (const gchar
static gboolean request_auth_info (gpointer data);
static void lookup_auth_info (gpointer data);
-#ifdef HAVE_CUPS_API_1_6
static void avahi_request_printer_list (GtkPrintBackendCups *cups_backend);
-#endif
static void secrets_service_appeared_cb (GDBusConnection *connection,
const gchar *name,
@@ -272,51 +267,6 @@ g_io_module_query (void)
return g_strdupv (eps);
}
-/* CUPS 1.6 Getter/Setter Functions CUPS 1.6 makes private most of the
- * IPP structures and enforces access via new getter functions, which
- * are unfortunately not available in earlier versions. We define
- * below those getter functions as macros for use when building
- * against earlier CUPS versions.
- */
-#ifndef HAVE_CUPS_API_1_6
-#define ippGetOperation(ipp_request) ipp_request->request.op.operation_id
-#define ippGet:Integer(attr, index) attr->values[index].integer
-#define ippGetBoolean(attr, index) attr->values[index].boolean
-#define ippGetString(attr, index, foo) attr->values[index].string.text
-#define ippGetValueTag(attr) attr->value_tag
-#define ippGetName(attr) attr->name
-#define ippGetCount(attr) attr->num_values
-#define ippGetGroupTag(attr) attr->group_tag
-#define ippGetCollection(attr, index) attr->values[index].collection
-
-static int
-ippGetRange (ipp_attribute_t *attr,
- int element,
- int *upper)
-{
- *upper = attr->values[element].range.upper;
- return (attr->values[element].range.lower);
-}
-
-static ipp_attribute_t *
-ippFirstAttribute (ipp_t *ipp)
-{
- if (!ipp)
- return (NULL);
-
- return (ipp->current = ipp->attrs);
-}
-
-static ipp_attribute_t *
-ippNextAttribute (ipp_t *ipp)
-{
- if (!ipp || !ipp->current)
- return (NULL);
-
- return (ipp->current = ipp->current->next);
-}
-#endif
-
/*
* GtkPrintBackendCups
*/
@@ -737,18 +687,13 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
cups_printer = GTK_PRINTER_CUPS (gtk_print_job_get_printer (job));
settings = gtk_print_job_get_settings (job);
-#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,
@@ -787,7 +732,6 @@ gtk_print_backend_cups_print_stream (GtkPrintBackend *print_backend,
}
}
else
-#endif
{
request = gtk_cups_request_new_with_username (NULL,
GTK_CUPS_POST,
@@ -897,9 +841,7 @@ void overwrite_and_free (gpointer data)
static void
gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
{
-#ifdef HAVE_CUPS_API_1_6
- gint i;
-#endif
+ int i;
backend_cups->list_printers_poll = FALSE;
backend_cups->got_default_printer = FALSE;
@@ -920,7 +862,6 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
backend_cups->colord_client = cd_client_new ();
#endif
-#ifdef HAVE_CUPS_API_1_6
backend_cups->dbus_connection = NULL;
backend_cups->avahi_default_printer = NULL;
backend_cups->avahi_service_browser_subscription_id = 0;
@@ -929,7 +870,6 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
backend_cups->avahi_service_browser_paths[i] = NULL;
backend_cups->avahi_service_browser_subscription_ids[i] = 0;
}
-#endif
cups_get_local_default_printer (backend_cups);
@@ -965,11 +905,9 @@ gtk_print_backend_cups_finalize (GObject *object)
g_object_unref (backend_cups->colord_client);
#endif
-#ifdef HAVE_CUPS_API_1_6
g_clear_object (&backend_cups->avahi_cancellable);
g_clear_pointer (&backend_cups->avahi_default_printer, g_free);
g_clear_object (&backend_cups->dbus_connection);
-#endif
g_clear_object (&backend_cups->secrets_service_cancellable);
if (backend_cups->secrets_service_watch_id != 0)
@@ -984,9 +922,7 @@ static void
gtk_print_backend_cups_dispose (GObject *object)
{
GtkPrintBackendCups *backend_cups;
-#ifdef HAVE_CUPS_API_1_6
- gint i;
-#endif
+ int i;
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: %s\n", G_STRFUNC));
@@ -1002,7 +938,6 @@ gtk_print_backend_cups_dispose (GObject *object)
g_source_remove (backend_cups->default_printer_poll);
backend_cups->default_printer_poll = 0;
-#ifdef HAVE_CUPS_API_1_6
g_cancellable_cancel (backend_cups->avahi_cancellable);
for (i = 0; i < 2; i++)
@@ -1038,7 +973,6 @@ gtk_print_backend_cups_dispose (GObject *object)
backend_cups->avahi_service_browser_subscription_id);
backend_cups->avahi_service_browser_subscription_id = 0;
}
-#endif
backend_parent_class->dispose (object);
}
@@ -1792,18 +1726,8 @@ cups_request_job_info_cb (GtkPrintBackendCups *print_backend,
state = 0;
-#ifdef HAVE_CUPS_API_1_6
attr = ippFindAttribute (response, "job-state", IPP_TAG_ENUM);
state = ippGetInteger (attr, 0);
-#else
- for (attr = response->attrs; attr != NULL; attr = attr->next)
- {
- if (!attr->name)
- continue;
-
- _CUPS_MAP_ATTR_INT (attr, state, "job-state");
- }
-#endif
done = FALSE;
switch (state)
@@ -2039,9 +1963,7 @@ typedef struct
gboolean default_printer;
gboolean got_printer_type;
gboolean remote_printer;
-#ifdef HAVE_CUPS_API_1_6
gboolean avahi_printer;
-#endif
gchar **auth_info_required;
gint default_number_up;
guchar ipp_version_major;
@@ -2472,13 +2394,11 @@ cups_create_printer (GtkPrintBackendCups *cups_backend,
char *cups_server; /* CUPS server */
#ifdef HAVE_COLORD
-#ifdef HAVE_CUPS_API_1_6
if (info->avahi_printer)
cups_printer = gtk_printer_cups_new (info->printer_name,
backend,
NULL);
else
-#endif
cups_printer = gtk_printer_cups_new (info->printer_name,
backend,
cups_backend->colord_client);
@@ -2554,9 +2474,7 @@ cups_create_printer (GtkPrintBackendCups *cups_backend,
strcmp (cups_backend->default_printer, gtk_printer_get_name (printer)) == 0)
gtk_printer_set_is_default (printer, TRUE);
-#ifdef HAVE_CUPS_API_1_6
cups_printer->avahi_browsed = info->avahi_printer;
-#endif
gtk_print_backend_add_printer (backend, printer);
return printer;
@@ -2735,7 +2653,6 @@ set_default_printer (GtkPrintBackendCups *cups_backend,
}
}
-#ifdef HAVE_CUPS_API_1_6
static void
cups_request_printer_info_cb (GtkPrintBackendCups *cups_backend,
GtkCupsResult *result,
@@ -2858,11 +2775,7 @@ 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,
@@ -2930,9 +2843,7 @@ find_printer_by_uuid (GtkPrintBackendCups *backend,
printer_uuid += 5;
printer_uuid = g_strndup (printer_uuid, 36);
-#if GLIB_CHECK_VERSION(2, 52, 0)
if (g_uuid_string_is_valid (printer_uuid))
-#endif
{
if (g_strcmp0 (printer_uuid, UUID) == 0)
{
@@ -3505,7 +3416,6 @@ avahi_request_printer_list (GtkPrintBackendCups *cups_backend)
cups_backend->avahi_cancellable = g_cancellable_new ();
g_bus_get (G_BUS_TYPE_SYSTEM, cups_backend->avahi_cancellable, avahi_create_browsers, cups_backend);
}
-#endif
static void
cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
@@ -3554,7 +3464,6 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
removed_printer_checklist = gtk_print_backend_get_printer_list (backend);
response = gtk_cups_result_get_response (result);
-#ifdef HAVE_CUPS_API_1_6
for (attr = ippFirstAttribute (response); attr != NULL;
attr = ippNextAttribute (response))
{
@@ -3570,42 +3479,21 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
if (attr == NULL)
break;
- while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
- {
- cups_printer_handle_attribute (cups_backend, attr, info);
- attr = ippNextAttribute (response);
- }
-#else
- for (attr = response->attrs; attr != NULL; attr = attr->next)
- {
- GtkPrinter *printer;
- gboolean status_changed = FALSE;
- GList *node;
- PrinterSetupInfo *info = g_slice_new0 (PrinterSetupInfo);
- info->default_number_up = 1;
- /* Skip leading attributes until we hit a printer...
- */
- while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
- attr = attr->next;
-
- if (attr == NULL)
- break;
while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
- {
- cups_printer_handle_attribute (cups_backend, attr, info);
- attr = attr->next;
- }
-#endif
+ {
+ cups_printer_handle_attribute (cups_backend, attr, info);
+ attr = ippNextAttribute (response);
+ }
if (info->printer_name == NULL ||
(info->printer_uri == NULL && info->member_uris == NULL))
- {
- if (attr == NULL)
- break;
- else
- continue;
- }
+ {
+ if (attr == NULL)
+ break;
+ else
+ continue;
+ }
if (info->got_printer_type)
{
@@ -3703,9 +3591,7 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
{
for (iter = removed_printer_checklist; iter; iter = iter->next)
{
-#ifdef HAVE_CUPS_API_1_6
if (!GTK_PRINTER_CUPS (iter->data)->avahi_browsed)
-#endif
{
mark_printer_inactive (GTK_PRINTER (iter->data), backend);
list_has_changed = TRUE;
@@ -3727,12 +3613,8 @@ done:
g_free (remote_default_printer);
}
-#ifdef HAVE_CUPS_API_1_6
if (!cups_backend->got_default_printer && cups_backend->avahi_default_printer != NULL)
- {
- set_default_printer (cups_backend, cups_backend->avahi_default_printer);
- }
-#endif
+ set_default_printer (cups_backend, cups_backend->avahi_default_printer);
}
static void
@@ -3821,9 +3703,7 @@ cups_get_printer_list (GtkPrintBackend *backend)
g_source_set_name_by_id (cups_backend->list_printers_poll, "[gtk] cups_request_printer_list");
}
-#ifdef HAVE_CUPS_API_1_6
avahi_request_printer_list (cups_backend);
-#endif
}
}
@@ -3859,26 +3739,6 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
GTK_PRINTER_CUPS (printer)->reading_ppd = FALSE;
print_backend->reading_ppds--;
-#ifndef HAVE_CUPS_API_1_6
- if (gtk_cups_result_is_error (result))
- {
- gboolean success = FALSE;
-
- /* If we get a 404 then it is just a raw printer without a ppd
- and not an error. */
- if ((gtk_cups_result_get_error_type (result) == GTK_CUPS_ERROR_HTTP) &&
- (gtk_cups_result_get_error_status (result) == HTTP_NOT_FOUND))
- {
- gtk_printer_set_has_details (printer, TRUE);
- success = TRUE;
- }
-
- g_signal_emit_by_name (printer, "details-acquired", success);
-
- return;
- }
-#endif
-
if (!gtk_cups_result_is_error (result))
{
/* let ppdOpenFd take over the ownership of the open file */
@@ -3888,7 +3748,6 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
ppdMarkDefaults (data->printer->ppd_file);
}
-#ifdef HAVE_CUPS_API_1_6
fstat (g_io_channel_unix_get_fd (data->ppd_io), &data_info);
/*
* Standalone Avahi printers and raw printers don't have PPD files or have
@@ -3908,7 +3767,6 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
return;
}
-#endif
gtk_printer_set_has_details (printer, TRUE);
g_signal_emit_by_name (printer, "details-acquired", TRUE);
@@ -3934,11 +3792,7 @@ cups_request_ppd (GtkPrinter *printer)
GTK_NOTE (PRINTING,
g_print ("CUPS Backend: %s\n", G_STRFUNC));
- if (cups_printer->remote
-#ifdef HAVE_CUPS_API_1_6
- && !cups_printer->avahi_browsed
-#endif
- )
+ if (cups_printer->remote && !cups_printer->avahi_browsed)
{
GtkCupsConnectionState state;
@@ -3972,16 +3826,10 @@ 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);
@@ -4285,13 +4133,14 @@ cups_request_default_printer_cb (GtkPrintBackendCups *print_backend,
response = gtk_cups_result_get_response (result);
if ((attr = ippFindAttribute (response, "printer-name", IPP_TAG_NAME)) != NULL)
- print_backend->default_printer = g_strdup (ippGetString (attr, 0, NULL));
+ print_backend->default_printer = g_strdup (ippGetString (attr, 0, NULL));
print_backend->got_default_printer = TRUE;
if (print_backend->default_printer != NULL)
{
- printer = gtk_print_backend_find_printer (GTK_PRINT_BACKEND (print_backend), print_backend->default_printer);
+ printer = gtk_print_backend_find_printer (GTK_PRINT_BACKEND (print_backend),
+ print_backend->default_printer);
if (printer != NULL)
{
gtk_printer_set_is_default (printer, TRUE);
@@ -4344,11 +4193,7 @@ cups_printer_request_details (GtkPrinter *printer)
if (!cups_printer->reading_ppd &&
gtk_printer_cups_get_ppd (cups_printer) == NULL)
{
- if (cups_printer->remote
-#ifdef HAVE_CUPS_API_1_6
- && !cups_printer->avahi_browsed
-#endif
- )
+ if (cups_printer->remote && !cups_printer->avahi_browsed)
{
if (cups_printer->get_remote_ppd_poll == 0)
{