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