]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $" | |
3 | * | |
4 | * Option encoding routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 2007-2009 by Apple Inc. | |
7 | * Copyright 1997-2007 by Easy Software Products. | |
8 | * | |
9 | * These coded instructions, statements, and computer programs are the | |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
14 | * | |
15 | * This file is subject to the Apple OS-Developed Software exception. | |
16 | * | |
17 | * Contents: | |
18 | * | |
19 | * cupsEncodeOptions() - Encode printer options into IPP attributes. | |
20 | * cupsEncodeOptions2() - Encode printer options into IPP attributes for | |
21 | * a group. | |
22 | * _ippFindOption() - Find the attribute information for an option. | |
23 | * compare_ipp_options() - Compare two IPP options. | |
24 | */ | |
25 | ||
26 | /* | |
27 | * Include necessary headers... | |
28 | */ | |
29 | ||
30 | #include "cups.h" | |
31 | #include "ipp-private.h" | |
32 | #include <stdlib.h> | |
33 | #include <ctype.h> | |
34 | #include "string.h" | |
35 | #include "debug.h" | |
36 | ||
37 | ||
38 | /* | |
39 | * Local list of option names and the value tags they should use... | |
40 | * | |
41 | * **** THIS LIST MUST BE SORTED **** | |
42 | */ | |
43 | ||
44 | static const _ipp_option_t ipp_options[] = | |
45 | { | |
46 | { 1, "auth-info", IPP_TAG_TEXT, IPP_TAG_JOB }, | |
47 | { 1, "auth-info-required", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
48 | { 0, "blackplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
49 | { 0, "blackplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
50 | { 0, "brightness", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
51 | { 0, "brightness-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
52 | { 0, "columns", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
53 | { 0, "columns-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
54 | { 0, "compression", IPP_TAG_KEYWORD, IPP_TAG_OPERATION }, | |
55 | { 0, "copies", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
56 | { 0, "copies-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
57 | { 0, "device-uri", IPP_TAG_URI, IPP_TAG_PRINTER }, | |
58 | { 0, "document-format", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION }, | |
59 | { 0, "document-format-default", IPP_TAG_MIMETYPE, IPP_TAG_PRINTER }, | |
60 | { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION }, | |
61 | { 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB }, | |
62 | { 1, "finishings-default", IPP_TAG_ENUM, IPP_TAG_PRINTER }, | |
63 | { 0, "fit-to-page", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
64 | { 0, "fit-to-page-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
65 | { 0, "fitplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
66 | { 0, "fitplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
67 | { 0, "gamma", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
68 | { 0, "gamma-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
69 | { 0, "hue", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
70 | { 0, "hue-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
71 | { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION }, | |
72 | { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
73 | { 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
74 | { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
75 | { 0, "job-priority", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
76 | { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
77 | { 1, "job-sheets", IPP_TAG_NAME, IPP_TAG_JOB }, | |
78 | { 1, "job-sheets-default", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
79 | { 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB }, | |
80 | { 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
81 | { 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
82 | { 1, "marker-colors", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
83 | { 1, "marker-high-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
84 | { 1, "marker-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
85 | { 1, "marker-low-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
86 | { 0, "marker-message", IPP_TAG_TEXT, IPP_TAG_PRINTER }, | |
87 | { 1, "marker-names", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
88 | { 1, "marker-types", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
89 | { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB }, | |
90 | { 0, "media-col", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB }, | |
91 | { 0, "media-col-default", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_PRINTER }, | |
92 | { 0, "media-color", IPP_TAG_KEYWORD, IPP_TAG_JOB }, | |
93 | { 1, "media-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
94 | { 0, "media-key", IPP_TAG_KEYWORD, IPP_TAG_JOB }, | |
95 | { 0, "media-size", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB }, | |
96 | { 0, "media-type", IPP_TAG_KEYWORD, IPP_TAG_JOB }, | |
97 | { 0, "mirror", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
98 | { 0, "mirror-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
99 | { 0, "natural-scaling", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
100 | { 0, "natural-scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
101 | { 0, "notify-charset", IPP_TAG_CHARSET, IPP_TAG_SUBSCRIPTION }, | |
102 | { 1, "notify-events", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION }, | |
103 | { 1, "notify-events-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
104 | { 0, "notify-lease-duration", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION }, | |
105 | { 0, "notify-lease-duration-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
106 | { 0, "notify-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_SUBSCRIPTION }, | |
107 | { 0, "notify-pull-method", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION }, | |
108 | { 0, "notify-recipient-uri", IPP_TAG_URI, IPP_TAG_SUBSCRIPTION }, | |
109 | { 0, "notify-time-interval", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION }, | |
110 | { 0, "notify-user-data", IPP_TAG_STRING, IPP_TAG_SUBSCRIPTION }, | |
111 | { 0, "number-up", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
112 | { 0, "number-up-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
113 | { 0, "orientation-requested", IPP_TAG_ENUM, IPP_TAG_JOB }, | |
114 | { 0, "orientation-requested-default", IPP_TAG_ENUM, IPP_TAG_PRINTER }, | |
115 | { 0, "page-bottom", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
116 | { 0, "page-bottom-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
117 | { 0, "page-left", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
118 | { 0, "page-left-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
119 | { 1, "page-ranges", IPP_TAG_RANGE, IPP_TAG_JOB }, | |
120 | { 1, "page-ranges-default", IPP_TAG_RANGE, IPP_TAG_PRINTER }, | |
121 | { 0, "page-right", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
122 | { 0, "page-right-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
123 | { 0, "page-top", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
124 | { 0, "page-top-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
125 | { 0, "penwidth", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
126 | { 0, "penwidth-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
127 | { 0, "port-monitor", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
128 | { 0, "ppi", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
129 | { 0, "ppi-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
130 | { 0, "prettyprint", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
131 | { 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
132 | { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB }, | |
133 | { 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER }, | |
134 | { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
135 | { 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
136 | { 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER }, | |
137 | { 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
138 | { 0, "printer-is-shared", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
139 | { 0, "printer-location", IPP_TAG_TEXT, IPP_TAG_PRINTER }, | |
140 | { 0, "printer-make-and-model", IPP_TAG_TEXT, IPP_TAG_PRINTER }, | |
141 | { 0, "printer-more-info", IPP_TAG_URI, IPP_TAG_PRINTER }, | |
142 | { 0, "printer-op-policy", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
143 | { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB }, | |
144 | { 0, "printer-state", IPP_TAG_ENUM, IPP_TAG_PRINTER }, | |
145 | { 0, "printer-state-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
146 | { 1, "printer-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
147 | { 0, "printer-type", IPP_TAG_ENUM, IPP_TAG_PRINTER }, | |
148 | { 0, "printer-uri", IPP_TAG_URI, IPP_TAG_OPERATION }, | |
149 | { 1, "printer-uri-supported", IPP_TAG_URI, IPP_TAG_PRINTER }, | |
150 | { 0, "queued-job-count", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
151 | { 0, "raw", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION }, | |
152 | { 1, "requested-attributes", IPP_TAG_NAME, IPP_TAG_OPERATION }, | |
153 | { 1, "requesting-user-name-allowed", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
154 | { 1, "requesting-user-name-denied", IPP_TAG_NAME, IPP_TAG_PRINTER }, | |
155 | { 0, "resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB }, | |
156 | { 0, "resolution-default", IPP_TAG_RESOLUTION, IPP_TAG_PRINTER }, | |
157 | { 0, "saturation", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
158 | { 0, "saturation-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
159 | { 0, "scaling", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
160 | { 0, "scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER }, | |
161 | { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB }, | |
162 | { 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER }, | |
163 | { 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB }, | |
164 | { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }, | |
165 | { 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB }, | |
166 | { 0, "y-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB } | |
167 | }; | |
168 | ||
169 | ||
170 | /* | |
171 | * Local functions... | |
172 | */ | |
173 | ||
174 | static int compare_ipp_options(_ipp_option_t *a, _ipp_option_t *b); | |
175 | ||
176 | ||
177 | /* | |
178 | * 'cupsEncodeOptions()' - Encode printer options into IPP attributes. | |
179 | * | |
180 | * This function adds operation, job, and then subscription attributes, | |
181 | * in that order. Use the cupsEncodeOptions2() function to add attributes | |
182 | * for a single group. | |
183 | */ | |
184 | ||
185 | void | |
186 | cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */ | |
187 | int num_options, /* I - Number of options */ | |
188 | cups_option_t *options) /* I - Options */ | |
189 | { | |
190 | DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)\n", ipp, num_options, options)); | |
191 | ||
192 | /* | |
193 | * Add the options in the proper groups & order... | |
194 | */ | |
195 | ||
196 | cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_OPERATION); | |
197 | cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_JOB); | |
198 | cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_SUBSCRIPTION); | |
199 | } | |
200 | ||
201 | ||
202 | /* | |
203 | * 'cupsEncodeOptions2()' - Encode printer options into IPP attributes for a group. | |
204 | * | |
205 | * This function only adds attributes for a single group. Call this | |
206 | * function multiple times for each group, or use cupsEncodeOptions() | |
207 | * to add the standard groups. | |
208 | * | |
209 | * @since CUPS 1.2/Mac OS X 10.5@ | |
210 | */ | |
211 | ||
212 | void | |
213 | cupsEncodeOptions2( | |
214 | ipp_t *ipp, /* I - Request to add to */ | |
215 | int num_options, /* I - Number of options */ | |
216 | cups_option_t *options, /* I - Options */ | |
217 | ipp_tag_t group_tag) /* I - Group to encode */ | |
218 | { | |
219 | int i, j; /* Looping vars */ | |
220 | int count; /* Number of values */ | |
221 | char *s, /* Pointer into option value */ | |
222 | *val, /* Pointer to option value */ | |
223 | *copy, /* Copy of option value */ | |
224 | *sep, /* Option separator */ | |
225 | quote; /* Quote character */ | |
226 | ipp_attribute_t *attr; /* IPP attribute */ | |
227 | ipp_tag_t value_tag; /* IPP value tag */ | |
228 | cups_option_t *option; /* Current option */ | |
229 | ipp_t *collection; /* Collection value */ | |
230 | int num_cols; /* Number of collection values */ | |
231 | cups_option_t *cols; /* Collection values */ | |
232 | ||
233 | ||
234 | DEBUG_printf(("cupsEncodeOptions2(ipp=%p, num_options=%d, options=%p, " | |
235 | "group_tag=%x)\n", ipp, num_options, options, group_tag)); | |
236 | ||
237 | /* | |
238 | * Range check input... | |
239 | */ | |
240 | ||
241 | if (!ipp || num_options < 1 || !options) | |
242 | return; | |
243 | ||
244 | /* | |
245 | * Do special handling for the document-format/raw options... | |
246 | */ | |
247 | ||
248 | if (group_tag == IPP_TAG_OPERATION) | |
249 | { | |
250 | /* | |
251 | * Handle the document format stuff first... | |
252 | */ | |
253 | ||
254 | if ((val = (char *)cupsGetOption("document-format", num_options, options)) != NULL) | |
255 | ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", | |
256 | NULL, val); | |
257 | else if (cupsGetOption("raw", num_options, options)) | |
258 | ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", | |
259 | NULL, "application/vnd.cups-raw"); | |
260 | else | |
261 | ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", | |
262 | NULL, "application/octet-stream"); | |
263 | } | |
264 | ||
265 | /* | |
266 | * Then loop through the options... | |
267 | */ | |
268 | ||
269 | for (i = num_options, option = options; i > 0; i --, option ++) | |
270 | { | |
271 | _ipp_option_t *match; /* Matching attribute */ | |
272 | ||
273 | ||
274 | /* | |
275 | * Skip document format options that are handled above... | |
276 | */ | |
277 | ||
278 | if (!strcasecmp(option->name, "raw") || | |
279 | !strcasecmp(option->name, "document-format") || | |
280 | !option->name[0]) | |
281 | continue; | |
282 | ||
283 | /* | |
284 | * Figure out the proper value and group tags for this option... | |
285 | */ | |
286 | ||
287 | if ((match = _ippFindOption(option->name)) != NULL) | |
288 | { | |
289 | if (match->group_tag != group_tag) | |
290 | continue; | |
291 | ||
292 | value_tag = match->value_tag; | |
293 | } | |
294 | else | |
295 | { | |
296 | int namelen; /* Length of name */ | |
297 | ||
298 | ||
299 | namelen = (int)strlen(option->name); | |
300 | ||
301 | if (namelen < 9 || strcmp(option->name + namelen - 8, "-default")) | |
302 | { | |
303 | if (group_tag != IPP_TAG_JOB) | |
304 | continue; | |
305 | } | |
306 | else if (group_tag != IPP_TAG_PRINTER) | |
307 | continue; | |
308 | ||
309 | if (!strcasecmp(option->value, "true") || | |
310 | !strcasecmp(option->value, "false")) | |
311 | value_tag = IPP_TAG_BOOLEAN; | |
312 | else | |
313 | value_tag = IPP_TAG_NAME; | |
314 | } | |
315 | ||
316 | /* | |
317 | * Count the number of values... | |
318 | */ | |
319 | ||
320 | if (match && match->multivalue) | |
321 | { | |
322 | for (count = 1, sep = option->value, quote = 0; *sep; sep ++) | |
323 | { | |
324 | if (*sep == quote) | |
325 | quote = 0; | |
326 | else if (!quote && (*sep == '\'' || *sep == '\"')) | |
327 | { | |
328 | /* | |
329 | * Skip quoted option value... | |
330 | */ | |
331 | ||
332 | quote = *sep++; | |
333 | } | |
334 | else if (*sep == ',' && !quote) | |
335 | count ++; | |
336 | else if (*sep == '\\' && sep[1]) | |
337 | sep ++; | |
338 | } | |
339 | } | |
340 | else | |
341 | count = 1; | |
342 | ||
343 | DEBUG_printf(("cupsEncodeOptions2: option = \'%s\', count = %d\n", | |
344 | option->name, count)); | |
345 | ||
346 | /* | |
347 | * Allocate memory for the attribute values... | |
348 | */ | |
349 | ||
350 | if ((attr = _ippAddAttr(ipp, count)) == NULL) | |
351 | { | |
352 | /* | |
353 | * Ran out of memory! | |
354 | */ | |
355 | ||
356 | DEBUG_puts("cupsEncodeOptions2: Ran out of memory for attributes!"); | |
357 | return; | |
358 | } | |
359 | ||
360 | /* | |
361 | * Now figure out what type of value we have... | |
362 | */ | |
363 | ||
364 | attr->group_tag = group_tag; | |
365 | attr->value_tag = value_tag; | |
366 | ||
367 | /* | |
368 | * Copy the name over... | |
369 | */ | |
370 | ||
371 | attr->name = _cupsStrAlloc(option->name); | |
372 | ||
373 | if (count > 1) | |
374 | { | |
375 | /* | |
376 | * Make a copy of the value we can fiddle with... | |
377 | */ | |
378 | ||
379 | if ((copy = strdup(option->value)) == NULL) | |
380 | { | |
381 | /* | |
382 | * Ran out of memory! | |
383 | */ | |
384 | ||
385 | DEBUG_puts("cupsEncodeOptions2: Ran out of memory for value copy!"); | |
386 | ippDeleteAttribute(ipp, attr); | |
387 | return; | |
388 | } | |
389 | ||
390 | val = copy; | |
391 | } | |
392 | else | |
393 | { | |
394 | /* | |
395 | * Since we have a single value, use the value directly... | |
396 | */ | |
397 | ||
398 | val = option->value; | |
399 | copy = NULL; | |
400 | } | |
401 | ||
402 | /* | |
403 | * Scan the value string for values... | |
404 | */ | |
405 | ||
406 | for (j = 0, sep = val; j < count; val = sep, j ++) | |
407 | { | |
408 | /* | |
409 | * Find the end of this value and mark it if needed... | |
410 | */ | |
411 | ||
412 | if (count > 1) | |
413 | { | |
414 | for (quote = 0; *sep; sep ++) | |
415 | { | |
416 | if (*sep == quote) | |
417 | { | |
418 | /* | |
419 | * Finish quoted value... | |
420 | */ | |
421 | ||
422 | quote = 0; | |
423 | } | |
424 | else if (!quote && (*sep == '\'' || *sep == '\"')) | |
425 | { | |
426 | /* | |
427 | * Handle quoted option value... | |
428 | */ | |
429 | ||
430 | quote = *sep; | |
431 | } | |
432 | else if (*sep == ',' && count > 1) | |
433 | break; | |
434 | else if (*sep == '\\' && sep[1]) | |
435 | { | |
436 | /* | |
437 | * Skip quoted character... | |
438 | */ | |
439 | ||
440 | sep ++; | |
441 | } | |
442 | } | |
443 | ||
444 | if (*sep == ',') | |
445 | *sep++ = '\0'; | |
446 | } | |
447 | ||
448 | /* | |
449 | * Copy the option value(s) over as needed by the type... | |
450 | */ | |
451 | ||
452 | switch (attr->value_tag) | |
453 | { | |
454 | case IPP_TAG_INTEGER : | |
455 | case IPP_TAG_ENUM : | |
456 | /* | |
457 | * Integer/enumeration value... | |
458 | */ | |
459 | ||
460 | attr->values[j].integer = strtol(val, &s, 10); | |
461 | ||
462 | DEBUG_printf(("cupsEncodeOptions2: Added integer option value %d...\n", | |
463 | attr->values[j].integer)); | |
464 | break; | |
465 | ||
466 | case IPP_TAG_BOOLEAN : | |
467 | if (!strcasecmp(val, "true") || | |
468 | !strcasecmp(val, "on") || | |
469 | !strcasecmp(val, "yes")) | |
470 | { | |
471 | /* | |
472 | * Boolean value - true... | |
473 | */ | |
474 | ||
475 | attr->values[j].boolean = 1; | |
476 | ||
477 | DEBUG_puts("cupsEncodeOptions2: Added boolean true value..."); | |
478 | } | |
479 | else | |
480 | { | |
481 | /* | |
482 | * Boolean value - false... | |
483 | */ | |
484 | ||
485 | attr->values[j].boolean = 0; | |
486 | ||
487 | DEBUG_puts("cupsEncodeOptions2: Added boolean false value..."); | |
488 | } | |
489 | break; | |
490 | ||
491 | case IPP_TAG_RANGE : | |
492 | /* | |
493 | * Range... | |
494 | */ | |
495 | ||
496 | if (*val == '-') | |
497 | { | |
498 | attr->values[j].range.lower = 1; | |
499 | s = val; | |
500 | } | |
501 | else | |
502 | attr->values[j].range.lower = strtol(val, &s, 10); | |
503 | ||
504 | if (*s == '-') | |
505 | { | |
506 | if (s[1]) | |
507 | attr->values[j].range.upper = strtol(s + 1, NULL, 10); | |
508 | else | |
509 | attr->values[j].range.upper = 2147483647; | |
510 | } | |
511 | else | |
512 | attr->values[j].range.upper = attr->values[j].range.lower; | |
513 | ||
514 | DEBUG_printf(("cupsEncodeOptions2: Added range option value %d-%d...\n", | |
515 | attr->values[j].range.lower, | |
516 | attr->values[j].range.upper)); | |
517 | break; | |
518 | ||
519 | case IPP_TAG_RESOLUTION : | |
520 | /* | |
521 | * Resolution... | |
522 | */ | |
523 | ||
524 | attr->values[j].resolution.xres = strtol(val, &s, 10); | |
525 | ||
526 | if (*s == 'x') | |
527 | attr->values[j].resolution.yres = strtol(s + 1, &s, 10); | |
528 | else | |
529 | attr->values[j].resolution.yres = attr->values[j].resolution.xres; | |
530 | ||
531 | if (!strcasecmp(s, "dpc")) | |
532 | attr->values[j].resolution.units = IPP_RES_PER_CM; | |
533 | else | |
534 | attr->values[j].resolution.units = IPP_RES_PER_INCH; | |
535 | ||
536 | DEBUG_printf(("cupsEncodeOptions2: Added resolution option value %s...\n", | |
537 | val)); | |
538 | break; | |
539 | ||
540 | case IPP_TAG_STRING : | |
541 | /* | |
542 | * octet-string | |
543 | */ | |
544 | ||
545 | attr->values[j].unknown.length = (int)strlen(val); | |
546 | attr->values[j].unknown.data = strdup(val); | |
547 | ||
548 | DEBUG_printf(("cupsEncodeOptions2: Added octet-string value " | |
549 | "\"%s\"...\n", (char *)attr->values[j].unknown.data)); | |
550 | break; | |
551 | ||
552 | case IPP_TAG_BEGIN_COLLECTION : | |
553 | /* | |
554 | * Collection value | |
555 | */ | |
556 | ||
557 | num_cols = cupsParseOptions(val, 0, &cols); | |
558 | if ((collection = ippNew()) == NULL) | |
559 | { | |
560 | cupsFreeOptions(num_cols, cols); | |
561 | ||
562 | if (copy) | |
563 | free(copy); | |
564 | ||
565 | ippDeleteAttribute(ipp, attr); | |
566 | return; | |
567 | } | |
568 | ||
569 | attr->values[j].collection = collection; | |
570 | cupsEncodeOptions2(collection, num_cols, cols, IPP_TAG_JOB); | |
571 | cupsFreeOptions(num_cols, cols); | |
572 | break; | |
573 | ||
574 | default : | |
575 | if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL) | |
576 | { | |
577 | /* | |
578 | * Ran out of memory! | |
579 | */ | |
580 | ||
581 | DEBUG_puts("cupsEncodeOptions2: Ran out of memory for string!"); | |
582 | ||
583 | if (copy) | |
584 | free(copy); | |
585 | ||
586 | ippDeleteAttribute(ipp, attr); | |
587 | return; | |
588 | } | |
589 | ||
590 | DEBUG_printf(("cupsEncodeOptions2: Added string value \"%s\"...\n", | |
591 | val)); | |
592 | break; | |
593 | } | |
594 | } | |
595 | ||
596 | if (copy) | |
597 | free(copy); | |
598 | } | |
599 | } | |
600 | ||
601 | ||
602 | /* | |
603 | * '_ippFindOption()' - Find the attribute information for an option. | |
604 | */ | |
605 | ||
606 | _ipp_option_t * /* O - Attribute information */ | |
607 | _ippFindOption(const char *name) /* I - Option/attribute name */ | |
608 | { | |
609 | _ipp_option_t key; /* Search key */ | |
610 | ||
611 | ||
612 | /* | |
613 | * Lookup the proper value and group tags for this option... | |
614 | */ | |
615 | ||
616 | key.name = name; | |
617 | ||
618 | return ((_ipp_option_t *)bsearch(&key, ipp_options, | |
619 | sizeof(ipp_options) / sizeof(ipp_options[0]), | |
620 | sizeof(ipp_options[0]), | |
621 | (int (*)(const void *, const void *)) | |
622 | compare_ipp_options)); | |
623 | } | |
624 | ||
625 | ||
626 | /* | |
627 | * 'compare_ipp_options()' - Compare two IPP options. | |
628 | */ | |
629 | ||
630 | static int /* O - Result of comparison */ | |
631 | compare_ipp_options(_ipp_option_t *a, /* I - First option */ | |
632 | _ipp_option_t *b) /* I - Second option */ | |
633 | { | |
634 | return (strcmp(a->name, b->name)); | |
635 | } | |
636 | ||
637 | ||
638 | /* | |
639 | * End of "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $". | |
640 | */ |