2 * "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $"
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
7 * Copyright 2007 by Apple Inc.
8 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
10 * These coded instructions, statements, and computer programs are the
11 * property of Apple Inc. and are protected by Federal copyright
12 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
13 * which should have been included with this file. If this file is
14 * file is missing or damaged, see the license at "http://www.cups.org/".
16 * This file is subject to the Apple OS-Developed Software exception.
20 * ippErrorString() - Return a name for the given status code.
21 * ippErrorValue() - Return a status code for the given name.
22 * ippOpString() - Return a name for the given operation id.
23 * ippOpValue() - Return an operation id for the given name.
24 * ippPort() - Return the default IPP port number.
25 * ippSetPort() - Set the default port number.
29 * Include necessary headers...
41 static const char * const ipp_status_oks
[] = /* "OK" status codes */
44 "successful-ok-ignored-or-substituted-attributes",
45 "successful-ok-conflicting-attributes",
46 "successful-ok-ignored-subscriptions",
47 "successful-ok-ignored-notifications",
48 "successful-ok-too-many-events",
49 "successful-ok-but-cancel-subscription",
50 "successful-ok-events-complete"
52 * const ipp_status_400s
[] = /* Client errors */
54 "client-error-bad-request",
55 "client-error-forbidden",
56 "client-error-not-authenticated",
57 "client-error-not-authorized",
58 "client-error-not-possible",
59 "client-error-timeout",
60 "client-error-not-found",
62 "client-error-request-entity-too-large",
63 "client-error-request-value-too-long",
64 "client-error-document-format-not-supported",
65 "client-error-attributes-or-values-not-supported",
66 "client-error-uri-scheme-not-supported",
67 "client-error-charset-not-supported",
68 "client-error-conflicting-attributes",
69 "client-error-compression-not-supported",
70 "client-error-compression-error",
71 "client-error-document-format-error",
72 "client-error-document-access-error",
73 "client-error-attributes-not-settable",
74 "client-error-ignored-all-subscriptions",
75 "client-error-too-many-subscriptions",
76 "client-error-ignored-all-notifications",
77 "client-error-print-support-file-not-found"
79 * const ipp_status_500s
[] = /* Server errors */
81 "server-error-internal-error",
82 "server-error-operation-not-supported",
83 "server-error-service-unavailable",
84 "server-error-version-not-supported",
85 "server-error-device-error",
86 "server-error-temporary-error",
87 "server-error-not-accepting-jobs",
89 "server-error-job-canceled",
90 "server-error-multiple-document-jobs-not-supported",
91 "server-error-printer-is-deactivated"
93 static char * const ipp_std_ops
[] =
96 "", "", "Print-Job", "Print-URI",
97 "Validate-Job", "Create-Job", "Send-Document",
98 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
99 "Get-Jobs", "Get-Printer-Attributes",
100 "Hold-Job", "Release-Job", "Restart-Job", "",
102 /* 0x0010 - 0x001f */
103 "Pause-Printer", "Resume-Printer",
104 "Purge-Jobs", "Set-Printer-Attributes",
105 "Set-Job-Attributes",
106 "Get-Printer-Supported-Values",
107 "Create-Printer-Subscription",
108 "Create-Job-Subscription",
109 "Get-Subscription-Attributes",
110 "Get-Subscriptions", "Renew-Subscription",
111 "Cancel-Subscription", "Get-Notifications",
112 "Send-Notifications", "", "",
114 /* 0x0020 - 0x002f */
116 "Get-Printer-Support-Files",
119 "Pause-Printer-After-Current-Job",
121 "Release-Held-New-Jobs",
122 "Deactivate-Printer",
128 "Cancel-Current-Job",
129 "Suspend-Current-Job",
132 /* 0x0030 - 0x0031 */
136 * const ipp_cups_ops
[] =
140 "CUPS-Add-Modify-Printer",
141 "CUPS-Delete-Printer",
143 "CUPS-Add-Modify-Class",
151 "CUPS-Authenticate-Job",
154 * const ipp_cups_ops2
[] =
158 * const ipp_tag_names
[] =
159 { /* Value/group tag names */
161 "operation-attributes-tag",
163 "job-attributes-tag", /* 0x02 */
164 "end-of-attributes-tag",
166 "printer-attributes-tag",
168 "unsupported-attributes-tag",
170 "subscription-attributes-tag",
172 "event-notification-attributes-tag",
174 "unknown-08", /* 0x08 */
175 "unknown-09", /* 0x09 */
176 "unknown-0a", /* 0x0a */
177 "unknown-0b", /* 0x0b */
178 "unknown-0c", /* 0x0c */
179 "unknown-0d", /* 0x0d */
180 "unknown-0e", /* 0x0e */
181 "unknown-0f", /* 0x0f */
182 "unsupported", /* 0x10 */
183 "default", /* 0x11 */
184 "unknown", /* 0x12 */
185 "no-value", /* 0x13 */
186 "unknown-14", /* 0x14 */
187 "not-settable", /* 0x15 */
188 "delete-attribute", /* 0x16 */
189 "admin-define", /* 0x17 */
190 "unknown-18", /* 0x18 */
191 "unknown-19", /* 0x19 */
192 "unknown-1a", /* 0x1a */
193 "unknown-1b", /* 0x1b */
194 "unknown-1c", /* 0x1c */
195 "unknown-1d", /* 0x1d */
196 "unknown-1e", /* 0x1e */
197 "unknown-1f", /* 0x1f */
198 "unknown-20", /* 0x20 */
199 "integer", /* 0x21 */
200 "boolean", /* 0x22 */
202 "unknown-24", /* 0x24 */
203 "unknown-25", /* 0x25 */
204 "unknown-26", /* 0x26 */
205 "unknown-27", /* 0x27 */
206 "unknown-28", /* 0x28 */
207 "unknown-29", /* 0x29 */
208 "unknown-2a", /* 0x2a */
209 "unknown-2b", /* 0x2b */
210 "unknown-2c", /* 0x2c */
211 "unknown-2d", /* 0x2d */
212 "unknown-2e", /* 0x2e */
213 "unknown-2f", /* 0x2f */
214 "octetString", /* 0x30 */
215 "dateTime", /* 0x31 */
216 "resolution", /* 0x32 */
217 "rangeOfInteger", /* 0x33 */
218 "begCollection", /* 0x34 */
219 "textWithLanguage", /* 0x35 */
220 "nameWithLanguage", /* 0x36 */
221 "endCollection", /* 0x37 */
222 "unknown-38", /* 0x38 */
223 "unknown-39", /* 0x39 */
224 "unknown-3a", /* 0x3a */
225 "unknown-3b", /* 0x3b */
226 "unknown-3c", /* 0x3c */
227 "unknown-3d", /* 0x3d */
228 "unknown-3e", /* 0x3e */
229 "unknown-3f", /* 0x3f */
230 "unknown-40", /* 0x40 */
231 "textWithoutLanguage",/* 0x41 */
232 "nameWithoutLanguage",/* 0x42 */
233 "unknown-43", /* 0x43 */
234 "keyword", /* 0x44 */
236 "uriScheme", /* 0x46 */
237 "charset", /* 0x47 */
238 "naturalLanguage", /* 0x48 */
239 "mimeMediaType", /* 0x49 */
240 "memberAttrName" /* 0x4a */
245 * 'ippErrorString()' - Return a name for the given status code.
248 const char * /* O - Text string */
249 ippErrorString(ipp_status_t error
) /* I - Error status */
251 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
255 * See if the error code is a known value...
258 if (error
>= IPP_OK
&& error
<= IPP_OK_EVENTS_COMPLETE
)
259 return (ipp_status_oks
[error
]);
260 else if (error
== IPP_REDIRECTION_OTHER_SITE
)
261 return ("redirection-other-site");
262 else if (error
== CUPS_SEE_OTHER
)
263 return ("cups-see-other");
264 else if (error
>= IPP_BAD_REQUEST
&& error
<= IPP_PRINT_SUPPORT_FILE_NOT_FOUND
)
265 return (ipp_status_400s
[error
- IPP_BAD_REQUEST
]);
266 else if (error
>= IPP_INTERNAL_ERROR
&& error
<= IPP_PRINTER_IS_DEACTIVATED
)
267 return (ipp_status_500s
[error
- IPP_INTERNAL_ERROR
]);
270 * No, build an "unknown-xxxx" error string...
273 sprintf(cg
->ipp_unknown
, "unknown-%04x", error
);
275 return (cg
->ipp_unknown
);
280 * 'ippErrorValue()' - Return a status code for the given name.
285 ipp_status_t
/* O - IPP status code */
286 ippErrorValue(const char *name
) /* I - Name */
291 for (i
= 0; i
< (sizeof(ipp_status_oks
) / sizeof(ipp_status_oks
[0])); i
++)
292 if (!strcasecmp(name
, ipp_status_oks
[i
]))
293 return ((ipp_status_t
)i
);
295 if (!strcasecmp(name
, "redirection-other-site"))
296 return (IPP_REDIRECTION_OTHER_SITE
);
298 if (!strcasecmp(name
, "cups-see-other"))
299 return (CUPS_SEE_OTHER
);
301 for (i
= 0; i
< (sizeof(ipp_status_400s
) / sizeof(ipp_status_400s
[0])); i
++)
302 if (!strcasecmp(name
, ipp_status_400s
[i
]))
303 return ((ipp_status_t
)(i
+ 0x400));
305 for (i
= 0; i
< (sizeof(ipp_status_500s
) / sizeof(ipp_status_500s
[0])); i
++)
306 if (!strcasecmp(name
, ipp_status_500s
[i
]))
307 return ((ipp_status_t
)(i
+ 0x500));
309 return ((ipp_status_t
)-1);
314 * 'ippOpString()' - Return a name for the given operation id.
319 const char * /* O - Name */
320 ippOpString(ipp_op_t op
) /* I - Operation ID */
322 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
326 * See if the operation ID is a known value...
329 if (op
>= IPP_PRINT_JOB
&& op
<= IPP_SCHEDULE_JOB_AFTER
)
330 return (ipp_std_ops
[op
]);
331 else if (op
== IPP_PRIVATE
)
332 return ("windows-ext");
333 else if (op
>= CUPS_GET_DEFAULT
&& op
<= CUPS_GET_PPD
)
334 return (ipp_cups_ops
[op
- CUPS_GET_DEFAULT
]);
335 else if (op
== CUPS_GET_DOCUMENT
)
336 return (ipp_cups_ops2
[0]);
339 * No, build an "unknown-xxxx" operation string...
342 sprintf(cg
->ipp_unknown
, "unknown-%04x", op
);
344 return (cg
->ipp_unknown
);
349 * 'ippOpValue()' - Return an operation id for the given name.
354 ipp_op_t
/* O - Operation ID */
355 ippOpValue(const char *name
) /* I - Textual name */
360 for (i
= 0; i
< (sizeof(ipp_std_ops
) / sizeof(ipp_std_ops
[0])); i
++)
361 if (!strcasecmp(name
, ipp_std_ops
[i
]))
362 return ((ipp_op_t
)i
);
364 if (!strcasecmp(name
, "windows-ext"))
365 return (IPP_PRIVATE
);
367 for (i
= 0; i
< (sizeof(ipp_cups_ops
) / sizeof(ipp_cups_ops
[0])); i
++)
368 if (!strcasecmp(name
, ipp_cups_ops
[i
]))
369 return ((ipp_op_t
)(i
+ 0x4001));
371 for (i
= 0; i
< (sizeof(ipp_cups_ops2
) / sizeof(ipp_cups_ops2
[0])); i
++)
372 if (!strcasecmp(name
, ipp_cups_ops2
[i
]))
373 return ((ipp_op_t
)(i
+ 0x4027));
375 if (!strcasecmp(name
, "CUPS-Add-Class"))
376 return (CUPS_ADD_MODIFY_CLASS
);
378 if (!strcasecmp(name
, "CUPS-Add-Printer"))
379 return (CUPS_ADD_MODIFY_PRINTER
);
381 return ((ipp_op_t
)-1);
386 * 'ippPort()' - Return the default IPP port number.
389 int /* O - Port number */
392 const char *ipp_port
; /* IPP_PORT environment variable */
393 struct servent
*port
; /* Port number info */
394 int portnum
; /* Port number */
395 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
398 DEBUG_puts("ippPort()");
403 * See if the server definition includes the port number...
406 DEBUG_puts("ippPort: Not initialized...");
412 DEBUG_puts(("ippPort: Set via cupsServer()..."));
418 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
420 DEBUG_puts("ippPort: Set via IPP_PORT...");
421 portnum
= atoi(ipp_port
);
423 else if ((port
= getservbyname("ipp", NULL
)) == NULL
)
425 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
426 portnum
= CUPS_DEFAULT_IPP_PORT
;
430 DEBUG_puts("ippPort: Set via ipp service entry...");
431 portnum
= ntohs(port
->s_port
);
435 cg
->ipp_port
= portnum
;
438 DEBUG_printf(("ippPort: Returning %d...\n", cg
->ipp_port
));
440 return (cg
->ipp_port
);
445 * 'ippSetPort()' - Set the default port number.
449 ippSetPort(int p
) /* I - Port number to use */
451 DEBUG_printf(("ippSetPort(p=%d)\n", p
));
453 _cupsGlobals()->ipp_port
= p
;
458 * 'ippTagString()' - Return the tag name corresponding to a tag value.
460 * The returned names are defined in RFC 2911 and 3382.
465 const char * /* O - Tag name */
466 ippTagString(ipp_tag_t tag
) /* I - Tag value */
468 if (tag
< (ipp_tag_t
)(sizeof(ipp_tag_names
) / sizeof(ipp_tag_names
[0])))
469 return (ipp_tag_names
[tag
]);
476 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
478 * The tag names are defined in RFC 2911 and 3382.
483 ipp_tag_t
/* O - Tag value */
484 ippTagValue(const char *name
) /* I - Tag name */
486 int i
; /* Looping var */
489 for (i
= 0; i
< (sizeof(ipp_tag_names
) / sizeof(ipp_tag_names
[0])); i
++)
490 if (!strcasecmp(name
, ipp_tag_names
[i
]))
491 return ((ipp_tag_t
)i
);
493 if (!strcasecmp(name
, "operation"))
494 return (IPP_TAG_OPERATION
);
495 else if (!strcasecmp(name
, "job"))
496 return (IPP_TAG_JOB
);
497 else if (!strcasecmp(name
, "printer"))
498 return (IPP_TAG_PRINTER
);
499 else if (!strcasecmp(name
, "subscription"))
500 return (IPP_TAG_SUBSCRIPTION
);
501 else if (!strcasecmp(name
, "language"))
502 return (IPP_TAG_LANGUAGE
);
503 else if (!strcasecmp(name
, "mimetype"))
504 return (IPP_TAG_MIMETYPE
);
505 else if (!strcasecmp(name
, "name"))
506 return (IPP_TAG_NAME
);
507 else if (!strcasecmp(name
, "text"))
508 return (IPP_TAG_TEXT
);
510 return (IPP_TAG_ZERO
);
515 * End of "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $".