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