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