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