2 * "$Id: ipp-support.c 9371 2010-11-17 06:21:32Z mike $"
4 * Internet Printing Protocol support functions for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * ippAttributeString() - Convert the attribute's value to a string.
20 * ippEnumString() - Return a string corresponding to the enum value.
21 * ippEnumValue() - Return the value associated with a given enum
23 * ippErrorString() - Return a name for the given status code.
24 * ippErrorValue() - Return a status code for the given name.
25 * ippOpString() - Return a name for the given operation id.
26 * ippOpValue() - Return an operation id for the given name.
27 * ippPort() - Return the default IPP port number.
28 * ippSetPort() - Set the default port number.
29 * ippTagString() - Return the tag name corresponding to a tag value.
30 * ippTagValue() - Return the tag value corresponding to a tag name.
31 * ipp_col_string() - Convert a collection to a string.
35 * Include necessary headers...
38 #include "cups-private.h"
45 static const char * const ipp_status_oks
[] = /* "OK" status codes */
46 { /* (name) = abandoned standard value */
48 "successful-ok-ignored-or-substituted-attributes",
49 "successful-ok-conflicting-attributes",
50 "successful-ok-ignored-subscriptions",
51 "(successful-ok-ignored-notifications)",
52 "successful-ok-too-many-events",
53 "(successful-ok-but-cancel-subscription)",
54 "successful-ok-events-complete"
56 * const ipp_status_400s
[] = /* Client errors */
57 { /* (name) = abandoned standard value */
58 "client-error-bad-request",
59 "client-error-forbidden",
60 "client-error-not-authenticated",
61 "client-error-not-authorized",
62 "client-error-not-possible",
63 "client-error-timeout",
64 "client-error-not-found",
66 "client-error-request-entity-too-large",
67 "client-error-request-value-too-long",
68 "client-error-document-format-not-supported",
69 "client-error-attributes-or-values-not-supported",
70 "client-error-uri-scheme-not-supported",
71 "client-error-charset-not-supported",
72 "client-error-conflicting-attributes",
73 "client-error-compression-not-supported",
74 "client-error-compression-error",
75 "client-error-document-format-error",
76 "client-error-document-access-error",
77 "client-error-attributes-not-settable",
78 "client-error-ignored-all-subscriptions",
79 "client-error-too-many-subscriptions",
80 "(client-error-ignored-all-notifications)",
81 "(client-error-client-print-support-file-not-found)"
83 * const ipp_status_500s
[] = /* Server errors */
85 "server-error-internal-error",
86 "server-error-operation-not-supported",
87 "server-error-service-unavailable",
88 "server-error-version-not-supported",
89 "server-error-device-error",
90 "server-error-temporary-error",
91 "server-error-not-accepting-jobs",
93 "server-error-job-canceled",
94 "server-error-multiple-document-jobs-not-supported",
95 "server-error-printer-is-deactivated",
96 "server-error-too-many-jobs",
97 "server-error-too-many-documents"
99 * const ipp_status_1000s
[] = /* CUPS internal */
101 "cups-authorization-canceled",
103 "cups-upgrade-required"
105 static const char * const ipp_std_ops
[] =
107 /* 0x0000 - 0x000f */
117 "Get-Job-Attributes",
119 "Get-Printer-Attributes",
125 /* 0x0010 - 0x001f */
129 "Set-Printer-Attributes",
130 "Set-Job-Attributes",
131 "Get-Printer-Supported-Values",
132 "Create-Printer-Subscription",
133 "Create-Job-Subscription",
134 "Get-Subscription-Attributes",
136 "Renew-Subscription",
137 "Cancel-Subscription",
139 "(Send-Notifications)",
140 "(Get-Resource-Attributes)",
141 "(Get-Resource-Data)",
143 /* 0x0020 - 0x002f */
145 "(Get-Printer-Support-Files)",
148 "Pause-Printer-After-Current-Job",
150 "Release-Held-New-Jobs",
151 "Deactivate-Printer",
157 "Cancel-Current-Job",
158 "Suspend-Current-Job",
161 /* 0x0030 - 0x003b */
163 "Schedule-Job-After",
166 "Get-Document-Attributes",
169 "Set-Document-Attributes",
176 * const ipp_cups_ops
[] =
180 "CUPS-Add-Modify-Printer",
181 "CUPS-Delete-Printer",
183 "CUPS-Add-Modify-Class",
191 "CUPS-Authenticate-Job",
194 * const ipp_cups_ops2
[] =
198 * const ipp_tag_names
[] =
199 { /* Value/group tag names */
201 "operation-attributes-tag",
203 "job-attributes-tag", /* 0x02 */
204 "end-of-attributes-tag",
206 "printer-attributes-tag",
208 "unsupported-attributes-tag",
210 "subscription-attributes-tag",
212 "event-notification-attributes-tag",
214 "(resource-attributes-tag)",
216 "document-attributes-tag",
224 "unsupported", /* 0x10 */
225 "default", /* 0x11 */
226 "unknown", /* 0x12 */
227 "no-value", /* 0x13 */
229 "not-settable", /* 0x15 */
230 "delete-attribute", /* 0x16 */
231 "admin-define", /* 0x17 */
241 "integer", /* 0x21 */
242 "boolean", /* 0x22 */
256 "octetString", /* 0x30 */
257 "dateTime", /* 0x31 */
258 "resolution", /* 0x32 */
259 "rangeOfInteger", /* 0x33 */
260 "collection", /* 0x34 */
261 "textWithLanguage", /* 0x35 */
262 "nameWithLanguage", /* 0x36 */
263 "endCollection", /* 0x37 */
273 "textWithoutLanguage",/* 0x41 */
274 "nameWithoutLanguage",/* 0x42 */
276 "keyword", /* 0x44 */
278 "uriScheme", /* 0x46 */
279 "charset", /* 0x47 */
280 "naturalLanguage", /* 0x48 */
281 "mimeMediaType", /* 0x49 */
282 "memberAttrName" /* 0x4a */
284 static const char * const ipp_document_states
[] =
285 { /* document-state-enums */
294 * const ipp_finishings
[] =
295 { /* finishings enums */
314 "staple-bottom-left",
316 "staple-bottom-right",
320 "edge-stitch-bottom",
324 "staple-dual-bottom",
354 "trim-after-documents",
358 * const ipp_job_collation_types
[] =
359 { /* job-collation-type enums */
361 "collated-documents",
362 "uncollated-documents"
364 * const ipp_job_states
[] =
365 { /* job-state enums */
369 "processing-stopped",
374 * const ipp_orientation_requesteds
[] =
375 { /* orientation-requested enums */
381 * const ipp_print_qualities
[] =
382 { /* print-quality enums */
387 * const ipp_printer_states
[] =
388 { /* printer-state enums */
399 static size_t ipp_col_string(ipp_t
*col
, char *buffer
, size_t bufsize
);
403 * 'ippAttributeString()' - Convert the attribute's value to a string.
405 * Returns the number of bytes that would be written, not including the
406 * trailing nul. The buffer pointer can be NULL to get the required length,
407 * just like (v)snprintf.
412 size_t /* O - Number of bytes less nul */
414 ipp_attribute_t
*attr
, /* I - Attribute */
415 char *buffer
, /* I - String buffer or NULL */
416 size_t bufsize
) /* I - Size of string buffer */
418 int i
; /* Looping var */
419 char *bufptr
, /* Pointer into buffer */
420 *bufend
, /* End of buffer */
421 temp
[256]; /* Temporary string */
422 const char *ptr
; /* Pointer into string */
423 _ipp_value_t
*val
; /* Current value */
426 if (!attr
|| !attr
->name
)
436 bufend
= buffer
+ bufsize
- 1;
440 for (i
= attr
->num_values
, val
= attr
->values
; i
> 0; i
--, val
++)
442 if (val
> attr
->values
)
444 if (buffer
&& bufptr
< bufend
)
450 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
453 ptr
= ippEnumString(attr
->name
, val
->integer
);
455 if (buffer
&& bufptr
< bufend
)
456 strlcpy(bufptr
, ptr
, bufend
- bufptr
+ 1);
458 bufptr
+= strlen(ptr
);
461 case IPP_TAG_INTEGER
:
462 if (buffer
&& bufptr
< bufend
)
463 bufptr
+= snprintf(bufptr
, bufend
- bufptr
+ 1, "%d", val
->integer
);
465 bufptr
+= snprintf(temp
, sizeof(temp
), "%d", val
->integer
);
468 case IPP_TAG_BOOLEAN
:
469 if (buffer
&& bufptr
< bufend
)
470 strlcpy(bufptr
, val
->boolean
? "true" : "false",
471 bufend
- bufptr
+ 1);
473 bufptr
+= val
->boolean
? 4 : 5;
477 if (buffer
&& bufptr
< bufend
)
478 bufptr
+= snprintf(bufptr
, bufend
- bufptr
+ 1, "%d-%d",
479 val
->range
.lower
, val
->range
.upper
);
481 bufptr
+= snprintf(temp
, sizeof(temp
), "%d-%d", val
->range
.lower
,
485 case IPP_TAG_RESOLUTION
:
486 if (buffer
&& bufptr
< bufend
)
487 bufptr
+= snprintf(bufptr
, bufend
- bufptr
+ 1, "%dx%d%s",
488 val
->resolution
.xres
, val
->resolution
.yres
,
489 val
->resolution
.units
== IPP_RES_PER_INCH
?
492 bufptr
+= snprintf(temp
, sizeof(temp
), "%dx%d%s",
493 val
->resolution
.xres
, val
->resolution
.yres
,
494 val
->resolution
.units
== IPP_RES_PER_INCH
?
500 unsigned year
; /* Year */
502 year
= (val
->date
[0] << 8) + val
->date
[1];
504 if (val
->date
[9] == 0 && val
->date
[10] == 0)
505 snprintf(temp
, sizeof(temp
), "%04u-%02u-%02uT%02u:%02u:%02uZ",
506 year
, val
->date
[2], val
->date
[3], val
->date
[4],
507 val
->date
[5], val
->date
[6]);
509 snprintf(temp
, sizeof(temp
),
510 "%04u-%02u-%02uT%02u:%02u:%02u%c%02u%02u",
511 year
, val
->date
[2], val
->date
[3], val
->date
[4],
512 val
->date
[5], val
->date
[6], val
->date
[8], val
->date
[9],
515 if (buffer
&& bufptr
< bufend
)
516 strlcpy(bufptr
, temp
, bufend
- bufptr
+ 1);
518 bufptr
+= strlen(temp
);
524 case IPP_TAG_KEYWORD
:
525 case IPP_TAG_CHARSET
:
527 case IPP_TAG_URISCHEME
:
528 case IPP_TAG_MIMETYPE
:
529 case IPP_TAG_LANGUAGE
:
530 case IPP_TAG_TEXTLANG
:
531 case IPP_TAG_NAMELANG
:
532 if (!val
->string
.text
)
535 for (ptr
= val
->string
.text
; *ptr
; ptr
++)
537 if (*ptr
== '\\' || *ptr
== '\"' || *ptr
== '[')
539 if (buffer
&& bufptr
< bufend
)
544 if (buffer
&& bufptr
< bufend
)
549 if (val
->string
.language
)
552 * Add "[language]" to end of string...
555 if (buffer
&& bufptr
< bufend
)
559 if (buffer
&& bufptr
< bufend
)
560 strlcpy(bufptr
, val
->string
.language
, bufend
- bufptr
);
561 bufptr
+= strlen(val
->string
.language
);
563 if (buffer
&& bufptr
< bufend
)
569 case IPP_TAG_BEGIN_COLLECTION
:
570 if (buffer
&& bufptr
< bufend
)
571 bufptr
+= ipp_col_string(val
->collection
, bufptr
,
572 bufend
- bufptr
+ 1);
574 bufptr
+= ipp_col_string(val
->collection
, NULL
, 0);
577 case IPP_TAG_STRING
:
578 for (ptr
= val
->string
.text
; *ptr
; ptr
++)
580 if (*ptr
== '\\' || _cups_isspace(*ptr
))
582 if (buffer
&& bufptr
< bufend
)
586 if (buffer
&& bufptr
< bufend
)
590 else if (!isprint(*ptr
& 255))
592 if (buffer
&& bufptr
< bufend
)
593 bufptr
+= snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o",
596 bufptr
+= snprintf(temp
, sizeof(temp
), "\\%03o",
601 if (buffer
&& bufptr
< bufend
)
609 ptr
= ippTagString(attr
->value_tag
);
610 if (buffer
&& bufptr
< bufend
)
611 strlcpy(bufptr
, ptr
, bufend
- bufptr
+ 1);
612 bufptr
+= strlen(ptr
);
617 if (buffer
&& bufptr
< bufend
)
622 return (bufptr
- buffer
);
627 * 'ippEnumString()' - Return a string corresponding to the enum value.
630 const char * /* O - Enum string */
631 ippEnumString(const char *attrname
, /* I - Attribute name */
632 int enumvalue
) /* I - Enum value */
634 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
638 * Check for standard enum values...
641 if (!strcmp(attrname
, "document-state") &&
643 enumvalue
<= (3 + (int)(sizeof(ipp_document_states
) /
644 sizeof(ipp_document_states
[0]))))
645 return (ipp_document_states
[enumvalue
- 3]);
646 else if ((!strcmp(attrname
, "finishings") ||
647 !strcmp(attrname
, "finishings-actual") ||
648 !strcmp(attrname
, "finishings-default") ||
649 !strcmp(attrname
, "finishings-ready") ||
650 !strcmp(attrname
, "finishings-supported")) &&
652 enumvalue
<= (3 + (int)(sizeof(ipp_finishings
) / sizeof(ipp_finishings
[0]))))
653 return (ipp_finishings
[enumvalue
- 3]);
654 else if ((!strcmp(attrname
, "job-collation-type") ||
655 !strcmp(attrname
, "job-collation-type-actual")) &&
657 enumvalue
<= (3 + (int)(sizeof(ipp_job_collation_types
) /
658 sizeof(ipp_job_collation_types
[0]))))
659 return (ipp_job_collation_types
[enumvalue
- 3]);
660 else if (!strcmp(attrname
, "job-state") &&
661 enumvalue
>= IPP_JOB_PENDING
&& enumvalue
<= IPP_JOB_COMPLETED
)
662 return (ipp_job_states
[enumvalue
- IPP_JOB_PENDING
]);
663 else if (!strcmp(attrname
, "operations-supported"))
664 return (ippOpString((ipp_op_t
)enumvalue
));
665 else if ((!strcmp(attrname
, "orientation-requested") ||
666 !strcmp(attrname
, "orientation-requested-actual") ||
667 !strcmp(attrname
, "orientation-requested-default") ||
668 !strcmp(attrname
, "orientation-requested-supported")) &&
670 enumvalue
<= (3 + (int)(sizeof(ipp_orientation_requesteds
) /
671 sizeof(ipp_orientation_requesteds
[0]))))
672 return (ipp_orientation_requesteds
[enumvalue
- 3]);
673 else if ((!strcmp(attrname
, "print-quality") ||
674 !strcmp(attrname
, "print-quality-actual") ||
675 !strcmp(attrname
, "print-quality-default") ||
676 !strcmp(attrname
, "print-quality-supported")) &&
678 enumvalue
<= (3 + (int)(sizeof(ipp_print_qualities
) /
679 sizeof(ipp_print_qualities
[0]))))
680 return (ipp_print_qualities
[enumvalue
- 3]);
681 else if (!strcmp(attrname
, "printer-state") &&
682 enumvalue
>= IPP_PRINTER_IDLE
&& enumvalue
<= IPP_PRINTER_STOPPED
)
683 return (ipp_printer_states
[enumvalue
- IPP_PRINTER_IDLE
]);
686 * Not a standard enum value, just return the decimal equivalent...
689 snprintf(cg
->ipp_unknown
, sizeof(cg
->ipp_unknown
), "%d", enumvalue
);
690 return (cg
->ipp_unknown
);
695 * 'ippEnumValue()' - Return the value associated with a given enum string.
698 int /* O - Enum value or -1 if unknown */
699 ippEnumValue(const char *attrname
, /* I - Attribute name */
700 const char *enumstring
) /* I - Enum string */
702 int i
, /* Looping var */
703 num_strings
; /* Number of strings to compare */
704 const char * const *strings
; /* Strings to compare */
708 * If the string is just a number, return it...
711 if (isdigit(*enumstring
& 255))
712 return (strtol(enumstring
, NULL
, 0));
715 * Otherwise look up the string...
718 if (!strcmp(attrname
, "document-state"))
720 num_strings
= (int)(sizeof(ipp_document_states
) / sizeof(ipp_document_states
[0]));
721 strings
= ipp_document_states
;
723 else if (!strcmp(attrname
, "finishings") ||
724 !strcmp(attrname
, "finishings-actual") ||
725 !strcmp(attrname
, "finishings-default") ||
726 !strcmp(attrname
, "finishings-ready") ||
727 !strcmp(attrname
, "finishings-supported"))
729 num_strings
= (int)(sizeof(ipp_finishings
) / sizeof(ipp_finishings
[0]));
730 strings
= ipp_finishings
;
732 else if (!strcmp(attrname
, "job-collation-type") ||
733 !strcmp(attrname
, "job-collation-type-actual"))
735 num_strings
= (int)(sizeof(ipp_job_collation_types
) /
736 sizeof(ipp_job_collation_types
[0]));
737 strings
= ipp_job_collation_types
;
739 else if (!strcmp(attrname
, "job-state"))
741 num_strings
= (int)(sizeof(ipp_job_states
) / sizeof(ipp_job_states
[0]));
742 strings
= ipp_job_states
;
744 else if (!strcmp(attrname
, "operations-supported"))
745 return (ippOpValue(enumstring
));
746 else if (!strcmp(attrname
, "orientation-requested") ||
747 !strcmp(attrname
, "orientation-requested-actual") ||
748 !strcmp(attrname
, "orientation-requested-default") ||
749 !strcmp(attrname
, "orientation-requested-supported"))
751 num_strings
= (int)(sizeof(ipp_orientation_requesteds
) /
752 sizeof(ipp_orientation_requesteds
[0]));
753 strings
= ipp_orientation_requesteds
;
755 else if (!strcmp(attrname
, "print-quality") ||
756 !strcmp(attrname
, "print-quality-actual") ||
757 !strcmp(attrname
, "print-quality-default") ||
758 !strcmp(attrname
, "print-quality-supported"))
760 num_strings
= (int)(sizeof(ipp_print_qualities
) / sizeof(ipp_print_qualities
[0]));
761 strings
= ipp_print_qualities
;
763 else if (!strcmp(attrname
, "printer-state"))
765 num_strings
= (int)(sizeof(ipp_printer_states
) / sizeof(ipp_printer_states
[0]));
766 strings
= ipp_printer_states
;
771 for (i
= 0; i
< num_strings
; i
++)
772 if (!strcmp(enumstring
, strings
[i
]))
780 * 'ippErrorString()' - Return a name for the given status code.
783 const char * /* O - Text string */
784 ippErrorString(ipp_status_t error
) /* I - Error status */
786 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
790 * See if the error code is a known value...
793 if (error
>= IPP_OK
&& error
<= IPP_OK_EVENTS_COMPLETE
)
794 return (ipp_status_oks
[error
]);
795 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
796 return ("redirection-other-site");
797 else if (error
== CUPS_SEE_OTHER
)
798 return ("cups-see-other");
799 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
800 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
801 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
802 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
803 else if (error
>= IPP_AUTHENTICATION_CANCELED
&& error
<= IPP_UPGRADE_REQUIRED
)
804 return (ipp_status_1000s
[error
- IPP_AUTHENTICATION_CANCELED
]);
807 * No, build an "0xxxxx" error string...
810 sprintf(cg
->ipp_unknown
, "0x%04x", error
);
812 return (cg
->ipp_unknown
);
817 * 'ippErrorValue()' - Return a status code for the given name.
819 * @since CUPS 1.2/Mac OS X 10.5@
822 ipp_status_t
/* O - IPP status code */
823 ippErrorValue(const char *name
) /* I - Name */
828 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
829 if (!_cups_strcasecmp(name
, ipp_status_oks
[i
]))
830 return ((ipp_status_t
)i
);
832 if (!_cups_strcasecmp(name
, "redirection-other-site"))
833 return (IPP_REDIRECTION_OTHER_SITE
);
835 if (!_cups_strcasecmp(name
, "cups-see-other"))
836 return (CUPS_SEE_OTHER
);
838 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
839 if (!_cups_strcasecmp(name
, ipp_status_400s
[i
]))
840 return ((ipp_status_t
)(i
+ 0x400));
842 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
843 if (!_cups_strcasecmp(name
, ipp_status_500s
[i
]))
844 return ((ipp_status_t
)(i
+ 0x500));
846 for (i
= 0; i
< (sizeof(ipp_status_1000s
) / sizeof(ipp_status_1000s
[0])); i
++)
847 if (!_cups_strcasecmp(name
, ipp_status_1000s
[i
]))
848 return ((ipp_status_t
)(i
+ 0x1000));
850 return ((ipp_status_t
)-1);
855 * 'ippOpString()' - Return a name for the given operation id.
857 * @since CUPS 1.2/Mac OS X 10.5@
860 const char * /* O - Name */
861 ippOpString(ipp_op_t op
) /* I - Operation ID */
863 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
867 * See if the operation ID is a known value...
870 if (op
>= IPP_PRINT_JOB
&& op
<= IPP_CLOSE_JOB
)
871 return (ipp_std_ops
[op
]);
872 else if (op
== IPP_PRIVATE
)
873 return ("windows-ext");
874 else if (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_GET_PPD
)
875 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
876 else if (op
== CUPS_GET_DOCUMENT
)
877 return (ipp_cups_ops2
[0]);
880 * No, build an "0xxxxx" operation string...
883 sprintf(cg
->ipp_unknown
, "0x%04x", op
);
885 return (cg
->ipp_unknown
);
890 * 'ippOpValue()' - Return an operation id for the given name.
892 * @since CUPS 1.2/Mac OS X 10.5@
895 ipp_op_t
/* O - Operation ID */
896 ippOpValue(const char *name
) /* I - Textual name */
901 if (!strncmp(name
, "0x", 2))
902 return ((ipp_op_t
)strtol(name
+ 2, NULL
, 16));
904 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
905 if (!_cups_strcasecmp(name
, ipp_std_ops
[i
]))
906 return ((ipp_op_t
)i
);
908 if (!_cups_strcasecmp(name
, "windows-ext"))
909 return (IPP_PRIVATE
);
911 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
912 if (!_cups_strcasecmp(name
, ipp_cups_ops
[i
]))
913 return ((ipp_op_t
)(i
+ 0x4001));
915 for (i
= 0; i
< (sizeof(ipp_cups_ops2
) / sizeof(ipp_cups_ops2
[0])); i
++)
916 if (!_cups_strcasecmp(name
, ipp_cups_ops2
[i
]))
917 return ((ipp_op_t
)(i
+ 0x4027));
919 if (!_cups_strcasecmp(name
, "CUPS-Add-Class"))
920 return (CUPS_ADD_MODIFY_CLASS
);
922 if (!_cups_strcasecmp(name
, "CUPS-Add-Printer"))
923 return (CUPS_ADD_MODIFY_PRINTER
);
925 return ((ipp_op_t
)-1);
930 * 'ippPort()' - Return the default IPP port number.
933 int /* O - Port number */
936 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
939 DEBUG_puts("ippPort()");
944 DEBUG_printf(("1ippPort: Returning %d...", cg
->ipp_port
));
946 return (cg
->ipp_port
);
951 * 'ippSetPort()' - Set the default port number.
955 ippSetPort(int p
) /* I - Port number to use */
957 DEBUG_printf(("ippSetPort(p=%d)", p
));
959 _cupsGlobals()->ipp_port
= p
;
964 * 'ippTagString()' - Return the tag name corresponding to a tag value.
966 * The returned names are defined in RFC 2911 and 3382.
968 * @since CUPS 1.4/Mac OS X 10.6@
971 const char * /* O - Tag name */
972 ippTagString(ipp_tag_t tag
) /* I - Tag value */
976 if (tag
< (ipp_tag_t
)(sizeof(ipp_tag_names
) / sizeof(ipp_tag_names
[0])))
977 return (ipp_tag_names
[tag
]);
984 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
986 * The tag names are defined in RFC 2911 and 3382.
988 * @since CUPS 1.4/Mac OS X 10.6@
991 ipp_tag_t
/* O - Tag value */
992 ippTagValue(const char *name
) /* I - Tag name */
994 int i
; /* Looping var */
997 for (i
= 0; i
< (sizeof(ipp_tag_names
) / sizeof(ipp_tag_names
[0])); i
++)
998 if (!_cups_strcasecmp(name
, ipp_tag_names
[i
]))
999 return ((ipp_tag_t
)i
);
1001 if (!_cups_strcasecmp(name
, "operation"))
1002 return (IPP_TAG_OPERATION
);
1003 else if (!_cups_strcasecmp(name
, "job"))
1004 return (IPP_TAG_JOB
);
1005 else if (!_cups_strcasecmp(name
, "printer"))
1006 return (IPP_TAG_PRINTER
);
1007 else if (!_cups_strcasecmp(name
, "unsupported"))
1008 return (IPP_TAG_UNSUPPORTED_GROUP
);
1009 else if (!_cups_strcasecmp(name
, "subscription"))
1010 return (IPP_TAG_SUBSCRIPTION
);
1011 else if (!_cups_strcasecmp(name
, "event"))
1012 return (IPP_TAG_EVENT_NOTIFICATION
);
1013 else if (!_cups_strcasecmp(name
, "language"))
1014 return (IPP_TAG_LANGUAGE
);
1015 else if (!_cups_strcasecmp(name
, "mimetype"))
1016 return (IPP_TAG_MIMETYPE
);
1017 else if (!_cups_strcasecmp(name
, "name"))
1018 return (IPP_TAG_NAME
);
1019 else if (!_cups_strcasecmp(name
, "text"))
1020 return (IPP_TAG_TEXT
);
1021 else if (!_cups_strcasecmp(name
, "begCollection"))
1022 return (IPP_TAG_BEGIN_COLLECTION
);
1024 return (IPP_TAG_ZERO
);
1029 * 'ipp_col_string()' - Convert a collection to a string.
1032 static size_t /* O - Number of bytes */
1033 ipp_col_string(ipp_t
*col
, /* I - Collection attribute */
1034 char *buffer
, /* I - Buffer or NULL */
1035 size_t bufsize
) /* I - Size of buffer */
1037 char *bufptr
, /* Position in buffer */
1038 *bufend
, /* End of buffer */
1039 temp
[256]; /* Temporary string */
1040 ipp_attribute_t
*attr
; /* Current member attribute */
1044 bufend
= buffer
+ bufsize
- 1;
1046 if (buffer
&& bufptr
< bufend
)
1050 for (attr
= col
->attrs
; attr
; attr
= attr
->next
)
1055 if (buffer
&& bufptr
< bufend
)
1056 bufptr
+= snprintf(bufptr
, bufend
- bufptr
+ 1, "%s=", attr
->name
);
1058 bufptr
+= strlen(attr
->name
) + 1;
1060 if (buffer
&& bufptr
< bufend
)
1061 bufptr
+= ippAttributeString(attr
, bufptr
, bufend
- bufptr
+ 1);
1063 bufptr
+= ippAttributeString(attr
, temp
, sizeof(temp
));
1066 if (buffer
&& bufptr
< bufend
)
1070 return (bufptr
- buffer
);
1075 * End of "$Id: ipp-support.c 9371 2010-11-17 06:21:32Z mike $".