]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/ipp-support.c
Merge changes from CUPS 1.4svn-r7851.
[thirdparty/cups.git] / cups / ipp-support.c
1 /*
2 * "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $"
3 *
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
6 *
7 * Copyright 2007 by Apple Inc.
8 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 *
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/".
15 *
16 * This file is subject to the Apple OS-Developed Software exception.
17 *
18 * Contents:
19 *
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.
26 */
27
28 /*
29 * Include necessary headers...
30 */
31
32 #include "globals.h"
33 #include "debug.h"
34 #include <stdlib.h>
35
36
37 /*
38 * Local globals...
39 */
40
41 static const char * const ipp_status_oks[] = /* "OK" status codes */
42 {
43 "successful-ok",
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"
51 },
52 * const ipp_status_400s[] = /* Client errors */
53 {
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",
61 "client-error-gone",
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"
78 },
79 * const ipp_status_500s[] = /* Server errors */
80 {
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",
88 "server-error-busy",
89 "server-error-job-canceled",
90 "server-error-multiple-document-jobs-not-supported",
91 "server-error-printer-is-deactivated"
92 };
93 static char * const ipp_std_ops[] =
94 {
95 /* 0x0000 - 0x000f */
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", "",
101
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", "", "",
113
114 /* 0x0020 - 0x002f */
115 "",
116 "Get-Printer-Support-Files",
117 "Enable-Printer",
118 "Disable-Printer",
119 "Pause-Printer-After-Current-Job",
120 "Hold-New-Jobs",
121 "Release-Held-New-Jobs",
122 "Deactivate-Printer",
123 "Activate-Printer",
124 "Restart-Printer",
125 "Shutdown-Printer",
126 "Startup-Printer",
127 "Reprocess-Job",
128 "Cancel-Current-Job",
129 "Suspend-Current-Job",
130 "Resume-Job",
131
132 /* 0x0030 - 0x0031 */
133 "Promote-Job",
134 "Schedule-Job-After"
135 },
136 * const ipp_cups_ops[] =
137 {
138 "CUPS-Get-Default",
139 "CUPS-Get-Printers",
140 "CUPS-Add-Modify-Printer",
141 "CUPS-Delete-Printer",
142 "CUPS-Get-Classes",
143 "CUPS-Add-Modify-Class",
144 "CUPS-Delete-Class",
145 "CUPS-Accept-Jobs",
146 "CUPS-Reject-Jobs",
147 "CUPS-Set-Default",
148 "CUPS-Get-Devices",
149 "CUPS-Get-PPDs",
150 "CUPS-Move-Job",
151 "CUPS-Authenticate-Job",
152 "CUPS-Get-PPD"
153 },
154 * const ipp_cups_ops2[] =
155 {
156 "CUPS-Get-Document"
157 },
158 * const ipp_tag_names[] =
159 { /* Value/group tag names */
160 "zero", /* 0x00 */
161 "operation-attributes-tag",
162 /* 0x01 */
163 "job-attributes-tag", /* 0x02 */
164 "end-of-attributes-tag",
165 /* 0x03 */
166 "printer-attributes-tag",
167 /* 0x04 */
168 "unsupported-attributes-tag",
169 /* 0x05 */
170 "subscription-attributes-tag",
171 /* 0x06 */
172 "event-notification-attributes-tag",
173 /* 0x07 */
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 */
201 "enum", /* 0x23 */
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 */
235 "uri", /* 0x45 */
236 "uriScheme", /* 0x46 */
237 "charset", /* 0x47 */
238 "naturalLanguage", /* 0x48 */
239 "mimeMediaType", /* 0x49 */
240 "memberAttrName" /* 0x4a */
241 };
242
243
244 /*
245 * 'ippErrorString()' - Return a name for the given status code.
246 */
247
248 const char * /* O - Text string */
249 ippErrorString(ipp_status_t error) /* I - Error status */
250 {
251 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
252
253
254 /*
255 * See if the error code is a known value...
256 */
257
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]);
268
269 /*
270 * No, build an "unknown-xxxx" error string...
271 */
272
273 sprintf(cg->ipp_unknown, "unknown-%04x", error);
274
275 return (cg->ipp_unknown);
276 }
277
278
279 /*
280 * 'ippErrorValue()' - Return a status code for the given name.
281 *
282 * @since CUPS 1.2@
283 */
284
285 ipp_status_t /* O - IPP status code */
286 ippErrorValue(const char *name) /* I - Name */
287 {
288 int i;
289
290
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);
294
295 if (!strcasecmp(name, "redirection-other-site"))
296 return (IPP_REDIRECTION_OTHER_SITE);
297
298 if (!strcasecmp(name, "cups-see-other"))
299 return (CUPS_SEE_OTHER);
300
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));
304
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));
308
309 return ((ipp_status_t)-1);
310 }
311
312
313 /*
314 * 'ippOpString()' - Return a name for the given operation id.
315 *
316 * @since CUPS 1.2@
317 */
318
319 const char * /* O - Name */
320 ippOpString(ipp_op_t op) /* I - Operation ID */
321 {
322 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
323
324
325 /*
326 * See if the operation ID is a known value...
327 */
328
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]);
337
338 /*
339 * No, build an "unknown-xxxx" operation string...
340 */
341
342 sprintf(cg->ipp_unknown, "unknown-%04x", op);
343
344 return (cg->ipp_unknown);
345 }
346
347
348 /*
349 * 'ippOpValue()' - Return an operation id for the given name.
350 *
351 * @since CUPS 1.2@
352 */
353
354 ipp_op_t /* O - Operation ID */
355 ippOpValue(const char *name) /* I - Textual name */
356 {
357 int i;
358
359
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);
363
364 if (!strcasecmp(name, "windows-ext"))
365 return (IPP_PRIVATE);
366
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));
370
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));
374
375 if (!strcasecmp(name, "CUPS-Add-Class"))
376 return (CUPS_ADD_MODIFY_CLASS);
377
378 if (!strcasecmp(name, "CUPS-Add-Printer"))
379 return (CUPS_ADD_MODIFY_PRINTER);
380
381 return ((ipp_op_t)-1);
382 }
383
384
385 /*
386 * 'ippPort()' - Return the default IPP port number.
387 */
388
389 int /* O - Port number */
390 ippPort(void)
391 {
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 */
396
397
398 DEBUG_puts("ippPort()");
399
400 if (!cg->ipp_port)
401 {
402 /*
403 * See if the server definition includes the port number...
404 */
405
406 DEBUG_puts("ippPort: Not initialized...");
407
408 cupsServer();
409
410 #ifdef DEBUG
411 if (cg->ipp_port)
412 DEBUG_puts(("ippPort: Set via cupsServer()..."));
413 #endif /* DEBUG */
414 }
415
416 if (!cg->ipp_port)
417 {
418 if ((ipp_port = getenv("IPP_PORT")) != NULL)
419 {
420 DEBUG_puts("ippPort: Set via IPP_PORT...");
421 portnum = atoi(ipp_port);
422 }
423 else if ((port = getservbyname("ipp", NULL)) == NULL)
424 {
425 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
426 portnum = CUPS_DEFAULT_IPP_PORT;
427 }
428 else
429 {
430 DEBUG_puts("ippPort: Set via ipp service entry...");
431 portnum = ntohs(port->s_port);
432 }
433
434 if (portnum > 0)
435 cg->ipp_port = portnum;
436 }
437
438 DEBUG_printf(("ippPort: Returning %d...\n", cg->ipp_port));
439
440 return (cg->ipp_port);
441 }
442
443
444 /*
445 * 'ippSetPort()' - Set the default port number.
446 */
447
448 void
449 ippSetPort(int p) /* I - Port number to use */
450 {
451 DEBUG_printf(("ippSetPort(p=%d)\n", p));
452
453 _cupsGlobals()->ipp_port = p;
454 }
455
456
457 /*
458 * 'ippTagString()' - Return the tag name corresponding to a tag value.
459 *
460 * The returned names are defined in RFC 2911 and 3382.
461 *
462 * @since CUPS 1.4@
463 */
464
465 const char * /* O - Tag name */
466 ippTagString(ipp_tag_t tag) /* I - Tag value */
467 {
468 if (tag < (ipp_tag_t)(sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])))
469 return (ipp_tag_names[tag]);
470 else
471 return ("UNKNOWN");
472 }
473
474
475 /*
476 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
477 *
478 * The tag names are defined in RFC 2911 and 3382.
479 *
480 * @since CUPS 1.4@
481 */
482
483 ipp_tag_t /* O - Tag value */
484 ippTagValue(const char *name) /* I - Tag name */
485 {
486 int i; /* Looping var */
487
488
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);
492
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);
509 else
510 return (IPP_TAG_ZERO);
511 }
512
513
514 /*
515 * End of "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $".
516 */