]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/ipp-support.c
What the heck, make it the full 1.3.3 release code - we've already got all of
[thirdparty/cups.git] / cups / ipp-support.c
CommitLineData
ef416fc2 1/*
bc44d920 2 * "$Id: ipp-support.c 6649 2007-07-11 21:46:42Z 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"
ef416fc2 153 };
154
155
156/*
157 * 'ippErrorString()' - Return a name for the given status code.
158 */
159
160const char * /* O - Text string */
161ippErrorString(ipp_status_t error) /* I - Error status */
162{
163 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
164
165
166 /*
167 * See if the error code is a known value...
168 */
169
bd7854cb 170 if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE)
ef416fc2 171 return (ipp_status_oks[error]);
172 else if (error == IPP_REDIRECTION_OTHER_SITE)
173 return ("redirection-other-site");
b94498cf 174 else if (error == CUPS_SEE_OTHER)
175 return ("cups-see-other");
ef416fc2 176 else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND)
177 return (ipp_status_400s[error - IPP_BAD_REQUEST]);
178 else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED)
179 return (ipp_status_500s[error - IPP_INTERNAL_ERROR]);
180
181 /*
182 * No, build an "unknown-xxxx" error string...
183 */
184
185 sprintf(cg->ipp_unknown, "unknown-%04x", error);
186
187 return (cg->ipp_unknown);
188}
189
190
191/*
192 * 'ippErrorValue()' - Return a status code for the given name.
193 *
194 * @since CUPS 1.2@
195 */
196
197ipp_status_t /* O - IPP status code */
198ippErrorValue(const char *name) /* I - Name */
199{
200 int i;
201
202
203 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
204 if (!strcasecmp(name, ipp_status_oks[i]))
205 return ((ipp_status_t)i);
206
207 if (!strcasecmp(name, "redirection-other-site"))
208 return (IPP_REDIRECTION_OTHER_SITE);
209
b94498cf 210 if (!strcasecmp(name, "cups-see-other"))
211 return (CUPS_SEE_OTHER);
212
ef416fc2 213 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
214 if (!strcasecmp(name, ipp_status_400s[i]))
215 return ((ipp_status_t)(i + 0x400));
216
217 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
218 if (!strcasecmp(name, ipp_status_500s[i]))
219 return ((ipp_status_t)(i + 0x500));
220
221 return ((ipp_status_t)-1);
222}
223
224
225/*
226 * 'ippOpString()' - Return a name for the given operation id.
227 *
228 * @since CUPS 1.2@
229 */
230
231const char * /* O - Name */
232ippOpString(ipp_op_t op) /* I - Operation ID */
233{
234 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
235
236
237 /*
238 * See if the operation ID is a known value...
239 */
240
241 if (op >= IPP_PRINT_JOB && op <= IPP_SCHEDULE_JOB_AFTER)
242 return (ipp_std_ops[op]);
243 else if (op == IPP_PRIVATE)
244 return ("windows-ext");
b94498cf 245 else if (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD)
ef416fc2 246 return (ipp_cups_ops[op - CUPS_GET_DEFAULT]);
247
248 /*
249 * No, build an "unknown-xxxx" operation string...
250 */
251
252 sprintf(cg->ipp_unknown, "unknown-%04x", op);
253
254 return (cg->ipp_unknown);
255}
256
257
258/*
259 * 'ippOpValue()' - Return an operation id for the given name.
260 *
261 * @since CUPS 1.2@
262 */
263
264ipp_op_t /* O - Operation ID */
265ippOpValue(const char *name) /* I - Textual name */
266{
267 int i;
268
269
270 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
271 if (!strcasecmp(name, ipp_std_ops[i]))
272 return ((ipp_op_t)i);
273
274 if (!strcasecmp(name, "windows-ext"))
275 return (IPP_PRIVATE);
276
277 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
278 if (!strcasecmp(name, ipp_cups_ops[i]))
279 return ((ipp_op_t)(i + 0x4001));
280
480ef0fe 281 if (!strcasecmp(name, "CUPS-Add-Class"))
282 return (CUPS_ADD_MODIFY_CLASS);
283
284 if (!strcasecmp(name, "CUPS-Add-Printer"))
285 return (CUPS_ADD_MODIFY_PRINTER);
286
ef416fc2 287 return ((ipp_op_t)-1);
288}
289
290
291/*
292 * 'ippPort()' - Return the default IPP port number.
293 */
294
295int /* O - Port number */
296ippPort(void)
297{
298 const char *ipp_port; /* IPP_PORT environment variable */
299 struct servent *port; /* Port number info */
300 int portnum; /* Port number */
301 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
302
303
d09495fa 304 DEBUG_puts("ippPort()");
305
306 if (!cg->ipp_port)
307 {
308 /*
309 * See if the server definition includes the port number...
310 */
311
312 DEBUG_puts("ippPort: Not initialized...");
313
314 cupsServer();
315
316#ifdef DEBUG
317 if (cg->ipp_port)
318 puts("ippPort: Set via cupsServer()...");
319#endif /* DEBUG */
320 }
321
ef416fc2 322 if (!cg->ipp_port)
323 {
324 if ((ipp_port = getenv("IPP_PORT")) != NULL)
d09495fa 325 {
326 DEBUG_puts("ippPort: Set via IPP_PORT...");
ef416fc2 327 portnum = atoi(ipp_port);
d09495fa 328 }
ef416fc2 329 else if ((port = getservbyname("ipp", NULL)) == NULL)
d09495fa 330 {
331 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
ef416fc2 332 portnum = CUPS_DEFAULT_IPP_PORT;
d09495fa 333 }
ef416fc2 334 else
d09495fa 335 {
336 DEBUG_puts("ippPort: Set via ipp service entry...");
ef416fc2 337 portnum = ntohs(port->s_port);
d09495fa 338 }
ef416fc2 339
340 if (portnum > 0)
341 cg->ipp_port = portnum;
342 }
343
d09495fa 344 DEBUG_printf(("ippPort: Returning %d...\n", cg->ipp_port));
345
ef416fc2 346 return (cg->ipp_port);
347}
348
349
350/*
351 * 'ippSetPort()' - Set the default port number.
352 */
353
354void
355ippSetPort(int p) /* I - Port number to use */
356{
d09495fa 357 DEBUG_printf(("ippSetPort(p=%d)\n", p));
358
ef416fc2 359 _cupsGlobals()->ipp_port = p;
360}
361
362
363/*
bc44d920 364 * End of "$Id: ipp-support.c 6649 2007-07-11 21:46:42Z mike $".
ef416fc2 365 */