1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
|
/*
* cups - Python bindings for CUPS
* Copyright (C) 2002-2020 Red Hat, Inc
* Authors: Tim Waugh <twaugh@redhat.com>
* Zdenek Dohnal <zdohnal@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdarg.h>
#include <Python.h>
#include <cups/cups.h>
#include <cups/language.h>
#include "cupsmodule.h"
#include <locale.h>
#include <pthread.h>
#include <wchar.h>
#include <wctype.h>
#include "cupsconnection.h"
#include "cupsppd.h"
#include "cupsipp.h"
static pthread_key_t tls_key = -1;
static pthread_once_t tls_key_once = PTHREAD_ONCE_INIT;
# define CUPS_SERVER_REMOTE_PRINTERS "_remote_printers"
//////////////////////
// Worker functions //
//////////////////////
/*
* Thread local storage functions
*/
static void
destroy_TLS (void *value)
{
struct TLS *tls = (struct TLS *) value;
/* CPython API needs to be run only when our process holds
* Python global interpret lock */
PyGILState_STATE gilstate;
gilstate = PyGILState_Ensure();
Py_XDECREF (tls->cups_password_callback);
Py_XDECREF (tls->cups_password_callback_context);
// release global interpret lock
PyGILState_Release(gilstate);
free (value);
}
static void
init_TLS (void)
{
pthread_key_create (&tls_key, destroy_TLS);
}
struct TLS *
get_TLS (void)
{
struct TLS *tls;
pthread_once (&tls_key_once, init_TLS);
tls = (struct TLS *) pthread_getspecific (tls_key);
if (tls == NULL)
{
tls = calloc (1, sizeof (struct TLS));
pthread_setspecific (tls_key, tls);
}
return tls;
}
static int
do_model_compare (const wchar_t *a, const wchar_t *b)
{
const wchar_t *digits = L"0123456789";
wchar_t quick_a, quick_b;
while ((quick_a = *a) != L'\0' && (quick_b = *b) != L'\0') {
int end_a = wcsspn (a, digits);
int end_b = wcsspn (b, digits);
int min;
int a_is_digit = 1;
int cmp;
if (quick_a != quick_b && !iswdigit (quick_a) && !iswdigit (quick_b)) {
if (quick_a < quick_b) return -1;
else return 1;
}
if (!end_a) {
end_a = wcscspn (a, digits);
a_is_digit = 0;
}
if (!end_b) {
if (a_is_digit)
return -1;
end_b = wcscspn (b, digits);
} else if (!a_is_digit)
return 1;
if (a_is_digit) {
unsigned long n_a, n_b;
n_a = wcstoul (a, NULL, 10);
n_b = wcstoul (b, NULL, 10);
if (n_a < n_b) cmp = -1;
else if (n_a == n_b) cmp = 0;
else cmp = 1;
} else {
min = end_a < end_b ? end_a : end_b;
cmp = wcsncmp (a, b, min);
}
if (!cmp) {
if (end_a != end_b)
return end_a < end_b ? -1 : 1;
a += end_a;
b += end_b;
continue;
}
return cmp;
}
if (quick_a == L'\0') {
if (*b == L'\0')
return 0;
return -1;
}
return 1;
}
//////////////////////////
// Module-level methods //
//////////////////////////
static PyObject *
cups_modelSort (PyObject *self, PyObject *args)
{
PyObject *Oa, *Ob, *a, *b;
long unsigned int len_a, len_b;
size_t size_a, size_b;
wchar_t *wca, *wcb;
if (!PyArg_ParseTuple (args, "OO", &Oa, &Ob))
return NULL;
a = PyUnicode_FromObject (Oa);
b = PyUnicode_FromObject (Ob);
if (a == NULL || b == NULL || !PyUnicode_Check (a) || !PyUnicode_Check (b)) {
if (a) {
Py_DECREF (a);
}
if (b) {
Py_DECREF (b);
}
PyErr_SetString (PyExc_TypeError, "Unable to convert to Unicode");
return NULL;
}
len_a = 1 + (long unsigned)PyUnicode_GetLength (a);
size_a = len_a * sizeof (wchar_t);
if ((size_a / sizeof (wchar_t)) != len_a) {
Py_DECREF (a);
Py_DECREF (b);
PyErr_SetString (PyExc_RuntimeError, "String too long");
return NULL;
}
len_b = 1 + (long unsigned)PyUnicode_GetLength (b);
size_b = len_b * sizeof (wchar_t);
if ((size_b / sizeof (wchar_t)) != len_b) {
Py_DECREF (a);
Py_DECREF (b);
PyErr_SetString (PyExc_RuntimeError, "String too long");
return NULL;
}
wca = malloc (size_a);
wcb = malloc (size_b);
if (wca == NULL || wcb == NULL) {
Py_DECREF (a);
Py_DECREF (b);
free (wca);
free (wcb);
PyErr_SetString (PyExc_RuntimeError, "Insufficient memory");
return NULL;
}
PyUnicode_AsWideChar (a, wca, size_a);
PyUnicode_AsWideChar (b, wcb, size_b);
Py_DECREF (a);
Py_DECREF (b);
return Py_BuildValue ("i", do_model_compare (wca, wcb));
}
static PyObject *
cups_setUser (PyObject *self, PyObject *args)
{
PyObject *userobj;
char *user;
if (!PyArg_ParseTuple (args, "O", &userobj))
return NULL;
if (UTF8_from_PyObj (&user, userobj) == NULL)
return NULL;
cupsSetUser (user);
free (user);
Py_RETURN_NONE;
}
static PyObject *
cups_setServer (PyObject *self, PyObject *args)
{
PyObject *serverobj;
char *server;
if (!PyArg_ParseTuple (args, "O", &serverobj))
return NULL;
if (UTF8_from_PyObj (&server, serverobj) == NULL)
return NULL;
cupsSetServer (server);
free (server);
Py_RETURN_NONE;
}
static PyObject *
cups_setPort (PyObject *self, PyObject *args)
{
int port;
if (!PyArg_ParseTuple (args, "i", &port))
return NULL;
ippSetPort (port);
Py_RETURN_NONE;
}
static PyObject *
cups_setEncryption (PyObject *self, PyObject *args)
{
int e;
if (!PyArg_ParseTuple (args, "i", &e))
return NULL;
cupsSetEncryption (e);
Py_RETURN_NONE;
}
static PyObject *
cups_getUser (PyObject *self)
{
return PyUnicode_FromString (cupsUser ());
}
static PyObject *
cups_getServer (PyObject *self)
{
return PyUnicode_FromString (cupsServer ());
}
static PyObject *
cups_getPort (PyObject *self)
{
return Py_BuildValue ("i", ippPort ());
}
static PyObject *
cups_getEncryption (PyObject *self)
{
return Py_BuildValue ("i", cupsEncryption ());
}
static PyObject *
cups_setPasswordCB (PyObject *self, PyObject *args)
{
struct TLS *tls = get_TLS ();
PyObject *cb;
if (!PyArg_ParseTuple (args, "O:cups_setPasswordCB", &cb))
return NULL;
if (!PyCallable_Check (cb)) {
PyErr_SetString (PyExc_TypeError, "Parameter must be callable");
return NULL;
}
debugprintf ("-> cups_setPasswordCB\n");
Py_XDECREF (tls->cups_password_callback_context);
tls->cups_password_callback_context = NULL;
Py_XINCREF (cb);
Py_XDECREF (tls->cups_password_callback);
tls->cups_password_callback = cb;
cupsSetPasswordCB2 (password_callback_oldstyle, NULL);
debugprintf ("<- cups_setPasswordCB\n");
Py_RETURN_NONE;
}
static PyObject *
cups_setPasswordCB2 (PyObject *self, PyObject *args)
{
struct TLS *tls = get_TLS ();
PyObject *cb;
PyObject *cb_context = NULL;
if (!PyArg_ParseTuple (args, "O|O", &cb, &cb_context))
return NULL;
if (cb == Py_None && cb_context != NULL) {
PyErr_SetString (PyExc_TypeError, "Default callback takes no context");
return NULL;
}
else if (cb != Py_None && !PyCallable_Check (cb)) {
PyErr_SetString (PyExc_TypeError, "Parameter must be callable");
return NULL;
}
debugprintf ("-> cups_setPasswordCB2\n");
Py_XINCREF (cb_context);
Py_XDECREF (tls->cups_password_callback_context);
tls->cups_password_callback_context = cb_context;
if (cb == Py_None)
{
Py_XDECREF (tls->cups_password_callback);
tls->cups_password_callback = NULL;
cupsSetPasswordCB2 (NULL, NULL);
}
else
{
Py_XINCREF (cb);
Py_XDECREF (tls->cups_password_callback);
tls->cups_password_callback = cb;
cupsSetPasswordCB2 (password_callback_newstyle, cb_context);
}
debugprintf ("<- cups_setPasswordCB2\n");
Py_RETURN_NONE;
}
static PyObject *
cups_ppdSetConformance (PyObject *self, PyObject *args)
{
int level;
if (!PyArg_ParseTuple (args, "i", &level))
return NULL;
ppdSetConformance (level);
Py_RETURN_NONE;
}
static PyObject *
cups_enumDests (PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *cb;
int flags = 0;
int msec = -1;
int type = 0;
int mask = 0;
PyObject *user_data = NULL;
CallbackContext context;
int ret;
static char *kwlist[] = { "cb",
"flags",
"msec",
"type",
"mask",
"user_data",
NULL };
if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|iiiiO", kwlist,
&cb,
&flags,
&msec,
&type,
&mask,
&user_data))
return NULL;
if (!PyCallable_Check (cb)) {
PyErr_SetString (PyExc_TypeError, "cb must be callable");
return NULL;
}
if (!user_data)
user_data = Py_None;
Py_XINCREF (cb);
Py_XINCREF (user_data);
context.cb = cb;
context.user_data = user_data;
ret = cupsEnumDests (flags,
msec,
NULL,
type,
mask,
cups_dest_cb,
&context);
Py_XDECREF (cb);
Py_XDECREF (user_data);
if (!ret) {
PyErr_SetString (PyExc_RuntimeError, "cupsEnumDests failed");
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *
cups_connectDest (PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *destobj;
PyObject *cb;
int flags = 0;
int msec = -1;
PyObject *user_data = NULL;
CallbackContext context;
char resource[HTTP_MAX_URI];
http_t *conn;
Connection *connobj;
Dest *dest_o;
cups_dest_t dest;
PyObject *ret;
static char *kwlist[] = { "dest",
"cb",
"flags",
"msec",
"user_data",
NULL };
if (!PyArg_ParseTupleAndKeywords (args, kwds, "OO|iiO", kwlist,
&destobj,
&cb,
&flags,
&msec,
&user_data))
return NULL;
if (Py_TYPE(destobj) != &cups_DestType) {
PyErr_SetString (PyExc_TypeError, "dest must be Dest object");
return NULL;
}
if (!PyCallable_Check (cb)) {
PyErr_SetString (PyExc_TypeError, "cb must be callable");
return NULL;
}
if (!user_data)
user_data = Py_None;
Py_XINCREF (cb);
Py_XINCREF (user_data);
context.cb = cb;
context.user_data = user_data;
resource[0] = '\0';
dest_o = (Dest *) destobj;
dest.is_default = dest_o->is_default;
dest.name = dest_o->destname;
dest.instance = dest_o->instance;
dest.num_options = dest_o->num_options;
dest.options = malloc (dest_o->num_options * sizeof (dest.options[0]));
int i;
for (i = 0; i < dest_o->num_options; i++) {
dest.options[i].name = dest_o->name[i];
dest.options[i].value = dest_o->value[i];
}
conn = cupsConnectDest (&dest,
flags,
msec,
NULL,
resource,
sizeof (resource),
cups_dest_cb,
&context);
Py_XDECREF (cb);
Py_XDECREF (user_data);
free (dest.options);
if (!conn) {
set_ipp_error (cupsLastError (), cupsLastErrorString ());
return NULL;
}
PyObject *largs = Py_BuildValue ("()");
PyObject *lkwlist = Py_BuildValue ("{}");
connobj = (Connection *) PyType_GenericNew (&cups_ConnectionType,
largs, lkwlist);
Py_DECREF (largs);
Py_DECREF (lkwlist);
connobj->host = strdup ("");
connobj->http = conn;
ret = Py_BuildValue ("(Os)", (PyObject *) connobj, resource);
return ret;
}
static PyObject *
cups_ippErrorString (PyObject *self, PyObject *args)
{
int op;
if (!PyArg_ParseTuple (args, "i", &op))
return NULL;
return PyUnicode_FromString (ippErrorString (op));
}
static PyObject *
cups_ippOpString (PyObject *self, PyObject *args)
{
int op;
if (!PyArg_ParseTuple (args, "i", &op))
return NULL;
return PyUnicode_FromString (ippOpString (op));
}
static PyObject *
cups_require (PyObject *self, PyObject *args)
{
const char *version = VERSION;
const char *required;
const char *pver, *preq;
char *end;
unsigned long nreq, nver;
if (!PyArg_ParseTuple (args, "s", &required))
return NULL;
pver = version;
preq = required;
nreq = strtoul (preq, &end, 0);
while (preq != end)
{
preq = end;
if (*preq == '.')
preq++;
nver = strtoul (pver, &end, 0);
if (pver == end)
goto fail;
else {
pver = end;
if (*pver == '.')
pver++;
}
if (nver < nreq)
goto fail;
if (nver > nreq)
goto good;
nreq = strtoul (preq, &end, 0);
}
good:
Py_RETURN_NONE;
fail:
PyErr_SetString (PyExc_RuntimeError, "I am version " VERSION);
return NULL;
}
struct module_state {
PyObject *error;
};
#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
static PyMethodDef cups_methods[] = {
{ "modelSort", cups_modelSort, METH_VARARGS,
"modelSort(s1,s2) -> integer\n\n"
"Sort two model strings.\n\n"
"@type s1: string\n"
"@param s1: first string\n"
"@type s2: string\n"
"@param s2: second string\n"
"@return: strcmp-style comparison result"},
{ "setUser", cups_setUser, METH_VARARGS,
"setUser(user) -> None\n\n"
"Set user to connect as.\n\n"
"@type user: string\n"
"@param user: username"},
{ "setServer", cups_setServer, METH_VARARGS,
"setServer(server) -> None\n\n"
"Set server to connect to.\n\n"
"@type server: string\n"
"@param server: server hostname" },
{ "setPort", cups_setPort, METH_VARARGS,
"setPort(port) -> None\n\n"
"Set IPP port to connect to.\n\n"
"@type port: integer\n"
"@param port: IPP port" },
{ "setEncryption", cups_setEncryption, METH_VARARGS,
"setEncryption(policy) -> None\n\n"
"Set encryption policy.\n\n"
"@type policy: integer\n"
"@param policy: L{HTTP_ENCRYPT_ALWAYS}, L{HTTP_ENCRYPT_IF_REQUESTED}, \n"
"L{HTTP_ENCRYPT_NEVER}, or L{HTTP_ENCRYPT_REQUIRED}" },
{ "getUser", (PyCFunction) cups_getUser, METH_NOARGS,
"getUser() -> string\n\n"
"@return: user to connect as." },
{ "getServer", (PyCFunction) cups_getServer, METH_NOARGS,
"getServer() -> string\n\n"
"@return: server to connect to." },
{ "getPort", (PyCFunction) cups_getPort, METH_NOARGS,
"getPort() -> integer\n\n"
"@return: IPP port to connect to." },
{ "getEncryption", (PyCFunction) cups_getEncryption, METH_NOARGS,
"getEncryption() -> integer\n\n"
"Get encryption policy.\n"
"@see: L{setEncryption}" },
{ "setPasswordCB", cups_setPasswordCB, METH_VARARGS,
"setPasswordCB(fn) -> None\n\n"
"Set password callback function. This Python function will be called \n"
"when a password is required. It must take one string parameter \n"
"(the password prompt) and it must return a string (the password), or \n"
"None to abort the operation.\n\n"
"@type fn: callable object\n"
"@param fn: callback function" },
{ "setPasswordCB2", cups_setPasswordCB2, METH_VARARGS,
"setPasswordCB2(fn, context=None) -> None\n\n"
"Set password callback function. This Python function will be called \n"
"when a password is required. It must take parameters of type string \n"
"(the password prompt), instance (the cups.Connection), string (the \n"
"HTTP method), string (the HTTP resource) and, optionally, the user-\n"
"supplied context. It must return a string (the password), or None \n"
"to abort the operation.\n\n"
"@type fn: callable object, or None for default handler\n"
"@param fn: callback function" },
{ "ppdSetConformance", cups_ppdSetConformance, METH_VARARGS,
"ppdSetConformance(level) -> None\n\n"
"Set PPD conformance level.\n\n"
"@type level: integer\n"
"@param level: PPD_CONFORM_RELAXED or PPD_CONFORM_STRICT" },
{ "enumDests",
(PyCFunction) cups_enumDests, METH_VARARGS | METH_KEYWORDS,
"enumDests(cb,flags=0,msec=-1,type=0,mask=0,user_data=None) -> None\n\n"
"@type cb: callable\n"
"@param cb: callback function, given user_data, dest flags, and dest.\n"
"Should return 1 to continue enumeration and 0 to cancel.\n"
"@type flags: integer\n"
"@param flags: enumeration flags\n"
"@type msec: integer\n"
"@param msec: timeout, or -1 for no timeout\n"
"@type type: integer\n"
"@param type: bitmask of printer types to return\n"
"@type mask: integer\n"
"@param mask: bitmask of type bits to examine\n"
"@type user_data: object\n"
"@param user_data: user data to pass to callback function\n"},
{ "connectDest",
(PyCFunction) cups_connectDest, METH_VARARGS | METH_KEYWORDS,
"connectDest(dest,cb,flags=0,msec=-1,user_data=None) -> (conn, resource)\n\n"
"@type dest: Dest object\n"
"@param dest: destination to connect to\n"
"@type cb: callable\n"
"@param cb: callback function, given user_data, dest flags, and dest.\n"
"Should return 1 to continue enumeration and 0 to cancel.\n"
"@type flags: integer\n"
"@param flags: enumeration flags\n"
"@type msec: integer\n"
"@param msec: timeout, or -1 for no timeout\n"
"@type user_data: object\n"
"@param user_data: user data to pass to callback function\n"
"@return: a 2-tuple of the Connection object and the HTTP resource.\n"},
{ "ippErrorString",
(PyCFunction) cups_ippErrorString, METH_VARARGS,
"ippErrorString(statuscode) -> name\n\n"
"@type statuscode: integer\n"
"@param statuscode: IPP Request status code\n"
"@return: a string describing the status code\n"},
{ "ippOpString",
(PyCFunction) cups_ippOpString, METH_VARARGS,
"ippOpString(op) -> name\n\n"
"@type op: integer\n"
"@param op: IPP Request operation\n"
"@return: a string representing the operation name\n"},
{ "require", cups_require, METH_VARARGS,
"require(version) -> None\n\n"
"Require pycups version.\n\n"
"@type version: string\n"
"@param version: minimum pycups version required\n"
"@raise RuntimeError: requirement not met" },
{ NULL, NULL, 0, NULL }
};
static int cups_traverse(PyObject *m, visitproc visit, void *arg) {
Py_VISIT(GETSTATE(m)->error);
return 0;
}
static int cups_clear(PyObject *m) {
Py_CLEAR(GETSTATE(m)->error);
return 0;
}
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"cups",
NULL,
sizeof(struct module_state),
cups_methods,
NULL,
cups_traverse,
cups_clear,
NULL
};
#define INITERROR return NULL
PyObject *
PyInit_cups(void)
{
PyObject *m = PyModule_Create(&moduledef);
if (m == NULL)
INITERROR;
struct module_state *st = GETSTATE(m);
st->error = PyErr_NewException("cups.Error", NULL, NULL);
if (st->error == NULL) {
Py_DECREF(m);
INITERROR;
}
PyObject *d = PyModule_GetDict (m);
PyObject *obj;
// Connection type
cups_ConnectionType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_ConnectionType) < 0)
INITERROR;
PyModule_AddObject (m, "Connection",
(PyObject *)&cups_ConnectionType);
// PPD type
cups_PPDType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_PPDType) < 0)
INITERROR;
PyModule_AddObject (m, "PPD",
(PyObject *)&cups_PPDType);
// Option type
cups_OptionType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_OptionType) < 0)
INITERROR;
PyModule_AddObject (m, "Option",
(PyObject *)&cups_OptionType);
// Group type
cups_GroupType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_GroupType) < 0)
INITERROR;
PyModule_AddObject (m, "Group",
(PyObject *)&cups_GroupType);
// Constraint type
cups_ConstraintType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_ConstraintType) < 0)
INITERROR;
PyModule_AddObject (m, "Constraint",
(PyObject *)&cups_ConstraintType);
// Attribute type
cups_AttributeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_AttributeType) < 0)
INITERROR;
PyModule_AddObject (m, "Attribute",
(PyObject *)&cups_AttributeType);
// Dest type
cups_DestType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_DestType) < 0)
INITERROR;
PyModule_AddObject (m, "Dest",
(PyObject *)&cups_DestType);
// IPPRequest type
cups_IPPRequestType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_IPPRequestType) < 0)
INITERROR;
PyModule_AddObject (m, "IPPRequest",
(PyObject *)&cups_IPPRequestType);
// IPPAttribute type
cups_IPPAttributeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&cups_IPPAttributeType) < 0)
INITERROR;
PyModule_AddObject (m, "IPPAttribute",
(PyObject *)&cups_IPPAttributeType);
// Constants
# define INT_CONSTANT(name) \
PyDict_SetItemString (d, #name, PyLong_FromLong (name))
# define INT_CONSTANT_AS(name,alias) \
PyDict_SetItemString (d, alias, PyLong_FromLong (name))
# define INT_CONSTANT_ALIAS(name,alias) \
PyDict_SetItemString (d, #name, PyLong_FromLong (name)); \
PyDict_SetItemString (d, alias, PyLong_FromLong (name))
#define STR_CONSTANT(name) \
PyDict_SetItemString (d, #name, PyUnicode_FromString (name))
# define INT_17_CONSTANT(newname,oldname) \
INT_CONSTANT_ALIAS(newname,#oldname)
# define INT_17_CONSTANT_NEWNAME(newname,oldname) \
INT_CONSTANT(newname)
// CUPS printer types
INT_CONSTANT (CUPS_PRINTER_LOCAL);
INT_CONSTANT (CUPS_PRINTER_CLASS);
INT_CONSTANT (CUPS_PRINTER_REMOTE);
INT_CONSTANT (CUPS_PRINTER_BW);
INT_CONSTANT (CUPS_PRINTER_COLOR);
INT_CONSTANT (CUPS_PRINTER_DUPLEX);
INT_CONSTANT (CUPS_PRINTER_STAPLE);
INT_CONSTANT (CUPS_PRINTER_COPIES);
INT_CONSTANT (CUPS_PRINTER_COLLATE);
INT_CONSTANT (CUPS_PRINTER_PUNCH);
INT_CONSTANT (CUPS_PRINTER_COVER);
INT_CONSTANT (CUPS_PRINTER_BIND);
INT_CONSTANT (CUPS_PRINTER_SORT);
INT_CONSTANT (CUPS_PRINTER_SMALL);
INT_CONSTANT (CUPS_PRINTER_MEDIUM);
INT_CONSTANT (CUPS_PRINTER_LARGE);
INT_CONSTANT (CUPS_PRINTER_VARIABLE);
INT_CONSTANT (CUPS_PRINTER_IMPLICIT);
INT_CONSTANT (CUPS_PRINTER_DEFAULT);
INT_CONSTANT (CUPS_PRINTER_FAX);
INT_CONSTANT (CUPS_PRINTER_REJECTING);
INT_CONSTANT (CUPS_PRINTER_DELETE);
INT_CONSTANT (CUPS_PRINTER_NOT_SHARED);
INT_CONSTANT (CUPS_PRINTER_AUTHENTICATED);
INT_CONSTANT (CUPS_PRINTER_COMMANDS);
INT_CONSTANT (CUPS_PRINTER_OPTIONS);
INT_CONSTANT (CUPS_PRINTER_DISCOVERED);
// HTTP encryption
INT_CONSTANT (HTTP_ENCRYPT_IF_REQUESTED);
INT_CONSTANT (HTTP_ENCRYPT_NEVER);
INT_CONSTANT (HTTP_ENCRYPT_REQUIRED);
INT_CONSTANT (HTTP_ENCRYPT_ALWAYS);
// Document formats
STR_CONSTANT (CUPS_FORMAT_AUTO);
STR_CONSTANT (CUPS_FORMAT_COMMAND);
STR_CONSTANT (CUPS_FORMAT_PDF);
STR_CONSTANT (CUPS_FORMAT_POSTSCRIPT);
STR_CONSTANT (CUPS_FORMAT_RAW);
STR_CONSTANT (CUPS_FORMAT_TEXT);
// Selected HTTP status codes
/* Also define legacy names */
# define INT_HTTP_STATUS_CONSTANT(name) \
INT_CONSTANT_ALIAS(HTTP_STATUS_##name, "HTTP_"#name)
INT_HTTP_STATUS_CONSTANT (ERROR);
INT_HTTP_STATUS_CONSTANT (OK);
INT_HTTP_STATUS_CONSTANT (NOT_MODIFIED);
INT_HTTP_STATUS_CONSTANT (BAD_REQUEST);
INT_HTTP_STATUS_CONSTANT (UNAUTHORIZED);
INT_HTTP_STATUS_CONSTANT (FORBIDDEN);
INT_HTTP_STATUS_CONSTANT (NOT_FOUND);
INT_HTTP_STATUS_CONSTANT (REQUEST_TIMEOUT);
INT_HTTP_STATUS_CONSTANT (UPGRADE_REQUIRED);
INT_HTTP_STATUS_CONSTANT (SERVER_ERROR);
INT_HTTP_STATUS_CONSTANT (NOT_IMPLEMENTED);
INT_HTTP_STATUS_CONSTANT (BAD_GATEWAY);
INT_HTTP_STATUS_CONSTANT (SERVICE_UNAVAILABLE);
INT_HTTP_STATUS_CONSTANT (GATEWAY_TIMEOUT);
INT_HTTP_STATUS_CONSTANT (NOT_SUPPORTED);
INT_17_CONSTANT (HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED,
HTTP_AUTHORIZATION_CANCELED);
INT_17_CONSTANT (HTTP_STATUS_CUPS_PKI_ERROR, HTTP_PKI_ERROR);
// PPD UI enum
INT_CONSTANT (PPD_UI_BOOLEAN);
INT_CONSTANT (PPD_UI_PICKONE);
INT_CONSTANT (PPD_UI_PICKMANY);
// PPD Order dependency enum
INT_CONSTANT (PPD_ORDER_ANY);
INT_CONSTANT (PPD_ORDER_DOCUMENT);
INT_CONSTANT (PPD_ORDER_EXIT);
INT_CONSTANT (PPD_ORDER_JCL);
INT_CONSTANT (PPD_ORDER_PAGE);
INT_CONSTANT (PPD_ORDER_PROLOG);
// Job states
INT_CONSTANT (IPP_JOB_PENDING);
INT_CONSTANT (IPP_JOB_HELD);
INT_CONSTANT (IPP_JOB_PROCESSING);
INT_CONSTANT (IPP_JOB_STOPPED);
INT_CONSTANT (IPP_JOB_CANCELED);
INT_CONSTANT (IPP_JOB_ABORTED);
INT_CONSTANT (IPP_JOB_COMPLETED);
// Printer states
INT_CONSTANT (IPP_PRINTER_IDLE);
INT_CONSTANT (IPP_PRINTER_PROCESSING);
INT_CONSTANT (IPP_PRINTER_STOPPED);
// IPP resolution units
INT_CONSTANT (IPP_RES_PER_CM);
INT_CONSTANT (IPP_RES_PER_INCH);
// IPP finishings
INT_CONSTANT (IPP_FINISHINGS_NONE);
INT_CONSTANT (IPP_FINISHINGS_STAPLE);
INT_CONSTANT (IPP_FINISHINGS_PUNCH);
INT_CONSTANT (IPP_FINISHINGS_COVER);
INT_CONSTANT (IPP_FINISHINGS_BIND);
INT_CONSTANT (IPP_FINISHINGS_SADDLE_STITCH);
INT_CONSTANT (IPP_FINISHINGS_EDGE_STITCH);
INT_CONSTANT (IPP_FINISHINGS_FOLD);
INT_CONSTANT (IPP_FINISHINGS_TRIM);
INT_CONSTANT (IPP_FINISHINGS_BALE);
INT_CONSTANT (IPP_FINISHINGS_BOOKLET_MAKER);
INT_CONSTANT (IPP_FINISHINGS_JOB_OFFSET);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_TOP_LEFT);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_BOTTOM_LEFT);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_TOP_RIGHT);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT);
INT_CONSTANT (IPP_FINISHINGS_EDGE_STITCH_LEFT);
INT_CONSTANT (IPP_FINISHINGS_EDGE_STITCH_TOP);
INT_CONSTANT (IPP_FINISHINGS_EDGE_STITCH_RIGHT);
INT_CONSTANT (IPP_FINISHINGS_EDGE_STITCH_BOTTOM);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_DUAL_LEFT);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_DUAL_TOP);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_DUAL_RIGHT);
INT_CONSTANT (IPP_FINISHINGS_STAPLE_DUAL_BOTTOM);
INT_CONSTANT (IPP_FINISHINGS_BIND_LEFT);
INT_CONSTANT (IPP_FINISHINGS_BIND_TOP);
INT_CONSTANT (IPP_FINISHINGS_BIND_RIGHT);
INT_CONSTANT (IPP_FINISHINGS_BIND_BOTTOM);
// IPP orientations
/* Also define legacy names */
# define INT_IPP_ORIENT_CONSTANT(name) \
INT_CONSTANT_ALIAS(IPP_ORIENT_##name, "IPP_"#name)
INT_IPP_ORIENT_CONSTANT (PORTRAIT);
INT_IPP_ORIENT_CONSTANT (LANDSCAPE);
INT_IPP_ORIENT_CONSTANT (REVERSE_PORTRAIT);
INT_IPP_ORIENT_CONSTANT (REVERSE_LANDSCAPE);
// IPP qualities
INT_CONSTANT (IPP_QUALITY_DRAFT);
INT_CONSTANT (IPP_QUALITY_NORMAL);
INT_CONSTANT (IPP_QUALITY_HIGH);
// IPP errors
/* Also define legacy names */
# define INT_IPP_STATUS_ERROR_CONSTANT(name) \
INT_CONSTANT_ALIAS(IPP_STATUS_ERROR_##name, "IPP_"#name)
# define INT_IPP_STATUS_OK_CONSTANT(name) \
INT_CONSTANT_ALIAS(IPP_STATUS_##name, "IPP_"#name)
INT_IPP_STATUS_OK_CONSTANT (OK);
INT_17_CONSTANT (IPP_STATUS_OK_IGNORED_OR_SUBSTITUTED, IPP_OK_SUBST);
INT_17_CONSTANT (IPP_STATUS_OK_CONFLICTING, IPP_OK_CONFLICT);
INT_IPP_STATUS_OK_CONSTANT (OK_IGNORED_SUBSCRIPTIONS);
INT_IPP_STATUS_OK_CONSTANT (OK_IGNORED_NOTIFICATIONS);
INT_IPP_STATUS_OK_CONSTANT (OK_TOO_MANY_EVENTS);
INT_IPP_STATUS_OK_CONSTANT (OK_BUT_CANCEL_SUBSCRIPTION);
INT_IPP_STATUS_OK_CONSTANT (OK_EVENTS_COMPLETE);
INT_17_CONSTANT (IPP_STATUS_REDIRECTION_OTHER_SITE,
IPP_REDIRECTION_OTHER_SITE);
INT_IPP_STATUS_ERROR_CONSTANT (BAD_REQUEST);
INT_IPP_STATUS_ERROR_CONSTANT (FORBIDDEN);
INT_IPP_STATUS_ERROR_CONSTANT (NOT_AUTHENTICATED);
INT_IPP_STATUS_ERROR_CONSTANT (NOT_AUTHORIZED);
INT_IPP_STATUS_ERROR_CONSTANT (NOT_POSSIBLE);
INT_IPP_STATUS_ERROR_CONSTANT (TIMEOUT);
INT_IPP_STATUS_ERROR_CONSTANT (NOT_FOUND);
INT_IPP_STATUS_ERROR_CONSTANT (GONE);
INT_IPP_STATUS_ERROR_CONSTANT (REQUEST_ENTITY);
INT_IPP_STATUS_ERROR_CONSTANT (REQUEST_VALUE);
INT_17_CONSTANT (IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED,
IPP_DOCUMENT_FORMAT);
INT_17_CONSTANT (IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, IPP_ATTRIBUTES);
INT_IPP_STATUS_ERROR_CONSTANT (URI_SCHEME);
INT_IPP_STATUS_ERROR_CONSTANT (CHARSET);
INT_17_CONSTANT (IPP_STATUS_ERROR_CONFLICTING, IPP_CONFLICT);
INT_IPP_STATUS_ERROR_CONSTANT (COMPRESSION_NOT_SUPPORTED);
INT_IPP_STATUS_ERROR_CONSTANT (COMPRESSION_ERROR);
INT_IPP_STATUS_ERROR_CONSTANT (DOCUMENT_FORMAT_ERROR);
INT_17_CONSTANT (IPP_STATUS_ERROR_DOCUMENT_ACCESS, IPP_DOCUMENT_ACCESS_ERROR);
INT_IPP_STATUS_ERROR_CONSTANT (ATTRIBUTES_NOT_SETTABLE);
INT_IPP_STATUS_ERROR_CONSTANT (IGNORED_ALL_SUBSCRIPTIONS);
INT_IPP_STATUS_ERROR_CONSTANT (TOO_MANY_SUBSCRIPTIONS);
INT_IPP_STATUS_ERROR_CONSTANT (IGNORED_ALL_NOTIFICATIONS);
INT_IPP_STATUS_ERROR_CONSTANT (PRINT_SUPPORT_FILE_NOT_FOUND);
INT_17_CONSTANT (IPP_STATUS_ERROR_INTERNAL, IPP_INTERNAL_ERROR);
INT_IPP_STATUS_ERROR_CONSTANT (OPERATION_NOT_SUPPORTED);
INT_IPP_STATUS_ERROR_CONSTANT (SERVICE_UNAVAILABLE);
INT_IPP_STATUS_ERROR_CONSTANT (VERSION_NOT_SUPPORTED);
INT_17_CONSTANT (IPP_STATUS_ERROR_DEVICE, IPP_DEVICE_ERROR);
INT_17_CONSTANT (IPP_STATUS_ERROR_TEMPORARY, IPP_TEMPORARY_ERROR);
INT_17_CONSTANT (IPP_STATUS_ERROR_NOT_ACCEPTING_JOBS, IPP_NOT_ACCEPTING);
INT_17_CONSTANT (IPP_STATUS_ERROR_BUSY, IPP_PRINTER_BUSY);
INT_17_CONSTANT (IPP_STATUS_ERROR_JOB_CANCELED, IPP_ERROR_JOB_CANCELED);
INT_IPP_STATUS_ERROR_CONSTANT (MULTIPLE_JOBS_NOT_SUPPORTED);
INT_IPP_STATUS_ERROR_CONSTANT (PRINTER_IS_DEACTIVATED);
INT_17_CONSTANT (IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED,
IPP_AUTHENTICATION_CANCELED);
INT_17_CONSTANT (IPP_STATUS_ERROR_CUPS_PKI, IPP_PKI_ERROR);
INT_17_CONSTANT (IPP_STATUS_ERROR_CUPS_UPGRADE_REQUIRED,
IPP_UPGRADE_REQUIRED);
// IPP states
/* Also define legacy names */
# define INT_IPP_STATE_CONSTANT(name) \
INT_CONSTANT_ALIAS(IPP_STATE_##name, "IPP_"#name)
INT_IPP_STATE_CONSTANT (ERROR);
INT_IPP_STATE_CONSTANT (IDLE);
INT_IPP_STATE_CONSTANT (HEADER);
INT_IPP_STATE_CONSTANT (ATTRIBUTE);
INT_IPP_STATE_CONSTANT (DATA);
// IPP attribute tags
INT_CONSTANT (IPP_TAG_ZERO);
INT_CONSTANT (IPP_TAG_OPERATION);
INT_CONSTANT (IPP_TAG_JOB);
INT_CONSTANT (IPP_TAG_PRINTER);
INT_CONSTANT (IPP_TAG_INTEGER);
INT_CONSTANT (IPP_TAG_BOOLEAN);
INT_CONSTANT (IPP_TAG_ENUM);
INT_CONSTANT (IPP_TAG_STRING);
INT_CONSTANT (IPP_TAG_RANGE);
INT_CONSTANT (IPP_TAG_TEXT);
INT_CONSTANT (IPP_TAG_NAME);
INT_CONSTANT (IPP_TAG_KEYWORD);
INT_CONSTANT (IPP_TAG_URI);
INT_CONSTANT (IPP_TAG_CHARSET);
INT_CONSTANT (IPP_TAG_LANGUAGE);
INT_CONSTANT (IPP_TAG_MIMETYPE);
// IPP operations
# define INT_IPP_OP_CONSTANT(name) \
INT_CONSTANT(IPP_OP_##name)
INT_IPP_OP_CONSTANT (PRINT_JOB);
INT_IPP_OP_CONSTANT (PRINT_URI);
INT_IPP_OP_CONSTANT (VALIDATE_JOB);
INT_IPP_OP_CONSTANT (CREATE_JOB);
INT_IPP_OP_CONSTANT (SEND_DOCUMENT);
INT_IPP_OP_CONSTANT (SEND_URI);
INT_IPP_OP_CONSTANT (CANCEL_JOB);
INT_IPP_OP_CONSTANT (GET_JOB_ATTRIBUTES);
INT_IPP_OP_CONSTANT (GET_JOBS);
INT_IPP_OP_CONSTANT (GET_PRINTER_ATTRIBUTES);
INT_IPP_OP_CONSTANT (HOLD_JOB);
INT_IPP_OP_CONSTANT (RELEASE_JOB);
INT_IPP_OP_CONSTANT (RESTART_JOB);
INT_IPP_OP_CONSTANT (PAUSE_PRINTER);
INT_IPP_OP_CONSTANT (RESUME_PRINTER);
INT_IPP_OP_CONSTANT (PURGE_JOBS);
INT_IPP_OP_CONSTANT (SET_PRINTER_ATTRIBUTES);
INT_IPP_OP_CONSTANT (SET_JOB_ATTRIBUTES);
INT_IPP_OP_CONSTANT (GET_PRINTER_SUPPORTED_VALUES);
INT_17_CONSTANT (IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS,
IPP_CREATE_PRINTER_SUBSCRIPTION);
INT_17_CONSTANT (IPP_OP_CREATE_JOB_SUBSCRIPTIONS,
IPP_CREATE_JOB_SUBSCRIPTION);
INT_IPP_OP_CONSTANT (GET_SUBSCRIPTIONS);
INT_IPP_OP_CONSTANT (RENEW_SUBSCRIPTION);
INT_IPP_OP_CONSTANT (CANCEL_SUBSCRIPTION);
INT_IPP_OP_CONSTANT (GET_NOTIFICATIONS);
INT_IPP_OP_CONSTANT (SEND_NOTIFICATIONS);
INT_IPP_OP_CONSTANT (GET_RESOURCE_ATTRIBUTES);
INT_IPP_OP_CONSTANT (GET_RESOURCE_DATA);
INT_IPP_OP_CONSTANT (GET_RESOURCES);
INT_IPP_OP_CONSTANT (GET_PRINT_SUPPORT_FILES);
INT_IPP_OP_CONSTANT (ENABLE_PRINTER);
INT_IPP_OP_CONSTANT (DISABLE_PRINTER);
INT_IPP_OP_CONSTANT (PAUSE_PRINTER_AFTER_CURRENT_JOB);
INT_IPP_OP_CONSTANT (HOLD_NEW_JOBS);
INT_IPP_OP_CONSTANT (RELEASE_HELD_NEW_JOBS);
INT_IPP_OP_CONSTANT (DEACTIVATE_PRINTER);
INT_IPP_OP_CONSTANT (ACTIVATE_PRINTER);
INT_IPP_OP_CONSTANT (RESTART_PRINTER);
INT_IPP_OP_CONSTANT (SHUTDOWN_PRINTER);
INT_IPP_OP_CONSTANT (STARTUP_PRINTER);
INT_IPP_OP_CONSTANT (REPROCESS_JOB);
INT_IPP_OP_CONSTANT (CANCEL_CURRENT_JOB);
INT_IPP_OP_CONSTANT (SUSPEND_CURRENT_JOB);
INT_IPP_OP_CONSTANT (RESUME_JOB);
INT_IPP_OP_CONSTANT (PROMOTE_JOB);
INT_IPP_OP_CONSTANT (SCHEDULE_JOB_AFTER);
INT_IPP_OP_CONSTANT (CANCEL_JOBS);
INT_IPP_OP_CONSTANT (CANCEL_MY_JOBS);
INT_IPP_OP_CONSTANT (RESUBMIT_JOB);
INT_IPP_OP_CONSTANT (CLOSE_JOB);
INT_IPP_OP_CONSTANT (IDENTIFY_PRINTER);
INT_IPP_OP_CONSTANT (VALIDATE_DOCUMENT);
INT_IPP_OP_CONSTANT (SEND_HARDCOPY_DOCUMENT);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_DEFAULT, CUPS_GET_DEFAULT);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_PRINTERS, CUPS_GET_PRINTERS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_ADD_MODIFY_PRINTER,
CUPS_ADD_MODIFY_PRINTER);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_DELETE_PRINTER, CUPS_DELETE_PRINTER);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_CLASSES, CUPS_GET_CLASSES);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_ADD_MODIFY_CLASS, CUPS_ADD_MODIFY_CLASS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_DELETE_CLASS, CUPS_DELETE_CLASS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_ACCEPT_JOBS, CUPS_ACCEPT_JOBS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_REJECT_JOBS, CUPS_REJECT_JOBS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_SET_DEFAULT, CUPS_SET_DEFAULT);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_PPDS, CUPS_GET_PPDS);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_MOVE_JOB, CUPS_MOVE_JOB);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_AUTHENTICATE_JOB, CUPS_AUTHENTICATE_JOB);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_PPD, CUPS_GET_PPD);
INT_17_CONSTANT_NEWNAME (IPP_OP_CUPS_GET_DOCUMENT, CUPS_GET_DOCUMENT);
// Limits
INT_CONSTANT (IPP_MAX_NAME);
// PPD conformance levels
INT_CONSTANT (PPD_CONFORM_RELAXED);
INT_CONSTANT (PPD_CONFORM_STRICT);
// Admin Util constants
STR_CONSTANT (CUPS_SERVER_DEBUG_LOGGING);
STR_CONSTANT (CUPS_SERVER_REMOTE_ADMIN);
STR_CONSTANT (CUPS_SERVER_REMOTE_PRINTERS);
STR_CONSTANT (CUPS_SERVER_SHARE_PRINTERS);
STR_CONSTANT (CUPS_SERVER_USER_CANCEL_ANY);
STR_CONSTANT (CUPS_SERVER_REMOTE_ANY);
// Dest enumeration flags
INT_CONSTANT (CUPS_DEST_FLAGS_NONE);
INT_CONSTANT (CUPS_DEST_FLAGS_UNCONNECTED);
INT_CONSTANT (CUPS_DEST_FLAGS_MORE);
INT_CONSTANT (CUPS_DEST_FLAGS_REMOVED);
INT_CONSTANT (CUPS_DEST_FLAGS_ERROR);
INT_CONSTANT (CUPS_DEST_FLAGS_RESOLVING);
INT_CONSTANT (CUPS_DEST_FLAGS_CONNECTING);
INT_CONSTANT (CUPS_DEST_FLAGS_CANCELED);
// Exceptions
obj = PyDict_New ();
PyDict_SetItemString (obj, "__doc__", PyUnicode_FromString(
"This exception is raised when an HTTP problem has occurred. It \n"
"provides an integer HTTP status code.\n\n"
"Use it like this::\n"
" try:\n"
" ...\n"
" except cups.HTTPError as (status):\n"
" print 'HTTP status is %d' % status\n"));
HTTPError = PyErr_NewException ("cups.HTTPError", NULL, obj);
Py_DECREF (obj);
if (HTTPError == NULL)
INITERROR;
Py_INCREF (HTTPError);
PyModule_AddObject (m, "HTTPError", HTTPError);
obj = PyDict_New ();
PyDict_SetItemString (obj, "__doc__", PyUnicode_FromString(
"This exception is raised when an IPP error has occurred. It \n"
"provides an integer IPP status code, and a human-readable string \n"
"describing the error.\n\n"
"Use it like this::\n"
" try:\n"
" ...\n"
" except cups.IPPError as (status, description):\n"
" print 'IPP status is %d' % status\n"
" print 'Meaning:', description\n"));
IPPError = PyErr_NewException ("cups.IPPError", NULL, obj);
Py_DECREF (obj);
if (IPPError == NULL)
INITERROR;
Py_INCREF (IPPError);
PyModule_AddObject (m, "IPPError", IPPError);
return m;
}
///////////////
// Debugging //
///////////////
#define ENVAR "PYCUPS_DEBUG"
static int debugging_enabled = -1;
void
debugprintf (const char *fmt, ...)
{
if (!debugging_enabled)
return;
if (debugging_enabled == -1)
{
if (!getenv (ENVAR))
{
debugging_enabled = 0;
return;
}
debugging_enabled = 1;
}
{
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
}
}
|