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