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