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