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