Lines 87-92
Link Here
|
87 |
#define PY_SSIZE_T_MIN INT_MIN |
87 |
#define PY_SSIZE_T_MIN INT_MIN |
88 |
#endif |
88 |
#endif |
89 |
|
89 |
|
|
|
90 |
#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 5) |
91 |
#define HAVE_CUPS_1_6 1 |
92 |
#endif |
93 |
|
94 |
#ifndef HAVE_CUPS_1_6 |
95 |
#define ippGetCount(attr) attr->num_values |
96 |
#define ippGetGroupTag(attr) attr->group_tag |
97 |
#define ippGetValueTag(attr) attr->value_tag |
98 |
#define ippGetName(attr) attr->name |
99 |
#define ippGetBoolean(attr, element) attr->values[element].boolean |
100 |
#define ippGetInteger(attr, element) attr->values[element].integer |
101 |
#define ippGetStatusCode(ipp) ipp->request.status.status_code |
102 |
#define ippGetString(attr, element, language) attr->values[element].string.text |
103 |
|
104 |
static ipp_attribute_t * ippFirstAttribute( ipp_t *ipp ) |
105 |
{ |
106 |
if (!ipp) |
107 |
return (NULL); |
108 |
return (ipp->current = ipp->attrs); |
109 |
} |
110 |
|
111 |
static ipp_attribute_t * ippNextAttribute( ipp_t *ipp ) |
112 |
{ |
113 |
if (!ipp || !ipp->current) |
114 |
return (NULL); |
115 |
return (ipp->current = ipp->current->next); |
116 |
} |
117 |
|
118 |
static int ippSetOperation( ipp_t *ipp, ipp_op_t op ) |
119 |
{ |
120 |
ipp->request.op.operation_id = op; |
121 |
return (1); |
122 |
} |
123 |
|
124 |
static int ippSetRequestId( ipp_t *ipp, int request_id ) |
125 |
{ |
126 |
ipp->request.any.request_id = request_id; |
127 |
return (1); |
128 |
} |
129 |
#endif |
90 |
|
130 |
|
91 |
int g_num_options = 0; |
131 |
int g_num_options = 0; |
92 |
cups_option_t * g_options; |
132 |
cups_option_t * g_options; |
Lines 333-340
Link Here
|
333 |
request = ippNew(); |
373 |
request = ippNew(); |
334 |
language = cupsLangDefault(); |
374 |
language = cupsLangDefault(); |
335 |
|
375 |
|
336 |
request->request.op.operation_id = CUPS_GET_PRINTERS; |
376 |
ippSetOperation( request, CUPS_GET_PRINTERS ); |
337 |
request->request.any.request_id = 1; |
377 |
ippSetRequestId ( request, 1); |
338 |
|
378 |
|
339 |
ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
379 |
ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
340 |
"attributes-charset", NULL, cupsLangEncoding( language ) ); |
380 |
"attributes-charset", NULL, cupsLangEncoding( language ) ); |
Lines 378-387
Link Here
|
378 |
ipp_pstate_t state; |
418 |
ipp_pstate_t state; |
379 |
int i = 0; |
419 |
int i = 0; |
380 |
|
420 |
|
381 |
for ( attr = response->attrs; attr != NULL; attr = attr->next ) |
421 |
for ( attr = ippFirstAttribute( response ); attr != NULL; attr = ippNextAttribute( response ) ) |
382 |
{ |
422 |
{ |
383 |
while ( attr != NULL && attr->group_tag != IPP_TAG_PRINTER ) |
423 |
while ( attr != NULL && ippGetGroupTag( attr ) != IPP_TAG_PRINTER ) |
384 |
attr = attr->next; |
424 |
attr = ippNextAttribute( response ); |
385 |
|
425 |
|
386 |
if ( attr == NULL ) |
426 |
if ( attr == NULL ) |
387 |
break; |
427 |
break; |
Lines 390-430
Link Here
|
390 |
state = IPP_PRINTER_IDLE; |
430 |
state = IPP_PRINTER_IDLE; |
391 |
accepting = 0; |
431 |
accepting = 0; |
392 |
|
432 |
|
393 |
while ( attr != NULL && attr->group_tag == IPP_TAG_PRINTER ) |
433 |
while ( attr != NULL && ippGetGroupTag( attr ) == IPP_TAG_PRINTER ) |
394 |
{ |
434 |
{ |
395 |
if ( strcmp( attr->name, "printer-name" ) == 0 && |
435 |
if ( strcmp( ippGetName( attr ), "printer-name" ) == 0 && |
396 |
attr->value_tag == IPP_TAG_NAME ) |
436 |
ippGetValueTag( attr ) == IPP_TAG_NAME ) |
397 |
name = attr->values[ 0 ].string.text; |
437 |
name = ippGetString( attr, 0, NULL ); |
398 |
|
438 |
|
399 |
else if ( strcmp( attr->name, "device-uri" ) == 0 && |
439 |
else if ( strcmp( ippGetName( attr ), "device-uri" ) == 0 && |
400 |
attr->value_tag == IPP_TAG_URI ) |
440 |
ippGetValueTag( attr ) == IPP_TAG_URI ) |
401 |
device_uri = attr->values[ 0 ].string.text; |
441 |
device_uri = ippGetString( attr, 0, NULL ); |
402 |
|
442 |
|
403 |
else if ( strcmp( attr->name, "printer-uri-supported" ) == 0 && |
443 |
else if ( strcmp( ippGetName( attr ), "printer-uri-supported" ) == 0 && |
404 |
attr->value_tag == IPP_TAG_URI ) |
444 |
ippGetValueTag( attr ) == IPP_TAG_URI ) |
405 |
printer_uri = attr->values[ 0 ].string.text; |
445 |
printer_uri = ippGetString( attr, 0, NULL ); |
406 |
|
446 |
|
407 |
else if ( strcmp( attr->name, "printer-info" ) == 0 && |
447 |
else if ( strcmp( ippGetName( attr ), "printer-info" ) == 0 && |
408 |
attr->value_tag == IPP_TAG_TEXT ) |
448 |
ippGetValueTag( attr ) == IPP_TAG_TEXT ) |
409 |
info = attr->values[ 0 ].string.text; |
449 |
info = ippGetString( attr, 0, NULL ); |
410 |
|
450 |
|
411 |
else if ( strcmp( attr->name, "printer-location" ) == 0 && |
451 |
else if ( strcmp( ippGetName( attr ), "printer-location" ) == 0 && |
412 |
attr->value_tag == IPP_TAG_TEXT ) |
452 |
ippGetValueTag( attr ) == IPP_TAG_TEXT ) |
413 |
location = attr->values[ 0 ].string.text; |
453 |
location = ippGetString( attr, 0, NULL ); |
414 |
|
454 |
|
415 |
else if ( strcmp( attr->name, "printer-make-and-model" ) == 0 && |
455 |
else if ( strcmp( ippGetName( attr ), "printer-make-and-model" ) == 0 && |
416 |
attr->value_tag == IPP_TAG_TEXT ) |
456 |
ippGetValueTag( attr ) == IPP_TAG_TEXT ) |
417 |
make_model = attr->values[ 0 ].string.text; |
457 |
make_model = ippGetString( attr, 0, NULL ); |
418 |
|
458 |
|
419 |
else if ( strcmp( attr->name, "printer-state" ) == 0 && |
459 |
else if ( strcmp( ippGetName( attr ), "printer-state" ) == 0 && |
420 |
attr->value_tag == IPP_TAG_ENUM ) |
460 |
ippGetValueTag( attr ) == IPP_TAG_ENUM ) |
421 |
state = ( ipp_pstate_t ) attr->values[ 0 ].integer; |
461 |
state = ( ipp_pstate_t ) ippGetInteger( attr, 0 ); |
422 |
|
462 |
|
423 |
else if (!strcmp(attr->name, "printer-is-accepting-jobs") && |
463 |
else if (!strcmp(ippGetName( attr ), "printer-is-accepting-jobs") && |
424 |
attr->value_tag == IPP_TAG_BOOLEAN) |
464 |
ippGetValueTag( attr ) == IPP_TAG_BOOLEAN) |
425 |
accepting = attr->values[ 0 ].boolean; |
465 |
accepting = ippGetBoolean( attr, 0 ); |
426 |
|
466 |
|
427 |
attr = attr->next; |
467 |
attr = ippNextAttribute( response ); |
428 |
} |
468 |
} |
429 |
|
469 |
|
430 |
if ( device_uri == NULL ) |
470 |
if ( device_uri == NULL ) |
Lines 522-529
Link Here
|
522 |
request = ippNew(); |
562 |
request = ippNew(); |
523 |
language = cupsLangDefault(); |
563 |
language = cupsLangDefault(); |
524 |
|
564 |
|
525 |
request->request.op.operation_id = CUPS_ADD_PRINTER; |
565 |
ippSetOperation( request, CUPS_ADD_PRINTER ); |
526 |
request->request.any.request_id = 1; |
566 |
ippSetRequestId ( request, 1 ); |
527 |
|
567 |
|
528 |
ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
568 |
ippAddString( request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, |
529 |
"attributes-charset", NULL, cupsLangEncoding( language ) ); |
569 |
"attributes-charset", NULL, cupsLangEncoding( language ) ); |
Lines 568-574
Link Here
|
568 |
} |
608 |
} |
569 |
else |
609 |
else |
570 |
{ |
610 |
{ |
571 |
status = response->request.status.status_code; |
611 |
status = ippGetStatusCode( response ); |
572 |
//ippDelete( response ); |
612 |
//ippDelete( response ); |
573 |
r = 1; |
613 |
r = 1; |
574 |
} |
614 |
} |
Lines 631-638
Link Here
|
631 |
*/ |
671 |
*/ |
632 |
request = ippNew(); |
672 |
request = ippNew(); |
633 |
|
673 |
|
634 |
request->request.op.operation_id = CUPS_DELETE_PRINTER; |
674 |
ippSetOperation( request, CUPS_DELETE_PRINTER ); |
635 |
request->request.op.request_id = 1; |
675 |
ippSetRequestId ( request, 1 ); |
636 |
|
676 |
|
637 |
language = cupsLangDefault(); |
677 |
language = cupsLangDefault(); |
638 |
|
678 |
|
Lines 650-656
Link Here
|
650 |
*/ |
690 |
*/ |
651 |
response = cupsDoRequest( http, request, "/admin/" ); |
691 |
response = cupsDoRequest( http, request, "/admin/" ); |
652 |
|
692 |
|
653 |
if ( ( response != NULL ) && ( response->request.status.status_code <= IPP_OK_CONFLICT ) ) |
693 |
if ( ( response != NULL ) && ( ippGetStatusCode( response ) <= IPP_OK_CONFLICT ) ) |
654 |
{ |
694 |
{ |
655 |
r = 1; |
695 |
r = 1; |
656 |
} |
696 |
} |
Lines 721-728
Link Here
|
721 |
|
761 |
|
722 |
request = ippNew(); |
762 |
request = ippNew(); |
723 |
|
763 |
|
724 |
request->request.op.operation_id = CUPS_SET_DEFAULT; |
764 |
ippSetOperation( request, CUPS_SET_DEFAULT ); |
725 |
request->request.op.request_id = 1; |
765 |
ippSetRequestId ( request, 1 ); |
726 |
|
766 |
|
727 |
language = cupsLangDefault(); |
767 |
language = cupsLangDefault(); |
728 |
|
768 |
|
Lines 743-749
Link Here
|
743 |
|
783 |
|
744 |
response = cupsDoRequest( http, request, "/admin/" ); |
784 |
response = cupsDoRequest( http, request, "/admin/" ); |
745 |
|
785 |
|
746 |
if ( ( response != NULL ) && ( response->request.status.status_code <= IPP_OK_CONFLICT ) ) |
786 |
if ( ( response != NULL ) && ( ippGetStatusCode( response ) <= IPP_OK_CONFLICT ) ) |
747 |
{ |
787 |
{ |
748 |
r = 1; |
788 |
r = 1; |
749 |
} |
789 |
} |
Lines 797-804
Link Here
|
797 |
|
837 |
|
798 |
request = ippNew(); |
838 |
request = ippNew(); |
799 |
|
839 |
|
800 |
request->request.op.operation_id = op; |
840 |
ippSetOperation( request, op ); |
801 |
request->request.op.request_id = 1; |
841 |
ippSetRequestId ( request, 1 ); |
802 |
|
842 |
|
803 |
language = cupsLangDefault(); |
843 |
language = cupsLangDefault(); |
804 |
|
844 |
|
Lines 822-828
Link Here
|
822 |
|
862 |
|
823 |
response = cupsDoRequest(http, request, "/admin/"); |
863 |
response = cupsDoRequest(http, request, "/admin/"); |
824 |
|
864 |
|
825 |
if (( response != NULL ) && (response->request.status.status_code <= IPP_OK_CONFLICT)) |
865 |
if (( response != NULL ) && (ippGetStatusCode( response ) <= IPP_OK_CONFLICT)) |
826 |
{ |
866 |
{ |
827 |
r = 1; |
867 |
r = 1; |
828 |
} |
868 |
} |
Lines 837-843
Link Here
|
837 |
if ( response != NULL ) |
877 |
if ( response != NULL ) |
838 |
ippDelete( response ); |
878 |
ippDelete( response ); |
839 |
|
879 |
|
840 |
return Py_BuildValue( "i", r );; |
880 |
return Py_BuildValue( "i", r ); |
841 |
} |
881 |
} |
842 |
|
882 |
|
843 |
|
883 |
|
Lines 1116-1123
Link Here
|
1116 |
|
1156 |
|
1117 |
request = ippNew(); |
1157 |
request = ippNew(); |
1118 |
|
1158 |
|
1119 |
request->request.op.operation_id = CUPS_GET_PPDS; |
1159 |
ippSetOperation( request, CUPS_GET_PPDS ); |
1120 |
request->request.op.request_id = 1; |
1160 |
ippSetRequestId ( request, 1 ); |
1121 |
|
1161 |
|
1122 |
language = cupsLangDefault(); |
1162 |
language = cupsLangDefault(); |
1123 |
|
1163 |
|
Lines 1143-1185
Link Here
|
1143 |
if ((response = cupsDoRequest(http, request, "/")) != NULL) |
1183 |
if ((response = cupsDoRequest(http, request, "/")) != NULL) |
1144 |
{ |
1184 |
{ |
1145 |
|
1185 |
|
1146 |
for (attr = response->attrs; attr; attr = attr->next) |
1186 |
for (attr = ippFirstAttribute( response ); attr; attr = ippNextAttribute( response )) |
1147 |
{ |
1187 |
{ |
1148 |
PyObject *dict; |
1188 |
PyObject *dict; |
1149 |
char *ppdname = NULL; |
1189 |
char *ppdname = NULL; |
1150 |
|
1190 |
|
1151 |
while (attr && attr->group_tag != IPP_TAG_PRINTER) |
1191 |
while (attr && ippGetGroupTag( attr ) != IPP_TAG_PRINTER) |
1152 |
attr = attr->next; |
1192 |
attr = ippNextAttribute( response ); |
1153 |
|
1193 |
|
1154 |
if (!attr) |
1194 |
if (!attr) |
1155 |
break; |
1195 |
break; |
1156 |
|
1196 |
|
1157 |
dict = PyDict_New (); |
1197 |
dict = PyDict_New (); |
1158 |
|
1198 |
|
1159 |
for (; attr && attr->group_tag == IPP_TAG_PRINTER; attr = attr->next) |
1199 |
for (; attr && ippGetGroupTag( attr ) == IPP_TAG_PRINTER; attr = ippNextAttribute( response )) |
1160 |
{ |
1200 |
{ |
1161 |
PyObject *val = NULL; |
1201 |
PyObject *val = NULL; |
1162 |
|
1202 |
|
1163 |
if (!strcmp (attr->name, "ppd-name") && attr->value_tag == IPP_TAG_NAME) |
1203 |
if (!strcmp (ippGetName( attr ), "ppd-name") && ippGetValueTag( attr ) == IPP_TAG_NAME) |
1164 |
{ |
1204 |
{ |
1165 |
ppdname = attr->values[0].string.text; |
1205 |
ppdname = ippGetString( attr, 0, NULL ); |
1166 |
|
1206 |
|
1167 |
//sprintf( buf, "print '%s'", ppdname); |
1207 |
//sprintf( buf, "print '%s'", ppdname); |
1168 |
//PyRun_SimpleString( buf ); |
1208 |
//PyRun_SimpleString( buf ); |
1169 |
} |
1209 |
} |
1170 |
|
1210 |
|
1171 |
else if (attr->value_tag == IPP_TAG_TEXT || attr->value_tag == IPP_TAG_NAME || attr->value_tag == IPP_TAG_KEYWORD) |
1211 |
else if (ippGetValueTag( attr ) == IPP_TAG_TEXT || ippGetValueTag( attr ) == IPP_TAG_NAME || ippGetValueTag( attr ) == IPP_TAG_KEYWORD) |
1172 |
//else if ((!strcmp (attr->name, "ppd-natural-language") && attr->value_tag == IPP_TAG_LANGUAGE) || |
1212 |
//else if ((!strcmp (ippGetName( attr ), "ppd-natural-language") && ippGetValueTag( attr ) == IPP_TAG_LANGUAGE) || |
1173 |
// (!strcmp (attr->name, "ppd-make-and-model") && attr->value_tag == IPP_TAG_TEXT) || |
1213 |
// (!strcmp (ippGetName( attr ), "ppd-make-and-model") && ippGetValueTag( attr ) == IPP_TAG_TEXT) || |
1174 |
// (!strcmp (attr->name, "ppd-make") && attr->value_tag == IPP_TAG_TEXT) || |
1214 |
// (!strcmp (ippGetName( attr ), "ppd-make") && ippGetValueTag( attr ) == IPP_TAG_TEXT) || |
1175 |
// (!strcmp (attr->name, "ppd-device-id") && attr->value_tag == IPP_TAG_TEXT)) |
1215 |
// (!strcmp (ippGetName( attr ), "ppd-device-id") && ippGetValueTag( attr ) == IPP_TAG_TEXT)) |
1176 |
{ |
1216 |
{ |
1177 |
val = PyObj_from_UTF8(attr->values[0].string.text); |
1217 |
val = PyObj_from_UTF8(ippGetString( attr, 0, NULL )); |
1178 |
} |
1218 |
} |
1179 |
|
1219 |
|
1180 |
if (val) |
1220 |
if (val) |
1181 |
{ |
1221 |
{ |
1182 |
PyDict_SetItemString (dict, attr->name, val); |
1222 |
PyDict_SetItemString (dict, ippGetName( attr ), val); |
1183 |
Py_DECREF (val); |
1223 |
Py_DECREF (val); |
1184 |
} |
1224 |
} |
1185 |
} |
1225 |
} |