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