From 3c35742d9cacda5a1e37dd1dfe8f579434a35b84 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Wed, 11 Jul 2012 17:25:09 +0200 Subject: [PATCH] Use CUPS-1.6 IPP API getter/setter functions. CUPS 1.6 makes various structures private and introduces these ippGet and ippSet functions for all of the fields in these structures. http://www.cups.org/str.php?L3928 We define our own accessors when building against CUPS < 1.6. [Alexandre Rostovtsev : backport to 3.2.x] --- panels/printers/cc-printers-panel.c | 20 +++- panels/printers/pp-new-printer-dialog.c | 10 ++- panels/printers/pp-utils.c | 159 ++++++++++++++++++------------ 3 files changed, 119 insertions(+), 70 deletions(-) diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c index 8ef9847..35751a6 100644 --- a/panels/printers/cc-printers-panel.c +++ b/panels/printers/cc-printers-panel.c @@ -59,6 +59,16 @@ G_DEFINE_DYNAMIC_TYPE (CcPrintersPanel, cc_printers_panel, CC_TYPE_PANEL) #define CUPS_STATUS_CHECK_INTERVAL 5 +#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5) +#define HAVE_CUPS_1_6 1 +#endif + +#ifndef HAVE_CUPS_1_6 +#define ippGetState(ipp) ipp->state +#define ippGetStatusCode(ipp) ipp->request.status.status_code +#define ippGetString(attr, element, language) attr->values[element].string.text +#endif + struct _CcPrintersPanelPrivate { GtkBuilder *builder; @@ -312,7 +322,7 @@ on_cups_notification (GDBusConnection *connection, if (response) { - if (response->request.status.status_code <= IPP_OK_CONFLICT) + if (ippGetStatusCode (response) <= IPP_OK_CONFLICT) { ipp_attribute_t *attr_username = NULL; ipp_attribute_t *attr_printer_uri = NULL; @@ -320,12 +330,12 @@ on_cups_notification (GDBusConnection *connection, attr_username = ippFindAttribute(response, "job-originating-user-name", IPP_TAG_NAME); attr_printer_uri = ippFindAttribute(response, "job-printer-uri", IPP_TAG_URI); if (attr_username && attr_printer_uri && - g_strcmp0 (attr_username->values[0].string.text, cupsUser ()) == 0 && - g_strrstr (attr_printer_uri->values[0].string.text, "/") != 0 && + g_strcmp0 (ippGetString (attr_username, 0, NULL), cupsUser ()) == 0 && + g_strrstr (ippGetString (attr_printer_uri, 0, NULL), "/") != 0 && priv->current_dest >= 0 && priv->current_dest < priv->num_dests && priv->dests != NULL && - g_strcmp0 (g_strrstr (attr_printer_uri->values[0].string.text, "/") + 1, + g_strcmp0 (g_strrstr (ippGetString (attr_printer_uri, 0, NULL), "/") + 1, priv->dests[priv->current_dest].name) == 0) actualize_jobs_list (self); } @@ -2263,7 +2273,7 @@ test_page_cb (GtkButton *button, if (response) { - if (response->state == IPP_ERROR) + if (ippGetState(response) == IPP_ERROR) g_warning ("An error has occured during printing of test page."); ippDelete (response); } diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c index 583fb60..d2f25c1 100644 --- a/panels/printers/pp-new-printer-dialog.c +++ b/panels/printers/pp-new-printer-dialog.c @@ -60,6 +60,14 @@ #define ALLOWED_CHARACTERS "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_" +#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5) +#define HAVE_CUPS_1_6 1 +#endif + +#ifndef HAVE_CUPS_1_6 +#define ippGetState(ipp) ipp->state +#endif + static void pp_new_printer_dialog_hide (PpNewPrinterDialog *pp); static void actualize_devices_list (PpNewPrinterDialog *pp); @@ -1696,7 +1704,7 @@ new_printer_add_button_cb (GtkButton *button, _("Automatic configuration")); if (response) { - if (response->state == IPP_ERROR) + if (ippGetState(response) == IPP_ERROR) g_warning ("An error has occured during automatic configuration of new printer."); ippDelete (response); } diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c index c89c4e4..830b39e 100644 --- a/panels/printers/pp-utils.c +++ b/panels/printers/pp-utils.c @@ -36,6 +36,37 @@ #define SCP_PATH "/org/fedoraproject/Config/Printing" #define SCP_IFACE "org.fedoraproject.Config.Printing" +#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5) +#define HAVE_CUPS_1_6 1 +#endif + +#ifndef HAVE_CUPS_1_6 +#define ippGetCount(attr) attr->num_values +#define ippGetGroupTag(attr) attr->group_tag +#define ippGetValueTag(attr) attr->value_tag +#define ippGetName(attr) attr->name +#define ippGetStatusCode(ipp) ipp->request.status.status_code +#define ippGetInteger(attr, element) attr->values[element].integer +#define ippGetString(attr, element, language) attr->values[element].string.text + +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 + + DBusGProxy * get_dbus_proxy (const gchar *name, const gchar *path, @@ -977,12 +1008,12 @@ DBus method \"GetBestDrivers\". Using fallback solution for now."); response = cupsDoRequest (http, request, "/"); if (response && - response->request.status.status_code <= IPP_OK_CONFLICT) + ippGetStatusCode (response) <= IPP_OK_CONFLICT) { - for (attr = response->attrs; attr != NULL; attr = attr->next) + for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response)) { - while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) - attr = attr->next; + while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER) + attr = ippNextAttribute (response); if (attr == NULL) break; @@ -992,22 +1023,22 @@ DBus method \"GetBestDrivers\". Using fallback solution for now."); ppd_name = NULL; ppd_product = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) + while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER) { - if (g_strcmp0 (attr->name, "ppd-device-id") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_device_id = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-make-and-model") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_make_and_model = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-name") == 0 && - attr->value_tag == IPP_TAG_NAME) - ppd_name = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-product") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_product = attr->values[0].string.text; - - attr = attr->next; + if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_device_id = (gchar *) ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-make-and-model") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_make_and_model = ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-name") == 0 && + ippGetValueTag (attr) == IPP_TAG_NAME) + ppd_name = ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-product") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_product = ippGetString (attr, 0, NULL); + + attr = ippNextAttribute (response); } if (ppd_device_id && ppd_name) @@ -1051,15 +1082,15 @@ DBus method \"GetBestDrivers\". Using fallback solution for now."); response = cupsDoRequest (http, request, "/"); if (response && - response->request.status.status_code <= IPP_OK_CONFLICT) + ippGetStatusCode (response) <= IPP_OK_CONFLICT) { for (i = 0; equivalents && equivalents[i]; i++) { eq_normalized = normalize (equivalents[i]); - for (attr = response->attrs; attr != NULL; attr = attr->next) + for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response)) { - while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) - attr = attr->next; + while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER) + attr = ippNextAttribute (response); if (attr == NULL) break; @@ -1069,22 +1100,22 @@ DBus method \"GetBestDrivers\". Using fallback solution for now."); ppd_name = NULL; ppd_product = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) + while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER) { - if (g_strcmp0 (attr->name, "ppd-device-id") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_device_id = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-make-and-model") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_make_and_model = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-name") == 0 && - attr->value_tag == IPP_TAG_NAME) - ppd_name = attr->values[0].string.text; - else if (g_strcmp0 (attr->name, "ppd-product") == 0 && - attr->value_tag == IPP_TAG_TEXT) - ppd_product = attr->values[0].string.text; - - attr = attr->next; + if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_device_id = ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-make-and-model") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_make_and_model = ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-name") == 0 && + ippGetValueTag (attr) == IPP_TAG_NAME) + ppd_name = ippGetString (attr, 0, NULL); + else if (g_strcmp0 (ippGetName (attr), "ppd-product") == 0 && + ippGetValueTag (attr) == IPP_TAG_TEXT) + ppd_product = ippGetString (attr, 0, NULL); + + attr = ippNextAttribute (response); } if (ppd_device_id && ppd_name) @@ -1382,23 +1413,23 @@ ccGetAllowedUsers (gchar ***allowed_users, const char *printer_name) ipp_attribute_t *attr = NULL; ipp_attribute_t *allowed = NULL; - for (attr = response->attrs; attr != NULL; attr = attr->next) + for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response)) { - if (attr->group_tag == IPP_TAG_PRINTER && - attr->value_tag == IPP_TAG_NAME && - !g_strcmp0 (attr->name, "requesting-user-name-allowed")) + if (ippGetGroupTag (attr)== IPP_TAG_PRINTER && + ippGetValueTag (attr) == IPP_TAG_NAME && + !g_strcmp0 (ippGetName (attr), "requesting-user-name-allowed")) allowed = attr; } - if (allowed && allowed->num_values > 0) + if (allowed && ippGetCount (allowed) > 0) { int i; - num_allowed_users = allowed->num_values; + num_allowed_users = ippGetCount (allowed); users = g_new (gchar*, num_allowed_users); for (i = 0; i < num_allowed_users; i ++) - users[i] = g_strdup (allowed->values[i].string.text); + users[i] = g_strdup (ippGetString (allowed, i, NULL)); } ippDelete(response); } @@ -1485,12 +1516,12 @@ renew_cups_subscription (gint id, "notify-lease-duration", lease_duration); response = cupsDoRequest (http, request, "/"); if (response != NULL && - response->request.status.status_code <= IPP_OK_CONFLICT) { + ippGetStatusCode (response) <= IPP_OK_CONFLICT) { if ((attr = ippFindAttribute (response, "notify-lease-duration", IPP_TAG_INTEGER)) == NULL) g_debug ("No notify-lease-duration in response!\n"); else - if (attr->values[0].integer == lease_duration) + if (ippGetInteger (attr, 0) == lease_duration) result = id; } } @@ -1512,12 +1543,12 @@ renew_cups_subscription (gint id, response = cupsDoRequest (http, request, "/"); if (response != NULL && - response->request.status.status_code <= IPP_OK_CONFLICT) { + ippGetStatusCode (response) <= IPP_OK_CONFLICT) { if ((attr = ippFindAttribute (response, "notify-subscription-id", IPP_TAG_INTEGER)) == NULL) g_debug ("No notify-subscription-id in response!\n"); else - result = attr->values[0].integer; + result = ippGetInteger (attr, 0); } } @@ -1687,38 +1718,38 @@ printer_rename (const gchar *old_name, if (response) { - if (response->request.status.status_code <= IPP_OK_CONFLICT) + if (ippGetStatusCode (response) <= IPP_OK_CONFLICT) { attr = ippFindAttribute (response, "printer-error-policy", IPP_TAG_NAME); if (attr) - error_policy = g_strdup (attr->values[0].string.text); + error_policy = g_strdup (ippGetString (attr, 0, NULL)); attr = ippFindAttribute (response, "printer-op-policy", IPP_TAG_NAME); if (attr) - op_policy = g_strdup (attr->values[0].string.text); + op_policy = g_strdup (ippGetString (attr, 0, NULL)); attr = ippFindAttribute (response, "requesting-user-name-allowed", IPP_TAG_NAME); - if (attr && attr->num_values > 0) + if (attr && ippGetCount (attr) > 0) { - users_allowed = g_new0 (gchar *, attr->num_values + 1); - for (i = 0; i < attr->num_values; i++) - users_allowed[i] = g_strdup (attr->values[i].string.text); + users_allowed = g_new0 (gchar *, ippGetCount (attr) + 1); + for (i = 0; i < ippGetCount (attr); i++) + users_allowed[i] = g_strdup (ippGetString (attr, i, NULL)); } attr = ippFindAttribute (response, "requesting-user-name-denied", IPP_TAG_NAME); - if (attr && attr->num_values > 0) + if (attr && ippGetCount (attr) > 0) { - users_denied = g_new0 (gchar *, attr->num_values + 1); - for (i = 0; i < attr->num_values; i++) - users_denied[i] = g_strdup (attr->values[i].string.text); + users_denied = g_new0 (gchar *, ippGetCount (attr) + 1); + for (i = 0; i < ippGetCount (attr); i++) + users_denied[i] = g_strdup (ippGetString (attr, i, NULL)); } attr = ippFindAttribute (response, "member-names", IPP_TAG_NAME); - if (attr && attr->num_values > 0) + if (attr && ippGetCount (attr) > 0) { - member_names = g_new0 (gchar *, attr->num_values + 1); - for (i = 0; i < attr->num_values; i++) - member_names[i] = g_strdup (attr->values[i].string.text); + member_names = g_new0 (gchar *, ippGetCount (attr) + 1); + for (i = 0; i < ippGetCount (attr); i++) + member_names[i] = g_strdup (ippGetString (attr, i, NULL)); } } ippDelete (response); -- 1.7.8.6