1 /*
2 * "$Id: encode.c 9258 2010-08-13 01:34:04Z 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_PRINTER },
74 { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
75 { 0, "job-priority", IPP_TAG_INTEGER, IPP_TAG_JOB },
76 { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
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, "ppd-name", IPP_TAG_NAME, IPP_TAG_PRINTER },
129 { 0, "ppi", IPP_TAG_INTEGER, IPP_TAG_JOB },
130 { 0, "ppi-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
131 { 0, "prettyprint", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
132 { 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
133 { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB },
134 { 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
135 { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
136 { 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
137 { 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER },
138 { 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
139 { 0, "printer-is-shared", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
140 { 0, "printer-location", IPP_TAG_TEXT, IPP_TAG_PRINTER },
141 { 0, "printer-make-and-model", IPP_TAG_TEXT, IPP_TAG_PRINTER },
142 { 0, "printer-more-info", IPP_TAG_URI, IPP_TAG_PRINTER },
143 { 0, "printer-op-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
144 { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
145 { 0, "printer-state", IPP_TAG_ENUM, IPP_TAG_PRINTER },
146 { 0, "printer-state-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
147 { 1, "printer-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
148 { 0, "printer-type", IPP_TAG_ENUM, IPP_TAG_PRINTER },
149 { 0, "printer-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
150 { 1, "printer-uri-supported", IPP_TAG_URI, IPP_TAG_PRINTER },
151 { 0, "queued-job-count", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
152 { 0, "raw", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION },
153 { 1, "requested-attributes", IPP_TAG_NAME, IPP_TAG_OPERATION },
154 { 1, "requesting-user-name-allowed", IPP_TAG_NAME, IPP_TAG_PRINTER },
155 { 1, "requesting-user-name-denied", IPP_TAG_NAME, IPP_TAG_PRINTER },
156 { 0, "resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
157 { 0, "resolution-default", IPP_TAG_RESOLUTION, IPP_TAG_PRINTER },
158 { 0, "saturation", IPP_TAG_INTEGER, IPP_TAG_JOB },
159 { 0, "saturation-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
160 { 0, "scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
161 { 0, "scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
162 { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB },
163 { 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
164 { 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
165 { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
166 { 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB },
167 { 0, "y-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB }
168 };
169
170
171 /*
172 * Local functions...
173 */
174
175 static int compare_ipp_options(_ipp_option_t *a, _ipp_option_t *b);
176
177
178 /*
179 * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
180 *
181 * This function adds operation, job, and then subscription attributes,
182 * in that order. Use the cupsEncodeOptions2() function to add attributes
183 * for a single group.
184 */
185
186 void
cupsEncodeOptions(ipp_t * ipp,int num_options,cups_option_t * options)187 cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */
188 int num_options, /* I - Number of options */
189 cups_option_t *options) /* I - Options */
190 {
191 DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)", ipp, num_options, options));
192
193 /*
194 * Add the options in the proper groups & order...
195 */
196
197 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_OPERATION);
198 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_JOB);
199 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_SUBSCRIPTION);
200 }
201
202
203 /*
204 * 'cupsEncodeOptions2()' - Encode printer options into IPP attributes for a group.
205 *
206 * This function only adds attributes for a single group. Call this
207 * function multiple times for each group, or use cupsEncodeOptions()
208 * to add the standard groups.
209 *
210 * @since CUPS 1.2/Mac OS X 10.5@
211 */
212
213 void
cupsEncodeOptions2(ipp_t * ipp,int num_options,cups_option_t * options,ipp_tag_t group_tag)214 cupsEncodeOptions2(
215 ipp_t *ipp, /* I - Request to add to */
216 int num_options, /* I - Number of options */
217 cups_option_t *options, /* I - Options */
218 ipp_tag_t group_tag) /* I - Group to encode */
219 {
220 int i, j; /* Looping vars */
221 int count; /* Number of values */
222 char *s, /* Pointer into option value */
223 *val, /* Pointer to option value */
224 *copy, /* Copy of option value */
225 *sep, /* Option separator */
226 quote; /* Quote character */
227 ipp_attribute_t *attr; /* IPP attribute */
228 ipp_tag_t value_tag; /* IPP value tag */
229 cups_option_t *option; /* Current option */
230 ipp_t *collection; /* Collection value */
231 int num_cols; /* Number of collection values */
232 cups_option_t *cols; /* Collection values */
233
234
235 DEBUG_printf(("cupsEncodeOptions2(ipp=%p, num_options=%d, options=%p, "
236 "group_tag=%x)", ipp, num_options, options, group_tag));
237
238 /*
239 * Range check input...
240 */
241
242 if (!ipp || num_options < 1 || !options)
243 return;
244
245 /*
246 * Do special handling for the document-format/raw options...
247 */
248
249 if (group_tag == IPP_TAG_OPERATION)
250 {
251 /*
252 * Handle the document format stuff first...
253 */
254
255 if ((val = (char *)cupsGetOption("document-format", num_options, options)) != NULL)
256 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
257 NULL, val);
258 else if (cupsGetOption("raw", num_options, options))
259 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
260 NULL, "application/vnd.cups-raw");
261 else
262 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
263 NULL, "application/octet-stream");
264 }
265
266 /*
267 * Then loop through the options...
268 */
269
270 for (i = num_options, option = options; i > 0; i --, option ++)
271 {
272 _ipp_option_t *match; /* Matching attribute */
273
274
275 /*
276 * Skip document format options that are handled above...
277 */
278
279 if (!strcasecmp(option->name, "raw") ||
280 !strcasecmp(option->name, "document-format") ||
281 !option->name[0])
282 continue;
283
284 /*
285 * Figure out the proper value and group tags for this option...
286 */
287
288 if ((match = _ippFindOption(option->name)) != NULL)
289 {
290 if (match->group_tag != group_tag)
291 continue;
292
293 value_tag = match->value_tag;
294 }
295 else
296 {
297 int namelen; /* Length of name */
298
299
300 namelen = (int)strlen(option->name);
301
302 if (namelen < 9 || strcmp(option->name + namelen - 8, "-default"))
303 {
304 if (group_tag != IPP_TAG_JOB)
305 continue;
306 }
307 else if (group_tag != IPP_TAG_PRINTER)
308 continue;
309
310 if (!strcasecmp(option->value, "true") ||
311 !strcasecmp(option->value, "false"))
312 value_tag = IPP_TAG_BOOLEAN;
313 else
314 value_tag = IPP_TAG_NAME;
315 }
316
317 /*
318 * Count the number of values...
319 */
320
321 if (match && match->multivalue)
322 {
323 for (count = 1, sep = option->value, quote = 0; *sep; sep ++)
324 {
325 if (*sep == quote)
326 quote = 0;
327 else if (!quote && (*sep == '\'' || *sep == '\"'))
328 {
329 /*
330 * Skip quoted option value...
331 */
332
333 quote = *sep++;
334 }
335 else if (*sep == ',' && !quote)
336 count ++;
337 else if (*sep == '\\' && sep[1])
338 sep ++;
339 }
340 }
341 else
342 count = 1;
343
344 DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", count=%d",
345 option->name, count));
346
347 /*
348 * Allocate memory for the attribute values...
349 */
350
351 if ((attr = _ippAddAttr(ipp, count)) == NULL)
352 {
353 /*
354 * Ran out of memory!
355 */
356
357 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for attributes!");
358 return;
359 }
360
361 /*
362 * Now figure out what type of value we have...
363 */
364
365 attr->group_tag = group_tag;
366 attr->value_tag = value_tag;
367
368 /*
369 * Copy the name over...
370 */
371
372 attr->name = _cupsStrAlloc(option->name);
373
374 if (count > 1)
375 {
376 /*
377 * Make a copy of the value we can fiddle with...
378 */
379
380 if ((copy = strdup(option->value)) == NULL)
381 {
382 /*
383 * Ran out of memory!
384 */
385
386 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for value copy!");
387 ippDeleteAttribute(ipp, attr);
388 return;
389 }
390
391 val = copy;
392 }
393 else
394 {
395 /*
396 * Since we have a single value, use the value directly...
397 */
398
399 val = option->value;
400 copy = NULL;
401 }
402
403 /*
404 * Scan the value string for values...
405 */
406
407 for (j = 0, sep = val; j < count; val = sep, j ++)
408 {
409 /*
410 * Find the end of this value and mark it if needed...
411 */
412
413 if (count > 1)
414 {
415 for (quote = 0; *sep; sep ++)
416 {
417 if (*sep == quote)
418 {
419 /*
420 * Finish quoted value...
421 */
422
423 quote = 0;
424 }
425 else if (!quote && (*sep == '\'' || *sep == '\"'))
426 {
427 /*
428 * Handle quoted option value...
429 */
430
431 quote = *sep;
432 }
433 else if (*sep == ',' && count > 1)
434 break;
435 else if (*sep == '\\' && sep[1])
436 {
437 /*
438 * Skip quoted character...
439 */
440
441 sep ++;
442 }
443 }
444
445 if (*sep == ',')
446 *sep++ = '\0';
447 }
448
449 /*
450 * Copy the option value(s) over as needed by the type...
451 */
452
453 switch (attr->value_tag)
454 {
455 case IPP_TAG_INTEGER :
456 case IPP_TAG_ENUM :
457 /*
458 * Integer/enumeration value...
459 */
460
461 attr->values[j].integer = strtol(val, &s, 10);
462
463 DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
464 "%d...", attr->values[j].integer));
465 break;
466
467 case IPP_TAG_BOOLEAN :
468 if (!strcasecmp(val, "true") ||
469 !strcasecmp(val, "on") ||
470 !strcasecmp(val, "yes"))
471 {
472 /*
473 * Boolean value - true...
474 */
475
476 attr->values[j].boolean = 1;
477
478 DEBUG_puts("2cupsEncodeOptions2: Added boolean true value...");
479 }
480 else
481 {
482 /*
483 * Boolean value - false...
484 */
485
486 attr->values[j].boolean = 0;
487
488 DEBUG_puts("2cupsEncodeOptions2: Added boolean false value...");
489 }
490 break;
491
492 case IPP_TAG_RANGE :
493 /*
494 * Range...
495 */
496
497 if (*val == '-')
498 {
499 attr->values[j].range.lower = 1;
500 s = val;
501 }
502 else
503 attr->values[j].range.lower = strtol(val, &s, 10);
504
505 if (*s == '-')
506 {
507 if (s[1])
508 attr->values[j].range.upper = strtol(s + 1, NULL, 10);
509 else
510 attr->values[j].range.upper = 2147483647;
511 }
512 else
513 attr->values[j].range.upper = attr->values[j].range.lower;
514
515 DEBUG_printf(("2cupsEncodeOptions2: Added range option value "
516 "%d-%d...", attr->values[j].range.lower,
517 attr->values[j].range.upper));
518 break;
519
520 case IPP_TAG_RESOLUTION :
521 /*
522 * Resolution...
523 */
524
525 attr->values[j].resolution.xres = strtol(val, &s, 10);
526
527 if (*s == 'x')
528 attr->values[j].resolution.yres = strtol(s + 1, &s, 10);
529 else
530 attr->values[j].resolution.yres = attr->values[j].resolution.xres;
531
532 if (!strcasecmp(s, "dpc"))
533 attr->values[j].resolution.units = IPP_RES_PER_CM;
534 else
535 attr->values[j].resolution.units = IPP_RES_PER_INCH;
536
537 DEBUG_printf(("2cupsEncodeOptions2: Added resolution option value "
538 "%s...", val));
539 break;
540
541 case IPP_TAG_STRING :
542 /*
543 * octet-string
544 */
545
546 attr->values[j].unknown.length = (int)strlen(val);
547 attr->values[j].unknown.data = strdup(val);
548
549 DEBUG_printf(("2cupsEncodeOptions2: Added octet-string value "
550 "\"%s\"...", (char *)attr->values[j].unknown.data));
551 break;
552
553 case IPP_TAG_BEGIN_COLLECTION :
554 /*
555 * Collection value
556 */
557
558 num_cols = cupsParseOptions(val, 0, &cols);
559 if ((collection = ippNew()) == NULL)
560 {
561 cupsFreeOptions(num_cols, cols);
562
563 if (copy)
564 free(copy);
565
566 ippDeleteAttribute(ipp, attr);
567 return;
568 }
569
570 attr->values[j].collection = collection;
571 cupsEncodeOptions2(collection, num_cols, cols, IPP_TAG_JOB);
572 cupsFreeOptions(num_cols, cols);
573 break;
574
575 default :
576 if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
577 {
578 /*
579 * Ran out of memory!
580 */
581
582 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for string!");
583
584 if (copy)
585 free(copy);
586
587 ippDeleteAttribute(ipp, attr);
588 return;
589 }
590
591 DEBUG_printf(("2cupsEncodeOptions2: Added string value \"%s\"...",
592 val));
593 break;
594 }
595 }
596
597 if (copy)
598 free(copy);
599 }
600 }
601
602
603 /*
604 * '_ippFindOption()' - Find the attribute information for an option.
605 */
606
607 _ipp_option_t * /* O - Attribute information */
_ippFindOption(const char * name)608 _ippFindOption(const char *name) /* I - Option/attribute name */
609 {
610 _ipp_option_t key; /* Search key */
611
612
613 /*
614 * Lookup the proper value and group tags for this option...
615 */
616
617 key.name = name;
618
619 return ((_ipp_option_t *)bsearch(&key, ipp_options,
620 sizeof(ipp_options) / sizeof(ipp_options[0]),
621 sizeof(ipp_options[0]),
622 (int (*)(const void *, const void *))
623 compare_ipp_options));
624 }
625
626
627 /*
628 * 'compare_ipp_options()' - Compare two IPP options.
629 */
630
631 static int /* O - Result of comparison */
compare_ipp_options(_ipp_option_t * a,_ipp_option_t * b)632 compare_ipp_options(_ipp_option_t *a, /* I - First option */
633 _ipp_option_t *b) /* I - Second option */
634 {
635 return (strcmp(a->name, b->name));
636 }
637
638
639 /*
640 * End of "$Id: encode.c 9258 2010-08-13 01:34:04Z mike $".
641 */
642