]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/ipp-support.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cups / ipp-support.c
CommitLineData
ef416fc2 1/*
d21dc0ed 2 * Internet Printing Protocol support functions for CUPS.
ef416fc2 3 *
7e86f2f6 4 * Copyright 2007-2014 by Apple Inc.
d21dc0ed 5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 6 *
d21dc0ed
MS
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 12 *
d21dc0ed 13 * This file is subject to the Apple OS-Developed Software exception.
ef416fc2 14 */
15
16/*
17 * Include necessary headers...
18 */
19
71e16022 20#include "cups-private.h"
ef416fc2 21
22
23/*
24 * Local globals...
25 */
26
d21dc0ed
MS
27static const char * const ipp_states[] =
28 {
29 "IPP_STATE_ERROR",
30 "IPP_STATE_IDLE",
31 "IPP_STATE_HEADER",
32 "IPP_STATE_ATTRIBUTE",
33 "IPP_STATE_DATA"
34 };
ef416fc2 35static const char * const ipp_status_oks[] = /* "OK" status codes */
a2326b5b 36 { /* (name) = abandoned standard value */
ef416fc2 37 "successful-ok",
38 "successful-ok-ignored-or-substituted-attributes",
39 "successful-ok-conflicting-attributes",
40 "successful-ok-ignored-subscriptions",
a2326b5b 41 "(successful-ok-ignored-notifications)",
ef416fc2 42 "successful-ok-too-many-events",
a2326b5b 43 "(successful-ok-but-cancel-subscription)",
bd7854cb 44 "successful-ok-events-complete"
ef416fc2 45 },
46 * const ipp_status_400s[] = /* Client errors */
a2326b5b 47 { /* (name) = abandoned standard value */
ef416fc2 48 "client-error-bad-request",
49 "client-error-forbidden",
50 "client-error-not-authenticated",
51 "client-error-not-authorized",
52 "client-error-not-possible",
53 "client-error-timeout",
54 "client-error-not-found",
55 "client-error-gone",
56 "client-error-request-entity-too-large",
57 "client-error-request-value-too-long",
58 "client-error-document-format-not-supported",
59 "client-error-attributes-or-values-not-supported",
60 "client-error-uri-scheme-not-supported",
61 "client-error-charset-not-supported",
62 "client-error-conflicting-attributes",
63 "client-error-compression-not-supported",
64 "client-error-compression-error",
65 "client-error-document-format-error",
66 "client-error-document-access-error",
67 "client-error-attributes-not-settable",
68 "client-error-ignored-all-subscriptions",
69 "client-error-too-many-subscriptions",
a2326b5b 70 "(client-error-ignored-all-notifications)",
82cc1f9a
MS
71 "(client-error-client-print-support-file-not-found)",
72 "client-error-document-password-error",
73 "client-error-document-permission-error",
74 "client-error-document-security-error",
6b13fa61
MS
75 "client-error-document-unprintable-error",
76 "client-error-account-info-needed",
77 "client-error-account-closed",
78 "client-error-account-limit-reached",
c47d4869
MS
79 "client-error-account-authorization-failed",
80 "client-error-not-fetchable"
ef416fc2 81 },
a469f8a5
MS
82 * const ipp_status_480s[] = /* Vendor client errors */
83 {
84 /* 0x0480 - 0x048F */
85 "0x0480",
86 "0x0481",
87 "0x0482",
88 "0x0483",
89 "0x0484",
90 "0x0485",
91 "0x0486",
92 "0x0487",
93 "0x0488",
94 "0x0489",
95 "0x048A",
96 "0x048B",
97 "0x048C",
98 "0x048D",
99 "0x048E",
100 "0x048F",
101 /* 0x0490 - 0x049F */
102 "0x0490",
103 "0x0491",
104 "0x0492",
105 "0x0493",
106 "0x0494",
107 "0x0495",
108 "0x0496",
109 "0x0497",
110 "0x0498",
111 "0x0499",
112 "0x049A",
113 "0x049B",
114 "cups-error-account-info-needed",
115 "cups-error-account-closed",
116 "cups-error-account-limit-reached",
117 "cups-error-account-authorization-failed"
118 },
ef416fc2 119 * const ipp_status_500s[] = /* Server errors */
120 {
121 "server-error-internal-error",
122 "server-error-operation-not-supported",
123 "server-error-service-unavailable",
124 "server-error-version-not-supported",
125 "server-error-device-error",
126 "server-error-temporary-error",
127 "server-error-not-accepting-jobs",
128 "server-error-busy",
129 "server-error-job-canceled",
130 "server-error-multiple-document-jobs-not-supported",
a2326b5b
MS
131 "server-error-printer-is-deactivated",
132 "server-error-too-many-jobs",
133 "server-error-too-many-documents"
7cf5915e
MS
134 },
135 * const ipp_status_1000s[] = /* CUPS internal */
136 {
a469f8a5 137 "cups-authentication-canceled",
7cf5915e
MS
138 "cups-pki-error",
139 "cups-upgrade-required"
ef416fc2 140 };
a2326b5b 141static const char * const ipp_std_ops[] =
ef416fc2 142 {
143 /* 0x0000 - 0x000f */
db8b865d
MS
144 "0x0000",
145 "0x0001",
aaf19ab0
MS
146 "Print-Job",
147 "Print-URI",
148 "Validate-Job",
149 "Create-Job",
150 "Send-Document",
151 "Send-URI",
152 "Cancel-Job",
153 "Get-Job-Attributes",
154 "Get-Jobs",
155 "Get-Printer-Attributes",
156 "Hold-Job",
157 "Release-Job",
158 "Restart-Job",
db8b865d 159 "0x000f",
ef416fc2 160
161 /* 0x0010 - 0x001f */
aaf19ab0
MS
162 "Pause-Printer",
163 "Resume-Printer",
164 "Purge-Jobs",
165 "Set-Printer-Attributes",
ef416fc2 166 "Set-Job-Attributes",
167 "Get-Printer-Supported-Values",
42404685
MS
168 "Create-Printer-Subscriptions",
169 "Create-Job-Subscriptions",
ef416fc2 170 "Get-Subscription-Attributes",
aaf19ab0
MS
171 "Get-Subscriptions",
172 "Renew-Subscription",
173 "Cancel-Subscription",
174 "Get-Notifications",
a2326b5b
MS
175 "(Send-Notifications)",
176 "(Get-Resource-Attributes)",
177 "(Get-Resource-Data)",
ef416fc2 178
179 /* 0x0020 - 0x002f */
a2326b5b
MS
180 "(Get-Resources)",
181 "(Get-Printer-Support-Files)",
ef416fc2 182 "Enable-Printer",
183 "Disable-Printer",
184 "Pause-Printer-After-Current-Job",
185 "Hold-New-Jobs",
186 "Release-Held-New-Jobs",
187 "Deactivate-Printer",
188 "Activate-Printer",
189 "Restart-Printer",
190 "Shutdown-Printer",
191 "Startup-Printer",
192 "Reprocess-Job",
193 "Cancel-Current-Job",
194 "Suspend-Current-Job",
195 "Resume-Job",
196
9b4bd602 197 /* 0x0030 - 0x003f */
ef416fc2 198 "Promote-Job",
aaf19ab0 199 "Schedule-Job-After",
db8b865d 200 "0x0032",
aaf19ab0
MS
201 "Cancel-Document",
202 "Get-Document-Attributes",
203 "Get-Documents",
204 "Delete-Document",
205 "Set-Document-Attributes",
206 "Cancel-Jobs",
207 "Cancel-My-Jobs",
208 "Resubmit-Job",
771bd8cb 209 "Close-Job",
82cc1f9a 210 "Identify-Printer",
9475ec92 211 "Validate-Document",
9b4bd602
MS
212 "Send-Hardcopy-Document",
213 "Acknowledge-Document",
214
215 /* 0x0040 - 0x004a */
216 "Acknowledge-Identify-Printer",
217 "Acknowledge-Job",
218 "Fetch-Document",
219 "Fetch-Job",
220 "Get-Output-Device-Attributes",
221 "Update-Active-Jobs",
222 "Deregister-Output-Device",
223 "Update-Document-Status",
224 "Update-Job-Status",
225 "Update-Output-Device-Attributes",
226 "Get-Next-Document-Data"
ef416fc2 227 },
228 * const ipp_cups_ops[] =
229 {
230 "CUPS-Get-Default",
231 "CUPS-Get-Printers",
480ef0fe 232 "CUPS-Add-Modify-Printer",
ef416fc2 233 "CUPS-Delete-Printer",
234 "CUPS-Get-Classes",
480ef0fe 235 "CUPS-Add-Modify-Class",
ef416fc2 236 "CUPS-Delete-Class",
237 "CUPS-Accept-Jobs",
238 "CUPS-Reject-Jobs",
239 "CUPS-Set-Default",
240 "CUPS-Get-Devices",
241 "CUPS-Get-PPDs",
242 "CUPS-Move-Job",
b94498cf 243 "CUPS-Authenticate-Job",
244 "CUPS-Get-PPD"
2e4ff8af
MS
245 },
246 * const ipp_cups_ops2[] =
247 {
95ece0cb
MS
248 "CUPS-Get-Document",
249 "CUPS-Create-Local-Printer"
1ff0402e
MS
250 },
251 * const ipp_tag_names[] =
252 { /* Value/group tag names */
253 "zero", /* 0x00 */
254 "operation-attributes-tag",
255 /* 0x01 */
256 "job-attributes-tag", /* 0x02 */
257 "end-of-attributes-tag",
258 /* 0x03 */
259 "printer-attributes-tag",
260 /* 0x04 */
261 "unsupported-attributes-tag",
262 /* 0x05 */
263 "subscription-attributes-tag",
264 /* 0x06 */
265 "event-notification-attributes-tag",
266 /* 0x07 */
a2326b5b
MS
267 "(resource-attributes-tag)",
268 /* 0x08 */
d7225fc2
MS
269 "document-attributes-tag",
270 /* 0x09 */
271 "0x0a", /* 0x0a */
272 "0x0b", /* 0x0b */
273 "0x0c", /* 0x0c */
274 "0x0d", /* 0x0d */
275 "0x0e", /* 0x0e */
276 "0x0f", /* 0x0f */
1ff0402e
MS
277 "unsupported", /* 0x10 */
278 "default", /* 0x11 */
279 "unknown", /* 0x12 */
280 "no-value", /* 0x13 */
d7225fc2 281 "0x14", /* 0x14 */
1ff0402e
MS
282 "not-settable", /* 0x15 */
283 "delete-attribute", /* 0x16 */
284 "admin-define", /* 0x17 */
d7225fc2
MS
285 "0x18", /* 0x18 */
286 "0x19", /* 0x19 */
287 "0x1a", /* 0x1a */
288 "0x1b", /* 0x1b */
289 "0x1c", /* 0x1c */
290 "0x1d", /* 0x1d */
291 "0x1e", /* 0x1e */
292 "0x1f", /* 0x1f */
293 "0x20", /* 0x20 */
1ff0402e
MS
294 "integer", /* 0x21 */
295 "boolean", /* 0x22 */
296 "enum", /* 0x23 */
d7225fc2
MS
297 "0x24", /* 0x24 */
298 "0x25", /* 0x25 */
299 "0x26", /* 0x26 */
300 "0x27", /* 0x27 */
301 "0x28", /* 0x28 */
302 "0x29", /* 0x29 */
303 "0x2a", /* 0x2a */
304 "0x2b", /* 0x2b */
305 "0x2c", /* 0x2c */
306 "0x2d", /* 0x2d */
307 "0x2e", /* 0x2e */
308 "0x2f", /* 0x2f */
1ff0402e
MS
309 "octetString", /* 0x30 */
310 "dateTime", /* 0x31 */
311 "resolution", /* 0x32 */
312 "rangeOfInteger", /* 0x33 */
f8b3a85b 313 "collection", /* 0x34 */
1ff0402e
MS
314 "textWithLanguage", /* 0x35 */
315 "nameWithLanguage", /* 0x36 */
316 "endCollection", /* 0x37 */
d7225fc2
MS
317 "0x38", /* 0x38 */
318 "0x39", /* 0x39 */
319 "0x3a", /* 0x3a */
320 "0x3b", /* 0x3b */
321 "0x3c", /* 0x3c */
322 "0x3d", /* 0x3d */
323 "0x3e", /* 0x3e */
324 "0x3f", /* 0x3f */
325 "0x40", /* 0x40 */
1ff0402e
MS
326 "textWithoutLanguage",/* 0x41 */
327 "nameWithoutLanguage",/* 0x42 */
d7225fc2 328 "0x43", /* 0x43 */
1ff0402e
MS
329 "keyword", /* 0x44 */
330 "uri", /* 0x45 */
331 "uriScheme", /* 0x46 */
332 "charset", /* 0x47 */
333 "naturalLanguage", /* 0x48 */
334 "mimeMediaType", /* 0x49 */
335 "memberAttrName" /* 0x4a */
ef416fc2 336 };
a2326b5b
MS
337static const char * const ipp_document_states[] =
338 { /* document-state-enums */
339 "pending",
340 "4",
341 "processing",
cd3614ae 342 "processing-stopped", /* IPPSIX */
a2326b5b
MS
343 "canceled",
344 "aborted",
345 "completed"
346 },
347 * const ipp_finishings[] =
348 { /* finishings enums */
349 "none",
350 "staple",
351 "punch",
352 "cover",
353 "bind",
354 "saddle-stitch",
355 "edge-stitch",
356 "fold",
357 "trim",
358 "bale",
359 "booklet-maker",
360 "jog-offset",
cd3614ae
MS
361 "coat", /* Finishings 2.0 */
362 "laminate", /* Finishings 2.0 */
a2326b5b
MS
363 "17",
364 "18",
365 "19",
366 "staple-top-left",
367 "staple-bottom-left",
368 "staple-top-right",
369 "staple-bottom-right",
370 "edge-stitch-left",
371 "edge-stitch-top",
372 "edge-stitch-right",
373 "edge-stitch-bottom",
374 "staple-dual-left",
375 "staple-dual-top",
376 "staple-dual-right",
377 "staple-dual-bottom",
cd3614ae
MS
378 "staple-triple-left", /* Finishings 2.0 */
379 "staple-triple-top", /* Finishings 2.0 */
380 "staple-triple-right",/* Finishings 2.0 */
381 "staple-triple-bottom",/* Finishings 2.0 */
a2326b5b
MS
382 "36",
383 "37",
384 "38",
385 "39",
386 "40",
387 "41",
388 "42",
389 "43",
390 "44",
391 "45",
392 "46",
393 "47",
394 "48",
395 "49",
396 "bind-left",
397 "bind-top",
398 "bind-right",
399 "bind-bottom",
400 "54",
401 "55",
402 "56",
403 "57",
404 "58",
405 "59",
406 "trim-after-pages",
407 "trim-after-documents",
408 "trim-after-copies",
9475ec92
MS
409 "trim-after-job",
410 "64",
411 "65",
412 "66",
413 "67",
414 "68",
415 "69",
cd3614ae
MS
416 "punch-top-left", /* Finishings 2.0 */
417 "punch-bottom-left", /* Finishings 2.0 */
418 "punch-top-right", /* Finishings 2.0 */
419 "punch-bottom-right", /* Finishings 2.0 */
420 "punch-dual-left", /* Finishings 2.0 */
421 "punch-dual-top", /* Finishings 2.0 */
422 "punch-dual-right", /* Finishings 2.0 */
423 "punch-dual-bottom", /* Finishings 2.0 */
424 "punch-triple-left", /* Finishings 2.0 */
425 "punch-triple-top", /* Finishings 2.0 */
426 "punch-triple-right", /* Finishings 2.0 */
427 "punch-triple-bottom",/* Finishings 2.0 */
428 "punch-quad-left", /* Finishings 2.0 */
429 "punch-quad-top", /* Finishings 2.0 */
430 "punch-quad-right", /* Finishings 2.0 */
431 "punch-quad-bottom", /* Finishings 2.0 */
9475ec92
MS
432 "86",
433 "87",
434 "88",
435 "89",
cd3614ae
MS
436 "fold-accordian", /* Finishings 2.0 */
437 "fold-double-gate", /* Finishings 2.0 */
438 "fold-gate", /* Finishings 2.0 */
439 "fold-half", /* Finishings 2.0 */
440 "fold-half-z", /* Finishings 2.0 */
441 "fold-left-gate", /* Finishings 2.0 */
442 "fold-letter", /* Finishings 2.0 */
443 "fold-parallel", /* Finishings 2.0 */
444 "fold-poster", /* Finishings 2.0 */
445 "fold-right-gate", /* Finishings 2.0 */
446 "fold-z" /* Finishings 2.0 */
a2326b5b 447 },
a469f8a5
MS
448 * const ipp_finishings_vendor[] =
449 {
450 /* 0x40000000 to 0x4000000F */
451 "0x40000000",
452 "0x40000001",
453 "0x40000002",
454 "0x40000003",
455 "0x40000004",
456 "0x40000005",
457 "0x40000006",
458 "0x40000007",
459 "0x40000008",
460 "0x40000009",
461 "0x4000000A",
462 "0x4000000B",
463 "0x4000000C",
464 "0x4000000D",
465 "0x4000000E",
466 "0x4000000F",
467 /* 0x40000010 to 0x4000001F */
468 "0x40000010",
469 "0x40000011",
470 "0x40000012",
471 "0x40000013",
472 "0x40000014",
473 "0x40000015",
474 "0x40000016",
475 "0x40000017",
476 "0x40000018",
477 "0x40000019",
478 "0x4000001A",
479 "0x4000001B",
480 "0x4000001C",
481 "0x4000001D",
482 "0x4000001E",
483 "0x4000001F",
484 /* 0x40000020 to 0x4000002F */
485 "0x40000020",
486 "0x40000021",
487 "0x40000022",
488 "0x40000023",
489 "0x40000024",
490 "0x40000025",
491 "0x40000026",
492 "0x40000027",
493 "0x40000028",
494 "0x40000029",
495 "0x4000002A",
496 "0x4000002B",
497 "0x4000002C",
498 "0x4000002D",
499 "0x4000002E",
500 "0x4000002F",
501 /* 0x40000030 to 0x4000003F */
502 "0x40000030",
503 "0x40000031",
504 "0x40000032",
505 "0x40000033",
506 "0x40000034",
507 "0x40000035",
508 "0x40000036",
509 "0x40000037",
510 "0x40000038",
511 "0x40000039",
512 "0x4000003A",
513 "0x4000003B",
514 "0x4000003C",
515 "0x4000003D",
516 "0x4000003E",
517 "0x4000003F",
518 /* 0x40000040 - 0x4000004F */
519 "0x40000040",
520 "0x40000041",
521 "0x40000042",
522 "0x40000043",
523 "0x40000044",
524 "0x40000045",
9475ec92
MS
525 "cups-punch-top-left",
526 "cups-punch-bottom-left",
527 "cups-punch-top-right",
528 "cups-punch-bottom-right",
529 "cups-punch-dual-left",
530 "cups-punch-dual-top",
531 "cups-punch-dual-right",
532 "cups-punch-dual-bottom",
533 "cups-punch-triple-left",
534 "cups-punch-triple-top",
6961465f 535 /* 0x40000050 - 0x4000005F */
9475ec92
MS
536 "cups-punch-triple-right",
537 "cups-punch-triple-bottom",
538 "cups-punch-quad-left",
539 "cups-punch-quad-top",
540 "cups-punch-quad-right",
541 "cups-punch-quad-bottom",
6961465f
MS
542 "0x40000056",
543 "0x40000057",
544 "0x40000058",
545 "0x40000059",
9475ec92
MS
546 "cups-fold-accordian",
547 "cups-fold-double-gate",
548 "cups-fold-gate",
549 "cups-fold-half",
550 "cups-fold-half-z",
551 "cups-fold-left-gate",
6961465f 552 /* 0x40000060 - 0x40000064 */
9475ec92
MS
553 "cups-fold-letter",
554 "cups-fold-parallel",
555 "cups-fold-poster",
556 "cups-fold-right-gate",
557 "cups-fold-z"
a469f8a5 558 },
a2326b5b
MS
559 * const ipp_job_collation_types[] =
560 { /* job-collation-type enums */
561 "uncollated-sheets",
562 "collated-documents",
563 "uncollated-documents"
564 },
565 * const ipp_job_states[] =
566 { /* job-state enums */
567 "pending",
568 "pending-held",
569 "processing",
570 "processing-stopped",
571 "canceled",
572 "aborted",
573 "completed"
574 },
575 * const ipp_orientation_requesteds[] =
576 { /* orientation-requested enums */
577 "portrait",
578 "landscape",
579 "reverse-landscape",
8f787fca
MS
580 "reverse-portrait",
581 "none"
a2326b5b
MS
582 },
583 * const ipp_print_qualities[] =
584 { /* print-quality enums */
585 "draft",
586 "normal",
587 "high"
588 },
589 * const ipp_printer_states[] =
590 { /* printer-state enums */
591 "idle",
592 "processing",
593 "stopped",
594 };
aaf19ab0
MS
595
596
597/*
598 * Local functions...
599 */
600
601static size_t ipp_col_string(ipp_t *col, char *buffer, size_t bufsize);
602
603
604/*
a2326b5b 605 * 'ippAttributeString()' - Convert the attribute's value to a string.
aaf19ab0
MS
606 *
607 * Returns the number of bytes that would be written, not including the
608 * trailing nul. The buffer pointer can be NULL to get the required length,
609 * just like (v)snprintf.
a2326b5b 610 *
f3c17241 611 * @since CUPS 1.6/OS X 10.8@
aaf19ab0
MS
612 */
613
614size_t /* O - Number of bytes less nul */
a2326b5b
MS
615ippAttributeString(
616 ipp_attribute_t *attr, /* I - Attribute */
617 char *buffer, /* I - String buffer or NULL */
618 size_t bufsize) /* I - Size of string buffer */
aaf19ab0
MS
619{
620 int i; /* Looping var */
621 char *bufptr, /* Pointer into buffer */
622 *bufend, /* End of buffer */
623 temp[256]; /* Temporary string */
db8b865d
MS
624 const char *ptr, /* Pointer into string */
625 *end; /* Pointer to end of string */
a2326b5b 626 _ipp_value_t *val; /* Current value */
aaf19ab0
MS
627
628
629 if (!attr || !attr->name)
630 {
631 if (buffer)
632 *buffer = '\0';
633
634 return (0);
635 }
636
637 bufptr = buffer;
638 if (buffer)
639 bufend = buffer + bufsize - 1;
640 else
641 bufend = NULL;
642
643 for (i = attr->num_values, val = attr->values; i > 0; i --, val ++)
644 {
645 if (val > attr->values)
646 {
7cf5915e 647 if (buffer && bufptr < bufend)
aaf19ab0
MS
648 *bufptr++ = ',';
649 else
650 bufptr ++;
651 }
652
cb7f98ee 653 switch (attr->value_tag & ~IPP_TAG_CUPS_CONST)
aaf19ab0
MS
654 {
655 case IPP_TAG_ENUM :
a2326b5b 656 ptr = ippEnumString(attr->name, val->integer);
aaf19ab0 657
a2326b5b 658 if (buffer && bufptr < bufend)
07623986 659 strlcpy(bufptr, ptr, (size_t)(bufend - bufptr + 1));
9b66acc5 660
a2326b5b
MS
661 bufptr += strlen(ptr);
662 break;
aaf19ab0
MS
663
664 case IPP_TAG_INTEGER :
7cf5915e 665 if (buffer && bufptr < bufend)
07623986 666 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d", val->integer);
aaf19ab0
MS
667 else
668 bufptr += snprintf(temp, sizeof(temp), "%d", val->integer);
669 break;
670
671 case IPP_TAG_BOOLEAN :
7cf5915e 672 if (buffer && bufptr < bufend)
07623986 673 strlcpy(bufptr, val->boolean ? "true" : "false", (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
674
675 bufptr += val->boolean ? 4 : 5;
676 break;
677
678 case IPP_TAG_RANGE :
7cf5915e 679 if (buffer && bufptr < bufend)
07623986 680 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d-%d", val->range.lower, val->range.upper);
aaf19ab0 681 else
07623986 682 bufptr += snprintf(temp, sizeof(temp), "%d-%d", val->range.lower, val->range.upper);
aaf19ab0
MS
683 break;
684
685 case IPP_TAG_RESOLUTION :
4a838088
MS
686 if (val->resolution.xres == val->resolution.yres)
687 {
688 if (buffer && bufptr < bufend)
689 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d%s", val->resolution.xres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
690 else
691 bufptr += snprintf(temp, sizeof(temp), "%d%s", val->resolution.xres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
692 }
693 else if (buffer && bufptr < bufend)
07623986 694 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%dx%d%s", val->resolution.xres, val->resolution.yres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
aaf19ab0 695 else
07623986 696 bufptr += snprintf(temp, sizeof(temp), "%dx%d%s", val->resolution.xres, val->resolution.yres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
aaf19ab0
MS
697 break;
698
699 case IPP_TAG_DATE :
700 {
701 unsigned year; /* Year */
702
7e86f2f6 703 year = ((unsigned)val->date[0] << 8) + (unsigned)val->date[1];
aaf19ab0
MS
704
705 if (val->date[9] == 0 && val->date[10] == 0)
706 snprintf(temp, sizeof(temp), "%04u-%02u-%02uT%02u:%02u:%02uZ",
707 year, val->date[2], val->date[3], val->date[4],
708 val->date[5], val->date[6]);
709 else
710 snprintf(temp, sizeof(temp),
711 "%04u-%02u-%02uT%02u:%02u:%02u%c%02u%02u",
712 year, val->date[2], val->date[3], val->date[4],
713 val->date[5], val->date[6], val->date[8], val->date[9],
714 val->date[10]);
715
7cf5915e 716 if (buffer && bufptr < bufend)
07623986 717 strlcpy(bufptr, temp, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
718
719 bufptr += strlen(temp);
720 }
721 break;
722
723 case IPP_TAG_TEXT :
724 case IPP_TAG_NAME :
725 case IPP_TAG_KEYWORD :
726 case IPP_TAG_CHARSET :
727 case IPP_TAG_URI :
d7225fc2 728 case IPP_TAG_URISCHEME :
aaf19ab0
MS
729 case IPP_TAG_MIMETYPE :
730 case IPP_TAG_LANGUAGE :
731 case IPP_TAG_TEXTLANG :
732 case IPP_TAG_NAMELANG :
7cf5915e
MS
733 if (!val->string.text)
734 break;
735
aaf19ab0
MS
736 for (ptr = val->string.text; *ptr; ptr ++)
737 {
a2326b5b 738 if (*ptr == '\\' || *ptr == '\"' || *ptr == '[')
aaf19ab0 739 {
7cf5915e 740 if (buffer && bufptr < bufend)
aaf19ab0
MS
741 *bufptr = '\\';
742 bufptr ++;
743 }
744
7cf5915e 745 if (buffer && bufptr < bufend)
aaf19ab0
MS
746 *bufptr = *ptr;
747 bufptr ++;
748 }
a2326b5b
MS
749
750 if (val->string.language)
751 {
752 /*
753 * Add "[language]" to end of string...
754 */
755
756 if (buffer && bufptr < bufend)
757 *bufptr = '[';
758 bufptr ++;
759
760 if (buffer && bufptr < bufend)
07623986 761 strlcpy(bufptr, val->string.language, (size_t)(bufend - bufptr));
a2326b5b
MS
762 bufptr += strlen(val->string.language);
763
764 if (buffer && bufptr < bufend)
765 *bufptr = ']';
766 bufptr ++;
767 }
aaf19ab0
MS
768 break;
769
770 case IPP_TAG_BEGIN_COLLECTION :
7cf5915e 771 if (buffer && bufptr < bufend)
7e86f2f6 772 bufptr += ipp_col_string(val->collection, bufptr, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
773 else
774 bufptr += ipp_col_string(val->collection, NULL, 0);
775 break;
776
777 case IPP_TAG_STRING :
db8b865d
MS
778 for (ptr = val->unknown.data, end = ptr + val->unknown.length;
779 ptr < end; ptr ++)
aaf19ab0 780 {
7cf5915e 781 if (*ptr == '\\' || _cups_isspace(*ptr))
aaf19ab0 782 {
7cf5915e 783 if (buffer && bufptr < bufend)
aaf19ab0
MS
784 *bufptr = '\\';
785 bufptr ++;
786
7cf5915e 787 if (buffer && bufptr < bufend)
aaf19ab0
MS
788 *bufptr = *ptr;
789 bufptr ++;
790 }
791 else if (!isprint(*ptr & 255))
792 {
7cf5915e 793 if (buffer && bufptr < bufend)
07623986 794 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "\\%03o", *ptr & 255);
aaf19ab0 795 else
07623986 796 bufptr += snprintf(temp, sizeof(temp), "\\%03o", *ptr & 255);
aaf19ab0
MS
797 }
798 else
799 {
7cf5915e 800 if (buffer && bufptr < bufend)
aaf19ab0
MS
801 *bufptr = *ptr;
802 bufptr ++;
803 }
804 }
805 break;
806
807 default :
808 ptr = ippTagString(attr->value_tag);
7cf5915e 809 if (buffer && bufptr < bufend)
07623986 810 strlcpy(bufptr, ptr, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
811 bufptr += strlen(ptr);
812 break;
813 }
814 }
815
7cf5915e 816 if (buffer && bufptr < bufend)
aaf19ab0
MS
817 *bufptr = '\0';
818 else if (bufend)
819 *bufend = '\0';
820
7e86f2f6 821 return ((size_t)(bufptr - buffer));
aaf19ab0 822}
ef416fc2 823
824
db8b865d
MS
825/*
826 * 'ippCreateRequestedArray()' - Create a CUPS array of attribute names from the
827 * given requested-attributes attribute.
828 *
829 * This function creates a (sorted) CUPS array of attribute names matching the
830 * list of "requested-attribute" values supplied in an IPP request. All IANA-
831 * registered values are supported in addition to the CUPS IPP extension
832 * attributes.
833 *
834 * The @code request@ parameter specifies the request message that was read from
835 * the client.
836 *
837 * @code NULL@ is returned if all attributes should be returned. Otherwise, the
838 * result is a sorted array of attribute names, where @code cupsArrayFind(array,
839 * "attribute-name")@ will return a non-NULL pointer. The array must be freed
840 * using the @code cupsArrayDelete@ function.
841 *
9c0e8e5d 842 * @since CUPS 1.7/OS X 10.9@
db8b865d
MS
843 */
844
845cups_array_t * /* O - CUPS array or @code NULL@ if all */
846ippCreateRequestedArray(ipp_t *request) /* I - IPP request */
847{
848 int i, j, /* Looping vars */
849 count, /* Number of values */
850 added; /* Was name added? */
851 ipp_attribute_t *requested; /* requested-attributes attribute */
852 cups_array_t *ra; /* Requested attributes array */
853 const char *value; /* Current value */
854 /* The following lists come from the current IANA IPP registry of attributes */
855 static const char * const document_description[] =
856 { /* document-description group */
857 "compression",
858 "copies-actual",
859 "cover-back-actual",
860 "cover-front-actual",
861 "current-page-order",
862 "date-time-at-completed",
863 "date-time-at-creation",
864 "date-time-at-processing",
865 "detailed-status-messages",
866 "document-access-errors",
867 "document-charset",
868 "document-digital-signature",
869 "document-format",
870 "document-format-details",
871 "document-format-detected",
872 "document-format-version",
873 "document-format-version-detected",
874 "document-job-id",
875 "document-job-uri",
876 "document-message",
877 "document-metadata",
878 "document-name",
879 "document-natural-language",
880 "document-number",
881 "document-printer-uri",
882 "document-state",
883 "document-state-message",
884 "document-state-reasons",
885 "document-uri",
886 "document-uuid",
887 "errors-count",
888 "finishings-actual",
889 "finishings-col-actual",
890 "force-front-side-actual",
891 "imposition-template-actual",
892 "impressions",
893 "impressions-completed",
894 "impressions-completed-current-copy",
895 "insert-sheet-actual",
896 "k-octets",
897 "k-octets-processed",
898 "last-document",
899 "media-actual",
900 "media-col-actual",
901 "media-input-tray-check-actual",
902 "media-sheets",
903 "media-sheets-completed",
904 "more-info",
905 "number-up-actual",
906 "orientation-requested-actual",
907 "output-bin-actual",
908 "output-device-assigned",
909 "overrides-actual",
910 "page-delivery-actual",
911 "page-order-received-actual",
912 "page-ranges-actual",
913 "pages",
914 "pages-completed",
915 "pages-completed-current-copy",
916 "presentation-direction-number-up-actual",
917 "print-color-mode-actual",
918 "print-content-optimize-actual",
919 "print-quality-actual",
920 "print-rendering-intent-actual",
6961465f 921 "print-scaling-actual", /* IPP Paid Printing */
db8b865d
MS
922 "printer-resolution-actual",
923 "printer-up-time",
924 "separator-sheets-actual",
925 "sheet-completed-copy-number",
926 "sides-actual",
927 "time-at-completed",
928 "time-at-creation",
929 "time-at-processing",
930 "x-image-position-actual",
931 "x-image-shift-actual",
932 "x-side1-image-shift-actual",
933 "x-side2-image-shift-actual",
934 "y-image-position-actual",
935 "y-image-shift-actual",
936 "y-side1-image-shift-actual",
937 "y-side2-image-shift-actual"
938 };
939 static const char * const document_template[] =
940 { /* document-template group */
941 "copies",
942 "copies-default",
943 "copies-supported",
944 "cover-back",
945 "cover-back-default",
946 "cover-back-supported",
947 "cover-front",
948 "cover-front-default",
949 "cover-front-supported",
950 "feed-orientation",
951 "feed-orientation-default",
952 "feed-orientation-supported",
953 "finishings",
954 "finishings-col",
955 "finishings-col-default",
956 "finishings-col-supported",
957 "finishings-default",
958 "finishings-supported",
959 "font-name-requested",
960 "font-name-requested-default",
961 "font-name-requested-supported",
962 "font-size-requested",
963 "font-size-requested-default",
964 "font-size-requested-supported",
965 "force-front-side",
966 "force-front-side-default",
967 "force-front-side-supported",
968 "imposition-template",
969 "imposition-template-default",
970 "imposition-template-supported",
971 "insert-after-page-number-supported",
972 "insert-count-supported",
973 "insert-sheet",
974 "insert-sheet-default",
975 "insert-sheet-supported",
976 "max-stitching-locations-supported",
977 "media",
978 "media-back-coating-supported",
979 "media-bottom-margin-supported",
980 "media-col",
981 "media-col-default",
982 "media-col-supported",
983 "media-color-supported",
984 "media-default",
985 "media-front-coating-supported",
986 "media-grain-supported",
987 "media-hole-count-supported",
988 "media-info-supported",
989 "media-input-tray-check",
990 "media-input-tray-check-default",
991 "media-input-tray-check-supported",
992 "media-key-supported",
993 "media-left-margin-supported",
994 "media-order-count-supported",
995 "media-pre-printed-supported",
996 "media-recycled-supported",
997 "media-right-margin-supported",
998 "media-size-supported",
999 "media-source-supported",
1000 "media-supported",
1001 "media-thickness-supported",
1002 "media-top-margin-supported",
1003 "media-type-supported",
1004 "media-weight-metric-supported",
1005 "multiple-document-handling",
1006 "multiple-document-handling-default",
1007 "multiple-document-handling-supported",
1008 "number-up",
1009 "number-up-default",
1010 "number-up-supported",
1011 "orientation-requested",
1012 "orientation-requested-default",
1013 "orientation-requested-supported",
6961465f
MS
1014 "output-mode", /* CUPS extension */
1015 "output-mode-default", /* CUPS extension */
1016 "output-mode-supported", /* CUPS extension */
db8b865d
MS
1017 "overrides",
1018 "overrides-supported",
1019 "page-delivery",
1020 "page-delivery-default",
1021 "page-delivery-supported",
1022 "page-order-received",
1023 "page-order-received-default",
1024 "page-order-received-supported",
1025 "page-ranges",
1026 "page-ranges-supported",
1027 "pages-per-subset",
1028 "pages-per-subset-supported",
1029 "pdl-init-file",
1030 "pdl-init-file-default",
1031 "pdl-init-file-entry-supported",
1032 "pdl-init-file-location-supported",
1033 "pdl-init-file-name-subdirectory-supported",
1034 "pdl-init-file-name-supported",
1035 "pdl-init-file-supported",
1036 "presentation-direction-number-up",
1037 "presentation-direction-number-up-default",
1038 "presentation-direction-number-up-supported",
1039 "print-color-mode",
1040 "print-color-mode-default",
1041 "print-color-mode-supported",
1042 "print-content-optimize",
1043 "print-content-optimize-default",
1044 "print-content-optimize-supported",
1045 "print-quality",
1046 "print-quality-default",
1047 "print-quality-supported",
1048 "print-rendering-intent",
1049 "print-rendering-intent-default",
1050 "print-rendering-intent-supported",
6961465f
MS
1051 "print-scaling", /* IPP Paid Printing */
1052 "print-scaling-default", /* IPP Paid Printing */
1053 "print-scaling-supported", /* IPP Paid Printing */
db8b865d
MS
1054 "printer-resolution",
1055 "printer-resolution-default",
1056 "printer-resolution-supported",
1057 "separator-sheets",
1058 "separator-sheets-default",
1059 "separator-sheets-supported",
1060 "sheet-collate",
1061 "sheet-collate-default",
1062 "sheet-collate-supported",
1063 "sides",
1064 "sides-default",
1065 "sides-supported",
1066 "stitching-locations-supported",
1067 "stitching-offset-supported",
1068 "x-image-position",
1069 "x-image-position-default",
1070 "x-image-position-supported",
1071 "x-image-shift",
1072 "x-image-shift-default",
1073 "x-image-shift-supported",
1074 "x-side1-image-shift",
1075 "x-side1-image-shift-default",
1076 "x-side1-image-shift-supported",
1077 "x-side2-image-shift",
1078 "x-side2-image-shift-default",
1079 "x-side2-image-shift-supported",
1080 "y-image-position",
1081 "y-image-position-default",
1082 "y-image-position-supported",
1083 "y-image-shift",
1084 "y-image-shift-default",
1085 "y-image-shift-supported",
1086 "y-side1-image-shift",
1087 "y-side1-image-shift-default",
1088 "y-side1-image-shift-supported",
1089 "y-side2-image-shift",
1090 "y-side2-image-shift-default",
1091 "y-side2-image-shift-supported"
1092 };
1093 static const char * const job_description[] =
1094 { /* job-description group */
1095 "compression-supplied",
1096 "copies-actual",
1097 "cover-back-actual",
1098 "cover-front-actual",
1099 "current-page-order",
1100 "date-time-at-completed",
1101 "date-time-at-creation",
1102 "date-time-at-processing",
1103 "destination-statuses",
1104 "document-charset-supplied",
1105 "document-digital-signature-supplied",
1106 "document-format-details-supplied",
1107 "document-format-supplied",
1108 "document-message-supplied",
1109 "document-metadata",
1110 "document-name-supplied",
1111 "document-natural-language-supplied",
1112 "document-overrides-actual",
1113 "errors-count",
1114 "finishings-actual",
1115 "finishings-col-actual",
1116 "force-front-side-actual",
1117 "imposition-template-actual",
1118 "impressions-completed-current-copy",
1119 "insert-sheet-actual",
1120 "job-account-id-actual",
1121 "job-accounting-sheets-actual",
1122 "job-accounting-user-id-actual",
1123 "job-attribute-fidelity",
1124 "job-charge-info", /* CUPS extension */
1125 "job-collation-type",
1126 "job-collation-type-actual",
1127 "job-copies-actual",
1128 "job-cover-back-actual",
1129 "job-cover-front-actual",
1130 "job-detailed-status-message",
1131 "job-document-access-errors",
1132 "job-error-sheet-actual",
1133 "job-finishings-actual",
1134 "job-finishings-col-actual",
1135 "job-hold-until-actual",
1136 "job-id",
1137 "job-impressions",
1138 "job-impressions-completed",
1139 "job-k-octets",
1140 "job-k-octets-processed",
1141 "job-mandatory-attributes",
1142 "job-media-progress", /* CUPS extension */
1143 "job-media-sheets",
1144 "job-media-sheets-completed",
1145 "job-message-from-operator",
1146 "job-more-info",
1147 "job-name",
1148 "job-originating-host-name", /* CUPS extension */
1149 "job-originating-user-name",
1150 "job-originating-user-uri",
1151 "job-pages",
1152 "job-pages-completed",
1153 "job-pages-completed-current-copy",
1154 "job-printer-state-message", /* CUPS extension */
1155 "job-printer-state-reasons", /* CUPS extension */
1156 "job-printer-up-time",
1157 "job-printer-uri",
1158 "job-priority-actual",
1159 "job-save-printer-make-and-model",
1160 "job-sheet-message-actual",
1161 "job-sheets-actual",
1162 "job-sheets-col-actual",
1163 "job-state",
1164 "job-state-message",
1165 "job-state-reasons",
1166 "job-uri",
1167 "job-uuid",
1168 "media-actual",
1169 "media-col-actual",
1170 "media-check-input-tray-actual",
1171 "multiple-document-handling-actual",
1172 "number-of-documents",
1173 "number-of-intervening-jobs",
1174 "number-up-actual",
1175 "orientation-requested-actual",
1176 "original-requesting-user-name",
1177 "output-bin-actual",
1178 "output-device-assigned",
1179 "overrides-actual",
1180 "page-delivery-actual",
1181 "page-order-received-actual",
1182 "page-ranges-actual",
1183 "presentation-direction-number-up-actual",
1184 "print-color-mode-actual",
1185 "print-content-optimize-actual",
1186 "print-quality-actual",
1187 "print-rendering-intent-actual",
6961465f 1188 "print-scaling-actual", /* IPP Paid Printing */
db8b865d
MS
1189 "printer-resolution-actual",
1190 "separator-sheets-actual",
1191 "sheet-collate-actual",
1192 "sheet-completed-copy-number",
1193 "sheet-completed-document-number",
1194 "sides-actual",
1195 "time-at-completed",
1196 "time-at-creation",
1197 "time-at-processing",
1198 "warnings-count",
1199 "x-image-position-actual",
1200 "x-image-shift-actual",
1201 "x-side1-image-shift-actual",
1202 "x-side2-image-shift-actual",
1203 "y-image-position-actual",
1204 "y-image-shift-actual",
1205 "y-side1-image-shift-actual",
1206 "y-side2-image-shift-actual"
1207 };
1208 static const char * const job_template[] =
1209 { /* job-template group */
1210 "confirmation-sheet-print", /* IPP FaxOut */
1211 "confirmation-sheet-print-default",
1212 "copies",
1213 "copies-default",
1214 "copies-supported",
1215 "cover-back",
1216 "cover-back-default",
1217 "cover-back-supported",
1218 "cover-front",
1219 "cover-front-default",
1220 "cover-front-supported",
1221 "cover-sheet-info", /* IPP FaxOut */
1222 "cover-sheet-info-default",
1223 "cover-sheet-info-supported",
1224 "destination-uri-schemes-supported",/* IPP FaxOut */
1225 "destination-uris", /* IPP FaxOut */
1226 "destination-uris-supported",
1227 "feed-orientation",
1228 "feed-orientation-default",
1229 "feed-orientation-supported",
1230 "finishings",
1231 "finishings-col",
1232 "finishings-col-default",
1233 "finishings-col-supported",
1234 "finishings-default",
1235 "finishings-supported",
1236 "font-name-requested",
1237 "font-name-requested-default",
1238 "font-name-requested-supported",
1239 "font-size-requested",
1240 "font-size-requested-default",
1241 "font-size-requested-supported",
1242 "force-front-side",
1243 "force-front-side-default",
1244 "force-front-side-supported",
1245 "imposition-template",
1246 "imposition-template-default",
1247 "imposition-template-supported",
1248 "insert-after-page-number-supported",
1249 "insert-count-supported",
1250 "insert-sheet",
1251 "insert-sheet-default",
1252 "insert-sheet-supported",
1253 "job-account-id",
1254 "job-account-id-default",
1255 "job-account-id-supported",
1256 "job-accounting-sheets"
1257 "job-accounting-sheets-default"
1258 "job-accounting-sheets-supported"
1259 "job-accounting-user-id",
1260 "job-accounting-user-id-default",
1261 "job-accounting-user-id-supported",
1262 "job-copies",
1263 "job-copies-default",
1264 "job-copies-supported",
1265 "job-cover-back",
1266 "job-cover-back-default",
1267 "job-cover-back-supported",
1268 "job-cover-front",
1269 "job-cover-front-default",
1270 "job-cover-front-supported",
1271 "job-delay-output-until",
1272 "job-delay-output-until-default",
1273 "job-delay-output-until-supported",
1274 "job-delay-output-until-time",
1275 "job-delay-output-until-time-default",
1276 "job-delay-output-until-time-supported",
1277 "job-error-action",
1278 "job-error-action-default",
1279 "job-error-action-supported",
1280 "job-error-sheet",
1281 "job-error-sheet-default",
1282 "job-error-sheet-supported",
1283 "job-finishings",
1284 "job-finishings-col",
1285 "job-finishings-col-default",
1286 "job-finishings-col-supported",
1287 "job-finishings-default",
1288 "job-finishings-supported",
1289 "job-hold-until",
1290 "job-hold-until-default",
1291 "job-hold-until-supported",
1292 "job-hold-until-time",
1293 "job-hold-until-time-default",
1294 "job-hold-until-time-supported",
1295 "job-message-to-operator",
1296 "job-message-to-operator-default",
1297 "job-message-to-operator-supported",
1298 "job-phone-number",
1299 "job-phone-number-default",
1300 "job-phone-number-supported",
1301 "job-priority",
1302 "job-priority-default",
1303 "job-priority-supported",
1304 "job-recipient-name",
1305 "job-recipient-name-default",
1306 "job-recipient-name-supported",
1307 "job-save-disposition",
1308 "job-save-disposition-default",
1309 "job-save-disposition-supported",
1310 "job-sheets",
1311 "job-sheets-col",
1312 "job-sheets-col-default",
1313 "job-sheets-col-supported",
1314 "job-sheets-default",
1315 "job-sheets-supported",
1316 "logo-uri-schemes-supported",
1317 "max-save-info-supported",
1318 "max-stitching-locations-supported",
1319 "media",
1320 "media-back-coating-supported",
1321 "media-bottom-margin-supported",
1322 "media-col",
1323 "media-col-default",
1324 "media-col-supported",
1325 "media-color-supported",
1326 "media-default",
1327 "media-front-coating-supported",
1328 "media-grain-supported",
1329 "media-hole-count-supported",
1330 "media-info-supported",
1331 "media-input-tray-check",
1332 "media-input-tray-check-default",
1333 "media-input-tray-check-supported",
1334 "media-key-supported",
1335 "media-left-margin-supported",
1336 "media-order-count-supported",
1337 "media-pre-printed-supported",
1338 "media-recycled-supported",
1339 "media-right-margin-supported",
1340 "media-size-supported",
1341 "media-source-supported",
1342 "media-supported",
1343 "media-thickness-supported",
1344 "media-top-margin-supported",
1345 "media-type-supported",
1346 "media-weight-metric-supported",
1347 "multiple-document-handling",
1348 "multiple-document-handling-default",
1349 "multiple-document-handling-supported",
1350 "number-of-retries", /* IPP FaxOut */
1351 "number-of-retries-default",
1352 "number-of-retries-supported",
1353 "number-up",
1354 "number-up-default",
1355 "number-up-supported",
1356 "orientation-requested",
1357 "orientation-requested-default",
1358 "orientation-requested-supported",
1359 "output-bin",
1360 "output-bin-default",
1361 "output-bin-supported",
1362 "output-device",
1363 "output-device-default",
1364 "output-device-supported",
6961465f
MS
1365 "output-mode", /* CUPS extension */
1366 "output-mode-default", /* CUPS extension */
1367 "output-mode-supported", /* CUPS extension */
db8b865d
MS
1368 "overrides",
1369 "overrides-supported",
1370 "page-delivery",
1371 "page-delivery-default",
1372 "page-delivery-supported",
1373 "page-order-received",
1374 "page-order-received-default",
1375 "page-order-received-supported",
1376 "page-ranges",
1377 "page-ranges-supported",
1378 "pages-per-subset",
1379 "pages-per-subset-supported",
1380 "pdl-init-file",
1381 "pdl-init-file-default",
1382 "pdl-init-file-entry-supported",
1383 "pdl-init-file-location-supported",
1384 "pdl-init-file-name-subdirectory-supported",
1385 "pdl-init-file-name-supported",
1386 "pdl-init-file-supported",
1387 "presentation-direction-number-up",
1388 "presentation-direction-number-up-default",
1389 "presentation-direction-number-up-supported",
1390 "print-color-mode",
1391 "print-color-mode-default",
1392 "print-color-mode-supported",
1393 "print-content-optimize",
1394 "print-content-optimize-default",
1395 "print-content-optimize-supported",
1396 "print-quality",
1397 "print-quality-default",
1398 "print-quality-supported",
1399 "print-rendering-intent",
1400 "print-rendering-intent-default",
1401 "print-rendering-intent-supported",
6961465f
MS
1402 "print-scaling", /* IPP Paid Printing */
1403 "print-scaling-default", /* IPP Paid Printing */
1404 "print-scaling-supported", /* IPP Paid Printing */
db8b865d
MS
1405 "printer-resolution",
1406 "printer-resolution-default",
1407 "printer-resolution-supported",
1408 "proof-print",
1409 "proof-print-default",
1410 "proof-print-supported",
1411 "retry-interval", /* IPP FaxOut */
1412 "retry-interval-default",
1413 "retry-interval-supported",
1414 "retry-timeout", /* IPP FaxOut */
1415 "retry-timeout-default",
1416 "retry-timeout-supported",
1417 "save-disposition-supported",
1418 "save-document-format-default",
1419 "save-document-format-supported",
1420 "save-location-default",
1421 "save-location-supported",
1422 "save-name-subdirectory-supported",
1423 "save-name-supported",
1424 "separator-sheets",
1425 "separator-sheets-default",
1426 "separator-sheets-supported",
1427 "sheet-collate",
1428 "sheet-collate-default",
1429 "sheet-collate-supported",
1430 "sides",
1431 "sides-default",
1432 "sides-supported",
1433 "stitching-locations-supported",
1434 "stitching-offset-supported",
1435 "x-image-position",
1436 "x-image-position-default",
1437 "x-image-position-supported",
1438 "x-image-shift",
1439 "x-image-shift-default",
1440 "x-image-shift-supported",
1441 "x-side1-image-shift",
1442 "x-side1-image-shift-default",
1443 "x-side1-image-shift-supported",
1444 "x-side2-image-shift",
1445 "x-side2-image-shift-default",
1446 "x-side2-image-shift-supported",
1447 "y-image-position",
1448 "y-image-position-default",
1449 "y-image-position-supported",
1450 "y-image-shift",
1451 "y-image-shift-default",
1452 "y-image-shift-supported",
1453 "y-side1-image-shift",
1454 "y-side1-image-shift-default",
1455 "y-side1-image-shift-supported",
1456 "y-side2-image-shift",
1457 "y-side2-image-shift-default",
1458 "y-side2-image-shift-supported"
1459 };
1460 static const char * const printer_description[] =
1461 { /* printer-description group */
1462 "auth-info-required", /* CUPS extension */
1463 "charset-configured",
1464 "charset-supported",
1465 "color-supported",
1466 "compression-supported",
1467 "device-service-count",
1468 "device-uri", /* CUPS extension */
1469 "device-uuid",
1470 "document-charset-default",
1471 "document-charset-supported",
1472 "document-creation-attributes-supported",
1473 "document-digital-signature-default",
1474 "document-digital-signature-supported",
1475 "document-format-default",
1476 "document-format-details-default",
1477 "document-format-details-supported",
1478 "document-format-supported",
1479 "document-format-varying-attributes",
1480 "document-format-version-default",
1481 "document-format-version-supported",
1482 "document-natural-language-default",
1483 "document-natural-language-supported",
1484 "document-password-supported",
1485 "generated-natural-language-supported",
1486 "identify-actions-default",
1487 "identify-actions-supported",
1488 "input-source-supported",
1489 "ipp-features-supported",
1490 "ipp-versions-supported",
1491 "ippget-event-life",
1492 "job-authorization-uri-supported", /* CUPS extension */
1493 "job-constraints-supported",
1494 "job-creation-attributes-supported",
1495 "job-finishings-col-ready",
1496 "job-finishings-ready",
1497 "job-ids-supported",
1498 "job-impressions-supported",
1499 "job-k-limit", /* CUPS extension */
1500 "job-k-octets-supported",
1501 "job-media-sheets-supported",
1502 "job-page-limit", /* CUPS extension */
1503 "job-password-encryption-supported",
1504 "job-password-supported",
1505 "job-quota-period", /* CUPS extension */
1506 "job-resolvers-supported",
1507 "job-settable-attributes-supported",
1508 "job-spooling-supported",
c5b24bfa
MS
1509 "jpeg-k-octets-supported", /* CUPS extension */
1510 "jpeg-x-dimension-supported", /* CUPS extension */
1511 "jpeg-y-dimension-supported", /* CUPS extension */
1512 "landscape-orientation-requested-preferred",
1513 /* CUPS extension */
db8b865d
MS
1514 "marker-change-time", /* CUPS extension */
1515 "marker-colors", /* CUPS extension */
1516 "marker-high-levels", /* CUPS extension */
1517 "marker-levels", /* CUPS extension */
1518 "marker-low-levels", /* CUPS extension */
1519 "marker-message", /* CUPS extension */
1520 "marker-names", /* CUPS extension */
1521 "marker-types", /* CUPS extension */
1522 "media-col-ready",
1523 "media-ready",
1524 "member-names", /* CUPS extension */
1525 "member-uris", /* CUPS extension */
1526 "multiple-destination-uris-supported",/* IPP FaxOut */
1527 "multiple-document-jobs-supported",
1528 "multiple-operation-time-out",
1529 "multiple-operation-time-out-action",
1530 "natural-language-configured",
1531 "operations-supported",
1532 "pages-per-minute",
1533 "pages-per-minute-color",
c5b24bfa
MS
1534 "pdf-k-octets-supported", /* CUPS extension */
1535 "pdf-versions-supported", /* CUPS extension */
db8b865d
MS
1536 "pdl-override-supported",
1537 "port-monitor", /* CUPS extension */
1538 "port-monitor-supported", /* CUPS extension */
1539 "preferred-attributes-supported",
1540 "printer-alert",
1541 "printer-alert-description",
1542 "printer-charge-info",
1543 "printer-charge-info-uri",
1544 "printer-commands", /* CUPS extension */
1545 "printer-current-time",
1546 "printer-detailed-status-messages",
1547 "printer-device-id",
1548 "printer-dns-sd-name", /* CUPS extension */
1549 "printer-driver-installer",
1550 "printer-fax-log-uri", /* IPP FaxOut */
1551 "printer-fax-modem-info", /* IPP FaxOut */
1552 "printer-fax-modem-name", /* IPP FaxOut */
1553 "printer-fax-modem-number", /* IPP FaxOut */
8f787fca
MS
1554 "printer-firmware-name", /* PWG 5110.1 */
1555 "printer-firmware-patches", /* PWG 5110.1 */
1556 "printer-firmware-string-version", /* PWG 5110.1 */
1557 "printer-firmware-version", /* PWG 5110.1 */
db8b865d
MS
1558 "printer-geo-location",
1559 "printer-get-attributes-supported",
1560 "printer-icc-profiles",
1561 "printer-icons",
1562 "printer-info",
8f787fca 1563 "printer-input-tray", /* IPP JPS3 */
db8b865d 1564 "printer-is-accepting-jobs",
6961465f 1565 "printer-is-shared", /* CUPS extension */
7ae00c35 1566 "printer-is-temporary", /* CUPS extension */
6961465f 1567 "printer-kind", /* IPP Paid Printing */
db8b865d
MS
1568 "printer-location",
1569 "printer-make-and-model",
1570 "printer-mandatory-job-attributes",
1571 "printer-message-date-time",
1572 "printer-message-from-operator",
1573 "printer-message-time",
1574 "printer-more-info",
1575 "printer-more-info-manufacturer",
1576 "printer-name",
6961465f 1577 "printer-native-formats",
db8b865d
MS
1578 "printer-organization",
1579 "printer-organizational-unit",
8f787fca 1580 "printer-output-tray", /* IPP JPS3 */
34a63bd9 1581 "printer-queue-id", /* CUPS extension */
db8b865d
MS
1582 "printer-settable-attributes-supported",
1583 "printer-state",
1584 "printer-state-change-date-time",
1585 "printer-state-change-time",
1586 "printer-state-message",
1587 "printer-state-reasons",
1588 "printer-supply",
1589 "printer-supply-description",
1590 "printer-supply-info-uri",
1591 "printer-type", /* CUPS extension */
1592 "printer-up-time",
1593 "printer-uri-supported",
1594 "printer-uuid",
1595 "printer-xri-supported",
1596 "pwg-raster-document-resolution-supported",
1597 "pwg-raster-document-sheet-back",
1598 "pwg-raster-document-type-supported",
1599 "queued-job-count",
1600 "reference-uri-schemes-supported",
1601 "repertoire-supported",
1602 "requesting-user-name-allowed", /* CUPS extension */
1603 "requesting-user-name-denied", /* CUPS extension */
1604 "requesting-user-uri-supported",
1605 "subordinate-printers-supported",
6961465f 1606 "urf-supported", /* CUPS extension */
db8b865d
MS
1607 "uri-authentication-supported",
1608 "uri-security-supported",
1609 "user-defined-value-supported",
1610 "which-jobs-supported",
1611 "xri-authentication-supported",
1612 "xri-security-supported",
1613 "xri-uri-scheme-supported"
1614 };
1615 static const char * const subscription_description[] =
1616 { /* subscription-description group */
1617 "notify-job-id",
1618 "notify-lease-expiration-time",
1619 "notify-printer-up-time",
1620 "notify-printer-uri",
1621 "notify-sequence-number",
1622 "notify-subscriber-user-name",
1623 "notify-subscriber-user-uri",
1624 "notify-subscription-id",
1625 "subscriptions-uuid"
1626 };
1627 static const char * const subscription_template[] =
1628 { /* subscription-template group */
1629 "notify-attributes",
1630 "notify-attributes-supported",
1631 "notify-charset",
1632 "notify-events",
1633 "notify-events-default",
1634 "notify-events-supported",
1635 "notify-lease-duration",
1636 "notify-lease-duration-default",
1637 "notify-lease-duration-supported",
1638 "notify-max-events-supported",
1639 "notify-natural-language",
1640 "notify-pull-method",
1641 "notify-pull-method-supported",
1642 "notify-recipient-uri",
1643 "notify-schemes-supported",
1644 "notify-time-interval",
1645 "notify-user-data"
1646 };
1647
1648
1649 /*
1650 * Get the requested-attributes attribute...
1651 */
1652
1653 if ((requested = ippFindAttribute(request, "requested-attributes",
1654 IPP_TAG_KEYWORD)) == NULL)
1655 {
1656 /*
1657 * The Get-Jobs operation defaults to "job-id" and "job-uri", all others
1658 * default to "all"...
1659 */
1660
cb7f98ee 1661 if (ippGetOperation(request) == IPP_OP_GET_JOBS)
db8b865d
MS
1662 {
1663 ra = cupsArrayNew((cups_array_func_t)strcmp, NULL);
1664 cupsArrayAdd(ra, "job-id");
1665 cupsArrayAdd(ra, "job-uri");
1666
1667 return (ra);
1668 }
1669 else
1670 return (NULL);
1671 }
1672
1673 /*
1674 * If the attribute contains a single "all" keyword, return NULL...
1675 */
1676
1677 count = ippGetCount(requested);
1678 if (count == 1 && !strcmp(ippGetString(requested, 0, NULL), "all"))
1679 return (NULL);
1680
1681 /*
1682 * Create an array using "strcmp" as the comparison function...
1683 */
1684
1685 ra = cupsArrayNew((cups_array_func_t)strcmp, NULL);
1686
1687 for (i = 0; i < count; i ++)
1688 {
1689 added = 0;
1690 value = ippGetString(requested, i, NULL);
1691
1692 if (!strcmp(value, "document-description") || !strcmp(value, "all"))
1693 {
1694 for (j = 0;
1695 j < (int)(sizeof(document_description) /
1696 sizeof(document_description[0]));
1697 j ++)
1698 cupsArrayAdd(ra, (void *)document_description[j]);
1699
1700 added = 1;
1701 }
1702
1703 if (!strcmp(value, "document-template") || !strcmp(value, "all"))
1704 {
1705 for (j = 0;
1706 j < (int)(sizeof(document_template) / sizeof(document_template[0]));
1707 j ++)
1708 cupsArrayAdd(ra, (void *)document_template[j]);
1709
1710 added = 1;
1711 }
1712
1713 if (!strcmp(value, "job-description") || !strcmp(value, "all"))
1714 {
1715 for (j = 0;
1716 j < (int)(sizeof(job_description) / sizeof(job_description[0]));
1717 j ++)
1718 cupsArrayAdd(ra, (void *)job_description[j]);
1719
1720 added = 1;
1721 }
1722
1723 if (!strcmp(value, "job-template") || !strcmp(value, "all"))
1724 {
1725 for (j = 0;
1726 j < (int)(sizeof(job_template) / sizeof(job_template[0]));
1727 j ++)
1728 cupsArrayAdd(ra, (void *)job_template[j]);
1729
1730 added = 1;
1731 }
1732
1733 if (!strcmp(value, "printer-description") || !strcmp(value, "all"))
1734 {
1735 for (j = 0;
1736 j < (int)(sizeof(printer_description) /
1737 sizeof(printer_description[0]));
1738 j ++)
1739 cupsArrayAdd(ra, (void *)printer_description[j]);
1740
1741 added = 1;
1742 }
1743
1744 if (!strcmp(value, "subscription-description") || !strcmp(value, "all"))
1745 {
1746 for (j = 0;
1747 j < (int)(sizeof(subscription_description) /
1748 sizeof(subscription_description[0]));
1749 j ++)
1750 cupsArrayAdd(ra, (void *)subscription_description[j]);
1751
1752 added = 1;
1753 }
1754
1755 if (!strcmp(value, "subscription-template") || !strcmp(value, "all"))
1756 {
1757 for (j = 0;
1758 j < (int)(sizeof(subscription_template) /
1759 sizeof(subscription_template[0]));
1760 j ++)
1761 cupsArrayAdd(ra, (void *)subscription_template[j]);
1762
1763 added = 1;
1764 }
1765
1766 if (!added)
1767 cupsArrayAdd(ra, (void *)value);
1768 }
1769
1770 return (ra);
1771}
1772
1773
a2326b5b
MS
1774/*
1775 * 'ippEnumString()' - Return a string corresponding to the enum value.
1776 */
1777
1778const char * /* O - Enum string */
1779ippEnumString(const char *attrname, /* I - Attribute name */
1780 int enumvalue) /* I - Enum value */
1781{
1782 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
1783
1784
1785 /*
1786 * Check for standard enum values...
1787 */
1788
1789 if (!strcmp(attrname, "document-state") &&
1790 enumvalue >= 3 &&
0fa6c7fa
MS
1791 enumvalue < (3 + (int)(sizeof(ipp_document_states) /
1792 sizeof(ipp_document_states[0]))))
a2326b5b 1793 return (ipp_document_states[enumvalue - 3]);
a469f8a5
MS
1794 else if (!strcmp(attrname, "finishings") ||
1795 !strcmp(attrname, "finishings-actual") ||
1796 !strcmp(attrname, "finishings-default") ||
1797 !strcmp(attrname, "finishings-ready") ||
6961465f
MS
1798 !strcmp(attrname, "finishings-supported") ||
1799 !strcmp(attrname, "job-finishings") ||
1800 !strcmp(attrname, "job-finishings-default") ||
1801 !strcmp(attrname, "job-finishings-supported"))
a469f8a5
MS
1802 {
1803 if (enumvalue >= 3 &&
0fa6c7fa
MS
1804 enumvalue < (3 + (int)(sizeof(ipp_finishings) /
1805 sizeof(ipp_finishings[0]))))
a469f8a5
MS
1806 return (ipp_finishings[enumvalue - 3]);
1807 else if (enumvalue >= 0x40000000 &&
1808 enumvalue <= (0x40000000 + (int)(sizeof(ipp_finishings_vendor) /
1809 sizeof(ipp_finishings_vendor[0]))))
1810 return (ipp_finishings_vendor[enumvalue - 0x40000000]);
1811 }
a2326b5b
MS
1812 else if ((!strcmp(attrname, "job-collation-type") ||
1813 !strcmp(attrname, "job-collation-type-actual")) &&
1814 enumvalue >= 3 &&
0fa6c7fa
MS
1815 enumvalue < (3 + (int)(sizeof(ipp_job_collation_types) /
1816 sizeof(ipp_job_collation_types[0]))))
a2326b5b
MS
1817 return (ipp_job_collation_types[enumvalue - 3]);
1818 else if (!strcmp(attrname, "job-state") &&
cb7f98ee
MS
1819 enumvalue >= IPP_JSTATE_PENDING && enumvalue <= IPP_JSTATE_COMPLETED)
1820 return (ipp_job_states[enumvalue - IPP_JSTATE_PENDING]);
a2326b5b
MS
1821 else if (!strcmp(attrname, "operations-supported"))
1822 return (ippOpString((ipp_op_t)enumvalue));
1823 else if ((!strcmp(attrname, "orientation-requested") ||
1824 !strcmp(attrname, "orientation-requested-actual") ||
1825 !strcmp(attrname, "orientation-requested-default") ||
1826 !strcmp(attrname, "orientation-requested-supported")) &&
1827 enumvalue >= 3 &&
0fa6c7fa
MS
1828 enumvalue < (3 + (int)(sizeof(ipp_orientation_requesteds) /
1829 sizeof(ipp_orientation_requesteds[0]))))
a2326b5b
MS
1830 return (ipp_orientation_requesteds[enumvalue - 3]);
1831 else if ((!strcmp(attrname, "print-quality") ||
1832 !strcmp(attrname, "print-quality-actual") ||
1833 !strcmp(attrname, "print-quality-default") ||
1834 !strcmp(attrname, "print-quality-supported")) &&
1835 enumvalue >= 3 &&
0fa6c7fa
MS
1836 enumvalue < (3 + (int)(sizeof(ipp_print_qualities) /
1837 sizeof(ipp_print_qualities[0]))))
a2326b5b
MS
1838 return (ipp_print_qualities[enumvalue - 3]);
1839 else if (!strcmp(attrname, "printer-state") &&
cb7f98ee
MS
1840 enumvalue >= IPP_PSTATE_IDLE && enumvalue <= IPP_PSTATE_STOPPED)
1841 return (ipp_printer_states[enumvalue - IPP_PSTATE_IDLE]);
a2326b5b
MS
1842
1843 /*
1844 * Not a standard enum value, just return the decimal equivalent...
1845 */
1846
1847 snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "%d", enumvalue);
1848 return (cg->ipp_unknown);
1849}
1850
1851
1852/*
1853 * 'ippEnumValue()' - Return the value associated with a given enum string.
1854 */
1855
1856int /* O - Enum value or -1 if unknown */
1857ippEnumValue(const char *attrname, /* I - Attribute name */
1858 const char *enumstring) /* I - Enum string */
1859{
1860 int i, /* Looping var */
1861 num_strings; /* Number of strings to compare */
1862 const char * const *strings; /* Strings to compare */
1863
1864
1865 /*
1866 * If the string is just a number, return it...
1867 */
1868
1869 if (isdigit(*enumstring & 255))
7e86f2f6 1870 return ((int)strtol(enumstring, NULL, 0));
a2326b5b
MS
1871
1872 /*
1873 * Otherwise look up the string...
1874 */
1875
1876 if (!strcmp(attrname, "document-state"))
1877 {
1878 num_strings = (int)(sizeof(ipp_document_states) / sizeof(ipp_document_states[0]));
1879 strings = ipp_document_states;
1880 }
1881 else if (!strcmp(attrname, "finishings") ||
1882 !strcmp(attrname, "finishings-actual") ||
1883 !strcmp(attrname, "finishings-default") ||
1884 !strcmp(attrname, "finishings-ready") ||
1885 !strcmp(attrname, "finishings-supported"))
1886 {
a469f8a5
MS
1887 for (i = 0;
1888 i < (int)(sizeof(ipp_finishings_vendor) /
1889 sizeof(ipp_finishings_vendor[0]));
1890 i ++)
1891 if (!strcmp(enumstring, ipp_finishings_vendor[i]))
1892 return (i + 0x40000000);
1893
a2326b5b
MS
1894 num_strings = (int)(sizeof(ipp_finishings) / sizeof(ipp_finishings[0]));
1895 strings = ipp_finishings;
1896 }
1897 else if (!strcmp(attrname, "job-collation-type") ||
1898 !strcmp(attrname, "job-collation-type-actual"))
1899 {
1900 num_strings = (int)(sizeof(ipp_job_collation_types) /
1901 sizeof(ipp_job_collation_types[0]));
1902 strings = ipp_job_collation_types;
1903 }
1904 else if (!strcmp(attrname, "job-state"))
1905 {
1906 num_strings = (int)(sizeof(ipp_job_states) / sizeof(ipp_job_states[0]));
1907 strings = ipp_job_states;
1908 }
1909 else if (!strcmp(attrname, "operations-supported"))
1910 return (ippOpValue(enumstring));
1911 else if (!strcmp(attrname, "orientation-requested") ||
1912 !strcmp(attrname, "orientation-requested-actual") ||
1913 !strcmp(attrname, "orientation-requested-default") ||
1914 !strcmp(attrname, "orientation-requested-supported"))
1915 {
1916 num_strings = (int)(sizeof(ipp_orientation_requesteds) /
1917 sizeof(ipp_orientation_requesteds[0]));
1918 strings = ipp_orientation_requesteds;
1919 }
1920 else if (!strcmp(attrname, "print-quality") ||
1921 !strcmp(attrname, "print-quality-actual") ||
1922 !strcmp(attrname, "print-quality-default") ||
1923 !strcmp(attrname, "print-quality-supported"))
1924 {
1925 num_strings = (int)(sizeof(ipp_print_qualities) / sizeof(ipp_print_qualities[0]));
1926 strings = ipp_print_qualities;
1927 }
1928 else if (!strcmp(attrname, "printer-state"))
1929 {
1930 num_strings = (int)(sizeof(ipp_printer_states) / sizeof(ipp_printer_states[0]));
1931 strings = ipp_printer_states;
1932 }
1933 else
1934 return (-1);
1935
1936 for (i = 0; i < num_strings; i ++)
1937 if (!strcmp(enumstring, strings[i]))
1938 return (i + 3);
1939
1940 return (-1);
1941}
1942
1943
ef416fc2 1944/*
1945 * 'ippErrorString()' - Return a name for the given status code.
1946 */
1947
1948const char * /* O - Text string */
1949ippErrorString(ipp_status_t error) /* I - Error status */
1950{
1951 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
1952
1953
1954 /*
1955 * See if the error code is a known value...
1956 */
1957
a469f8a5 1958 if (error >= IPP_STATUS_OK && error <= IPP_STATUS_OK_EVENTS_COMPLETE)
ef416fc2 1959 return (ipp_status_oks[error]);
a469f8a5 1960 else if (error == IPP_STATUS_REDIRECTION_OTHER_SITE)
ef416fc2 1961 return ("redirection-other-site");
a469f8a5 1962 else if (error == IPP_STATUS_CUPS_SEE_OTHER)
b94498cf 1963 return ("cups-see-other");
a469f8a5 1964 else if (error >= IPP_STATUS_ERROR_BAD_REQUEST &&
6b13fa61 1965 error <= IPP_STATUS_ERROR_ACCOUNT_AUTHORIZATION_FAILED)
a469f8a5
MS
1966 return (ipp_status_400s[error - IPP_STATUS_ERROR_BAD_REQUEST]);
1967 else if (error >= 0x480 &&
1968 error <= IPP_STATUS_ERROR_CUPS_ACCOUNT_AUTHORIZATION_FAILED)
1969 return (ipp_status_480s[error - 0x0480]);
1970 else if (error >= IPP_STATUS_ERROR_INTERNAL &&
1971 error <= IPP_STATUS_ERROR_TOO_MANY_DOCUMENTS)
1972 return (ipp_status_500s[error - IPP_STATUS_ERROR_INTERNAL]);
1973 else if (error >= IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED &&
1974 error <= IPP_STATUS_ERROR_CUPS_UPGRADE_REQUIRED)
1975 return (ipp_status_1000s[error -
1976 IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED]);
ef416fc2 1977
1978 /*
d7225fc2 1979 * No, build an "0xxxxx" error string...
ef416fc2 1980 */
1981
d7225fc2 1982 sprintf(cg->ipp_unknown, "0x%04x", error);
ef416fc2 1983
1984 return (cg->ipp_unknown);
1985}
1986
1987
1988/*
1989 * 'ippErrorValue()' - Return a status code for the given name.
1990 *
f3c17241 1991 * @since CUPS 1.2/OS X 10.5@
ef416fc2 1992 */
1993
1994ipp_status_t /* O - IPP status code */
1995ippErrorValue(const char *name) /* I - Name */
1996{
7e86f2f6 1997 size_t i; /* Looping var */
ef416fc2 1998
1999
2000 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
88f9aafc 2001 if (!_cups_strcasecmp(name, ipp_status_oks[i]))
ef416fc2 2002 return ((ipp_status_t)i);
2003
88f9aafc 2004 if (!_cups_strcasecmp(name, "redirection-other-site"))
a469f8a5 2005 return (IPP_STATUS_REDIRECTION_OTHER_SITE);
ef416fc2 2006
88f9aafc 2007 if (!_cups_strcasecmp(name, "cups-see-other"))
a469f8a5 2008 return (IPP_STATUS_CUPS_SEE_OTHER);
b94498cf 2009
ef416fc2 2010 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
88f9aafc 2011 if (!_cups_strcasecmp(name, ipp_status_400s[i]))
ef416fc2 2012 return ((ipp_status_t)(i + 0x400));
2013
a469f8a5
MS
2014 for (i = 0; i < (sizeof(ipp_status_480s) / sizeof(ipp_status_480s[0])); i ++)
2015 if (!_cups_strcasecmp(name, ipp_status_480s[i]))
2016 return ((ipp_status_t)(i + 0x480));
2017
ef416fc2 2018 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
88f9aafc 2019 if (!_cups_strcasecmp(name, ipp_status_500s[i]))
ef416fc2 2020 return ((ipp_status_t)(i + 0x500));
2021
7cf5915e 2022 for (i = 0; i < (sizeof(ipp_status_1000s) / sizeof(ipp_status_1000s[0])); i ++)
88f9aafc 2023 if (!_cups_strcasecmp(name, ipp_status_1000s[i]))
7cf5915e
MS
2024 return ((ipp_status_t)(i + 0x1000));
2025
ef416fc2 2026 return ((ipp_status_t)-1);
2027}
2028
2029
2030/*
2031 * 'ippOpString()' - Return a name for the given operation id.
2032 *
f3c17241 2033 * @since CUPS 1.2/OS X 10.5@
ef416fc2 2034 */
2035
2036const char * /* O - Name */
2037ippOpString(ipp_op_t op) /* I - Operation ID */
2038{
2039 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
2040
2041
2042 /*
2043 * See if the operation ID is a known value...
2044 */
2045
db8b865d 2046 if (op >= IPP_OP_PRINT_JOB && op <= IPP_OP_VALIDATE_DOCUMENT)
ef416fc2 2047 return (ipp_std_ops[op]);
a469f8a5 2048 else if (op == IPP_OP_PRIVATE)
ef416fc2 2049 return ("windows-ext");
a469f8a5 2050 else if (op >= IPP_OP_CUPS_GET_DEFAULT && op <= IPP_OP_CUPS_GET_PPD)
cb7f98ee 2051 return (ipp_cups_ops[op - IPP_OP_CUPS_GET_DEFAULT]);
c585706d
MS
2052 else if (op >= IPP_OP_CUPS_GET_DOCUMENT && op <= IPP_OP_CUPS_CREATE_LOCAL_PRINTER)
2053 return (ipp_cups_ops2[op - IPP_OP_CUPS_GET_DOCUMENT]);
ef416fc2 2054
2055 /*
d7225fc2 2056 * No, build an "0xxxxx" operation string...
ef416fc2 2057 */
2058
9b66acc5 2059 sprintf(cg->ipp_unknown, "0x%04x", op);
ef416fc2 2060
2061 return (cg->ipp_unknown);
2062}
2063
2064
2065/*
2066 * 'ippOpValue()' - Return an operation id for the given name.
2067 *
f3c17241 2068 * @since CUPS 1.2/OS X 10.5@
ef416fc2 2069 */
2070
2071ipp_op_t /* O - Operation ID */
2072ippOpValue(const char *name) /* I - Textual name */
2073{
7e86f2f6 2074 size_t i; /* Looping var */
ef416fc2 2075
2076
9b66acc5
MS
2077 if (!strncmp(name, "0x", 2))
2078 return ((ipp_op_t)strtol(name + 2, NULL, 16));
2079
ef416fc2 2080 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
88f9aafc 2081 if (!_cups_strcasecmp(name, ipp_std_ops[i]))
ef416fc2 2082 return ((ipp_op_t)i);
2083
88f9aafc 2084 if (!_cups_strcasecmp(name, "windows-ext"))
a469f8a5 2085 return (IPP_OP_PRIVATE);
ef416fc2 2086
2087 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
88f9aafc 2088 if (!_cups_strcasecmp(name, ipp_cups_ops[i]))
ef416fc2 2089 return ((ipp_op_t)(i + 0x4001));
2090
2e4ff8af 2091 for (i = 0; i < (sizeof(ipp_cups_ops2) / sizeof(ipp_cups_ops2[0])); i ++)
88f9aafc 2092 if (!_cups_strcasecmp(name, ipp_cups_ops2[i]))
2e4ff8af
MS
2093 return ((ipp_op_t)(i + 0x4027));
2094
42404685
MS
2095 if (!_cups_strcasecmp(name, "Create-Job-Subscription"))
2096 return (IPP_OP_CREATE_JOB_SUBSCRIPTIONS);
2097
2098 if (!_cups_strcasecmp(name, "Create-Printer-Subscription"))
2099 return (IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS);
2100
88f9aafc 2101 if (!_cups_strcasecmp(name, "CUPS-Add-Class"))
a469f8a5 2102 return (IPP_OP_CUPS_ADD_MODIFY_CLASS);
480ef0fe 2103
88f9aafc 2104 if (!_cups_strcasecmp(name, "CUPS-Add-Printer"))
a469f8a5 2105 return (IPP_OP_CUPS_ADD_MODIFY_PRINTER);
480ef0fe 2106
a469f8a5 2107 return (IPP_OP_CUPS_INVALID);
ef416fc2 2108}
2109
2110
2111/*
2112 * 'ippPort()' - Return the default IPP port number.
2113 */
2114
2115int /* O - Port number */
2116ippPort(void)
2117{
ef416fc2 2118 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
2119
2120
d09495fa 2121 DEBUG_puts("ippPort()");
2122
2123 if (!cg->ipp_port)
e07d4801 2124 _cupsSetDefaults();
d09495fa 2125
e07d4801 2126 DEBUG_printf(("1ippPort: Returning %d...", cg->ipp_port));
d09495fa 2127
ef416fc2 2128 return (cg->ipp_port);
2129}
2130
2131
2132/*
2133 * 'ippSetPort()' - Set the default port number.
2134 */
2135
2136void
2137ippSetPort(int p) /* I - Port number to use */
2138{
e07d4801 2139 DEBUG_printf(("ippSetPort(p=%d)", p));
d09495fa 2140
ef416fc2 2141 _cupsGlobals()->ipp_port = p;
2142}
2143
2144
d21dc0ed
MS
2145/*
2146 * 'ippStateString()' - Return the name corresponding to a state value.
2147 *
e1f19878 2148 * @since CUPS 2.0/OS 10.10@
d21dc0ed
MS
2149 */
2150
2151const char * /* O - State name */
2152ippStateString(ipp_state_t state) /* I - State value */
2153{
2154 if (state >= IPP_STATE_ERROR && state <= IPP_STATE_DATA)
2155 return (ipp_states[state - IPP_STATE_ERROR]);
2156 else
2157 return ("UNKNOWN");
2158}
2159
2160
ef416fc2 2161/*
1ff0402e
MS
2162 * 'ippTagString()' - Return the tag name corresponding to a tag value.
2163 *
2164 * The returned names are defined in RFC 2911 and 3382.
2165 *
f3c17241 2166 * @since CUPS 1.4/OS X 10.6@
1ff0402e
MS
2167 */
2168
2169const char * /* O - Tag name */
2170ippTagString(ipp_tag_t tag) /* I - Tag value */
2171{
cb7f98ee 2172 tag &= IPP_TAG_CUPS_MASK;
ed6e7faf 2173
1ff0402e
MS
2174 if (tag < (ipp_tag_t)(sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])))
2175 return (ipp_tag_names[tag]);
2176 else
2177 return ("UNKNOWN");
2178}
2179
2180
2181/*
2182 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
2183 *
2184 * The tag names are defined in RFC 2911 and 3382.
2185 *
f3c17241 2186 * @since CUPS 1.4/OS X 10.6@
1ff0402e
MS
2187 */
2188
2189ipp_tag_t /* O - Tag value */
2190ippTagValue(const char *name) /* I - Tag name */
2191{
7e86f2f6 2192 size_t i; /* Looping var */
1ff0402e
MS
2193
2194
2195 for (i = 0; i < (sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])); i ++)
88f9aafc 2196 if (!_cups_strcasecmp(name, ipp_tag_names[i]))
1ff0402e
MS
2197 return ((ipp_tag_t)i);
2198
88f9aafc 2199 if (!_cups_strcasecmp(name, "operation"))
1ff0402e 2200 return (IPP_TAG_OPERATION);
88f9aafc 2201 else if (!_cups_strcasecmp(name, "job"))
1ff0402e 2202 return (IPP_TAG_JOB);
88f9aafc 2203 else if (!_cups_strcasecmp(name, "printer"))
1ff0402e 2204 return (IPP_TAG_PRINTER);
88f9aafc 2205 else if (!_cups_strcasecmp(name, "unsupported"))
5a6b583a 2206 return (IPP_TAG_UNSUPPORTED_GROUP);
88f9aafc 2207 else if (!_cups_strcasecmp(name, "subscription"))
1ff0402e 2208 return (IPP_TAG_SUBSCRIPTION);
88f9aafc 2209 else if (!_cups_strcasecmp(name, "event"))
5a6b583a 2210 return (IPP_TAG_EVENT_NOTIFICATION);
88f9aafc 2211 else if (!_cups_strcasecmp(name, "language"))
1ff0402e 2212 return (IPP_TAG_LANGUAGE);
88f9aafc 2213 else if (!_cups_strcasecmp(name, "mimetype"))
1ff0402e 2214 return (IPP_TAG_MIMETYPE);
88f9aafc 2215 else if (!_cups_strcasecmp(name, "name"))
1ff0402e 2216 return (IPP_TAG_NAME);
88f9aafc 2217 else if (!_cups_strcasecmp(name, "text"))
1ff0402e 2218 return (IPP_TAG_TEXT);
88f9aafc 2219 else if (!_cups_strcasecmp(name, "begCollection"))
5a6b583a 2220 return (IPP_TAG_BEGIN_COLLECTION);
1ff0402e
MS
2221 else
2222 return (IPP_TAG_ZERO);
2223}
2224
2225
2226/*
1106b00e
MS
2227 * 'ipp_col_string()' - Convert a collection to a string.
2228 */
2229
2230static size_t /* O - Number of bytes */
2231ipp_col_string(ipp_t *col, /* I - Collection attribute */
2232 char *buffer, /* I - Buffer or NULL */
2233 size_t bufsize) /* I - Size of buffer */
2234{
2235 char *bufptr, /* Position in buffer */
2236 *bufend, /* End of buffer */
9c80ffa2 2237 prefix = '{', /* Prefix character */
1106b00e
MS
2238 temp[256]; /* Temporary string */
2239 ipp_attribute_t *attr; /* Current member attribute */
2240
2241
2c69d462
MS
2242 if (!col)
2243 {
2244 if (buffer)
2245 *buffer = '\0';
2246
2247 return (0);
2248 }
2249
1106b00e
MS
2250 bufptr = buffer;
2251 bufend = buffer + bufsize - 1;
2252
1106b00e
MS
2253 for (attr = col->attrs; attr; attr = attr->next)
2254 {
2255 if (!attr->name)
2256 continue;
2257
9c80ffa2
MS
2258 if (buffer && bufptr < bufend)
2259 *bufptr = prefix;
2260 bufptr ++;
2261 prefix = ' ';
2262
1106b00e 2263 if (buffer && bufptr < bufend)
07623986 2264 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%s=", attr->name);
1106b00e
MS
2265 else
2266 bufptr += strlen(attr->name) + 1;
2267
2268 if (buffer && bufptr < bufend)
7e86f2f6 2269 bufptr += ippAttributeString(attr, bufptr, (size_t)(bufend - bufptr + 1));
1106b00e 2270 else
a2326b5b 2271 bufptr += ippAttributeString(attr, temp, sizeof(temp));
1106b00e
MS
2272 }
2273
9c80ffa2
MS
2274 if (prefix == '{')
2275 {
2276 if (buffer && bufptr < bufend)
2277 *bufptr = prefix;
2278 bufptr ++;
2279 }
2280
1106b00e
MS
2281 if (buffer && bufptr < bufend)
2282 *bufptr = '}';
2283 bufptr ++;
2284
7e86f2f6 2285 return ((size_t)(bufptr - buffer));
1106b00e 2286}