]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/ipp-support.c
Fix source file header text duplication text duplication.
[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
57b7b66b 11 * 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",
e06e4eb5 212 "Add-Document-Images",
9b4bd602
MS
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 */
2a8afc20
MS
432 "punch-multiple-left",/* Finishings 2.1/Canon */
433 "punch-multiple-top", /* Finishings 2.1/Canon */
434 "punch-multiple-right",/* Finishings 2.1/Canon */
435 "punch-multiple-bottom",/* Finishings 2.1/Canon */
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 */
2a8afc20
MS
446 "fold-z", /* Finishings 2.0 */
447 "fold-engineering-z" /* Finishings 2.1 */
a2326b5b 448 },
a469f8a5
MS
449 * const ipp_finishings_vendor[] =
450 {
451 /* 0x40000000 to 0x4000000F */
452 "0x40000000",
453 "0x40000001",
454 "0x40000002",
455 "0x40000003",
456 "0x40000004",
457 "0x40000005",
458 "0x40000006",
459 "0x40000007",
460 "0x40000008",
461 "0x40000009",
462 "0x4000000A",
463 "0x4000000B",
464 "0x4000000C",
465 "0x4000000D",
466 "0x4000000E",
467 "0x4000000F",
468 /* 0x40000010 to 0x4000001F */
469 "0x40000010",
470 "0x40000011",
471 "0x40000012",
472 "0x40000013",
473 "0x40000014",
474 "0x40000015",
475 "0x40000016",
476 "0x40000017",
477 "0x40000018",
478 "0x40000019",
479 "0x4000001A",
480 "0x4000001B",
481 "0x4000001C",
482 "0x4000001D",
483 "0x4000001E",
484 "0x4000001F",
485 /* 0x40000020 to 0x4000002F */
486 "0x40000020",
487 "0x40000021",
488 "0x40000022",
489 "0x40000023",
490 "0x40000024",
491 "0x40000025",
492 "0x40000026",
493 "0x40000027",
494 "0x40000028",
495 "0x40000029",
496 "0x4000002A",
497 "0x4000002B",
498 "0x4000002C",
499 "0x4000002D",
500 "0x4000002E",
501 "0x4000002F",
502 /* 0x40000030 to 0x4000003F */
503 "0x40000030",
504 "0x40000031",
505 "0x40000032",
506 "0x40000033",
507 "0x40000034",
508 "0x40000035",
509 "0x40000036",
510 "0x40000037",
511 "0x40000038",
512 "0x40000039",
513 "0x4000003A",
514 "0x4000003B",
515 "0x4000003C",
516 "0x4000003D",
517 "0x4000003E",
518 "0x4000003F",
519 /* 0x40000040 - 0x4000004F */
520 "0x40000040",
521 "0x40000041",
522 "0x40000042",
523 "0x40000043",
524 "0x40000044",
525 "0x40000045",
9475ec92
MS
526 "cups-punch-top-left",
527 "cups-punch-bottom-left",
528 "cups-punch-top-right",
529 "cups-punch-bottom-right",
530 "cups-punch-dual-left",
531 "cups-punch-dual-top",
532 "cups-punch-dual-right",
533 "cups-punch-dual-bottom",
534 "cups-punch-triple-left",
535 "cups-punch-triple-top",
6961465f 536 /* 0x40000050 - 0x4000005F */
9475ec92
MS
537 "cups-punch-triple-right",
538 "cups-punch-triple-bottom",
539 "cups-punch-quad-left",
540 "cups-punch-quad-top",
541 "cups-punch-quad-right",
542 "cups-punch-quad-bottom",
6961465f
MS
543 "0x40000056",
544 "0x40000057",
545 "0x40000058",
546 "0x40000059",
9475ec92
MS
547 "cups-fold-accordian",
548 "cups-fold-double-gate",
549 "cups-fold-gate",
550 "cups-fold-half",
551 "cups-fold-half-z",
552 "cups-fold-left-gate",
6961465f 553 /* 0x40000060 - 0x40000064 */
9475ec92
MS
554 "cups-fold-letter",
555 "cups-fold-parallel",
556 "cups-fold-poster",
557 "cups-fold-right-gate",
558 "cups-fold-z"
a469f8a5 559 },
a2326b5b
MS
560 * const ipp_job_collation_types[] =
561 { /* job-collation-type enums */
562 "uncollated-sheets",
563 "collated-documents",
564 "uncollated-documents"
565 },
566 * const ipp_job_states[] =
567 { /* job-state enums */
568 "pending",
569 "pending-held",
570 "processing",
571 "processing-stopped",
572 "canceled",
573 "aborted",
574 "completed"
575 },
576 * const ipp_orientation_requesteds[] =
577 { /* orientation-requested enums */
578 "portrait",
579 "landscape",
580 "reverse-landscape",
8f787fca
MS
581 "reverse-portrait",
582 "none"
a2326b5b
MS
583 },
584 * const ipp_print_qualities[] =
585 { /* print-quality enums */
586 "draft",
587 "normal",
588 "high"
589 },
590 * const ipp_printer_states[] =
591 { /* printer-state enums */
592 "idle",
593 "processing",
594 "stopped",
595 };
aaf19ab0
MS
596
597
598/*
599 * Local functions...
600 */
601
602static size_t ipp_col_string(ipp_t *col, char *buffer, size_t bufsize);
603
604
605/*
a2326b5b 606 * 'ippAttributeString()' - Convert the attribute's value to a string.
aaf19ab0
MS
607 *
608 * Returns the number of bytes that would be written, not including the
609 * trailing nul. The buffer pointer can be NULL to get the required length,
610 * just like (v)snprintf.
a2326b5b 611 *
8072030b 612 * @since CUPS 1.6/macOS 10.8@
aaf19ab0
MS
613 */
614
615size_t /* O - Number of bytes less nul */
a2326b5b
MS
616ippAttributeString(
617 ipp_attribute_t *attr, /* I - Attribute */
618 char *buffer, /* I - String buffer or NULL */
619 size_t bufsize) /* I - Size of string buffer */
aaf19ab0
MS
620{
621 int i; /* Looping var */
622 char *bufptr, /* Pointer into buffer */
623 *bufend, /* End of buffer */
624 temp[256]; /* Temporary string */
db8b865d
MS
625 const char *ptr, /* Pointer into string */
626 *end; /* Pointer to end of string */
a2326b5b 627 _ipp_value_t *val; /* Current value */
aaf19ab0
MS
628
629
630 if (!attr || !attr->name)
631 {
632 if (buffer)
633 *buffer = '\0';
634
635 return (0);
636 }
637
638 bufptr = buffer;
639 if (buffer)
640 bufend = buffer + bufsize - 1;
641 else
642 bufend = NULL;
643
644 for (i = attr->num_values, val = attr->values; i > 0; i --, val ++)
645 {
646 if (val > attr->values)
647 {
7cf5915e 648 if (buffer && bufptr < bufend)
aaf19ab0
MS
649 *bufptr++ = ',';
650 else
651 bufptr ++;
652 }
653
cb7f98ee 654 switch (attr->value_tag & ~IPP_TAG_CUPS_CONST)
aaf19ab0
MS
655 {
656 case IPP_TAG_ENUM :
a2326b5b 657 ptr = ippEnumString(attr->name, val->integer);
aaf19ab0 658
a2326b5b 659 if (buffer && bufptr < bufend)
07623986 660 strlcpy(bufptr, ptr, (size_t)(bufend - bufptr + 1));
9b66acc5 661
a2326b5b
MS
662 bufptr += strlen(ptr);
663 break;
aaf19ab0
MS
664
665 case IPP_TAG_INTEGER :
7cf5915e 666 if (buffer && bufptr < bufend)
07623986 667 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d", val->integer);
aaf19ab0
MS
668 else
669 bufptr += snprintf(temp, sizeof(temp), "%d", val->integer);
670 break;
671
672 case IPP_TAG_BOOLEAN :
7cf5915e 673 if (buffer && bufptr < bufend)
07623986 674 strlcpy(bufptr, val->boolean ? "true" : "false", (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
675
676 bufptr += val->boolean ? 4 : 5;
677 break;
678
679 case IPP_TAG_RANGE :
7cf5915e 680 if (buffer && bufptr < bufend)
07623986 681 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d-%d", val->range.lower, val->range.upper);
aaf19ab0 682 else
07623986 683 bufptr += snprintf(temp, sizeof(temp), "%d-%d", val->range.lower, val->range.upper);
aaf19ab0
MS
684 break;
685
686 case IPP_TAG_RESOLUTION :
4a838088
MS
687 if (val->resolution.xres == val->resolution.yres)
688 {
689 if (buffer && bufptr < bufend)
690 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%d%s", val->resolution.xres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
691 else
692 bufptr += snprintf(temp, sizeof(temp), "%d%s", val->resolution.xres, val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
693 }
694 else if (buffer && bufptr < bufend)
07623986 695 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 696 else
07623986 697 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
698 break;
699
700 case IPP_TAG_DATE :
701 {
702 unsigned year; /* Year */
703
7e86f2f6 704 year = ((unsigned)val->date[0] << 8) + (unsigned)val->date[1];
aaf19ab0
MS
705
706 if (val->date[9] == 0 && val->date[10] == 0)
707 snprintf(temp, sizeof(temp), "%04u-%02u-%02uT%02u:%02u:%02uZ",
708 year, val->date[2], val->date[3], val->date[4],
709 val->date[5], val->date[6]);
710 else
711 snprintf(temp, sizeof(temp),
712 "%04u-%02u-%02uT%02u:%02u:%02u%c%02u%02u",
713 year, val->date[2], val->date[3], val->date[4],
714 val->date[5], val->date[6], val->date[8], val->date[9],
715 val->date[10]);
716
7cf5915e 717 if (buffer && bufptr < bufend)
07623986 718 strlcpy(bufptr, temp, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
719
720 bufptr += strlen(temp);
721 }
722 break;
723
724 case IPP_TAG_TEXT :
725 case IPP_TAG_NAME :
726 case IPP_TAG_KEYWORD :
727 case IPP_TAG_CHARSET :
728 case IPP_TAG_URI :
d7225fc2 729 case IPP_TAG_URISCHEME :
aaf19ab0
MS
730 case IPP_TAG_MIMETYPE :
731 case IPP_TAG_LANGUAGE :
732 case IPP_TAG_TEXTLANG :
733 case IPP_TAG_NAMELANG :
7cf5915e
MS
734 if (!val->string.text)
735 break;
736
aaf19ab0
MS
737 for (ptr = val->string.text; *ptr; ptr ++)
738 {
a2326b5b 739 if (*ptr == '\\' || *ptr == '\"' || *ptr == '[')
aaf19ab0 740 {
7cf5915e 741 if (buffer && bufptr < bufend)
aaf19ab0
MS
742 *bufptr = '\\';
743 bufptr ++;
744 }
745
7cf5915e 746 if (buffer && bufptr < bufend)
aaf19ab0
MS
747 *bufptr = *ptr;
748 bufptr ++;
749 }
a2326b5b
MS
750
751 if (val->string.language)
752 {
753 /*
754 * Add "[language]" to end of string...
755 */
756
757 if (buffer && bufptr < bufend)
758 *bufptr = '[';
759 bufptr ++;
760
761 if (buffer && bufptr < bufend)
07623986 762 strlcpy(bufptr, val->string.language, (size_t)(bufend - bufptr));
a2326b5b
MS
763 bufptr += strlen(val->string.language);
764
765 if (buffer && bufptr < bufend)
766 *bufptr = ']';
767 bufptr ++;
768 }
aaf19ab0
MS
769 break;
770
771 case IPP_TAG_BEGIN_COLLECTION :
7cf5915e 772 if (buffer && bufptr < bufend)
7e86f2f6 773 bufptr += ipp_col_string(val->collection, bufptr, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
774 else
775 bufptr += ipp_col_string(val->collection, NULL, 0);
776 break;
777
778 case IPP_TAG_STRING :
db8b865d
MS
779 for (ptr = val->unknown.data, end = ptr + val->unknown.length;
780 ptr < end; ptr ++)
aaf19ab0 781 {
7cf5915e 782 if (*ptr == '\\' || _cups_isspace(*ptr))
aaf19ab0 783 {
7cf5915e 784 if (buffer && bufptr < bufend)
aaf19ab0
MS
785 *bufptr = '\\';
786 bufptr ++;
787
7cf5915e 788 if (buffer && bufptr < bufend)
aaf19ab0
MS
789 *bufptr = *ptr;
790 bufptr ++;
791 }
792 else if (!isprint(*ptr & 255))
793 {
7cf5915e 794 if (buffer && bufptr < bufend)
07623986 795 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "\\%03o", *ptr & 255);
aaf19ab0 796 else
07623986 797 bufptr += snprintf(temp, sizeof(temp), "\\%03o", *ptr & 255);
aaf19ab0
MS
798 }
799 else
800 {
7cf5915e 801 if (buffer && bufptr < bufend)
aaf19ab0
MS
802 *bufptr = *ptr;
803 bufptr ++;
804 }
805 }
806 break;
807
808 default :
809 ptr = ippTagString(attr->value_tag);
7cf5915e 810 if (buffer && bufptr < bufend)
07623986 811 strlcpy(bufptr, ptr, (size_t)(bufend - bufptr + 1));
aaf19ab0
MS
812 bufptr += strlen(ptr);
813 break;
814 }
815 }
816
7cf5915e 817 if (buffer && bufptr < bufend)
aaf19ab0
MS
818 *bufptr = '\0';
819 else if (bufend)
820 *bufend = '\0';
821
7e86f2f6 822 return ((size_t)(bufptr - buffer));
aaf19ab0 823}
ef416fc2 824
825
db8b865d
MS
826/*
827 * 'ippCreateRequestedArray()' - Create a CUPS array of attribute names from the
828 * given requested-attributes attribute.
829 *
830 * This function creates a (sorted) CUPS array of attribute names matching the
831 * list of "requested-attribute" values supplied in an IPP request. All IANA-
832 * registered values are supported in addition to the CUPS IPP extension
833 * attributes.
834 *
835 * The @code request@ parameter specifies the request message that was read from
836 * the client.
837 *
838 * @code NULL@ is returned if all attributes should be returned. Otherwise, the
839 * result is a sorted array of attribute names, where @code cupsArrayFind(array,
840 * "attribute-name")@ will return a non-NULL pointer. The array must be freed
841 * using the @code cupsArrayDelete@ function.
842 *
8072030b 843 * @since CUPS 1.7/macOS 10.9@
db8b865d
MS
844 */
845
846cups_array_t * /* O - CUPS array or @code NULL@ if all */
847ippCreateRequestedArray(ipp_t *request) /* I - IPP request */
848{
849 int i, j, /* Looping vars */
850 count, /* Number of values */
851 added; /* Was name added? */
852 ipp_attribute_t *requested; /* requested-attributes attribute */
853 cups_array_t *ra; /* Requested attributes array */
854 const char *value; /* Current value */
855 /* The following lists come from the current IANA IPP registry of attributes */
856 static const char * const document_description[] =
857 { /* document-description group */
858 "compression",
859 "copies-actual",
860 "cover-back-actual",
861 "cover-front-actual",
862 "current-page-order",
863 "date-time-at-completed",
864 "date-time-at-creation",
865 "date-time-at-processing",
866 "detailed-status-messages",
867 "document-access-errors",
868 "document-charset",
869 "document-digital-signature",
870 "document-format",
871 "document-format-details",
872 "document-format-detected",
873 "document-format-version",
874 "document-format-version-detected",
875 "document-job-id",
876 "document-job-uri",
877 "document-message",
878 "document-metadata",
879 "document-name",
880 "document-natural-language",
881 "document-number",
882 "document-printer-uri",
883 "document-state",
884 "document-state-message",
885 "document-state-reasons",
886 "document-uri",
887 "document-uuid",
888 "errors-count",
889 "finishings-actual",
890 "finishings-col-actual",
891 "force-front-side-actual",
892 "imposition-template-actual",
893 "impressions",
894 "impressions-completed",
895 "impressions-completed-current-copy",
896 "insert-sheet-actual",
897 "k-octets",
898 "k-octets-processed",
899 "last-document",
900 "media-actual",
901 "media-col-actual",
902 "media-input-tray-check-actual",
903 "media-sheets",
904 "media-sheets-completed",
905 "more-info",
906 "number-up-actual",
907 "orientation-requested-actual",
908 "output-bin-actual",
909 "output-device-assigned",
910 "overrides-actual",
911 "page-delivery-actual",
912 "page-order-received-actual",
913 "page-ranges-actual",
914 "pages",
915 "pages-completed",
916 "pages-completed-current-copy",
917 "presentation-direction-number-up-actual",
918 "print-color-mode-actual",
919 "print-content-optimize-actual",
920 "print-quality-actual",
921 "print-rendering-intent-actual",
6961465f 922 "print-scaling-actual", /* IPP Paid Printing */
db8b865d
MS
923 "printer-resolution-actual",
924 "printer-up-time",
925 "separator-sheets-actual",
926 "sheet-completed-copy-number",
927 "sides-actual",
928 "time-at-completed",
929 "time-at-creation",
930 "time-at-processing",
931 "x-image-position-actual",
932 "x-image-shift-actual",
933 "x-side1-image-shift-actual",
934 "x-side2-image-shift-actual",
935 "y-image-position-actual",
936 "y-image-shift-actual",
937 "y-side1-image-shift-actual",
938 "y-side2-image-shift-actual"
939 };
940 static const char * const document_template[] =
941 { /* document-template group */
942 "copies",
943 "copies-default",
944 "copies-supported",
945 "cover-back",
946 "cover-back-default",
947 "cover-back-supported",
948 "cover-front",
949 "cover-front-default",
950 "cover-front-supported",
951 "feed-orientation",
952 "feed-orientation-default",
953 "feed-orientation-supported",
954 "finishings",
955 "finishings-col",
956 "finishings-col-default",
957 "finishings-col-supported",
958 "finishings-default",
959 "finishings-supported",
960 "font-name-requested",
961 "font-name-requested-default",
962 "font-name-requested-supported",
963 "font-size-requested",
964 "font-size-requested-default",
965 "font-size-requested-supported",
966 "force-front-side",
967 "force-front-side-default",
968 "force-front-side-supported",
969 "imposition-template",
970 "imposition-template-default",
971 "imposition-template-supported",
972 "insert-after-page-number-supported",
973 "insert-count-supported",
974 "insert-sheet",
975 "insert-sheet-default",
976 "insert-sheet-supported",
977 "max-stitching-locations-supported",
978 "media",
979 "media-back-coating-supported",
980 "media-bottom-margin-supported",
981 "media-col",
982 "media-col-default",
983 "media-col-supported",
984 "media-color-supported",
985 "media-default",
986 "media-front-coating-supported",
987 "media-grain-supported",
988 "media-hole-count-supported",
989 "media-info-supported",
990 "media-input-tray-check",
991 "media-input-tray-check-default",
992 "media-input-tray-check-supported",
993 "media-key-supported",
994 "media-left-margin-supported",
995 "media-order-count-supported",
996 "media-pre-printed-supported",
997 "media-recycled-supported",
998 "media-right-margin-supported",
999 "media-size-supported",
1000 "media-source-supported",
1001 "media-supported",
1002 "media-thickness-supported",
1003 "media-top-margin-supported",
1004 "media-type-supported",
1005 "media-weight-metric-supported",
1006 "multiple-document-handling",
1007 "multiple-document-handling-default",
1008 "multiple-document-handling-supported",
1009 "number-up",
1010 "number-up-default",
1011 "number-up-supported",
1012 "orientation-requested",
1013 "orientation-requested-default",
1014 "orientation-requested-supported",
6961465f
MS
1015 "output-mode", /* CUPS extension */
1016 "output-mode-default", /* CUPS extension */
1017 "output-mode-supported", /* CUPS extension */
db8b865d
MS
1018 "overrides",
1019 "overrides-supported",
1020 "page-delivery",
1021 "page-delivery-default",
1022 "page-delivery-supported",
1023 "page-order-received",
1024 "page-order-received-default",
1025 "page-order-received-supported",
1026 "page-ranges",
1027 "page-ranges-supported",
1028 "pages-per-subset",
1029 "pages-per-subset-supported",
1030 "pdl-init-file",
1031 "pdl-init-file-default",
1032 "pdl-init-file-entry-supported",
1033 "pdl-init-file-location-supported",
1034 "pdl-init-file-name-subdirectory-supported",
1035 "pdl-init-file-name-supported",
1036 "pdl-init-file-supported",
1037 "presentation-direction-number-up",
1038 "presentation-direction-number-up-default",
1039 "presentation-direction-number-up-supported",
1040 "print-color-mode",
1041 "print-color-mode-default",
1042 "print-color-mode-supported",
1043 "print-content-optimize",
1044 "print-content-optimize-default",
1045 "print-content-optimize-supported",
1046 "print-quality",
1047 "print-quality-default",
1048 "print-quality-supported",
1049 "print-rendering-intent",
1050 "print-rendering-intent-default",
1051 "print-rendering-intent-supported",
6961465f
MS
1052 "print-scaling", /* IPP Paid Printing */
1053 "print-scaling-default", /* IPP Paid Printing */
1054 "print-scaling-supported", /* IPP Paid Printing */
db8b865d
MS
1055 "printer-resolution",
1056 "printer-resolution-default",
1057 "printer-resolution-supported",
1058 "separator-sheets",
1059 "separator-sheets-default",
1060 "separator-sheets-supported",
1061 "sheet-collate",
1062 "sheet-collate-default",
1063 "sheet-collate-supported",
1064 "sides",
1065 "sides-default",
1066 "sides-supported",
1067 "stitching-locations-supported",
1068 "stitching-offset-supported",
1069 "x-image-position",
1070 "x-image-position-default",
1071 "x-image-position-supported",
1072 "x-image-shift",
1073 "x-image-shift-default",
1074 "x-image-shift-supported",
1075 "x-side1-image-shift",
1076 "x-side1-image-shift-default",
1077 "x-side1-image-shift-supported",
1078 "x-side2-image-shift",
1079 "x-side2-image-shift-default",
1080 "x-side2-image-shift-supported",
1081 "y-image-position",
1082 "y-image-position-default",
1083 "y-image-position-supported",
1084 "y-image-shift",
1085 "y-image-shift-default",
1086 "y-image-shift-supported",
1087 "y-side1-image-shift",
1088 "y-side1-image-shift-default",
1089 "y-side1-image-shift-supported",
1090 "y-side2-image-shift",
1091 "y-side2-image-shift-default",
1092 "y-side2-image-shift-supported"
1093 };
1094 static const char * const job_description[] =
1095 { /* job-description group */
1096 "compression-supplied",
1097 "copies-actual",
1098 "cover-back-actual",
1099 "cover-front-actual",
1100 "current-page-order",
1101 "date-time-at-completed",
1102 "date-time-at-creation",
1103 "date-time-at-processing",
1104 "destination-statuses",
1105 "document-charset-supplied",
1106 "document-digital-signature-supplied",
1107 "document-format-details-supplied",
1108 "document-format-supplied",
1109 "document-message-supplied",
1110 "document-metadata",
1111 "document-name-supplied",
1112 "document-natural-language-supplied",
1113 "document-overrides-actual",
1114 "errors-count",
1115 "finishings-actual",
1116 "finishings-col-actual",
1117 "force-front-side-actual",
1118 "imposition-template-actual",
1119 "impressions-completed-current-copy",
1120 "insert-sheet-actual",
1121 "job-account-id-actual",
1122 "job-accounting-sheets-actual",
1123 "job-accounting-user-id-actual",
1124 "job-attribute-fidelity",
1125 "job-charge-info", /* CUPS extension */
1126 "job-collation-type",
1127 "job-collation-type-actual",
1128 "job-copies-actual",
1129 "job-cover-back-actual",
1130 "job-cover-front-actual",
1131 "job-detailed-status-message",
1132 "job-document-access-errors",
1133 "job-error-sheet-actual",
1134 "job-finishings-actual",
1135 "job-finishings-col-actual",
1136 "job-hold-until-actual",
1137 "job-id",
1138 "job-impressions",
1139 "job-impressions-completed",
1140 "job-k-octets",
1141 "job-k-octets-processed",
1142 "job-mandatory-attributes",
1143 "job-media-progress", /* CUPS extension */
1144 "job-media-sheets",
1145 "job-media-sheets-completed",
1146 "job-message-from-operator",
1147 "job-more-info",
1148 "job-name",
1149 "job-originating-host-name", /* CUPS extension */
1150 "job-originating-user-name",
1151 "job-originating-user-uri",
1152 "job-pages",
1153 "job-pages-completed",
1154 "job-pages-completed-current-copy",
1155 "job-printer-state-message", /* CUPS extension */
1156 "job-printer-state-reasons", /* CUPS extension */
1157 "job-printer-up-time",
1158 "job-printer-uri",
1159 "job-priority-actual",
1160 "job-save-printer-make-and-model",
1161 "job-sheet-message-actual",
1162 "job-sheets-actual",
1163 "job-sheets-col-actual",
1164 "job-state",
1165 "job-state-message",
1166 "job-state-reasons",
1167 "job-uri",
1168 "job-uuid",
1169 "media-actual",
1170 "media-col-actual",
1171 "media-check-input-tray-actual",
1172 "multiple-document-handling-actual",
1173 "number-of-documents",
1174 "number-of-intervening-jobs",
1175 "number-up-actual",
1176 "orientation-requested-actual",
1177 "original-requesting-user-name",
1178 "output-bin-actual",
1179 "output-device-assigned",
1180 "overrides-actual",
1181 "page-delivery-actual",
1182 "page-order-received-actual",
1183 "page-ranges-actual",
1184 "presentation-direction-number-up-actual",
1185 "print-color-mode-actual",
1186 "print-content-optimize-actual",
1187 "print-quality-actual",
1188 "print-rendering-intent-actual",
6961465f 1189 "print-scaling-actual", /* IPP Paid Printing */
db8b865d
MS
1190 "printer-resolution-actual",
1191 "separator-sheets-actual",
1192 "sheet-collate-actual",
1193 "sheet-completed-copy-number",
1194 "sheet-completed-document-number",
1195 "sides-actual",
1196 "time-at-completed",
1197 "time-at-creation",
1198 "time-at-processing",
1199 "warnings-count",
1200 "x-image-position-actual",
1201 "x-image-shift-actual",
1202 "x-side1-image-shift-actual",
1203 "x-side2-image-shift-actual",
1204 "y-image-position-actual",
1205 "y-image-shift-actual",
1206 "y-side1-image-shift-actual",
1207 "y-side2-image-shift-actual"
1208 };
1209 static const char * const job_template[] =
1210 { /* job-template group */
1211 "confirmation-sheet-print", /* IPP FaxOut */
1212 "confirmation-sheet-print-default",
1213 "copies",
1214 "copies-default",
1215 "copies-supported",
1216 "cover-back",
1217 "cover-back-default",
1218 "cover-back-supported",
1219 "cover-front",
1220 "cover-front-default",
1221 "cover-front-supported",
1222 "cover-sheet-info", /* IPP FaxOut */
1223 "cover-sheet-info-default",
1224 "cover-sheet-info-supported",
1225 "destination-uri-schemes-supported",/* IPP FaxOut */
1226 "destination-uris", /* IPP FaxOut */
1227 "destination-uris-supported",
1228 "feed-orientation",
1229 "feed-orientation-default",
1230 "feed-orientation-supported",
1231 "finishings",
1232 "finishings-col",
1233 "finishings-col-default",
1234 "finishings-col-supported",
1235 "finishings-default",
1236 "finishings-supported",
1237 "font-name-requested",
1238 "font-name-requested-default",
1239 "font-name-requested-supported",
1240 "font-size-requested",
1241 "font-size-requested-default",
1242 "font-size-requested-supported",
1243 "force-front-side",
1244 "force-front-side-default",
1245 "force-front-side-supported",
1246 "imposition-template",
1247 "imposition-template-default",
1248 "imposition-template-supported",
1249 "insert-after-page-number-supported",
1250 "insert-count-supported",
1251 "insert-sheet",
1252 "insert-sheet-default",
1253 "insert-sheet-supported",
1254 "job-account-id",
1255 "job-account-id-default",
1256 "job-account-id-supported",
1257 "job-accounting-sheets"
1258 "job-accounting-sheets-default"
1259 "job-accounting-sheets-supported"
1260 "job-accounting-user-id",
1261 "job-accounting-user-id-default",
1262 "job-accounting-user-id-supported",
1263 "job-copies",
1264 "job-copies-default",
1265 "job-copies-supported",
1266 "job-cover-back",
1267 "job-cover-back-default",
1268 "job-cover-back-supported",
1269 "job-cover-front",
1270 "job-cover-front-default",
1271 "job-cover-front-supported",
1272 "job-delay-output-until",
1273 "job-delay-output-until-default",
1274 "job-delay-output-until-supported",
1275 "job-delay-output-until-time",
1276 "job-delay-output-until-time-default",
1277 "job-delay-output-until-time-supported",
1278 "job-error-action",
1279 "job-error-action-default",
1280 "job-error-action-supported",
1281 "job-error-sheet",
1282 "job-error-sheet-default",
1283 "job-error-sheet-supported",
1284 "job-finishings",
1285 "job-finishings-col",
1286 "job-finishings-col-default",
1287 "job-finishings-col-supported",
1288 "job-finishings-default",
1289 "job-finishings-supported",
1290 "job-hold-until",
1291 "job-hold-until-default",
1292 "job-hold-until-supported",
1293 "job-hold-until-time",
1294 "job-hold-until-time-default",
1295 "job-hold-until-time-supported",
1296 "job-message-to-operator",
1297 "job-message-to-operator-default",
1298 "job-message-to-operator-supported",
1299 "job-phone-number",
1300 "job-phone-number-default",
1301 "job-phone-number-supported",
1302 "job-priority",
1303 "job-priority-default",
1304 "job-priority-supported",
1305 "job-recipient-name",
1306 "job-recipient-name-default",
1307 "job-recipient-name-supported",
1308 "job-save-disposition",
1309 "job-save-disposition-default",
1310 "job-save-disposition-supported",
1311 "job-sheets",
1312 "job-sheets-col",
1313 "job-sheets-col-default",
1314 "job-sheets-col-supported",
1315 "job-sheets-default",
1316 "job-sheets-supported",
1317 "logo-uri-schemes-supported",
1318 "max-save-info-supported",
1319 "max-stitching-locations-supported",
1320 "media",
1321 "media-back-coating-supported",
1322 "media-bottom-margin-supported",
1323 "media-col",
1324 "media-col-default",
1325 "media-col-supported",
1326 "media-color-supported",
1327 "media-default",
1328 "media-front-coating-supported",
1329 "media-grain-supported",
1330 "media-hole-count-supported",
1331 "media-info-supported",
1332 "media-input-tray-check",
1333 "media-input-tray-check-default",
1334 "media-input-tray-check-supported",
1335 "media-key-supported",
1336 "media-left-margin-supported",
1337 "media-order-count-supported",
1338 "media-pre-printed-supported",
1339 "media-recycled-supported",
1340 "media-right-margin-supported",
1341 "media-size-supported",
1342 "media-source-supported",
1343 "media-supported",
1344 "media-thickness-supported",
1345 "media-top-margin-supported",
1346 "media-type-supported",
1347 "media-weight-metric-supported",
1348 "multiple-document-handling",
1349 "multiple-document-handling-default",
1350 "multiple-document-handling-supported",
1351 "number-of-retries", /* IPP FaxOut */
1352 "number-of-retries-default",
1353 "number-of-retries-supported",
1354 "number-up",
1355 "number-up-default",
1356 "number-up-supported",
1357 "orientation-requested",
1358 "orientation-requested-default",
1359 "orientation-requested-supported",
1360 "output-bin",
1361 "output-bin-default",
1362 "output-bin-supported",
1363 "output-device",
1364 "output-device-default",
1365 "output-device-supported",
6961465f
MS
1366 "output-mode", /* CUPS extension */
1367 "output-mode-default", /* CUPS extension */
1368 "output-mode-supported", /* CUPS extension */
db8b865d
MS
1369 "overrides",
1370 "overrides-supported",
1371 "page-delivery",
1372 "page-delivery-default",
1373 "page-delivery-supported",
1374 "page-order-received",
1375 "page-order-received-default",
1376 "page-order-received-supported",
1377 "page-ranges",
1378 "page-ranges-supported",
1379 "pages-per-subset",
1380 "pages-per-subset-supported",
1381 "pdl-init-file",
1382 "pdl-init-file-default",
1383 "pdl-init-file-entry-supported",
1384 "pdl-init-file-location-supported",
1385 "pdl-init-file-name-subdirectory-supported",
1386 "pdl-init-file-name-supported",
1387 "pdl-init-file-supported",
1388 "presentation-direction-number-up",
1389 "presentation-direction-number-up-default",
1390 "presentation-direction-number-up-supported",
1391 "print-color-mode",
1392 "print-color-mode-default",
1393 "print-color-mode-supported",
1394 "print-content-optimize",
1395 "print-content-optimize-default",
1396 "print-content-optimize-supported",
1397 "print-quality",
1398 "print-quality-default",
1399 "print-quality-supported",
1400 "print-rendering-intent",
1401 "print-rendering-intent-default",
1402 "print-rendering-intent-supported",
6961465f
MS
1403 "print-scaling", /* IPP Paid Printing */
1404 "print-scaling-default", /* IPP Paid Printing */
1405 "print-scaling-supported", /* IPP Paid Printing */
db8b865d
MS
1406 "printer-resolution",
1407 "printer-resolution-default",
1408 "printer-resolution-supported",
1409 "proof-print",
1410 "proof-print-default",
1411 "proof-print-supported",
1412 "retry-interval", /* IPP FaxOut */
1413 "retry-interval-default",
1414 "retry-interval-supported",
1415 "retry-timeout", /* IPP FaxOut */
1416 "retry-timeout-default",
1417 "retry-timeout-supported",
1418 "save-disposition-supported",
1419 "save-document-format-default",
1420 "save-document-format-supported",
1421 "save-location-default",
1422 "save-location-supported",
1423 "save-name-subdirectory-supported",
1424 "save-name-supported",
1425 "separator-sheets",
1426 "separator-sheets-default",
1427 "separator-sheets-supported",
1428 "sheet-collate",
1429 "sheet-collate-default",
1430 "sheet-collate-supported",
1431 "sides",
1432 "sides-default",
1433 "sides-supported",
1434 "stitching-locations-supported",
1435 "stitching-offset-supported",
1436 "x-image-position",
1437 "x-image-position-default",
1438 "x-image-position-supported",
1439 "x-image-shift",
1440 "x-image-shift-default",
1441 "x-image-shift-supported",
1442 "x-side1-image-shift",
1443 "x-side1-image-shift-default",
1444 "x-side1-image-shift-supported",
1445 "x-side2-image-shift",
1446 "x-side2-image-shift-default",
1447 "x-side2-image-shift-supported",
1448 "y-image-position",
1449 "y-image-position-default",
1450 "y-image-position-supported",
1451 "y-image-shift",
1452 "y-image-shift-default",
1453 "y-image-shift-supported",
1454 "y-side1-image-shift",
1455 "y-side1-image-shift-default",
1456 "y-side1-image-shift-supported",
1457 "y-side2-image-shift",
1458 "y-side2-image-shift-default",
1459 "y-side2-image-shift-supported"
1460 };
1461 static const char * const printer_description[] =
1462 { /* printer-description group */
1463 "auth-info-required", /* CUPS extension */
1464 "charset-configured",
1465 "charset-supported",
1466 "color-supported",
1467 "compression-supported",
1468 "device-service-count",
1469 "device-uri", /* CUPS extension */
1470 "device-uuid",
1471 "document-charset-default",
1472 "document-charset-supported",
1473 "document-creation-attributes-supported",
1474 "document-digital-signature-default",
1475 "document-digital-signature-supported",
1476 "document-format-default",
1477 "document-format-details-default",
1478 "document-format-details-supported",
1479 "document-format-supported",
1480 "document-format-varying-attributes",
1481 "document-format-version-default",
1482 "document-format-version-supported",
1483 "document-natural-language-default",
1484 "document-natural-language-supported",
1485 "document-password-supported",
1486 "generated-natural-language-supported",
1487 "identify-actions-default",
1488 "identify-actions-supported",
1489 "input-source-supported",
1490 "ipp-features-supported",
1491 "ipp-versions-supported",
1492 "ippget-event-life",
1493 "job-authorization-uri-supported", /* CUPS extension */
1494 "job-constraints-supported",
1495 "job-creation-attributes-supported",
1496 "job-finishings-col-ready",
1497 "job-finishings-ready",
1498 "job-ids-supported",
1499 "job-impressions-supported",
1500 "job-k-limit", /* CUPS extension */
1501 "job-k-octets-supported",
1502 "job-media-sheets-supported",
1503 "job-page-limit", /* CUPS extension */
1504 "job-password-encryption-supported",
1505 "job-password-supported",
1506 "job-quota-period", /* CUPS extension */
1507 "job-resolvers-supported",
1508 "job-settable-attributes-supported",
1509 "job-spooling-supported",
c5b24bfa
MS
1510 "jpeg-k-octets-supported", /* CUPS extension */
1511 "jpeg-x-dimension-supported", /* CUPS extension */
1512 "jpeg-y-dimension-supported", /* CUPS extension */
1513 "landscape-orientation-requested-preferred",
1514 /* CUPS extension */
db8b865d
MS
1515 "marker-change-time", /* CUPS extension */
1516 "marker-colors", /* CUPS extension */
1517 "marker-high-levels", /* CUPS extension */
1518 "marker-levels", /* CUPS extension */
1519 "marker-low-levels", /* CUPS extension */
1520 "marker-message", /* CUPS extension */
1521 "marker-names", /* CUPS extension */
1522 "marker-types", /* CUPS extension */
1523 "media-col-ready",
1524 "media-ready",
1525 "member-names", /* CUPS extension */
1526 "member-uris", /* CUPS extension */
1527 "multiple-destination-uris-supported",/* IPP FaxOut */
1528 "multiple-document-jobs-supported",
1529 "multiple-operation-time-out",
1530 "multiple-operation-time-out-action",
1531 "natural-language-configured",
1532 "operations-supported",
1533 "pages-per-minute",
1534 "pages-per-minute-color",
c5b24bfa
MS
1535 "pdf-k-octets-supported", /* CUPS extension */
1536 "pdf-versions-supported", /* CUPS extension */
db8b865d
MS
1537 "pdl-override-supported",
1538 "port-monitor", /* CUPS extension */
1539 "port-monitor-supported", /* CUPS extension */
1540 "preferred-attributes-supported",
1541 "printer-alert",
1542 "printer-alert-description",
1543 "printer-charge-info",
1544 "printer-charge-info-uri",
1545 "printer-commands", /* CUPS extension */
1546 "printer-current-time",
1547 "printer-detailed-status-messages",
1548 "printer-device-id",
1549 "printer-dns-sd-name", /* CUPS extension */
1550 "printer-driver-installer",
1551 "printer-fax-log-uri", /* IPP FaxOut */
1552 "printer-fax-modem-info", /* IPP FaxOut */
1553 "printer-fax-modem-name", /* IPP FaxOut */
1554 "printer-fax-modem-number", /* IPP FaxOut */
8f787fca
MS
1555 "printer-firmware-name", /* PWG 5110.1 */
1556 "printer-firmware-patches", /* PWG 5110.1 */
1557 "printer-firmware-string-version", /* PWG 5110.1 */
1558 "printer-firmware-version", /* PWG 5110.1 */
db8b865d
MS
1559 "printer-geo-location",
1560 "printer-get-attributes-supported",
1561 "printer-icc-profiles",
1562 "printer-icons",
cd3a0368 1563 "printer-id", /* CUPS extension */
db8b865d 1564 "printer-info",
8f787fca 1565 "printer-input-tray", /* IPP JPS3 */
db8b865d 1566 "printer-is-accepting-jobs",
6961465f 1567 "printer-is-shared", /* CUPS extension */
7ae00c35 1568 "printer-is-temporary", /* CUPS extension */
6961465f 1569 "printer-kind", /* IPP Paid Printing */
db8b865d
MS
1570 "printer-location",
1571 "printer-make-and-model",
1572 "printer-mandatory-job-attributes",
1573 "printer-message-date-time",
1574 "printer-message-from-operator",
1575 "printer-message-time",
1576 "printer-more-info",
1577 "printer-more-info-manufacturer",
1578 "printer-name",
6961465f 1579 "printer-native-formats",
db8b865d
MS
1580 "printer-organization",
1581 "printer-organizational-unit",
8f787fca 1582 "printer-output-tray", /* IPP JPS3 */
34a63bd9 1583 "printer-queue-id", /* CUPS extension */
db8b865d
MS
1584 "printer-settable-attributes-supported",
1585 "printer-state",
1586 "printer-state-change-date-time",
1587 "printer-state-change-time",
1588 "printer-state-message",
1589 "printer-state-reasons",
1590 "printer-supply",
1591 "printer-supply-description",
1592 "printer-supply-info-uri",
1593 "printer-type", /* CUPS extension */
1594 "printer-up-time",
1595 "printer-uri-supported",
1596 "printer-uuid",
1597 "printer-xri-supported",
1598 "pwg-raster-document-resolution-supported",
1599 "pwg-raster-document-sheet-back",
1600 "pwg-raster-document-type-supported",
1601 "queued-job-count",
1602 "reference-uri-schemes-supported",
1603 "repertoire-supported",
1604 "requesting-user-name-allowed", /* CUPS extension */
1605 "requesting-user-name-denied", /* CUPS extension */
1606 "requesting-user-uri-supported",
1607 "subordinate-printers-supported",
6961465f 1608 "urf-supported", /* CUPS extension */
db8b865d
MS
1609 "uri-authentication-supported",
1610 "uri-security-supported",
1611 "user-defined-value-supported",
1612 "which-jobs-supported",
1613 "xri-authentication-supported",
1614 "xri-security-supported",
1615 "xri-uri-scheme-supported"
1616 };
1617 static const char * const subscription_description[] =
1618 { /* subscription-description group */
1619 "notify-job-id",
1620 "notify-lease-expiration-time",
1621 "notify-printer-up-time",
1622 "notify-printer-uri",
1623 "notify-sequence-number",
1624 "notify-subscriber-user-name",
1625 "notify-subscriber-user-uri",
1626 "notify-subscription-id",
1627 "subscriptions-uuid"
1628 };
1629 static const char * const subscription_template[] =
1630 { /* subscription-template group */
1631 "notify-attributes",
1632 "notify-attributes-supported",
1633 "notify-charset",
1634 "notify-events",
1635 "notify-events-default",
1636 "notify-events-supported",
1637 "notify-lease-duration",
1638 "notify-lease-duration-default",
1639 "notify-lease-duration-supported",
1640 "notify-max-events-supported",
1641 "notify-natural-language",
1642 "notify-pull-method",
1643 "notify-pull-method-supported",
1644 "notify-recipient-uri",
1645 "notify-schemes-supported",
1646 "notify-time-interval",
1647 "notify-user-data"
1648 };
1649
1650
1651 /*
1652 * Get the requested-attributes attribute...
1653 */
1654
1655 if ((requested = ippFindAttribute(request, "requested-attributes",
1656 IPP_TAG_KEYWORD)) == NULL)
1657 {
1658 /*
1659 * The Get-Jobs operation defaults to "job-id" and "job-uri", all others
1660 * default to "all"...
1661 */
1662
cb7f98ee 1663 if (ippGetOperation(request) == IPP_OP_GET_JOBS)
db8b865d
MS
1664 {
1665 ra = cupsArrayNew((cups_array_func_t)strcmp, NULL);
1666 cupsArrayAdd(ra, "job-id");
1667 cupsArrayAdd(ra, "job-uri");
1668
1669 return (ra);
1670 }
1671 else
1672 return (NULL);
1673 }
1674
1675 /*
1676 * If the attribute contains a single "all" keyword, return NULL...
1677 */
1678
1679 count = ippGetCount(requested);
1680 if (count == 1 && !strcmp(ippGetString(requested, 0, NULL), "all"))
1681 return (NULL);
1682
1683 /*
1684 * Create an array using "strcmp" as the comparison function...
1685 */
1686
1687 ra = cupsArrayNew((cups_array_func_t)strcmp, NULL);
1688
1689 for (i = 0; i < count; i ++)
1690 {
1691 added = 0;
1692 value = ippGetString(requested, i, NULL);
1693
1694 if (!strcmp(value, "document-description") || !strcmp(value, "all"))
1695 {
1696 for (j = 0;
1697 j < (int)(sizeof(document_description) /
1698 sizeof(document_description[0]));
1699 j ++)
1700 cupsArrayAdd(ra, (void *)document_description[j]);
1701
1702 added = 1;
1703 }
1704
1705 if (!strcmp(value, "document-template") || !strcmp(value, "all"))
1706 {
1707 for (j = 0;
1708 j < (int)(sizeof(document_template) / sizeof(document_template[0]));
1709 j ++)
1710 cupsArrayAdd(ra, (void *)document_template[j]);
1711
1712 added = 1;
1713 }
1714
1715 if (!strcmp(value, "job-description") || !strcmp(value, "all"))
1716 {
1717 for (j = 0;
1718 j < (int)(sizeof(job_description) / sizeof(job_description[0]));
1719 j ++)
1720 cupsArrayAdd(ra, (void *)job_description[j]);
1721
1722 added = 1;
1723 }
1724
1725 if (!strcmp(value, "job-template") || !strcmp(value, "all"))
1726 {
1727 for (j = 0;
1728 j < (int)(sizeof(job_template) / sizeof(job_template[0]));
1729 j ++)
1730 cupsArrayAdd(ra, (void *)job_template[j]);
1731
1732 added = 1;
1733 }
1734
1735 if (!strcmp(value, "printer-description") || !strcmp(value, "all"))
1736 {
1737 for (j = 0;
1738 j < (int)(sizeof(printer_description) /
1739 sizeof(printer_description[0]));
1740 j ++)
1741 cupsArrayAdd(ra, (void *)printer_description[j]);
1742
1743 added = 1;
1744 }
1745
1746 if (!strcmp(value, "subscription-description") || !strcmp(value, "all"))
1747 {
1748 for (j = 0;
1749 j < (int)(sizeof(subscription_description) /
1750 sizeof(subscription_description[0]));
1751 j ++)
1752 cupsArrayAdd(ra, (void *)subscription_description[j]);
1753
1754 added = 1;
1755 }
1756
1757 if (!strcmp(value, "subscription-template") || !strcmp(value, "all"))
1758 {
1759 for (j = 0;
1760 j < (int)(sizeof(subscription_template) /
1761 sizeof(subscription_template[0]));
1762 j ++)
1763 cupsArrayAdd(ra, (void *)subscription_template[j]);
1764
1765 added = 1;
1766 }
1767
1768 if (!added)
1769 cupsArrayAdd(ra, (void *)value);
1770 }
1771
1772 return (ra);
1773}
1774
1775
a2326b5b
MS
1776/*
1777 * 'ippEnumString()' - Return a string corresponding to the enum value.
1778 */
1779
1780const char * /* O - Enum string */
1781ippEnumString(const char *attrname, /* I - Attribute name */
1782 int enumvalue) /* I - Enum value */
1783{
1784 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
1785
1786
1787 /*
1788 * Check for standard enum values...
1789 */
1790
1791 if (!strcmp(attrname, "document-state") &&
1792 enumvalue >= 3 &&
0fa6c7fa
MS
1793 enumvalue < (3 + (int)(sizeof(ipp_document_states) /
1794 sizeof(ipp_document_states[0]))))
a2326b5b 1795 return (ipp_document_states[enumvalue - 3]);
a469f8a5
MS
1796 else if (!strcmp(attrname, "finishings") ||
1797 !strcmp(attrname, "finishings-actual") ||
1798 !strcmp(attrname, "finishings-default") ||
1799 !strcmp(attrname, "finishings-ready") ||
6961465f
MS
1800 !strcmp(attrname, "finishings-supported") ||
1801 !strcmp(attrname, "job-finishings") ||
1802 !strcmp(attrname, "job-finishings-default") ||
1803 !strcmp(attrname, "job-finishings-supported"))
a469f8a5
MS
1804 {
1805 if (enumvalue >= 3 &&
0fa6c7fa
MS
1806 enumvalue < (3 + (int)(sizeof(ipp_finishings) /
1807 sizeof(ipp_finishings[0]))))
a469f8a5
MS
1808 return (ipp_finishings[enumvalue - 3]);
1809 else if (enumvalue >= 0x40000000 &&
1810 enumvalue <= (0x40000000 + (int)(sizeof(ipp_finishings_vendor) /
1811 sizeof(ipp_finishings_vendor[0]))))
1812 return (ipp_finishings_vendor[enumvalue - 0x40000000]);
1813 }
a2326b5b
MS
1814 else if ((!strcmp(attrname, "job-collation-type") ||
1815 !strcmp(attrname, "job-collation-type-actual")) &&
1816 enumvalue >= 3 &&
0fa6c7fa
MS
1817 enumvalue < (3 + (int)(sizeof(ipp_job_collation_types) /
1818 sizeof(ipp_job_collation_types[0]))))
a2326b5b
MS
1819 return (ipp_job_collation_types[enumvalue - 3]);
1820 else if (!strcmp(attrname, "job-state") &&
cb7f98ee
MS
1821 enumvalue >= IPP_JSTATE_PENDING && enumvalue <= IPP_JSTATE_COMPLETED)
1822 return (ipp_job_states[enumvalue - IPP_JSTATE_PENDING]);
a2326b5b
MS
1823 else if (!strcmp(attrname, "operations-supported"))
1824 return (ippOpString((ipp_op_t)enumvalue));
1825 else if ((!strcmp(attrname, "orientation-requested") ||
1826 !strcmp(attrname, "orientation-requested-actual") ||
1827 !strcmp(attrname, "orientation-requested-default") ||
1828 !strcmp(attrname, "orientation-requested-supported")) &&
1829 enumvalue >= 3 &&
0fa6c7fa
MS
1830 enumvalue < (3 + (int)(sizeof(ipp_orientation_requesteds) /
1831 sizeof(ipp_orientation_requesteds[0]))))
a2326b5b
MS
1832 return (ipp_orientation_requesteds[enumvalue - 3]);
1833 else if ((!strcmp(attrname, "print-quality") ||
1834 !strcmp(attrname, "print-quality-actual") ||
1835 !strcmp(attrname, "print-quality-default") ||
1836 !strcmp(attrname, "print-quality-supported")) &&
1837 enumvalue >= 3 &&
0fa6c7fa
MS
1838 enumvalue < (3 + (int)(sizeof(ipp_print_qualities) /
1839 sizeof(ipp_print_qualities[0]))))
a2326b5b
MS
1840 return (ipp_print_qualities[enumvalue - 3]);
1841 else if (!strcmp(attrname, "printer-state") &&
cb7f98ee
MS
1842 enumvalue >= IPP_PSTATE_IDLE && enumvalue <= IPP_PSTATE_STOPPED)
1843 return (ipp_printer_states[enumvalue - IPP_PSTATE_IDLE]);
a2326b5b
MS
1844
1845 /*
1846 * Not a standard enum value, just return the decimal equivalent...
1847 */
1848
1849 snprintf(cg->ipp_unknown, sizeof(cg->ipp_unknown), "%d", enumvalue);
1850 return (cg->ipp_unknown);
1851}
1852
1853
1854/*
1855 * 'ippEnumValue()' - Return the value associated with a given enum string.
1856 */
1857
1858int /* O - Enum value or -1 if unknown */
1859ippEnumValue(const char *attrname, /* I - Attribute name */
1860 const char *enumstring) /* I - Enum string */
1861{
1862 int i, /* Looping var */
1863 num_strings; /* Number of strings to compare */
1864 const char * const *strings; /* Strings to compare */
1865
1866
1867 /*
1868 * If the string is just a number, return it...
1869 */
1870
1871 if (isdigit(*enumstring & 255))
7e86f2f6 1872 return ((int)strtol(enumstring, NULL, 0));
a2326b5b
MS
1873
1874 /*
1875 * Otherwise look up the string...
1876 */
1877
1878 if (!strcmp(attrname, "document-state"))
1879 {
1880 num_strings = (int)(sizeof(ipp_document_states) / sizeof(ipp_document_states[0]));
1881 strings = ipp_document_states;
1882 }
1883 else if (!strcmp(attrname, "finishings") ||
1884 !strcmp(attrname, "finishings-actual") ||
1885 !strcmp(attrname, "finishings-default") ||
1886 !strcmp(attrname, "finishings-ready") ||
1887 !strcmp(attrname, "finishings-supported"))
1888 {
a469f8a5
MS
1889 for (i = 0;
1890 i < (int)(sizeof(ipp_finishings_vendor) /
1891 sizeof(ipp_finishings_vendor[0]));
1892 i ++)
1893 if (!strcmp(enumstring, ipp_finishings_vendor[i]))
1894 return (i + 0x40000000);
1895
a2326b5b
MS
1896 num_strings = (int)(sizeof(ipp_finishings) / sizeof(ipp_finishings[0]));
1897 strings = ipp_finishings;
1898 }
1899 else if (!strcmp(attrname, "job-collation-type") ||
1900 !strcmp(attrname, "job-collation-type-actual"))
1901 {
1902 num_strings = (int)(sizeof(ipp_job_collation_types) /
1903 sizeof(ipp_job_collation_types[0]));
1904 strings = ipp_job_collation_types;
1905 }
1906 else if (!strcmp(attrname, "job-state"))
1907 {
1908 num_strings = (int)(sizeof(ipp_job_states) / sizeof(ipp_job_states[0]));
1909 strings = ipp_job_states;
1910 }
1911 else if (!strcmp(attrname, "operations-supported"))
1912 return (ippOpValue(enumstring));
1913 else if (!strcmp(attrname, "orientation-requested") ||
1914 !strcmp(attrname, "orientation-requested-actual") ||
1915 !strcmp(attrname, "orientation-requested-default") ||
1916 !strcmp(attrname, "orientation-requested-supported"))
1917 {
1918 num_strings = (int)(sizeof(ipp_orientation_requesteds) /
1919 sizeof(ipp_orientation_requesteds[0]));
1920 strings = ipp_orientation_requesteds;
1921 }
1922 else if (!strcmp(attrname, "print-quality") ||
1923 !strcmp(attrname, "print-quality-actual") ||
1924 !strcmp(attrname, "print-quality-default") ||
1925 !strcmp(attrname, "print-quality-supported"))
1926 {
1927 num_strings = (int)(sizeof(ipp_print_qualities) / sizeof(ipp_print_qualities[0]));
1928 strings = ipp_print_qualities;
1929 }
1930 else if (!strcmp(attrname, "printer-state"))
1931 {
1932 num_strings = (int)(sizeof(ipp_printer_states) / sizeof(ipp_printer_states[0]));
1933 strings = ipp_printer_states;
1934 }
1935 else
1936 return (-1);
1937
1938 for (i = 0; i < num_strings; i ++)
1939 if (!strcmp(enumstring, strings[i]))
1940 return (i + 3);
1941
1942 return (-1);
1943}
1944
1945
ef416fc2 1946/*
1947 * 'ippErrorString()' - Return a name for the given status code.
1948 */
1949
1950const char * /* O - Text string */
1951ippErrorString(ipp_status_t error) /* I - Error status */
1952{
1953 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
1954
1955
1956 /*
1957 * See if the error code is a known value...
1958 */
1959
a469f8a5 1960 if (error >= IPP_STATUS_OK && error <= IPP_STATUS_OK_EVENTS_COMPLETE)
ef416fc2 1961 return (ipp_status_oks[error]);
a469f8a5 1962 else if (error == IPP_STATUS_REDIRECTION_OTHER_SITE)
ef416fc2 1963 return ("redirection-other-site");
a469f8a5 1964 else if (error == IPP_STATUS_CUPS_SEE_OTHER)
b94498cf 1965 return ("cups-see-other");
a469f8a5 1966 else if (error >= IPP_STATUS_ERROR_BAD_REQUEST &&
6b13fa61 1967 error <= IPP_STATUS_ERROR_ACCOUNT_AUTHORIZATION_FAILED)
a469f8a5
MS
1968 return (ipp_status_400s[error - IPP_STATUS_ERROR_BAD_REQUEST]);
1969 else if (error >= 0x480 &&
1970 error <= IPP_STATUS_ERROR_CUPS_ACCOUNT_AUTHORIZATION_FAILED)
1971 return (ipp_status_480s[error - 0x0480]);
1972 else if (error >= IPP_STATUS_ERROR_INTERNAL &&
1973 error <= IPP_STATUS_ERROR_TOO_MANY_DOCUMENTS)
1974 return (ipp_status_500s[error - IPP_STATUS_ERROR_INTERNAL]);
1975 else if (error >= IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED &&
1976 error <= IPP_STATUS_ERROR_CUPS_UPGRADE_REQUIRED)
1977 return (ipp_status_1000s[error -
1978 IPP_STATUS_ERROR_CUPS_AUTHENTICATION_CANCELED]);
ef416fc2 1979
1980 /*
d7225fc2 1981 * No, build an "0xxxxx" error string...
ef416fc2 1982 */
1983
d7225fc2 1984 sprintf(cg->ipp_unknown, "0x%04x", error);
ef416fc2 1985
1986 return (cg->ipp_unknown);
1987}
1988
1989
1990/*
1991 * 'ippErrorValue()' - Return a status code for the given name.
1992 *
8072030b 1993 * @since CUPS 1.2/macOS 10.5@
ef416fc2 1994 */
1995
1996ipp_status_t /* O - IPP status code */
1997ippErrorValue(const char *name) /* I - Name */
1998{
7e86f2f6 1999 size_t i; /* Looping var */
ef416fc2 2000
2001
2002 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
88f9aafc 2003 if (!_cups_strcasecmp(name, ipp_status_oks[i]))
ef416fc2 2004 return ((ipp_status_t)i);
2005
88f9aafc 2006 if (!_cups_strcasecmp(name, "redirection-other-site"))
a469f8a5 2007 return (IPP_STATUS_REDIRECTION_OTHER_SITE);
ef416fc2 2008
88f9aafc 2009 if (!_cups_strcasecmp(name, "cups-see-other"))
a469f8a5 2010 return (IPP_STATUS_CUPS_SEE_OTHER);
b94498cf 2011
ef416fc2 2012 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
88f9aafc 2013 if (!_cups_strcasecmp(name, ipp_status_400s[i]))
ef416fc2 2014 return ((ipp_status_t)(i + 0x400));
2015
a469f8a5
MS
2016 for (i = 0; i < (sizeof(ipp_status_480s) / sizeof(ipp_status_480s[0])); i ++)
2017 if (!_cups_strcasecmp(name, ipp_status_480s[i]))
2018 return ((ipp_status_t)(i + 0x480));
2019
ef416fc2 2020 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
88f9aafc 2021 if (!_cups_strcasecmp(name, ipp_status_500s[i]))
ef416fc2 2022 return ((ipp_status_t)(i + 0x500));
2023
7cf5915e 2024 for (i = 0; i < (sizeof(ipp_status_1000s) / sizeof(ipp_status_1000s[0])); i ++)
88f9aafc 2025 if (!_cups_strcasecmp(name, ipp_status_1000s[i]))
7cf5915e
MS
2026 return ((ipp_status_t)(i + 0x1000));
2027
ef416fc2 2028 return ((ipp_status_t)-1);
2029}
2030
2031
2032/*
2033 * 'ippOpString()' - Return a name for the given operation id.
2034 *
8072030b 2035 * @since CUPS 1.2/macOS 10.5@
ef416fc2 2036 */
2037
2038const char * /* O - Name */
2039ippOpString(ipp_op_t op) /* I - Operation ID */
2040{
2041 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
2042
2043
2044 /*
2045 * See if the operation ID is a known value...
2046 */
2047
db8b865d 2048 if (op >= IPP_OP_PRINT_JOB && op <= IPP_OP_VALIDATE_DOCUMENT)
ef416fc2 2049 return (ipp_std_ops[op]);
a469f8a5 2050 else if (op == IPP_OP_PRIVATE)
ef416fc2 2051 return ("windows-ext");
a469f8a5 2052 else if (op >= IPP_OP_CUPS_GET_DEFAULT && op <= IPP_OP_CUPS_GET_PPD)
cb7f98ee 2053 return (ipp_cups_ops[op - IPP_OP_CUPS_GET_DEFAULT]);
c585706d
MS
2054 else if (op >= IPP_OP_CUPS_GET_DOCUMENT && op <= IPP_OP_CUPS_CREATE_LOCAL_PRINTER)
2055 return (ipp_cups_ops2[op - IPP_OP_CUPS_GET_DOCUMENT]);
ef416fc2 2056
2057 /*
d7225fc2 2058 * No, build an "0xxxxx" operation string...
ef416fc2 2059 */
2060
9b66acc5 2061 sprintf(cg->ipp_unknown, "0x%04x", op);
ef416fc2 2062
2063 return (cg->ipp_unknown);
2064}
2065
2066
2067/*
2068 * 'ippOpValue()' - Return an operation id for the given name.
2069 *
8072030b 2070 * @since CUPS 1.2/macOS 10.5@
ef416fc2 2071 */
2072
2073ipp_op_t /* O - Operation ID */
2074ippOpValue(const char *name) /* I - Textual name */
2075{
7e86f2f6 2076 size_t i; /* Looping var */
ef416fc2 2077
2078
9b66acc5
MS
2079 if (!strncmp(name, "0x", 2))
2080 return ((ipp_op_t)strtol(name + 2, NULL, 16));
2081
ef416fc2 2082 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
88f9aafc 2083 if (!_cups_strcasecmp(name, ipp_std_ops[i]))
ef416fc2 2084 return ((ipp_op_t)i);
2085
88f9aafc 2086 if (!_cups_strcasecmp(name, "windows-ext"))
a469f8a5 2087 return (IPP_OP_PRIVATE);
ef416fc2 2088
2089 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
88f9aafc 2090 if (!_cups_strcasecmp(name, ipp_cups_ops[i]))
ef416fc2 2091 return ((ipp_op_t)(i + 0x4001));
2092
2e4ff8af 2093 for (i = 0; i < (sizeof(ipp_cups_ops2) / sizeof(ipp_cups_ops2[0])); i ++)
88f9aafc 2094 if (!_cups_strcasecmp(name, ipp_cups_ops2[i]))
2e4ff8af
MS
2095 return ((ipp_op_t)(i + 0x4027));
2096
42404685
MS
2097 if (!_cups_strcasecmp(name, "Create-Job-Subscription"))
2098 return (IPP_OP_CREATE_JOB_SUBSCRIPTIONS);
2099
2100 if (!_cups_strcasecmp(name, "Create-Printer-Subscription"))
2101 return (IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS);
2102
88f9aafc 2103 if (!_cups_strcasecmp(name, "CUPS-Add-Class"))
a469f8a5 2104 return (IPP_OP_CUPS_ADD_MODIFY_CLASS);
480ef0fe 2105
88f9aafc 2106 if (!_cups_strcasecmp(name, "CUPS-Add-Printer"))
a469f8a5 2107 return (IPP_OP_CUPS_ADD_MODIFY_PRINTER);
480ef0fe 2108
a469f8a5 2109 return (IPP_OP_CUPS_INVALID);
ef416fc2 2110}
2111
2112
2113/*
2114 * 'ippPort()' - Return the default IPP port number.
2115 */
2116
2117int /* O - Port number */
2118ippPort(void)
2119{
ef416fc2 2120 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
2121
2122
d09495fa 2123 DEBUG_puts("ippPort()");
2124
2125 if (!cg->ipp_port)
e07d4801 2126 _cupsSetDefaults();
d09495fa 2127
e07d4801 2128 DEBUG_printf(("1ippPort: Returning %d...", cg->ipp_port));
d09495fa 2129
ef416fc2 2130 return (cg->ipp_port);
2131}
2132
2133
2134/*
2135 * 'ippSetPort()' - Set the default port number.
2136 */
2137
2138void
2139ippSetPort(int p) /* I - Port number to use */
2140{
e07d4801 2141 DEBUG_printf(("ippSetPort(p=%d)", p));
d09495fa 2142
ef416fc2 2143 _cupsGlobals()->ipp_port = p;
2144}
2145
2146
d21dc0ed
MS
2147/*
2148 * 'ippStateString()' - Return the name corresponding to a state value.
2149 *
e1f19878 2150 * @since CUPS 2.0/OS 10.10@
d21dc0ed
MS
2151 */
2152
2153const char * /* O - State name */
2154ippStateString(ipp_state_t state) /* I - State value */
2155{
2156 if (state >= IPP_STATE_ERROR && state <= IPP_STATE_DATA)
2157 return (ipp_states[state - IPP_STATE_ERROR]);
2158 else
2159 return ("UNKNOWN");
2160}
2161
2162
ef416fc2 2163/*
1ff0402e
MS
2164 * 'ippTagString()' - Return the tag name corresponding to a tag value.
2165 *
2166 * The returned names are defined in RFC 2911 and 3382.
2167 *
8072030b 2168 * @since CUPS 1.4/macOS 10.6@
1ff0402e
MS
2169 */
2170
2171const char * /* O - Tag name */
2172ippTagString(ipp_tag_t tag) /* I - Tag value */
2173{
cb7f98ee 2174 tag &= IPP_TAG_CUPS_MASK;
ed6e7faf 2175
1ff0402e
MS
2176 if (tag < (ipp_tag_t)(sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])))
2177 return (ipp_tag_names[tag]);
2178 else
2179 return ("UNKNOWN");
2180}
2181
2182
2183/*
2184 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
2185 *
2186 * The tag names are defined in RFC 2911 and 3382.
2187 *
8072030b 2188 * @since CUPS 1.4/macOS 10.6@
1ff0402e
MS
2189 */
2190
2191ipp_tag_t /* O - Tag value */
2192ippTagValue(const char *name) /* I - Tag name */
2193{
7e86f2f6 2194 size_t i; /* Looping var */
1ff0402e
MS
2195
2196
2197 for (i = 0; i < (sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])); i ++)
88f9aafc 2198 if (!_cups_strcasecmp(name, ipp_tag_names[i]))
1ff0402e
MS
2199 return ((ipp_tag_t)i);
2200
88f9aafc 2201 if (!_cups_strcasecmp(name, "operation"))
1ff0402e 2202 return (IPP_TAG_OPERATION);
88f9aafc 2203 else if (!_cups_strcasecmp(name, "job"))
1ff0402e 2204 return (IPP_TAG_JOB);
88f9aafc 2205 else if (!_cups_strcasecmp(name, "printer"))
1ff0402e 2206 return (IPP_TAG_PRINTER);
88f9aafc 2207 else if (!_cups_strcasecmp(name, "unsupported"))
5a6b583a 2208 return (IPP_TAG_UNSUPPORTED_GROUP);
88f9aafc 2209 else if (!_cups_strcasecmp(name, "subscription"))
1ff0402e 2210 return (IPP_TAG_SUBSCRIPTION);
88f9aafc 2211 else if (!_cups_strcasecmp(name, "event"))
5a6b583a 2212 return (IPP_TAG_EVENT_NOTIFICATION);
88f9aafc 2213 else if (!_cups_strcasecmp(name, "language"))
1ff0402e 2214 return (IPP_TAG_LANGUAGE);
88f9aafc 2215 else if (!_cups_strcasecmp(name, "mimetype"))
1ff0402e 2216 return (IPP_TAG_MIMETYPE);
88f9aafc 2217 else if (!_cups_strcasecmp(name, "name"))
1ff0402e 2218 return (IPP_TAG_NAME);
88f9aafc 2219 else if (!_cups_strcasecmp(name, "text"))
1ff0402e 2220 return (IPP_TAG_TEXT);
88f9aafc 2221 else if (!_cups_strcasecmp(name, "begCollection"))
5a6b583a 2222 return (IPP_TAG_BEGIN_COLLECTION);
1ff0402e
MS
2223 else
2224 return (IPP_TAG_ZERO);
2225}
2226
2227
2228/*
1106b00e
MS
2229 * 'ipp_col_string()' - Convert a collection to a string.
2230 */
2231
2232static size_t /* O - Number of bytes */
2233ipp_col_string(ipp_t *col, /* I - Collection attribute */
2234 char *buffer, /* I - Buffer or NULL */
2235 size_t bufsize) /* I - Size of buffer */
2236{
2237 char *bufptr, /* Position in buffer */
2238 *bufend, /* End of buffer */
9c80ffa2 2239 prefix = '{', /* Prefix character */
1106b00e
MS
2240 temp[256]; /* Temporary string */
2241 ipp_attribute_t *attr; /* Current member attribute */
2242
2243
2c69d462
MS
2244 if (!col)
2245 {
2246 if (buffer)
2247 *buffer = '\0';
2248
2249 return (0);
2250 }
2251
1106b00e
MS
2252 bufptr = buffer;
2253 bufend = buffer + bufsize - 1;
2254
1106b00e
MS
2255 for (attr = col->attrs; attr; attr = attr->next)
2256 {
2257 if (!attr->name)
2258 continue;
2259
9c80ffa2
MS
2260 if (buffer && bufptr < bufend)
2261 *bufptr = prefix;
2262 bufptr ++;
2263 prefix = ' ';
2264
1106b00e 2265 if (buffer && bufptr < bufend)
07623986 2266 bufptr += snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%s=", attr->name);
1106b00e
MS
2267 else
2268 bufptr += strlen(attr->name) + 1;
2269
2270 if (buffer && bufptr < bufend)
7e86f2f6 2271 bufptr += ippAttributeString(attr, bufptr, (size_t)(bufend - bufptr + 1));
1106b00e 2272 else
a2326b5b 2273 bufptr += ippAttributeString(attr, temp, sizeof(temp));
1106b00e
MS
2274 }
2275
9c80ffa2
MS
2276 if (prefix == '{')
2277 {
2278 if (buffer && bufptr < bufend)
2279 *bufptr = prefix;
2280 bufptr ++;
2281 }
2282
1106b00e
MS
2283 if (buffer && bufptr < bufend)
2284 *bufptr = '}';
2285 bufptr ++;
2286
7e86f2f6 2287 return ((size_t)(bufptr - buffer));
1106b00e 2288}