]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/ipp-support.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / ipp-support.c
1 /*
2 * "$Id: ipp-support.c 5903 2006-08-29 20:45:15Z mike $"
3 *
4 * Internet Printing Protocol support functions for the Common UNIX
5 * Printing System (CUPS).
6 *
7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
14 * at:
15 *
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
20 *
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 *
25 * This file is subject to the Apple OS-Developed Software exception.
26 *
27 * Contents:
28 *
29 * ippErrorString() - Return a name for the given status code.
30 * ippErrorValue() - Return a status code for the given name.
31 * ippOpString() - Return a name for the given operation id.
32 * ippOpValue() - Return an operation id for the given name.
33 * ippPort() - Return the default IPP port number.
34 * ippSetPort() - Set the default port number.
35 */
36
37 /*
38 * Include necessary headers...
39 */
40
41 #include "globals.h"
42 #include "debug.h"
43 #include <stdlib.h>
44
45
46 /*
47 * Local globals...
48 */
49
50 static const char * const ipp_status_oks[] = /* "OK" status codes */
51 {
52 "successful-ok",
53 "successful-ok-ignored-or-substituted-attributes",
54 "successful-ok-conflicting-attributes",
55 "successful-ok-ignored-subscriptions",
56 "successful-ok-ignored-notifications",
57 "successful-ok-too-many-events",
58 "successful-ok-but-cancel-subscription",
59 "successful-ok-events-complete"
60 },
61 * const ipp_status_400s[] = /* Client errors */
62 {
63 "client-error-bad-request",
64 "client-error-forbidden",
65 "client-error-not-authenticated",
66 "client-error-not-authorized",
67 "client-error-not-possible",
68 "client-error-timeout",
69 "client-error-not-found",
70 "client-error-gone",
71 "client-error-request-entity-too-large",
72 "client-error-request-value-too-long",
73 "client-error-document-format-not-supported",
74 "client-error-attributes-or-values-not-supported",
75 "client-error-uri-scheme-not-supported",
76 "client-error-charset-not-supported",
77 "client-error-conflicting-attributes",
78 "client-error-compression-not-supported",
79 "client-error-compression-error",
80 "client-error-document-format-error",
81 "client-error-document-access-error",
82 "client-error-attributes-not-settable",
83 "client-error-ignored-all-subscriptions",
84 "client-error-too-many-subscriptions",
85 "client-error-ignored-all-notifications",
86 "client-error-print-support-file-not-found"
87 },
88 * const ipp_status_500s[] = /* Server errors */
89 {
90 "server-error-internal-error",
91 "server-error-operation-not-supported",
92 "server-error-service-unavailable",
93 "server-error-version-not-supported",
94 "server-error-device-error",
95 "server-error-temporary-error",
96 "server-error-not-accepting-jobs",
97 "server-error-busy",
98 "server-error-job-canceled",
99 "server-error-multiple-document-jobs-not-supported",
100 "server-error-printer-is-deactivated"
101 };
102 static char * const ipp_std_ops[] =
103 {
104 /* 0x0000 - 0x000f */
105 "", "", "Print-Job", "Print-URI",
106 "Validate-Job", "Create-Job", "Send-Document",
107 "Send-URI", "Cancel-Job", "Get-Job-Attributes",
108 "Get-Jobs", "Get-Printer-Attributes",
109 "Hold-Job", "Release-Job", "Restart-Job", "",
110
111 /* 0x0010 - 0x001f */
112 "Pause-Printer", "Resume-Printer",
113 "Purge-Jobs", "Set-Printer-Attributes",
114 "Set-Job-Attributes",
115 "Get-Printer-Supported-Values",
116 "Create-Printer-Subscription",
117 "Create-Job-Subscription",
118 "Get-Subscription-Attributes",
119 "Get-Subscriptions", "Renew-Subscription",
120 "Cancel-Subscription", "Get-Notifications",
121 "Send-Notifications", "", "",
122
123 /* 0x0020 - 0x002f */
124 "",
125 "Get-Printer-Support-Files",
126 "Enable-Printer",
127 "Disable-Printer",
128 "Pause-Printer-After-Current-Job",
129 "Hold-New-Jobs",
130 "Release-Held-New-Jobs",
131 "Deactivate-Printer",
132 "Activate-Printer",
133 "Restart-Printer",
134 "Shutdown-Printer",
135 "Startup-Printer",
136 "Reprocess-Job",
137 "Cancel-Current-Job",
138 "Suspend-Current-Job",
139 "Resume-Job",
140
141 /* 0x0030 - 0x0031 */
142 "Promote-Job",
143 "Schedule-Job-After"
144 },
145 * const ipp_cups_ops[] =
146 {
147 "CUPS-Get-Default",
148 "CUPS-Get-Printers",
149 "CUPS-Add-Modify-Printer",
150 "CUPS-Delete-Printer",
151 "CUPS-Get-Classes",
152 "CUPS-Add-Modify-Class",
153 "CUPS-Delete-Class",
154 "CUPS-Accept-Jobs",
155 "CUPS-Reject-Jobs",
156 "CUPS-Set-Default",
157 "CUPS-Get-Devices",
158 "CUPS-Get-PPDs",
159 "CUPS-Move-Job",
160 "CUPS-Authenticate-Job"
161 };
162
163
164 /*
165 * 'ippErrorString()' - Return a name for the given status code.
166 */
167
168 const char * /* O - Text string */
169 ippErrorString(ipp_status_t error) /* I - Error status */
170 {
171 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
172
173
174 /*
175 * See if the error code is a known value...
176 */
177
178 if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE)
179 return (ipp_status_oks[error]);
180 else if (error == IPP_REDIRECTION_OTHER_SITE)
181 return ("redirection-other-site");
182 else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND)
183 return (ipp_status_400s[error - IPP_BAD_REQUEST]);
184 else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED)
185 return (ipp_status_500s[error - IPP_INTERNAL_ERROR]);
186
187 /*
188 * No, build an "unknown-xxxx" error string...
189 */
190
191 sprintf(cg->ipp_unknown, "unknown-%04x", error);
192
193 return (cg->ipp_unknown);
194 }
195
196
197 /*
198 * 'ippErrorValue()' - Return a status code for the given name.
199 *
200 * @since CUPS 1.2@
201 */
202
203 ipp_status_t /* O - IPP status code */
204 ippErrorValue(const char *name) /* I - Name */
205 {
206 int i;
207
208
209 for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++)
210 if (!strcasecmp(name, ipp_status_oks[i]))
211 return ((ipp_status_t)i);
212
213 if (!strcasecmp(name, "redirection-other-site"))
214 return (IPP_REDIRECTION_OTHER_SITE);
215
216 for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++)
217 if (!strcasecmp(name, ipp_status_400s[i]))
218 return ((ipp_status_t)(i + 0x400));
219
220 for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++)
221 if (!strcasecmp(name, ipp_status_500s[i]))
222 return ((ipp_status_t)(i + 0x500));
223
224 return ((ipp_status_t)-1);
225 }
226
227
228 /*
229 * 'ippOpString()' - Return a name for the given operation id.
230 *
231 * @since CUPS 1.2@
232 */
233
234 const char * /* O - Name */
235 ippOpString(ipp_op_t op) /* I - Operation ID */
236 {
237 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
238
239
240 /*
241 * See if the operation ID is a known value...
242 */
243
244 if (op >= IPP_PRINT_JOB && op <= IPP_SCHEDULE_JOB_AFTER)
245 return (ipp_std_ops[op]);
246 else if (op == IPP_PRIVATE)
247 return ("windows-ext");
248 else if (op >= CUPS_GET_DEFAULT && op <= CUPS_AUTHENTICATE_JOB)
249 return (ipp_cups_ops[op - CUPS_GET_DEFAULT]);
250
251 /*
252 * No, build an "unknown-xxxx" operation string...
253 */
254
255 sprintf(cg->ipp_unknown, "unknown-%04x", op);
256
257 return (cg->ipp_unknown);
258 }
259
260
261 /*
262 * 'ippOpValue()' - Return an operation id for the given name.
263 *
264 * @since CUPS 1.2@
265 */
266
267 ipp_op_t /* O - Operation ID */
268 ippOpValue(const char *name) /* I - Textual name */
269 {
270 int i;
271
272
273 for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++)
274 if (!strcasecmp(name, ipp_std_ops[i]))
275 return ((ipp_op_t)i);
276
277 if (!strcasecmp(name, "windows-ext"))
278 return (IPP_PRIVATE);
279
280 for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++)
281 if (!strcasecmp(name, ipp_cups_ops[i]))
282 return ((ipp_op_t)(i + 0x4001));
283
284 if (!strcasecmp(name, "CUPS-Add-Class"))
285 return (CUPS_ADD_MODIFY_CLASS);
286
287 if (!strcasecmp(name, "CUPS-Add-Printer"))
288 return (CUPS_ADD_MODIFY_PRINTER);
289
290 return ((ipp_op_t)-1);
291 }
292
293
294 /*
295 * 'ippPort()' - Return the default IPP port number.
296 */
297
298 int /* O - Port number */
299 ippPort(void)
300 {
301 const char *ipp_port; /* IPP_PORT environment variable */
302 struct servent *port; /* Port number info */
303 int portnum; /* Port number */
304 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
305
306
307 DEBUG_puts("ippPort()");
308
309 if (!cg->ipp_port)
310 {
311 /*
312 * See if the server definition includes the port number...
313 */
314
315 DEBUG_puts("ippPort: Not initialized...");
316
317 cupsServer();
318
319 #ifdef DEBUG
320 if (cg->ipp_port)
321 puts("ippPort: Set via cupsServer()...");
322 #endif /* DEBUG */
323 }
324
325 if (!cg->ipp_port)
326 {
327 if ((ipp_port = getenv("IPP_PORT")) != NULL)
328 {
329 DEBUG_puts("ippPort: Set via IPP_PORT...");
330 portnum = atoi(ipp_port);
331 }
332 else if ((port = getservbyname("ipp", NULL)) == NULL)
333 {
334 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
335 portnum = CUPS_DEFAULT_IPP_PORT;
336 }
337 else
338 {
339 DEBUG_puts("ippPort: Set via ipp service entry...");
340 portnum = ntohs(port->s_port);
341 }
342
343 if (portnum > 0)
344 cg->ipp_port = portnum;
345 }
346
347 DEBUG_printf(("ippPort: Returning %d...\n", cg->ipp_port));
348
349 return (cg->ipp_port);
350 }
351
352
353 /*
354 * 'ippSetPort()' - Set the default port number.
355 */
356
357 void
358 ippSetPort(int p) /* I - Port number to use */
359 {
360 DEBUG_printf(("ippSetPort(p=%d)\n", p));
361
362 _cupsGlobals()->ipp_port = p;
363 }
364
365
366 /*
367 * End of "$Id: ipp-support.c 5903 2006-08-29 20:45:15Z mike $".
368 */