openbsd-ports/print/hplip/patches/patch-scan_sane_hpaio_c
2012-08-05 06:46:10 +00:00

89 lines
3.0 KiB
Plaintext

$OpenBSD: patch-scan_sane_hpaio_c,v 1.1 2012/08/05 06:46:10 ajacoutot Exp $
https://bugs.launchpad.net/hplip/+bug/1026666
--- scan/sane/hpaio.c.orig Mon Jun 18 12:42:51 2012
+++ scan/sane/hpaio.c Sun Aug 5 08:28:22 2012
@@ -47,6 +47,43 @@
#define DEBUG_DECLARE_ONLY
#include "sanei_debug.h"
+#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
+#define HAVE_CUPS_1_6 1
+#endif
+
+#ifndef HAVE_CUPS_1_6
+#define ippGetGroupTag(attr) attr->group_tag
+#define ippGetValueTag(attr) attr->value_tag
+#define ippGetName(attr) attr->name
+#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);
+}
+
+static int ippSetOperation( ipp_t *ipp, ipp_op_t op )
+{
+ ipp->request.op.operation_id = op;
+ return (1);
+}
+
+static int ippSetRequestId( ipp_t *ipp, int request_id )
+{
+ ipp->request.any.request_id = request_id;
+ return (1);
+}
+#endif
+
static SANE_Device **DeviceList = NULL;
static int AddDeviceList(char *uri, char *model, SANE_Device ***pd)
@@ -186,8 +223,8 @@ static int GetCupsPrinters(char ***printer)
/* Assemble the IPP request */
request = ippNew();
- request->request.op.operation_id = CUPS_GET_PRINTERS;
- request->request.any.request_id = 1;
+ ippSetOperation( request, CUPS_GET_PRINTERS );
+ ippSetRequestId( request, 1 );
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8");
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, "en");
@@ -197,20 +234,20 @@ static int GetCupsPrinters(char ***printer)
if ((response = cupsDoRequest(http, request, "/")) == NULL)
goto bugout;
- for (attr = response->attrs; attr != NULL; attr = attr->next)
+ for (attr = ippFirstAttribute ( response ); attr != NULL; attr = ippNextAttribute( response ))
{
/* Skip leading attributes until we hit a printer. */
- 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;
- while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
+ while (attr != NULL && ippGetGroupTag( attr ) == IPP_TAG_PRINTER)
{
- if (strcmp(attr->name, "device-uri") == 0 && attr->value_tag == IPP_TAG_URI && AddCupsList(attr->values[0].string.text, printer) == 0)
+ if (strcmp(ippGetName( attr ), "device-uri") == 0 && ippGetValueTag( attr ) == IPP_TAG_URI && AddCupsList(ippGetString( attr, 0, NULL ), printer) == 0)
cnt++;
- attr = attr->next;
+ attr = ippNextAttribute( response );
}
if (attr == NULL)