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