]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/ipp-support.c
Make sure EOL is right on import file.
[thirdparty/cups.git] / cups / ipp-support.c
CommitLineData
ef416fc2 1/*
1ff0402e 2 * "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $"
ef416fc2 3 *
71e16022 4 * Internet Printing Protocol support functions for CUPS.
ef416fc2 5 *
71e16022 6 * Copyright 2007-2010 by Apple Inc.
b94498cf 7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * ippErrorString() - Return a name for the given status code.
20 * ippErrorValue() - Return a status code for the given name.
21 * ippOpString() - Return a name for the given operation id.
22 * ippOpValue() - Return an operation id for the given name.
23 * ippPort() - Return the default IPP port number.
24 * ippSetPort() - Set the default port number.
ed6e7faf
MS
25 * ippTagString() - Return the tag name corresponding to a tag value.
26 * ippTagValue() - Return the tag value corresponding to a tag name.
ef416fc2 27 */
28
29/*
30 * Include necessary headers...
31 */
32
71e16022 33#include "cups-private.h"
ef416fc2 34
35
36/*
37 * Local globals...
38 */
39
40static const char * const ipp_status_oks[] = /* "OK" status codes */
41 {
42 "successful-ok",
43 "successful-ok-ignored-or-substituted-attributes",
44 "successful-ok-conflicting-attributes",
45 "successful-ok-ignored-subscriptions",
46 "successful-ok-ignored-notifications",
47 "successful-ok-too-many-events",
bd7854cb 48 "successful-ok-but-cancel-subscription",
49 "successful-ok-events-complete"
ef416fc2 50 },
51 * const ipp_status_400s[] = /* Client errors */
52 {
53 "client-error-bad-request",
54 "client-error-forbidden",
55 "client-error-not-authenticated",
56 "client-error-not-authorized",
57 "client-error-not-possible",
58 "client-error-timeout",
59 "client-error-not-found",
60 "client-error-gone",
61 "client-error-request-entity-too-large",
62 "client-error-request-value-too-long",
63 "client-error-document-format-not-supported",
64 "client-error-attributes-or-values-not-supported",
65 "client-error-uri-scheme-not-supported",
66 "client-error-charset-not-supported",
67 "client-error-conflicting-attributes",
68 "client-error-compression-not-supported",
69 "client-error-compression-error",
70 "client-error-document-format-error",
71 "client-error-document-access-error",
72 "client-error-attributes-not-settable",
73 "client-error-ignored-all-subscriptions",
74 "client-error-too-many-subscriptions",
75 "client-error-ignored-all-notifications",
76 "client-error-print-support-file-not-found"
77 },
78 * const ipp_status_500s[] = /* Server errors */
79 {
80 "server-error-internal-error",
81 "server-error-operation-not-supported",
82 "server-error-service-unavailable",
83 "server-error-version-not-supported",
84 "server-error-device-error",
85 "server-error-temporary-error",
86 "server-error-not-accepting-jobs",
87 "server-error-busy",
88 "server-error-job-canceled",
89 "server-error-multiple-document-jobs-not-supported",
90 "server-error-printer-is-deactivated"
91 };
92static char * const ipp_std_ops[] =
93 {
94 /* 0x0000 - 0x000f */
95 "", "", "Print-Job", "Print-URI",
96 "Validate-Job", "Create-Job", "Send-Document",
97 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
98 "Get-Jobs", "Get-Printer-Attributes",
99 "Hold-Job", "Release-Job", "Restart-Job", "",
100
101 /* 0x0010 - 0x001f */
102 "Pause-Printer", "Resume-Printer",
103 "Purge-Jobs", "Set-Printer-Attributes",
104 "Set-Job-Attributes",
105 "Get-Printer-Supported-Values",
106 "Create-Printer-Subscription",
107 "Create-Job-Subscription",
108 "Get-Subscription-Attributes",
109 "Get-Subscriptions", "Renew-Subscription",
110 "Cancel-Subscription", "Get-Notifications",
111 "Send-Notifications", "", "",
112
113 /* 0x0020 - 0x002f */
114 "",
115 "Get-Printer-Support-Files",
116 "Enable-Printer",
117 "Disable-Printer",
118 "Pause-Printer-After-Current-Job",
119 "Hold-New-Jobs",
120 "Release-Held-New-Jobs",
121 "Deactivate-Printer",
122 "Activate-Printer",
123 "Restart-Printer",
124 "Shutdown-Printer",
125 "Startup-Printer",
126 "Reprocess-Job",
127 "Cancel-Current-Job",
128 "Suspend-Current-Job",
129 "Resume-Job",
130
131 /* 0x0030 - 0x0031 */
132 "Promote-Job",
133 "Schedule-Job-After"
134 },
135 * const ipp_cups_ops[] =
136 {
137 "CUPS-Get-Default",
138 "CUPS-Get-Printers",
480ef0fe 139 "CUPS-Add-Modify-Printer",
ef416fc2 140 "CUPS-Delete-Printer",
141 "CUPS-Get-Classes",
480ef0fe 142 "CUPS-Add-Modify-Class",
ef416fc2 143 "CUPS-Delete-Class",
144 "CUPS-Accept-Jobs",
145 "CUPS-Reject-Jobs",
146 "CUPS-Set-Default",
147 "CUPS-Get-Devices",
148 "CUPS-Get-PPDs",
149 "CUPS-Move-Job",
b94498cf 150 "CUPS-Authenticate-Job",
151 "CUPS-Get-PPD"
2e4ff8af
MS
152 },
153 * const ipp_cups_ops2[] =
154 {
155 "CUPS-Get-Document"
1ff0402e
MS
156 },
157 * const ipp_tag_names[] =
158 { /* Value/group tag names */
159 "zero", /* 0x00 */
160 "operation-attributes-tag",
161 /* 0x01 */
162 "job-attributes-tag", /* 0x02 */
163 "end-of-attributes-tag",
164 /* 0x03 */
165 "printer-attributes-tag",
166 /* 0x04 */
167 "unsupported-attributes-tag",
168 /* 0x05 */
169 "subscription-attributes-tag",
170 /* 0x06 */
171 "event-notification-attributes-tag",
172 /* 0x07 */
173 "unknown-08", /* 0x08 */
174 "unknown-09", /* 0x09 */
175 "unknown-0a", /* 0x0a */
176 "unknown-0b", /* 0x0b */
177 "unknown-0c", /* 0x0c */
178 "unknown-0d", /* 0x0d */
179 "unknown-0e", /* 0x0e */
180 "unknown-0f", /* 0x0f */
181 "unsupported", /* 0x10 */
182 "default", /* 0x11 */
183 "unknown", /* 0x12 */
184 "no-value", /* 0x13 */
185 "unknown-14", /* 0x14 */
186 "not-settable", /* 0x15 */
187 "delete-attribute", /* 0x16 */
188 "admin-define", /* 0x17 */
189 "unknown-18", /* 0x18 */
190 "unknown-19", /* 0x19 */
191 "unknown-1a", /* 0x1a */
192 "unknown-1b", /* 0x1b */
193 "unknown-1c", /* 0x1c */
194 "unknown-1d", /* 0x1d */
195 "unknown-1e", /* 0x1e */
196 "unknown-1f", /* 0x1f */
197 "unknown-20", /* 0x20 */
198 "integer", /* 0x21 */
199 "boolean", /* 0x22 */
200 "enum", /* 0x23 */
201 "unknown-24", /* 0x24 */
202 "unknown-25", /* 0x25 */
203 "unknown-26", /* 0x26 */
204 "unknown-27", /* 0x27 */
205 "unknown-28", /* 0x28 */
206 "unknown-29", /* 0x29 */
207 "unknown-2a", /* 0x2a */
208 "unknown-2b", /* 0x2b */
209 "unknown-2c", /* 0x2c */
210 "unknown-2d", /* 0x2d */
211 "unknown-2e", /* 0x2e */
212 "unknown-2f", /* 0x2f */
213 "octetString", /* 0x30 */
214 "dateTime", /* 0x31 */
215 "resolution", /* 0x32 */
216 "rangeOfInteger", /* 0x33 */
f8b3a85b 217 "collection", /* 0x34 */
1ff0402e
MS
218 "textWithLanguage", /* 0x35 */
219 "nameWithLanguage", /* 0x36 */
220 "endCollection", /* 0x37 */
221 "unknown-38", /* 0x38 */
222 "unknown-39", /* 0x39 */
223 "unknown-3a", /* 0x3a */
224 "unknown-3b", /* 0x3b */
225 "unknown-3c", /* 0x3c */
226 "unknown-3d", /* 0x3d */
227 "unknown-3e", /* 0x3e */
228 "unknown-3f", /* 0x3f */
229 "unknown-40", /* 0x40 */
230 "textWithoutLanguage",/* 0x41 */
231 "nameWithoutLanguage",/* 0x42 */
232 "unknown-43", /* 0x43 */
233 "keyword", /* 0x44 */
234 "uri", /* 0x45 */
235 "uriScheme", /* 0x46 */
236 "charset", /* 0x47 */
237 "naturalLanguage", /* 0x48 */
238 "mimeMediaType", /* 0x49 */
239 "memberAttrName" /* 0x4a */
ef416fc2 240 };
241
242
243/*
244 * 'ippErrorString()' - Return a name for the given status code.
245 */
246
247const char * /* O - Text string */
248ippErrorString(ipp_status_t error) /* I - Error status */
249{
250 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
251
252
253 /*
254 * See if the error code is a known value...
255 */
256
bd7854cb 257 if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE)
ef416fc2 258 return (ipp_status_oks[error]);
259 else if (error == IPP_REDIRECTION_OTHER_SITE)
260 return ("redirection-other-site");
b94498cf 261 else if (error == CUPS_SEE_OTHER)
262 return ("cups-see-other");
ef416fc2 263 else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND)
264 return (ipp_status_400s[error - IPP_BAD_REQUEST]);
265 else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED)
266 return (ipp_status_500s[error - IPP_INTERNAL_ERROR]);
267
268 /*
269 * No, build an "unknown-xxxx" error string...
270 */
271
272 sprintf(cg->ipp_unknown, "unknown-%04x", error);
273
274 return (cg->ipp_unknown);
275}
276
277
278/*
279 * 'ippErrorValue()' - Return a status code for the given name.
280 *
426c6a59 281 * @since CUPS 1.2/Mac OS X 10.5@
ef416fc2 282 */
283
284ipp_status_t /* O - IPP status code */
285ippErrorValue(const char *name) /* I - Name */
286{
287 int i;
288
289
290 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
291 if (!strcasecmp(name, ipp_status_oks[i]))
292 return ((ipp_status_t)i);
293
294 if (!strcasecmp(name, "redirection-other-site"))
295 return (IPP_REDIRECTION_OTHER_SITE);
296
b94498cf 297 if (!strcasecmp(name, "cups-see-other"))
298 return (CUPS_SEE_OTHER);
299
ef416fc2 300 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
301 if (!strcasecmp(name, ipp_status_400s[i]))
302 return ((ipp_status_t)(i + 0x400));
303
304 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
305 if (!strcasecmp(name, ipp_status_500s[i]))
306 return ((ipp_status_t)(i + 0x500));
307
308 return ((ipp_status_t)-1);
309}
310
311
312/*
313 * 'ippOpString()' - Return a name for the given operation id.
314 *
426c6a59 315 * @since CUPS 1.2/Mac OS X 10.5@
ef416fc2 316 */
317
318const char * /* O - Name */
319ippOpString(ipp_op_t op) /* I - Operation ID */
320{
321 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
322
323
324 /*
325 * See if the operation ID is a known value...
326 */
327
328 if (op >= IPP_PRINT_JOB && op <= IPP_SCHEDULE_JOB_AFTER)
329 return (ipp_std_ops[op]);
330 else if (op == IPP_PRIVATE)
331 return ("windows-ext");
b94498cf 332 else if (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD)
ef416fc2 333 return (ipp_cups_ops[op - CUPS_GET_DEFAULT]);
2e4ff8af
MS
334 else if (op == CUPS_GET_DOCUMENT)
335 return (ipp_cups_ops2[0]);
ef416fc2 336
337 /*
338 * No, build an "unknown-xxxx" operation string...
339 */
340
341 sprintf(cg->ipp_unknown, "unknown-%04x", op);
342
343 return (cg->ipp_unknown);
344}
345
346
347/*
348 * 'ippOpValue()' - Return an operation id for the given name.
349 *
426c6a59 350 * @since CUPS 1.2/Mac OS X 10.5@
ef416fc2 351 */
352
353ipp_op_t /* O - Operation ID */
354ippOpValue(const char *name) /* I - Textual name */
355{
356 int i;
357
358
359 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
360 if (!strcasecmp(name, ipp_std_ops[i]))
361 return ((ipp_op_t)i);
362
363 if (!strcasecmp(name, "windows-ext"))
364 return (IPP_PRIVATE);
365
366 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
367 if (!strcasecmp(name, ipp_cups_ops[i]))
368 return ((ipp_op_t)(i + 0x4001));
369
2e4ff8af
MS
370 for (i = 0; i < (sizeof(ipp_cups_ops2) / sizeof(ipp_cups_ops2[0])); i ++)
371 if (!strcasecmp(name, ipp_cups_ops2[i]))
372 return ((ipp_op_t)(i + 0x4027));
373
480ef0fe 374 if (!strcasecmp(name, "CUPS-Add-Class"))
375 return (CUPS_ADD_MODIFY_CLASS);
376
377 if (!strcasecmp(name, "CUPS-Add-Printer"))
378 return (CUPS_ADD_MODIFY_PRINTER);
379
ef416fc2 380 return ((ipp_op_t)-1);
381}
382
383
384/*
385 * 'ippPort()' - Return the default IPP port number.
386 */
387
388int /* O - Port number */
389ippPort(void)
390{
ef416fc2 391 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
392
393
d09495fa 394 DEBUG_puts("ippPort()");
395
396 if (!cg->ipp_port)
e07d4801 397 _cupsSetDefaults();
d09495fa 398
e07d4801 399 DEBUG_printf(("1ippPort: Returning %d...", cg->ipp_port));
d09495fa 400
ef416fc2 401 return (cg->ipp_port);
402}
403
404
405/*
406 * 'ippSetPort()' - Set the default port number.
407 */
408
409void
410ippSetPort(int p) /* I - Port number to use */
411{
e07d4801 412 DEBUG_printf(("ippSetPort(p=%d)", p));
d09495fa 413
ef416fc2 414 _cupsGlobals()->ipp_port = p;
415}
416
417
418/*
1ff0402e
MS
419 * 'ippTagString()' - Return the tag name corresponding to a tag value.
420 *
421 * The returned names are defined in RFC 2911 and 3382.
422 *
178cb736 423 * @since CUPS 1.4/Mac OS X 10.6@
1ff0402e
MS
424 */
425
426const char * /* O - Tag name */
427ippTagString(ipp_tag_t tag) /* I - Tag value */
428{
ed6e7faf
MS
429 tag &= IPP_TAG_MASK;
430
1ff0402e
MS
431 if (tag < (ipp_tag_t)(sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])))
432 return (ipp_tag_names[tag]);
433 else
434 return ("UNKNOWN");
435}
436
437
438/*
439 * 'ippTagValue()' - Return the tag value corresponding to a tag name.
440 *
441 * The tag names are defined in RFC 2911 and 3382.
442 *
178cb736 443 * @since CUPS 1.4/Mac OS X 10.6@
1ff0402e
MS
444 */
445
446ipp_tag_t /* O - Tag value */
447ippTagValue(const char *name) /* I - Tag name */
448{
449 int i; /* Looping var */
450
451
452 for (i = 0; i < (sizeof(ipp_tag_names) / sizeof(ipp_tag_names[0])); i ++)
453 if (!strcasecmp(name, ipp_tag_names[i]))
454 return ((ipp_tag_t)i);
455
456 if (!strcasecmp(name, "operation"))
457 return (IPP_TAG_OPERATION);
458 else if (!strcasecmp(name, "job"))
459 return (IPP_TAG_JOB);
460 else if (!strcasecmp(name, "printer"))
461 return (IPP_TAG_PRINTER);
5a6b583a
MS
462 else if (!strcasecmp(name, "unsupported"))
463 return (IPP_TAG_UNSUPPORTED_GROUP);
1ff0402e
MS
464 else if (!strcasecmp(name, "subscription"))
465 return (IPP_TAG_SUBSCRIPTION);
5a6b583a
MS
466 else if (!strcasecmp(name, "event"))
467 return (IPP_TAG_EVENT_NOTIFICATION);
1ff0402e
MS
468 else if (!strcasecmp(name, "language"))
469 return (IPP_TAG_LANGUAGE);
470 else if (!strcasecmp(name, "mimetype"))
471 return (IPP_TAG_MIMETYPE);
472 else if (!strcasecmp(name, "name"))
473 return (IPP_TAG_NAME);
474 else if (!strcasecmp(name, "text"))
475 return (IPP_TAG_TEXT);
5a6b583a
MS
476 else if (!strcasecmp(name, "begCollection"))
477 return (IPP_TAG_BEGIN_COLLECTION);
1ff0402e
MS
478 else
479 return (IPP_TAG_ZERO);
480}
481
482
483/*
484 * End of "$Id: ipp-support.c 7847 2008-08-19 04:22:14Z mike $".
ef416fc2 485 */