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