]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
fa73b229 | 2 | * "$Id: ipp-support.c 4987 2006-01-26 00:25:21Z mike $" |
ef416fc2 | 3 | * |
4 | * Internet Printing Protocol support functions for the Common UNIX | |
5 | * Printing System (CUPS). | |
6 | * | |
7 | * Copyright 1997-2005 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 | }, | |
60 | * const ipp_status_400s[] = /* Client errors */ | |
61 | { | |
62 | "client-error-bad-request", | |
63 | "client-error-forbidden", | |
64 | "client-error-not-authenticated", | |
65 | "client-error-not-authorized", | |
66 | "client-error-not-possible", | |
67 | "client-error-timeout", | |
68 | "client-error-not-found", | |
69 | "client-error-gone", | |
70 | "client-error-request-entity-too-large", | |
71 | "client-error-request-value-too-long", | |
72 | "client-error-document-format-not-supported", | |
73 | "client-error-attributes-or-values-not-supported", | |
74 | "client-error-uri-scheme-not-supported", | |
75 | "client-error-charset-not-supported", | |
76 | "client-error-conflicting-attributes", | |
77 | "client-error-compression-not-supported", | |
78 | "client-error-compression-error", | |
79 | "client-error-document-format-error", | |
80 | "client-error-document-access-error", | |
81 | "client-error-attributes-not-settable", | |
82 | "client-error-ignored-all-subscriptions", | |
83 | "client-error-too-many-subscriptions", | |
84 | "client-error-ignored-all-notifications", | |
85 | "client-error-print-support-file-not-found" | |
86 | }, | |
87 | * const ipp_status_500s[] = /* Server errors */ | |
88 | { | |
89 | "server-error-internal-error", | |
90 | "server-error-operation-not-supported", | |
91 | "server-error-service-unavailable", | |
92 | "server-error-version-not-supported", | |
93 | "server-error-device-error", | |
94 | "server-error-temporary-error", | |
95 | "server-error-not-accepting-jobs", | |
96 | "server-error-busy", | |
97 | "server-error-job-canceled", | |
98 | "server-error-multiple-document-jobs-not-supported", | |
99 | "server-error-printer-is-deactivated" | |
100 | }; | |
101 | static char * const ipp_std_ops[] = | |
102 | { | |
103 | /* 0x0000 - 0x000f */ | |
104 | "", "", "Print-Job", "Print-URI", | |
105 | "Validate-Job", "Create-Job", "Send-Document", | |
106 | "Send-URI", "Cancel-Job", "Get-Job-Attributes", | |
107 | "Get-Jobs", "Get-Printer-Attributes", | |
108 | "Hold-Job", "Release-Job", "Restart-Job", "", | |
109 | ||
110 | /* 0x0010 - 0x001f */ | |
111 | "Pause-Printer", "Resume-Printer", | |
112 | "Purge-Jobs", "Set-Printer-Attributes", | |
113 | "Set-Job-Attributes", | |
114 | "Get-Printer-Supported-Values", | |
115 | "Create-Printer-Subscription", | |
116 | "Create-Job-Subscription", | |
117 | "Get-Subscription-Attributes", | |
118 | "Get-Subscriptions", "Renew-Subscription", | |
119 | "Cancel-Subscription", "Get-Notifications", | |
120 | "Send-Notifications", "", "", | |
121 | ||
122 | /* 0x0020 - 0x002f */ | |
123 | "", | |
124 | "Get-Printer-Support-Files", | |
125 | "Enable-Printer", | |
126 | "Disable-Printer", | |
127 | "Pause-Printer-After-Current-Job", | |
128 | "Hold-New-Jobs", | |
129 | "Release-Held-New-Jobs", | |
130 | "Deactivate-Printer", | |
131 | "Activate-Printer", | |
132 | "Restart-Printer", | |
133 | "Shutdown-Printer", | |
134 | "Startup-Printer", | |
135 | "Reprocess-Job", | |
136 | "Cancel-Current-Job", | |
137 | "Suspend-Current-Job", | |
138 | "Resume-Job", | |
139 | ||
140 | /* 0x0030 - 0x0031 */ | |
141 | "Promote-Job", | |
142 | "Schedule-Job-After" | |
143 | }, | |
144 | * const ipp_cups_ops[] = | |
145 | { | |
146 | "CUPS-Get-Default", | |
147 | "CUPS-Get-Printers", | |
148 | "CUPS-Add-Printer", | |
149 | "CUPS-Delete-Printer", | |
150 | "CUPS-Get-Classes", | |
151 | "CUPS-Add-Class", | |
152 | "CUPS-Delete-Class", | |
153 | "CUPS-Accept-Jobs", | |
154 | "CUPS-Reject-Jobs", | |
155 | "CUPS-Set-Default", | |
156 | "CUPS-Get-Devices", | |
157 | "CUPS-Get-PPDs", | |
158 | "CUPS-Move-Job", | |
159 | "CUPS-Authenticate-Job" | |
160 | }; | |
161 | ||
162 | ||
163 | /* | |
164 | * 'ippErrorString()' - Return a name for the given status code. | |
165 | */ | |
166 | ||
167 | const char * /* O - Text string */ | |
168 | ippErrorString(ipp_status_t error) /* I - Error status */ | |
169 | { | |
170 | _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ | |
171 | ||
172 | ||
173 | /* | |
174 | * See if the error code is a known value... | |
175 | */ | |
176 | ||
177 | if (error >= IPP_OK && error <= IPP_OK_BUT_CANCEL_SUBSCRIPTION) | |
178 | return (ipp_status_oks[error]); | |
179 | else if (error == IPP_REDIRECTION_OTHER_SITE) | |
180 | return ("redirection-other-site"); | |
181 | else if (error >= IPP_BAD_REQUEST && error <= IPP_PRINT_SUPPORT_FILE_NOT_FOUND) | |
182 | return (ipp_status_400s[error - IPP_BAD_REQUEST]); | |
183 | else if (error >= IPP_INTERNAL_ERROR && error <= IPP_PRINTER_IS_DEACTIVATED) | |
184 | return (ipp_status_500s[error - IPP_INTERNAL_ERROR]); | |
185 | ||
186 | /* | |
187 | * No, build an "unknown-xxxx" error string... | |
188 | */ | |
189 | ||
190 | sprintf(cg->ipp_unknown, "unknown-%04x", error); | |
191 | ||
192 | return (cg->ipp_unknown); | |
193 | } | |
194 | ||
195 | ||
196 | /* | |
197 | * 'ippErrorValue()' - Return a status code for the given name. | |
198 | * | |
199 | * @since CUPS 1.2@ | |
200 | */ | |
201 | ||
202 | ipp_status_t /* O - IPP status code */ | |
203 | ippErrorValue(const char *name) /* I - Name */ | |
204 | { | |
205 | int i; | |
206 | ||
207 | ||
208 | for (i = 0; i < (sizeof(ipp_status_oks) / sizeof(ipp_status_oks[0])); i ++) | |
209 | if (!strcasecmp(name, ipp_status_oks[i])) | |
210 | return ((ipp_status_t)i); | |
211 | ||
212 | if (!strcasecmp(name, "redirection-other-site")) | |
213 | return (IPP_REDIRECTION_OTHER_SITE); | |
214 | ||
215 | for (i = 0; i < (sizeof(ipp_status_400s) / sizeof(ipp_status_400s[0])); i ++) | |
216 | if (!strcasecmp(name, ipp_status_400s[i])) | |
217 | return ((ipp_status_t)(i + 0x400)); | |
218 | ||
219 | for (i = 0; i < (sizeof(ipp_status_500s) / sizeof(ipp_status_500s[0])); i ++) | |
220 | if (!strcasecmp(name, ipp_status_500s[i])) | |
221 | return ((ipp_status_t)(i + 0x500)); | |
222 | ||
223 | return ((ipp_status_t)-1); | |
224 | } | |
225 | ||
226 | ||
227 | /* | |
228 | * 'ippOpString()' - Return a name for the given operation id. | |
229 | * | |
230 | * @since CUPS 1.2@ | |
231 | */ | |
232 | ||
233 | const char * /* O - Name */ | |
234 | ippOpString(ipp_op_t op) /* I - Operation ID */ | |
235 | { | |
236 | _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ | |
237 | ||
238 | ||
239 | /* | |
240 | * See if the operation ID is a known value... | |
241 | */ | |
242 | ||
243 | if (op >= IPP_PRINT_JOB && op <= IPP_SCHEDULE_JOB_AFTER) | |
244 | return (ipp_std_ops[op]); | |
245 | else if (op == IPP_PRIVATE) | |
246 | return ("windows-ext"); | |
247 | else if (op >= CUPS_GET_DEFAULT && op <= CUPS_AUTHENTICATE_JOB) | |
248 | return (ipp_cups_ops[op - CUPS_GET_DEFAULT]); | |
249 | ||
250 | /* | |
251 | * No, build an "unknown-xxxx" operation string... | |
252 | */ | |
253 | ||
254 | sprintf(cg->ipp_unknown, "unknown-%04x", op); | |
255 | ||
256 | return (cg->ipp_unknown); | |
257 | } | |
258 | ||
259 | ||
260 | /* | |
261 | * 'ippOpValue()' - Return an operation id for the given name. | |
262 | * | |
263 | * @since CUPS 1.2@ | |
264 | */ | |
265 | ||
266 | ipp_op_t /* O - Operation ID */ | |
267 | ippOpValue(const char *name) /* I - Textual name */ | |
268 | { | |
269 | int i; | |
270 | ||
271 | ||
272 | for (i = 0; i < (sizeof(ipp_std_ops) / sizeof(ipp_std_ops[0])); i ++) | |
273 | if (!strcasecmp(name, ipp_std_ops[i])) | |
274 | return ((ipp_op_t)i); | |
275 | ||
276 | if (!strcasecmp(name, "windows-ext")) | |
277 | return (IPP_PRIVATE); | |
278 | ||
279 | for (i = 0; i < (sizeof(ipp_cups_ops) / sizeof(ipp_cups_ops[0])); i ++) | |
280 | if (!strcasecmp(name, ipp_cups_ops[i])) | |
281 | return ((ipp_op_t)(i + 0x4001)); | |
282 | ||
283 | return ((ipp_op_t)-1); | |
284 | } | |
285 | ||
286 | ||
287 | /* | |
288 | * 'ippPort()' - Return the default IPP port number. | |
289 | */ | |
290 | ||
291 | int /* O - Port number */ | |
292 | ippPort(void) | |
293 | { | |
294 | const char *ipp_port; /* IPP_PORT environment variable */ | |
295 | struct servent *port; /* Port number info */ | |
296 | int portnum; /* Port number */ | |
297 | _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ | |
298 | ||
299 | ||
300 | if (!cg->ipp_port) | |
301 | { | |
302 | if ((ipp_port = getenv("IPP_PORT")) != NULL) | |
303 | portnum = atoi(ipp_port); | |
304 | else if ((port = getservbyname("ipp", NULL)) == NULL) | |
305 | portnum = CUPS_DEFAULT_IPP_PORT; | |
306 | else | |
307 | portnum = ntohs(port->s_port); | |
308 | ||
309 | if (portnum > 0) | |
310 | cg->ipp_port = portnum; | |
311 | } | |
312 | ||
313 | return (cg->ipp_port); | |
314 | } | |
315 | ||
316 | ||
317 | /* | |
318 | * 'ippSetPort()' - Set the default port number. | |
319 | */ | |
320 | ||
321 | void | |
322 | ippSetPort(int p) /* I - Port number to use */ | |
323 | { | |
ef416fc2 | 324 | _cupsGlobals()->ipp_port = p; |
325 | } | |
326 | ||
327 | ||
328 | /* | |
fa73b229 | 329 | * End of "$Id: ipp-support.c 4987 2006-01-26 00:25:21Z mike $". |
ef416fc2 | 330 | */ |