]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/ipp-support.c
Import CUPS 1.4svn r7023 into easysw/current.
[thirdparty/cups.git] / cups / ipp-support.c
CommitLineData
ef416fc2 1/*
2e4ff8af 2 * "$Id: ipp-support.c 6879 2007-08-29 20:26:50Z mike $"
ef416fc2 3 *
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
6 *
bc44d920 7 * Copyright 2007 by Apple Inc.
b94498cf 8 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 9 *
10 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 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
41static 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",
bd7854cb 49 "successful-ok-but-cancel-subscription",
50 "successful-ok-events-complete"
ef416fc2 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 };
93static 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",
480ef0fe 140 "CUPS-Add-Modify-Printer",
ef416fc2 141 "CUPS-Delete-Printer",
142 "CUPS-Get-Classes",
480ef0fe 143 "CUPS-Add-Modify-Class",
ef416fc2 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",
b94498cf 151 "CUPS-Authenticate-Job",
152 "CUPS-Get-PPD"
2e4ff8af
MS
153 },
154 * const ipp_cups_ops2[] =
155 {
156 "CUPS-Get-Document"
ef416fc2 157 };
158
159
160/*
161 * 'ippErrorString()' - Return a name for the given status code.
162 */
163
164const char * /* O - Text string */
165ippErrorString(ipp_status_t error) /* I - Error status */
166{
167 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
168
169
170 /*
171 * See if the error code is a known value...
172 */
173
bd7854cb 174 if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE)
ef416fc2 175 return (ipp_status_oks[error]);
176 else if (error == IPP_REDIRECTION_OTHER_SITE)
177 return ("redirection-other-site");
b94498cf 178 else if (error == CUPS_SEE_OTHER)
179 return ("cups-see-other");
ef416fc2 180 else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND)
181 return (ipp_status_400s[error - IPP_BAD_REQUEST]);
182 else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED)
183 return (ipp_status_500s[error - IPP_INTERNAL_ERROR]);
184
185 /*
186 * No, build an "unknown-xxxx" error string...
187 */
188
189 sprintf(cg->ipp_unknown, "unknown-%04x", error);
190
191 return (cg->ipp_unknown);
192}
193
194
195/*
196 * 'ippErrorValue()' - Return a status code for the given name.
197 *
198 * @since CUPS 1.2@
199 */
200
201ipp_status_t /* O - IPP status code */
202ippErrorValue(const char *name) /* I - Name */
203{
204 int i;
205
206
207 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
208 if (!strcasecmp(name, ipp_status_oks[i]))
209 return ((ipp_status_t)i);
210
211 if (!strcasecmp(name, "redirection-other-site"))
212 return (IPP_REDIRECTION_OTHER_SITE);
213
b94498cf 214 if (!strcasecmp(name, "cups-see-other"))
215 return (CUPS_SEE_OTHER);
216
ef416fc2 217 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
218 if (!strcasecmp(name, ipp_status_400s[i]))
219 return ((ipp_status_t)(i + 0x400));
220
221 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
222 if (!strcasecmp(name, ipp_status_500s[i]))
223 return ((ipp_status_t)(i + 0x500));
224
225 return ((ipp_status_t)-1);
226}
227
228
229/*
230 * 'ippOpString()' - Return a name for the given operation id.
231 *
232 * @since CUPS 1.2@
233 */
234
235const char * /* O - Name */
236ippOpString(ipp_op_t op) /* I - Operation ID */
237{
238 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
239
240
241 /*
242 * See if the operation ID is a known value...
243 */
244
245 if (op >= IPP_PRINT_JOB && op <= IPP_SCHEDULE_JOB_AFTER)
246 return (ipp_std_ops[op]);
247 else if (op == IPP_PRIVATE)
248 return ("windows-ext");
b94498cf 249 else if (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD)
ef416fc2 250 return (ipp_cups_ops[op - CUPS_GET_DEFAULT]);
2e4ff8af
MS
251 else if (op == CUPS_GET_DOCUMENT)
252 return (ipp_cups_ops2[0]);
ef416fc2 253
254 /*
255 * No, build an "unknown-xxxx" operation string...
256 */
257
258 sprintf(cg->ipp_unknown, "unknown-%04x", op);
259
260 return (cg->ipp_unknown);
261}
262
263
264/*
265 * 'ippOpValue()' - Return an operation id for the given name.
266 *
267 * @since CUPS 1.2@
268 */
269
270ipp_op_t /* O - Operation ID */
271ippOpValue(const char *name) /* I - Textual name */
272{
273 int i;
274
275
276 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
277 if (!strcasecmp(name, ipp_std_ops[i]))
278 return ((ipp_op_t)i);
279
280 if (!strcasecmp(name, "windows-ext"))
281 return (IPP_PRIVATE);
282
283 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
284 if (!strcasecmp(name, ipp_cups_ops[i]))
285 return ((ipp_op_t)(i + 0x4001));
286
2e4ff8af
MS
287 for (i = 0; i < (sizeof(ipp_cups_ops2) / sizeof(ipp_cups_ops2[0])); i ++)
288 if (!strcasecmp(name, ipp_cups_ops2[i]))
289 return ((ipp_op_t)(i + 0x4027));
290
480ef0fe 291 if (!strcasecmp(name, "CUPS-Add-Class"))
292 return (CUPS_ADD_MODIFY_CLASS);
293
294 if (!strcasecmp(name, "CUPS-Add-Printer"))
295 return (CUPS_ADD_MODIFY_PRINTER);
296
ef416fc2 297 return ((ipp_op_t)-1);
298}
299
300
301/*
302 * 'ippPort()' - Return the default IPP port number.
303 */
304
305int /* O - Port number */
306ippPort(void)
307{
308 const char *ipp_port; /* IPP_PORT environment variable */
309 struct servent *port; /* Port number info */
310 int portnum; /* Port number */
311 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
312
313
d09495fa 314 DEBUG_puts("ippPort()");
315
316 if (!cg->ipp_port)
317 {
318 /*
319 * See if the server definition includes the port number...
320 */
321
322 DEBUG_puts("ippPort: Not initialized...");
323
324 cupsServer();
325
326#ifdef DEBUG
327 if (cg->ipp_port)
328 puts("ippPort: Set via cupsServer()...");
329#endif /* DEBUG */
330 }
331
ef416fc2 332 if (!cg->ipp_port)
333 {
334 if ((ipp_port = getenv("IPP_PORT")) != NULL)
d09495fa 335 {
336 DEBUG_puts("ippPort: Set via IPP_PORT...");
ef416fc2 337 portnum = atoi(ipp_port);
d09495fa 338 }
ef416fc2 339 else if ((port = getservbyname("ipp", NULL)) == NULL)
d09495fa 340 {
341 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
ef416fc2 342 portnum = CUPS_DEFAULT_IPP_PORT;
d09495fa 343 }
ef416fc2 344 else
d09495fa 345 {
346 DEBUG_puts("ippPort: Set via ipp service entry...");
ef416fc2 347 portnum = ntohs(port->s_port);
d09495fa 348 }
ef416fc2 349
350 if (portnum > 0)
351 cg->ipp_port = portnum;
352 }
353
d09495fa 354 DEBUG_printf(("ippPort: Returning %d...\n", cg->ipp_port));
355
ef416fc2 356 return (cg->ipp_port);
357}
358
359
360/*
361 * 'ippSetPort()' - Set the default port number.
362 */
363
364void
365ippSetPort(int p) /* I - Port number to use */
366{
d09495fa 367 DEBUG_printf(("ippSetPort(p=%d)\n", p));
368
ef416fc2 369 _cupsGlobals()->ipp_port = p;
370}
371
372
373/*
2e4ff8af 374 * End of "$Id: ipp-support.c 6879 2007-08-29 20:26:50Z mike $".
ef416fc2 375 */