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