]> 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 6649 2007-07-11 21:46:42Z 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
155
156 /*
157 * 'ippErrorString()' - Return a name for the given status code.
158 */
159
160 const char * /* O - Text string */
161 ippErrorString(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
170 if (error >= IPP_OK && error <= IPP_OK_EVENTS_COMPLETE)
171 return (ipp_status_oks[error]);
172 else if (error == IPP_REDIRECTION_OTHER_SITE)
173 return ("redirection-other-site");
174 else if (error == CUPS_SEE_OTHER)
175 return ("cups-see-other");
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
197 ipp_status_t /* O - IPP status code */
198 ippErrorValue(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
210 if (!strcasecmp(name, "cups-see-other"))
211 return (CUPS_SEE_OTHER);
212
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
231 const char * /* O - Name */
232 ippOpString(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");
245 else if (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD)
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
264 ipp_op_t /* O - Operation ID */
265 ippOpValue(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
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
287 return ((ipp_op_t)-1);
288 }
289
290
291 /*
292 * 'ippPort()' - Return the default IPP port number.
293 */
294
295 int /* O - Port number */
296 ippPort(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
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
322 if (!cg->ipp_port)
323 {
324 if ((ipp_port = getenv("IPP_PORT")) != NULL)
325 {
326 DEBUG_puts("ippPort: Set via IPP_PORT...");
327 portnum = atoi(ipp_port);
328 }
329 else if ((port = getservbyname("ipp", NULL)) == NULL)
330 {
331 DEBUG_puts("ippPort: Set via CUPS_DEFAULT_IPP_PORT...");
332 portnum = CUPS_DEFAULT_IPP_PORT;
333 }
334 else
335 {
336 DEBUG_puts("ippPort: Set via ipp service entry...");
337 portnum = ntohs(port->s_port);
338 }
339
340 if (portnum > 0)
341 cg->ipp_port = portnum;
342 }
343
344 DEBUG_printf(("ippPort: Returning %d...\n", cg->ipp_port));
345
346 return (cg->ipp_port);
347 }
348
349
350 /*
351 * 'ippSetPort()' - Set the default port number.
352 */
353
354 void
355 ippSetPort(int p) /* I - Port number to use */
356 {
357 DEBUG_printf(("ippSetPort(p=%d)\n", p));
358
359 _cupsGlobals()->ipp_port = p;
360 }
361
362
363 /*
364 * End of "$Id: ipp-support.c 6649 2007-07-11 21:46:42Z mike $".
365 */