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