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