blob: 7df01aab33bd8ed7f81b492e1ec00bfcec314e83 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001Imported from gentoo:
2https://bugs.gentoo.org/show_bug.cgi?id=428672
3
4diff -Naur hplip-3.12.6_old/prnt/cupsext/cupsext.c hplip-3.12.6/prnt/cupsext/cupsext.c
5--- hplip-3.12.6_old/prnt/cupsext/cupsext.c 2012-08-04 09:18:18.388330038 +0200
6+++ hplip-3.12.6/prnt/cupsext/cupsext.c 2012-08-04 09:18:27.855181327 +0200
7@@ -87,6 +87,46 @@
8 #define PY_SSIZE_T_MIN INT_MIN
9 #endif
10
11+#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
12+#define HAVE_CUPS_1_6 1
13+#endif
14+
15+#ifndef HAVE_CUPS_1_6
16+#define ippGetCount(attr) attr->num_values
17+#define ippGetGroupTag(attr) attr->group_tag
18+#define ippGetValueTag(attr) attr->value_tag
19+#define ippGetName(attr) attr->name
20+#define ippGetBoolean(attr, element) attr->values[element].boolean
21+#define ippGetInteger(attr, element) attr->values[element].integer
22+#define ippGetStatusCode(ipp) ipp->request.status.status_code
23+#define ippGetString(attr, element, language) attr->values[element].string.text
24+
25+static ipp_attribute_t * ippFirstAttribute( ipp_t *ipp )
26+{
27+ if (!ipp)
28+ return (NULL);
29+ return (ipp->current = ipp->attrs);
30+}
31+
32+static ipp_attribute_t * ippNextAttribute( ipp_t *ipp )
33+{
34+ if (!ipp || !ipp->current)
35+ return (NULL);
36+ return (ipp->current = ipp->current->next);
37+}
38+
39+static int ippSetOperation( ipp_t *ipp, ipp_op_t op )
40+{
41+ ipp->request.op.operation_id = op;
42+ return (1);
43+}
44+
45+static int ippSetRequestId( ipp_t *ipp, int request_id )
46+{
47+ ipp->request.any.request_id = request_id;
48+ return (1);
49+}
50+#endif
51
52 int g_num_options = 0;
53 cups_option_t * g_options;
54@@ -333,8 +373,8 @@
55 request = ippNew();
56 language = cupsLangDefault();
57
58- request->request.op.operation_id = CUPS_GET_PRINTERS;
59- request->request.any.request_id = 1;
60+ ippSetOperation( request, CUPS_GET_PRINTERS );
61+ ippSetRequestId ( request, 1);
62
63 ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
64 "attributes-charset", NULL, cupsLangEncoding( language ) );
65@@ -378,10 +418,10 @@
66 ipp_pstate_t state;
67 int i = 0;
68
69- for ( attr = response->attrs; attr != NULL; attr = attr->next )
70+ for ( attr = ippFirstAttribute( response ); attr != NULL; attr = ippNextAttribute( response ) )
71 {
72- while ( attr != NULL && attr->group_tag != IPP_TAG_PRINTER )
73- attr = attr->next;
74+ while ( attr != NULL && ippGetGroupTag( attr ) != IPP_TAG_PRINTER )
75+ attr = ippNextAttribute( response );
76
77 if ( attr == NULL )
78 break;
79@@ -390,41 +430,41 @@
80 state = IPP_PRINTER_IDLE;
81 accepting = 0;
82
83- while ( attr != NULL && attr->group_tag == IPP_TAG_PRINTER )
84+ while ( attr != NULL && ippGetGroupTag( attr ) == IPP_TAG_PRINTER )
85 {
86- if ( strcmp( attr->name, "printer-name" ) == 0 &&
87- attr->value_tag == IPP_TAG_NAME )
88- name = attr->values[ 0 ].string.text;
89-
90- else if ( strcmp( attr->name, "device-uri" ) == 0 &&
91- attr->value_tag == IPP_TAG_URI )
92- device_uri = attr->values[ 0 ].string.text;
93-
94- else if ( strcmp( attr->name, "printer-uri-supported" ) == 0 &&
95- attr->value_tag == IPP_TAG_URI )
96- printer_uri = attr->values[ 0 ].string.text;
97-
98- else if ( strcmp( attr->name, "printer-info" ) == 0 &&
99- attr->value_tag == IPP_TAG_TEXT )
100- info = attr->values[ 0 ].string.text;
101-
102- else if ( strcmp( attr->name, "printer-location" ) == 0 &&
103- attr->value_tag == IPP_TAG_TEXT )
104- location = attr->values[ 0 ].string.text;
105-
106- else if ( strcmp( attr->name, "printer-make-and-model" ) == 0 &&
107- attr->value_tag == IPP_TAG_TEXT )
108- make_model = attr->values[ 0 ].string.text;
109-
110- else if ( strcmp( attr->name, "printer-state" ) == 0 &&
111- attr->value_tag == IPP_TAG_ENUM )
112- state = ( ipp_pstate_t ) attr->values[ 0 ].integer;
113-
114- else if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
115- attr->value_tag == IPP_TAG_BOOLEAN)
116- accepting = attr->values[ 0 ].boolean;
117+ if ( strcmp( ippGetName( attr ), "printer-name" ) == 0 &&
118+ ippGetValueTag( attr ) == IPP_TAG_NAME )
119+ name = ippGetString( attr, 0, NULL );
120+
121+ else if ( strcmp( ippGetName( attr ), "device-uri" ) == 0 &&
122+ ippGetValueTag( attr ) == IPP_TAG_URI )
123+ device_uri = ippGetString( attr, 0, NULL );
124+
125+ else if ( strcmp( ippGetName( attr ), "printer-uri-supported" ) == 0 &&
126+ ippGetValueTag( attr ) == IPP_TAG_URI )
127+ printer_uri = ippGetString( attr, 0, NULL );
128+
129+ else if ( strcmp( ippGetName( attr ), "printer-info" ) == 0 &&
130+ ippGetValueTag( attr ) == IPP_TAG_TEXT )
131+ info = ippGetString( attr, 0, NULL );
132+
133+ else if ( strcmp( ippGetName( attr ), "printer-location" ) == 0 &&
134+ ippGetValueTag( attr ) == IPP_TAG_TEXT )
135+ location = ippGetString( attr, 0, NULL );
136+
137+ else if ( strcmp( ippGetName( attr ), "printer-make-and-model" ) == 0 &&
138+ ippGetValueTag( attr ) == IPP_TAG_TEXT )
139+ make_model = ippGetString( attr, 0, NULL );
140+
141+ else if ( strcmp( ippGetName( attr ), "printer-state" ) == 0 &&
142+ ippGetValueTag( attr ) == IPP_TAG_ENUM )
143+ state = ( ipp_pstate_t ) ippGetInteger( attr, 0 );
144+
145+ else if (!strcmp(ippGetName( attr ), "printer-is-accepting-jobs") &&
146+ ippGetValueTag( attr ) == IPP_TAG_BOOLEAN)
147+ accepting = ippGetBoolean( attr, 0 );
148
149- attr = attr->next;
150+ attr = ippNextAttribute( response );
151 }
152
153 if ( device_uri == NULL )
154@@ -522,8 +562,8 @@
155 request = ippNew();
156 language = cupsLangDefault();
157
158- request->request.op.operation_id = CUPS_ADD_PRINTER;
159- request->request.any.request_id = 1;
160+ ippSetOperation( request, CUPS_ADD_PRINTER );
161+ ippSetRequestId ( request, 1 );
162
163 ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
164 "attributes-charset", NULL, cupsLangEncoding( language ) );
165@@ -568,7 +608,7 @@
166 }
167 else
168 {
169- status = response->request.status.status_code;
170+ status = ippGetStatusCode( response );
171 //ippDelete( response );
172 r = 1;
173 }
174@@ -631,8 +671,8 @@
175 */
176 request = ippNew();
177
178- request->request.op.operation_id = CUPS_DELETE_PRINTER;
179- request->request.op.request_id = 1;
180+ ippSetOperation( request, CUPS_DELETE_PRINTER );
181+ ippSetRequestId ( request, 1 );
182
183 language = cupsLangDefault();
184
185@@ -650,7 +690,7 @@
186 */
187 response = cupsDoRequest( http, request, "/admin/" );
188
189- if ( ( response != NULL ) && ( response->request.status.status_code <= IPP_OK_CONFLICT ) )
190+ if ( ( response != NULL ) && ( ippGetStatusCode( response ) <= IPP_OK_CONFLICT ) )
191 {
192 r = 1;
193 }
194@@ -721,8 +761,8 @@
195
196 request = ippNew();
197
198- request->request.op.operation_id = CUPS_SET_DEFAULT;
199- request->request.op.request_id = 1;
200+ ippSetOperation( request, CUPS_SET_DEFAULT );
201+ ippSetRequestId ( request, 1 );
202
203 language = cupsLangDefault();
204
205@@ -743,7 +783,7 @@
206
207 response = cupsDoRequest( http, request, "/admin/" );
208
209- if ( ( response != NULL ) && ( response->request.status.status_code <= IPP_OK_CONFLICT ) )
210+ if ( ( response != NULL ) && ( ippGetStatusCode( response ) <= IPP_OK_CONFLICT ) )
211 {
212 r = 1;
213 }
214@@ -797,8 +837,8 @@
215
216 request = ippNew();
217
218- request->request.op.operation_id = op;
219- request->request.op.request_id = 1;
220+ ippSetOperation( request, op );
221+ ippSetRequestId ( request, 1 );
222
223 language = cupsLangDefault();
224
225@@ -822,7 +862,7 @@
226
227 response = cupsDoRequest(http, request, "/admin/");
228
229- if (( response != NULL ) && (response->request.status.status_code <= IPP_OK_CONFLICT))
230+ if (( response != NULL ) && (ippGetStatusCode( response ) <= IPP_OK_CONFLICT))
231 {
232 r = 1;
233 }
234@@ -837,7 +877,7 @@
235 if ( response != NULL )
236 ippDelete( response );
237
238- return Py_BuildValue( "i", r );;
239+ return Py_BuildValue( "i", r );
240 }
241
242
243@@ -1116,8 +1156,8 @@
244
245 request = ippNew();
246
247- request->request.op.operation_id = CUPS_GET_PPDS;
248- request->request.op.request_id = 1;
249+ ippSetOperation( request, CUPS_GET_PPDS );
250+ ippSetRequestId ( request, 1 );
251
252 language = cupsLangDefault();
253
254@@ -1143,43 +1183,43 @@
255 if ((response = cupsDoRequest(http, request, "/")) != NULL)
256 {
257
258- for (attr = response->attrs; attr; attr = attr->next)
259+ for (attr = ippFirstAttribute( response ); attr; attr = ippNextAttribute( response ))
260 {
261 PyObject *dict;
262 char *ppdname = NULL;
263
264- while (attr && attr->group_tag != IPP_TAG_PRINTER)
265- attr = attr->next;
266+ while (attr && ippGetGroupTag( attr ) != IPP_TAG_PRINTER)
267+ attr = ippNextAttribute( response );
268
269 if (!attr)
270 break;
271
272 dict = PyDict_New ();
273
274- for (; attr && attr->group_tag == IPP_TAG_PRINTER; attr = attr->next)
275+ for (; attr && ippGetGroupTag( attr ) == IPP_TAG_PRINTER; attr = ippNextAttribute( response ))
276 {
277 PyObject *val = NULL;
278
279- if (!strcmp (attr->name, "ppd-name") && attr->value_tag == IPP_TAG_NAME)
280+ if (!strcmp (ippGetName( attr ), "ppd-name") && ippGetValueTag( attr ) == IPP_TAG_NAME)
281 {
282- ppdname = attr->values[0].string.text;
283+ ppdname = ippGetString( attr, 0, NULL );
284
285 //sprintf( buf, "print '%s'", ppdname);
286 //PyRun_SimpleString( buf );
287 }
288
289- else if (attr->value_tag == IPP_TAG_TEXT || attr->value_tag == IPP_TAG_NAME || attr->value_tag == IPP_TAG_KEYWORD)
290- //else if ((!strcmp (attr->name, "ppd-natural-language") && attr->value_tag == IPP_TAG_LANGUAGE) ||
291- // (!strcmp (attr->name, "ppd-make-and-model") && attr->value_tag == IPP_TAG_TEXT) ||
292- // (!strcmp (attr->name, "ppd-make") && attr->value_tag == IPP_TAG_TEXT) ||
293- // (!strcmp (attr->name, "ppd-device-id") && attr->value_tag == IPP_TAG_TEXT))
294+ else if (ippGetValueTag( attr ) == IPP_TAG_TEXT || ippGetValueTag( attr ) == IPP_TAG_NAME || ippGetValueTag( attr ) == IPP_TAG_KEYWORD)
295+ //else if ((!strcmp (ippGetName( attr ), "ppd-natural-language") && ippGetValueTag( attr ) == IPP_TAG_LANGUAGE) ||
296+ // (!strcmp (ippGetName( attr ), "ppd-make-and-model") && ippGetValueTag( attr ) == IPP_TAG_TEXT) ||
297+ // (!strcmp (ippGetName( attr ), "ppd-make") && ippGetValueTag( attr ) == IPP_TAG_TEXT) ||
298+ // (!strcmp (ippGetName( attr ), "ppd-device-id") && ippGetValueTag( attr ) == IPP_TAG_TEXT))
299 {
300- val = PyObj_from_UTF8(attr->values[0].string.text);
301+ val = PyObj_from_UTF8(ippGetString( attr, 0, NULL ));
302 }
303
304 if (val)
305 {
306- PyDict_SetItemString (dict, attr->name, val);
307+ PyDict_SetItemString (dict, ippGetName( attr ), val);
308 Py_DECREF (val);
309 }
310 }
311diff -Naur hplip-3.12.6_old/scan/sane/hpaio.c hplip-3.12.6/scan/sane/hpaio.c
312--- hplip-3.12.6_old/scan/sane/hpaio.c 2012-08-04 09:18:21.458389913 +0200
313+++ hplip-3.12.6/scan/sane/hpaio.c 2012-08-04 09:18:27.875181720 +0200
314@@ -47,6 +47,43 @@
315 #define DEBUG_DECLARE_ONLY
316 #include "sanei_debug.h"
317
318+#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5)
319+#define HAVE_CUPS_1_6 1
320+#endif
321+
322+#ifndef HAVE_CUPS_1_6
323+#define ippGetGroupTag(attr) attr->group_tag
324+#define ippGetValueTag(attr) attr->value_tag
325+#define ippGetName(attr) attr->name
326+#define ippGetString(attr, element, language) attr->values[element].string.text
327+
328+static ipp_attribute_t * ippFirstAttribute( ipp_t *ipp )
329+{
330+ if (!ipp)
331+ return (NULL);
332+ return (ipp->current = ipp->attrs);
333+}
334+
335+static ipp_attribute_t * ippNextAttribute( ipp_t *ipp )
336+{
337+ if (!ipp || !ipp->current)
338+ return (NULL);
339+ return (ipp->current = ipp->current->next);
340+}
341+
342+static int ippSetOperation( ipp_t *ipp, ipp_op_t op )
343+{
344+ ipp->request.op.operation_id = op;
345+ return (1);
346+}
347+
348+static int ippSetRequestId( ipp_t *ipp, int request_id )
349+{
350+ ipp->request.any.request_id = request_id;
351+ return (1);
352+}
353+#endif
354+
355 static SANE_Device **DeviceList = NULL;
356
357 static int AddDeviceList(char *uri, char *model, SANE_Device ***pd)
358@@ -186,8 +223,8 @@
359 /* Assemble the IPP request */
360 request = ippNew();
361
362- request->request.op.operation_id = CUPS_GET_PRINTERS;
363- request->request.any.request_id = 1;
364+ ippSetOperation( request, CUPS_GET_PRINTERS );
365+ ippSetRequestId( request, 1 );
366
367 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8");
368 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, "en");
369@@ -197,20 +234,20 @@
370 if ((response = cupsDoRequest(http, request, "/")) == NULL)
371 goto bugout;
372
373- for (attr = response->attrs; attr != NULL; attr = attr->next)
374+ for (attr = ippFirstAttribute ( response ); attr != NULL; attr = ippNextAttribute( response ))
375 {
376 /* Skip leading attributes until we hit a printer. */
377- while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
378- attr = attr->next;
379+ while (attr != NULL && ippGetGroupTag( attr ) != IPP_TAG_PRINTER)
380+ attr = ippNextAttribute( response );
381
382 if (attr == NULL)
383 break;
384
385- while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
386+ while (attr != NULL && ippGetGroupTag( attr ) == IPP_TAG_PRINTER)
387 {
388- if (strcmp(attr->name, "device-uri") == 0 && attr->value_tag == IPP_TAG_URI && AddCupsList(attr->values[0].string.text, printer) == 0)
389+ if (strcmp(ippGetName( attr ), "device-uri") == 0 && ippGetValueTag( attr ) == IPP_TAG_URI && AddCupsList(ippGetString( attr, 0, NULL ), printer) == 0)
390 cnt++;
391- attr = attr->next;
392+ attr = ippNextAttribute( response );
393 }
394
395 if (attr == NULL)