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