1*2264Sjacobs /*
2*2264Sjacobs * CDDL HEADER START
3*2264Sjacobs *
4*2264Sjacobs * The contents of this file are subject to the terms of the
5*2264Sjacobs * Common Development and Distribution License (the "License").
6*2264Sjacobs * You may not use this file except in compliance with the License.
7*2264Sjacobs *
8*2264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2264Sjacobs * or http://www.opensolaris.org/os/licensing.
10*2264Sjacobs * See the License for the specific language governing permissions
11*2264Sjacobs * and limitations under the License.
12*2264Sjacobs *
13*2264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each
14*2264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2264Sjacobs * If applicable, add the following below this CDDL HEADER, with the
16*2264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying
17*2264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner]
18*2264Sjacobs *
19*2264Sjacobs * CDDL HEADER END
20*2264Sjacobs */
21*2264Sjacobs
22*2264Sjacobs /*
23*2264Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*2264Sjacobs * Use is subject to license terms.
25*2264Sjacobs *
26*2264Sjacobs */
27*2264Sjacobs
28*2264Sjacobs /* $Id: strings.c 151 2006-04-25 16:55:34Z njacobs $ */
29*2264Sjacobs
30*2264Sjacobs #pragma ident "%Z%%M% %I% %E% SMI"
31*2264Sjacobs
32*2264Sjacobs #include <stdio.h>
33*2264Sjacobs #include <stdlib.h>
34*2264Sjacobs #include <string.h>
35*2264Sjacobs
36*2264Sjacobs #include "ipp.h"
37*2264Sjacobs
38*2264Sjacobs static char *tag_strings[] = {
39*2264Sjacobs /* delimiter tags */
40*2264Sjacobs "reserved-delimiter-00",
41*2264Sjacobs "operational-attributes-group",
42*2264Sjacobs "job-attributes-group",
43*2264Sjacobs "end-of-attributes-group",
44*2264Sjacobs "printer-attributes-group",
45*2264Sjacobs "unsupported-attributes-group",
46*2264Sjacobs "subscription-attributes-group",
47*2264Sjacobs "event-notification-attributes-group",
48*2264Sjacobs "reserved-delimiter-08",
49*2264Sjacobs "reserved-delimiter-09",
50*2264Sjacobs "reserved-delimiter-0a",
51*2264Sjacobs "reserved-delimiter-0b",
52*2264Sjacobs "reserved-delimiter-0c",
53*2264Sjacobs "reserved-delimiter-0d",
54*2264Sjacobs "reserved-delimiter-0e",
55*2264Sjacobs "reserved-delimiter-0f",
56*2264Sjacobs /* value tags */
57*2264Sjacobs "unsupported",
58*2264Sjacobs "reserved-default",
59*2264Sjacobs "unknown",
60*2264Sjacobs "no-value",
61*2264Sjacobs "reserved-out-of-band-14",
62*2264Sjacobs "not-settable",
63*2264Sjacobs "delete-attribute",
64*2264Sjacobs "admin-define",
65*2264Sjacobs "reserved-out-of-band-18",
66*2264Sjacobs "reserved-out-of-band-19",
67*2264Sjacobs "reserved-out-of-band-1a",
68*2264Sjacobs "reserved-out-of-band-1b",
69*2264Sjacobs "reserved-out-of-band-1c",
70*2264Sjacobs "reserved-out-of-band-1d",
71*2264Sjacobs "reserved-out-of-band-1e",
72*2264Sjacobs "reserved-out-of-band-1f",
73*2264Sjacobs "reserved",
74*2264Sjacobs "integer",
75*2264Sjacobs "boolean",
76*2264Sjacobs "enum",
77*2264Sjacobs "reserved-integer-type-24",
78*2264Sjacobs "reserved-integer-type-25",
79*2264Sjacobs "reserved-integer-type-26",
80*2264Sjacobs "reserved-integer-type-27",
81*2264Sjacobs "reserved-integer-type-28",
82*2264Sjacobs "reserved-integer-type-29",
83*2264Sjacobs "reserved-integer-type-2a",
84*2264Sjacobs "reserved-integer-type-2b",
85*2264Sjacobs "reserved-integer-type-2c",
86*2264Sjacobs "reserved-integer-type-2d",
87*2264Sjacobs "reserved-integer-type-2e",
88*2264Sjacobs "reserved-integer-type-2f",
89*2264Sjacobs "octetString",
90*2264Sjacobs "dateTime",
91*2264Sjacobs "resolution",
92*2264Sjacobs "rangeOfInteger",
93*2264Sjacobs "begCollection",
94*2264Sjacobs "textWithLanguage",
95*2264Sjacobs "nameWithLanguage",
96*2264Sjacobs "endCollection",
97*2264Sjacobs "reserved-octetString-38",
98*2264Sjacobs "reserved-octetString-39",
99*2264Sjacobs "reserved-octetString-3a",
100*2264Sjacobs "reserved-octetString-3b",
101*2264Sjacobs "reserved-octetString-3c",
102*2264Sjacobs "reserved-octetString-3d",
103*2264Sjacobs "reserved-octetString-3e",
104*2264Sjacobs "reserved-octetString-3f",
105*2264Sjacobs "reserved",
106*2264Sjacobs "textWithoutLanguage",
107*2264Sjacobs "nameWithoutLanguage",
108*2264Sjacobs "reserved",
109*2264Sjacobs "keyword",
110*2264Sjacobs "uri",
111*2264Sjacobs "uriScheme",
112*2264Sjacobs "charset",
113*2264Sjacobs "naturalLanguage",
114*2264Sjacobs "mimeMediaType",
115*2264Sjacobs "memberAttrName",
116*2264Sjacobs "reserved-charString-4b",
117*2264Sjacobs "reserved-charString-4c",
118*2264Sjacobs "reserved-charString-4d",
119*2264Sjacobs "reserved-charString-4e",
120*2264Sjacobs "reserved-charString-4f",
121*2264Sjacobs "reserved-charString-50",
122*2264Sjacobs "reserved-charString-51",
123*2264Sjacobs "reserved-charString-52",
124*2264Sjacobs "reserved-charString-53",
125*2264Sjacobs "reserved-charString-54",
126*2264Sjacobs "reserved-charString-55",
127*2264Sjacobs "reserved-charString-56",
128*2264Sjacobs "reserved-charString-57",
129*2264Sjacobs "reserved-charString-58",
130*2264Sjacobs "reserved-charString-59",
131*2264Sjacobs "reserved-charString-5a",
132*2264Sjacobs "reserved-charString-5b",
133*2264Sjacobs "reserved-charString-5c",
134*2264Sjacobs "reserved-charString-5d",
135*2264Sjacobs "reserved-charString-5e",
136*2264Sjacobs "reserved-charString-5f",
137*2264Sjacobs };
138*2264Sjacobs
139*2264Sjacobs static char *opid_strings[] = {
140*2264Sjacobs "reserved-0x0000",
141*2264Sjacobs "reserved-0x0001",
142*2264Sjacobs "Print-Job",
143*2264Sjacobs "Print-URI",
144*2264Sjacobs "Validate-Job",
145*2264Sjacobs "Create-Job",
146*2264Sjacobs "Send-Document",
147*2264Sjacobs "Send-URI",
148*2264Sjacobs "Cancel-Job",
149*2264Sjacobs "Get-Job-Attributes",
150*2264Sjacobs "Get-Jobs",
151*2264Sjacobs "Get-Printer-Attributes",
152*2264Sjacobs "Hold-Job",
153*2264Sjacobs "Release-Job",
154*2264Sjacobs "Restart-Job",
155*2264Sjacobs "reserved-0x000f",
156*2264Sjacobs "Pause-Printer",
157*2264Sjacobs "Resume-Printer",
158*2264Sjacobs "Purge-Jobs",
159*2264Sjacobs "Set-Printer-Attributes",
160*2264Sjacobs "Set-Job-Attributes",
161*2264Sjacobs "Get-Printer-Supported-Values",
162*2264Sjacobs "Create-Printer-Subscription",
163*2264Sjacobs "Create-Job-Subscription",
164*2264Sjacobs "Get-Subscription-Attributes",
165*2264Sjacobs "Get-Subscriptions",
166*2264Sjacobs "Renew-Subscription",
167*2264Sjacobs "Cancel-Subscription",
168*2264Sjacobs "Get-Notifications",
169*2264Sjacobs "Send-Notifications",
170*2264Sjacobs "Get-Resource-Attributes-deleted",
171*2264Sjacobs "Get-Resource-Data-deleted",
172*2264Sjacobs "Get-Resources-deleted",
173*2264Sjacobs "Get-Print-Support-Files",
174*2264Sjacobs "Disable-Printer",
175*2264Sjacobs "Pause-Printer-After-Current-Job",
176*2264Sjacobs "Hold-New-Jobs",
177*2264Sjacobs "Release-Held-New-Jobs",
178*2264Sjacobs "Deactivate-Printer",
179*2264Sjacobs "Activate-Printer",
180*2264Sjacobs "Restart-Printer",
181*2264Sjacobs "Shutdown-Printer",
182*2264Sjacobs "Startup-Printer",
183*2264Sjacobs "Reprocess-Job",
184*2264Sjacobs "Cancel-Current-Job",
185*2264Sjacobs "Suspend-Current-Job",
186*2264Sjacobs "Resume-Job",
187*2264Sjacobs "Promote-Job",
188*2264Sjacobs "Schedule-Job-After",
189*2264Sjacobs NULL
190*2264Sjacobs };
191*2264Sjacobs
192*2264Sjacobs static char *res_opid_strings[] = {
193*2264Sjacobs "Microsoft-0x4000",
194*2264Sjacobs "CUPS-Get-Default",
195*2264Sjacobs "CUPS-Get-Printers",
196*2264Sjacobs "CUPS-Add-Printer",
197*2264Sjacobs "CUPS-Delete-Printer",
198*2264Sjacobs "CUPS-Get-Classes",
199*2264Sjacobs "CUPS-Add-Class",
200*2264Sjacobs "CUPS-Delete-Class",
201*2264Sjacobs "CUPS-Accept-Jobs",
202*2264Sjacobs "CUPS-Reject-Jobs",
203*2264Sjacobs "CUPS-Set-Default",
204*2264Sjacobs "CUPS-Get-Devices",
205*2264Sjacobs "CUPS-Get-PPDs",
206*2264Sjacobs "CUPS-Move-Job",
207*2264Sjacobs "CUPS-0x400e",
208*2264Sjacobs "CUPS-0x400f",
209*2264Sjacobs "Peerless-0x4010",
210*2264Sjacobs NULL
211*2264Sjacobs };
212*2264Sjacobs #define KNOWN_RESERVED_MIN 0x4000
213*2264Sjacobs #define KNOWN_RESERVED_MAX 0x4010
214*2264Sjacobs
215*2264Sjacobs static char *ok_status_strings[] = {
216*2264Sjacobs "successful-ok",
217*2264Sjacobs "successful-ok-ignored-or-substituted-attributes",
218*2264Sjacobs "successful-ok-conflicting-attributes",
219*2264Sjacobs "successful-ok-ignored-subscriptions",
220*2264Sjacobs "successful-ok-ignored-notifications",
221*2264Sjacobs "successful-ok-too-many-events",
222*2264Sjacobs "successful-ok-but-cancel-subscription"
223*2264Sjacobs };
224*2264Sjacobs
225*2264Sjacobs static char *redir_status_strings[] = {
226*2264Sjacobs "redirection-other-site"
227*2264Sjacobs };
228*2264Sjacobs
229*2264Sjacobs static char *client_error_status_strings[] = {
230*2264Sjacobs "client-error-bad-request",
231*2264Sjacobs "client-error-forbidden",
232*2264Sjacobs "client-error-not-authenticated",
233*2264Sjacobs "client-error-not-authorized",
234*2264Sjacobs "client-error-not-possible",
235*2264Sjacobs "client-error-timeout",
236*2264Sjacobs "client-error-not-found",
237*2264Sjacobs "client-error-gone",
238*2264Sjacobs "client-error-request-entity-too-large",
239*2264Sjacobs "client-error-request-value-too-long",
240*2264Sjacobs "client-error-document-format-not-supported",
241*2264Sjacobs "client-error-attributes-or-values-not-supported",
242*2264Sjacobs "client-error-uri-scheme-not-supported",
243*2264Sjacobs "client-error-charset-not-supported",
244*2264Sjacobs "client-error-conflicting-attributes",
245*2264Sjacobs "client-error-compression-not-supported",
246*2264Sjacobs "client-error-compression-error",
247*2264Sjacobs "client-error-document-format-error",
248*2264Sjacobs "client-error-document-access-error",
249*2264Sjacobs "client-error-attributes-not-settable",
250*2264Sjacobs "client-error-ignored-all-subscriptions",
251*2264Sjacobs "client-error-too-many-subscriptions",
252*2264Sjacobs "client-error-ignored-all-notifications",
253*2264Sjacobs "client-error-print-support-file-not-found"
254*2264Sjacobs };
255*2264Sjacobs
256*2264Sjacobs static char *server_error_status_strings[] = {
257*2264Sjacobs "server-error-internal-error",
258*2264Sjacobs "server-error-operation-not-supported",
259*2264Sjacobs "server-error-service-unavailable",
260*2264Sjacobs "server-error-version-not-supported",
261*2264Sjacobs "server-error-device-error",
262*2264Sjacobs "server-error-temporary-error",
263*2264Sjacobs "server-error-not-accepting-jobs",
264*2264Sjacobs "server-error-busy",
265*2264Sjacobs "server-error-job-canceled",
266*2264Sjacobs "server-error-multiple-document-jobs-not-supported",
267*2264Sjacobs "server-error-printer-is-deactivated"
268*2264Sjacobs };
269*2264Sjacobs
270*2264Sjacobs char *
ipp_tag_string(int8_t id,char * ret,size_t len)271*2264Sjacobs ipp_tag_string(int8_t id, char *ret, size_t len)
272*2264Sjacobs {
273*2264Sjacobs if (id < VTAG_MAX)
274*2264Sjacobs (void) strlcpy(ret, tag_strings[id], len);
275*2264Sjacobs else if (id == VTAG_EXTEND)
276*2264Sjacobs (void) strlcpy(ret, "extension", len);
277*2264Sjacobs else
278*2264Sjacobs (void) snprintf(ret, len, "bogus-0x%.2x", id);
279*2264Sjacobs
280*2264Sjacobs return (ret);
281*2264Sjacobs }
282*2264Sjacobs
283*2264Sjacobs char *
ipp_opid_string(int16_t id,char * ret,size_t len)284*2264Sjacobs ipp_opid_string(int16_t id, char *ret, size_t len)
285*2264Sjacobs {
286*2264Sjacobs if (id < OPID_RESERVED_MIN)
287*2264Sjacobs (void) strlcpy(ret, opid_strings[id], len);
288*2264Sjacobs else if (id < OPID_RESERVED_VENDOR_MIN)
289*2264Sjacobs (void) snprintf(ret, len, "reserved-0x%.4x", id);
290*2264Sjacobs else if (id <= KNOWN_RESERVED_MAX)
291*2264Sjacobs (void) strlcpy(ret,
292*2264Sjacobs res_opid_strings[id - KNOWN_RESERVED_MIN], len);
293*2264Sjacobs else /* if (id <= OPID_RESERVED_VENDOR_MAX) */
294*2264Sjacobs (void) snprintf(ret, len, "reserved-vendor-0x%.4x", id);
295*2264Sjacobs
296*2264Sjacobs return (ret);
297*2264Sjacobs }
298*2264Sjacobs
299*2264Sjacobs int16_t
ipp_string_opid(char * string)300*2264Sjacobs ipp_string_opid(char *string)
301*2264Sjacobs {
302*2264Sjacobs int i;
303*2264Sjacobs
304*2264Sjacobs for (i = 0; opid_strings[i] != NULL; i++)
305*2264Sjacobs if (strcasecmp(opid_strings[i], string) == 0)
306*2264Sjacobs return (i);
307*2264Sjacobs
308*2264Sjacobs for (i = 0; res_opid_strings[i] != NULL; i++)
309*2264Sjacobs if (strcasecmp(res_opid_strings[i], string) == 0)
310*2264Sjacobs return (0x4000 + i);
311*2264Sjacobs
312*2264Sjacobs return (-1);
313*2264Sjacobs }
314*2264Sjacobs
315*2264Sjacobs char *
ipp_status_string(int16_t id,char * ret,size_t len)316*2264Sjacobs ipp_status_string(int16_t id, char *ret, size_t len)
317*2264Sjacobs {
318*2264Sjacobs if (id <= IPP_OK_MAX)
319*2264Sjacobs (void) strlcpy(ret, ok_status_strings[id], len);
320*2264Sjacobs else if (id >= IPP_REDIR_MIN && id <= IPP_REDIR_MAX)
321*2264Sjacobs (void) strlcpy(ret,
322*2264Sjacobs redir_status_strings[id - IPP_REDIR_MIN], len);
323*2264Sjacobs else if (id >= IPP_CERR_MIN && id <= IPP_CERR_MAX)
324*2264Sjacobs (void) strlcpy(ret,
325*2264Sjacobs client_error_status_strings[id - IPP_CERR_MIN], len);
326*2264Sjacobs else if (id >= IPP_SERR_MIN && id <= IPP_SERR_MAX)
327*2264Sjacobs (void) strlcpy(ret,
328*2264Sjacobs server_error_status_strings[id - IPP_SERR_MIN], len);
329*2264Sjacobs else
330*2264Sjacobs (void) snprintf(ret, len, "bogus-0x%.4hx", id);
331*2264Sjacobs
332*2264Sjacobs return (ret);
333*2264Sjacobs }
334*2264Sjacobs
335*2264Sjacobs
336*2264Sjacobs
337*2264Sjacobs /*
338*2264Sjacobs * attribute template handling routines
339*2264Sjacobs */
340*2264Sjacobs char *job_template[] = {
341*2264Sjacobs "copies",
342*2264Sjacobs "finishing",
343*2264Sjacobs "job-hold-until",
344*2264Sjacobs "job-priority",
345*2264Sjacobs "job-sheets",
346*2264Sjacobs "media",
347*2264Sjacobs "multiple-document-handling",
348*2264Sjacobs "number-up",
349*2264Sjacobs "page-ranges-supported",
350*2264Sjacobs "print-quality",
351*2264Sjacobs "printer-resoultion",
352*2264Sjacobs "sides",
353*2264Sjacobs NULL
354*2264Sjacobs };
355*2264Sjacobs
356*2264Sjacobs char *job_description[] = {
357*2264Sjacobs "copies-default", "copies-supported",
358*2264Sjacobs "finishing-default", "finishing-supported",
359*2264Sjacobs "job-hold-until-default", "job-hold-until-supported",
360*2264Sjacobs "job-priority-default", "job-priority-supported",
361*2264Sjacobs "job-sheets-default", "job-sheets-supported",
362*2264Sjacobs "media-default", "media-supported",
363*2264Sjacobs "multiple-document-handling-default",
364*2264Sjacobs "multiple-document-handling-supported",
365*2264Sjacobs "number-up-default", "number-up-supported",
366*2264Sjacobs "page-ranges-supported",
367*2264Sjacobs "print-quality-default", "print-quality-supported",
368*2264Sjacobs "printer-resoultion-default", "printer-resoultion-supported",
369*2264Sjacobs "sides-default", "sides-supported",
370*2264Sjacobs NULL
371*2264Sjacobs };
372*2264Sjacobs
373*2264Sjacobs char *printer_description[] = {
374*2264Sjacobs "printer-uri-supported",
375*2264Sjacobs "uri-security-supported",
376*2264Sjacobs "uri-authentication-supported",
377*2264Sjacobs "printer-name",
378*2264Sjacobs "printer-location",
379*2264Sjacobs "printer-info",
380*2264Sjacobs "printer-more-info",
381*2264Sjacobs "printer-driver-installer",
382*2264Sjacobs "printer-make-and-model",
383*2264Sjacobs "printer-more-info-manufacturer",
384*2264Sjacobs "printer-state",
385*2264Sjacobs "printer-state-reasons",
386*2264Sjacobs "printer-state-message",
387*2264Sjacobs "ipp-versions-supported",
388*2264Sjacobs "multiple-document-jobs-supported",
389*2264Sjacobs "charset-configured",
390*2264Sjacobs "charset-supported",
391*2264Sjacobs "natural-language-configured",
392*2264Sjacobs "generated-natural-language-supported",
393*2264Sjacobs "document-format-default",
394*2264Sjacobs "document-format-supported",
395*2264Sjacobs "printer-is-accepting-jobs",
396*2264Sjacobs "queued-job-count",
397*2264Sjacobs "printer-message-from-operator",
398*2264Sjacobs "color-supported",
399*2264Sjacobs "reference-uri-schemes-supported",
400*2264Sjacobs "pdl-override-supported",
401*2264Sjacobs "printer-up-time",
402*2264Sjacobs "printer-current-time",
403*2264Sjacobs "multiple-operation-time-out",
404*2264Sjacobs "compression-supported",
405*2264Sjacobs "job-k-octets-supported",
406*2264Sjacobs "job-impressions-supported",
407*2264Sjacobs "job-media-sheets-supported",
408*2264Sjacobs "pages-per-minute",
409*2264Sjacobs "pages-per-minute-color",
410*2264Sjacobs NULL
411*2264Sjacobs };
412