]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/encode.c
Move CUPS->IPP mapping code to libcups.
[thirdparty/cups.git] / cups / encode.c
1 /*
2 * "$Id$"
3 *
4 * Option encoding routines for CUPS.
5 *
6 * Copyright 2007-2015 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
18 /*
19 * Include necessary headers...
20 */
21
22 #include "cups-private.h"
23
24
25 /*
26 * Local list of option names, the value tags they should use, and the list of
27 * supported operations...
28 *
29 * **** THIS LIST MUST BE SORTED BY ATTRIBUTE NAME ****
30 */
31
32 static const ipp_op_t ipp_job_creation[] =
33 {
34 IPP_OP_PRINT_JOB,
35 IPP_OP_PRINT_URI,
36 IPP_OP_VALIDATE_JOB,
37 IPP_OP_CREATE_JOB,
38 IPP_OP_HOLD_JOB,
39 IPP_OP_SET_JOB_ATTRIBUTES,
40 IPP_OP_CUPS_NONE
41 };
42
43 static const ipp_op_t ipp_doc_creation[] =
44 {
45 IPP_OP_PRINT_JOB,
46 IPP_OP_PRINT_URI,
47 IPP_OP_SEND_DOCUMENT,
48 IPP_OP_SEND_URI,
49 IPP_OP_SET_JOB_ATTRIBUTES,
50 IPP_OP_SET_DOCUMENT_ATTRIBUTES,
51 IPP_OP_CUPS_NONE
52 };
53
54 static const ipp_op_t ipp_sub_creation[] =
55 {
56 IPP_OP_PRINT_JOB,
57 IPP_OP_PRINT_URI,
58 IPP_OP_CREATE_JOB,
59 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS,
60 IPP_OP_CREATE_JOB_SUBSCRIPTIONS,
61 IPP_OP_CUPS_NONE
62 };
63
64 static const ipp_op_t ipp_all_print[] =
65 {
66 IPP_OP_PRINT_JOB,
67 IPP_OP_PRINT_URI,
68 IPP_OP_VALIDATE_JOB,
69 IPP_OP_CREATE_JOB,
70 IPP_OP_SEND_DOCUMENT,
71 IPP_OP_SEND_URI,
72 IPP_OP_CUPS_NONE
73 };
74
75 static const ipp_op_t ipp_set_printer[] =
76 {
77 IPP_OP_SET_PRINTER_ATTRIBUTES,
78 IPP_OP_CUPS_ADD_MODIFY_PRINTER,
79 IPP_OP_CUPS_ADD_MODIFY_CLASS,
80 IPP_OP_CUPS_NONE
81 };
82
83 static const ipp_op_t cups_schemes[] =
84 {
85 IPP_OP_CUPS_GET_DEVICES,
86 IPP_OP_CUPS_GET_PPDS,
87 IPP_OP_CUPS_NONE
88 };
89
90 static const ipp_op_t cups_get_ppds[] =
91 {
92 IPP_OP_CUPS_GET_PPDS,
93 IPP_OP_CUPS_NONE
94 };
95
96 static const ipp_op_t cups_ppd_name[] =
97 {
98 IPP_OP_CUPS_ADD_MODIFY_PRINTER,
99 IPP_OP_CUPS_GET_PPD,
100 IPP_OP_CUPS_NONE
101 };
102
103 static const _ipp_option_t ipp_options[] =
104 {
105 { 1, "auth-info", IPP_TAG_TEXT, IPP_TAG_JOB },
106 { 1, "auth-info-default", IPP_TAG_TEXT, IPP_TAG_PRINTER },
107 { 1, "auth-info-required", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
108 { 0, "blackplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
109 { 0, "blackplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
110 { 0, "brightness", IPP_TAG_INTEGER, IPP_TAG_JOB },
111 { 0, "brightness-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
112 { 0, "columns", IPP_TAG_INTEGER, IPP_TAG_JOB },
113 { 0, "columns-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
114 { 0, "compression", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
115 IPP_TAG_ZERO,
116 ipp_doc_creation },
117 { 0, "copies", IPP_TAG_INTEGER, IPP_TAG_JOB,
118 IPP_TAG_DOCUMENT },
119 { 0, "copies-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
120 { 0, "device-uri", IPP_TAG_URI, IPP_TAG_PRINTER },
121 { 1, "document-copies", IPP_TAG_RANGE, IPP_TAG_JOB,
122 IPP_TAG_DOCUMENT,
123 ipp_doc_creation },
124 { 0, "document-format", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION,
125 IPP_TAG_ZERO,
126 ipp_doc_creation },
127 { 0, "document-format-default", IPP_TAG_MIMETYPE, IPP_TAG_PRINTER },
128 { 1, "document-numbers", IPP_TAG_RANGE, IPP_TAG_JOB,
129 IPP_TAG_DOCUMENT,
130 ipp_all_print },
131 { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
132 IPP_TAG_ZERO,
133 cups_schemes },
134 { 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB,
135 IPP_TAG_DOCUMENT },
136 { 1, "finishings-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
137 { 0, "fit-to-page", IPP_TAG_BOOLEAN, IPP_TAG_JOB,
138 IPP_TAG_DOCUMENT },
139 { 0, "fit-to-page-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
140 { 0, "fitplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
141 { 0, "fitplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
142 { 0, "gamma", IPP_TAG_INTEGER, IPP_TAG_JOB },
143 { 0, "gamma-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
144 { 0, "hue", IPP_TAG_INTEGER, IPP_TAG_JOB },
145 { 0, "hue-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
146 { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
147 IPP_TAG_ZERO,
148 cups_schemes },
149 { 0, "job-account-id", IPP_TAG_NAME, IPP_TAG_JOB },
150 { 0, "job-account-id-default",IPP_TAG_NAME, IPP_TAG_PRINTER },
151 { 0, "job-accounting-user-id", IPP_TAG_NAME, IPP_TAG_JOB },
152 { 0, "job-accounting-user-id-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
153 { 0, "job-authorization-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
154 { 0, "job-cancel-after", IPP_TAG_INTEGER, IPP_TAG_JOB },
155 { 0, "job-cancel-after-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
156 { 0, "job-hold-until", IPP_TAG_KEYWORD, IPP_TAG_JOB },
157 { 0, "job-id", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
158 { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
159 { 0, "job-impressions-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
160 { 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
161 { 0, "job-k-octets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
162 { 0, "job-k-octets-completed",IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
163 { 0, "job-media-sheets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
164 { 0, "job-media-sheets-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
165 { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
166 { 0, "job-password", IPP_TAG_STRING, IPP_TAG_OPERATION,
167 IPP_TAG_ZERO,
168 ipp_job_creation },
169 { 0, "job-password-encryption", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
170 IPP_TAG_ZERO,
171 ipp_job_creation },
172 { 0, "job-priority", IPP_TAG_INTEGER, IPP_TAG_JOB },
173 { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
174 { 1, "job-sheets", IPP_TAG_NAME, IPP_TAG_JOB },
175 { 1, "job-sheets-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
176 { 0, "job-state", IPP_TAG_ENUM, IPP_TAG_ZERO }, /* never send as option */
177 { 0, "job-state-message", IPP_TAG_TEXT, IPP_TAG_ZERO }, /* never send as option */
178 { 0, "job-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_ZERO }, /* never send as option */
179 { 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB },
180 { 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
181 { 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
182 { 1, "marker-colors", IPP_TAG_NAME, IPP_TAG_PRINTER },
183 { 1, "marker-high-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
184 { 1, "marker-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
185 { 1, "marker-low-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
186 { 0, "marker-message", IPP_TAG_TEXT, IPP_TAG_PRINTER },
187 { 1, "marker-names", IPP_TAG_NAME, IPP_TAG_PRINTER },
188 { 1, "marker-types", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
189 { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB,
190 IPP_TAG_DOCUMENT },
191 { 0, "media-col", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
192 IPP_TAG_DOCUMENT },
193 { 0, "media-col-default", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_PRINTER },
194 { 0, "media-color", IPP_TAG_KEYWORD, IPP_TAG_JOB,
195 IPP_TAG_DOCUMENT },
196 { 1, "media-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
197 { 0, "media-key", IPP_TAG_KEYWORD, IPP_TAG_JOB,
198 IPP_TAG_DOCUMENT },
199 { 0, "media-size", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
200 IPP_TAG_DOCUMENT },
201 { 0, "media-type", IPP_TAG_KEYWORD, IPP_TAG_JOB,
202 IPP_TAG_DOCUMENT },
203 { 0, "mirror", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
204 { 0, "mirror-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
205 { 0, "natural-scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
206 { 0, "natural-scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
207 { 0, "notify-charset", IPP_TAG_CHARSET, IPP_TAG_SUBSCRIPTION },
208 { 1, "notify-events", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION },
209 { 1, "notify-events-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
210 { 0, "notify-lease-duration", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION },
211 { 0, "notify-lease-duration-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
212 { 0, "notify-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_SUBSCRIPTION },
213 { 0, "notify-pull-method", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION },
214 { 0, "notify-recipient-uri", IPP_TAG_URI, IPP_TAG_SUBSCRIPTION },
215 { 0, "notify-time-interval", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION },
216 { 0, "notify-user-data", IPP_TAG_STRING, IPP_TAG_SUBSCRIPTION },
217 { 0, "number-up", IPP_TAG_INTEGER, IPP_TAG_JOB,
218 IPP_TAG_DOCUMENT },
219 { 0, "number-up-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
220 { 0, "orientation-requested", IPP_TAG_ENUM, IPP_TAG_JOB,
221 IPP_TAG_DOCUMENT },
222 { 0, "orientation-requested-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
223 { 1, "overrides", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
224 IPP_TAG_DOCUMENT },
225 { 0, "page-bottom", IPP_TAG_INTEGER, IPP_TAG_JOB },
226 { 0, "page-bottom-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
227 { 0, "page-left", IPP_TAG_INTEGER, IPP_TAG_JOB },
228 { 0, "page-left-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
229 { 1, "page-ranges", IPP_TAG_RANGE, IPP_TAG_JOB,
230 IPP_TAG_DOCUMENT },
231 { 1, "page-ranges-default", IPP_TAG_RANGE, IPP_TAG_PRINTER },
232 { 0, "page-right", IPP_TAG_INTEGER, IPP_TAG_JOB },
233 { 0, "page-right-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
234 { 0, "page-top", IPP_TAG_INTEGER, IPP_TAG_JOB },
235 { 0, "page-top-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
236 { 1, "pages", IPP_TAG_RANGE, IPP_TAG_JOB,
237 IPP_TAG_DOCUMENT },
238 { 0, "penwidth", IPP_TAG_INTEGER, IPP_TAG_JOB },
239 { 0, "penwidth-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
240 { 0, "port-monitor", IPP_TAG_NAME, IPP_TAG_PRINTER },
241 { 0, "ppd-device-id", IPP_TAG_TEXT, IPP_TAG_OPERATION,
242 IPP_TAG_ZERO,
243 cups_get_ppds },
244 { 0, "ppd-make", IPP_TAG_TEXT, IPP_TAG_OPERATION,
245 IPP_TAG_ZERO,
246 cups_get_ppds },
247 { 0, "ppd-make-and-model", IPP_TAG_TEXT, IPP_TAG_OPERATION,
248 IPP_TAG_ZERO,
249 cups_get_ppds },
250 { 0, "ppd-model-number", IPP_TAG_INTEGER, IPP_TAG_OPERATION,
251 IPP_TAG_ZERO,
252 cups_get_ppds },
253 { 0, "ppd-name", IPP_TAG_NAME, IPP_TAG_OPERATION,
254 IPP_TAG_ZERO,
255 cups_ppd_name },
256 { 0, "ppd-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_OPERATION,
257 IPP_TAG_ZERO,
258 cups_get_ppds },
259 { 0, "ppd-product", IPP_TAG_TEXT, IPP_TAG_OPERATION,
260 IPP_TAG_ZERO,
261 cups_get_ppds },
262 { 0, "ppd-psversion", IPP_TAG_TEXT, IPP_TAG_OPERATION,
263 IPP_TAG_ZERO,
264 cups_get_ppds },
265 { 0, "ppd-type", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
266 IPP_TAG_ZERO,
267 cups_get_ppds },
268 { 0, "ppi", IPP_TAG_INTEGER, IPP_TAG_JOB },
269 { 0, "ppi-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
270 { 0, "prettyprint", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
271 { 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
272 { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB,
273 IPP_TAG_DOCUMENT },
274 { 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
275 { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
276 { 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
277 { 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER },
278 { 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
279 { 0, "printer-is-shared", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
280 { 0, "printer-location", IPP_TAG_TEXT, IPP_TAG_PRINTER },
281 { 0, "printer-make-and-model", IPP_TAG_TEXT, IPP_TAG_PRINTER },
282 { 0, "printer-more-info", IPP_TAG_URI, IPP_TAG_PRINTER },
283 { 0, "printer-op-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
284 { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB,
285 IPP_TAG_DOCUMENT },
286 { 0, "printer-state", IPP_TAG_ENUM, IPP_TAG_PRINTER },
287 { 0, "printer-state-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
288 { 1, "printer-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
289 { 0, "printer-type", IPP_TAG_ENUM, IPP_TAG_PRINTER },
290 { 0, "printer-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
291 { 1, "printer-uri-supported", IPP_TAG_URI, IPP_TAG_PRINTER },
292 { 0, "queued-job-count", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
293 { 0, "raw", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION },
294 { 1, "requested-attributes", IPP_TAG_NAME, IPP_TAG_OPERATION },
295 { 1, "requesting-user-name-allowed", IPP_TAG_NAME, IPP_TAG_PRINTER },
296 { 1, "requesting-user-name-denied", IPP_TAG_NAME, IPP_TAG_PRINTER },
297 { 0, "resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
298 { 0, "resolution-default", IPP_TAG_RESOLUTION, IPP_TAG_PRINTER },
299 { 0, "saturation", IPP_TAG_INTEGER, IPP_TAG_JOB },
300 { 0, "saturation-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
301 { 0, "scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
302 { 0, "scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
303 { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB,
304 IPP_TAG_DOCUMENT },
305 { 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
306 { 0, "time-at-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
307 { 0, "time-at-creation", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
308 { 0, "time-at-processing", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
309 { 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
310 { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
311 { 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
312 IPP_TAG_DOCUMENT },
313 { 0, "y-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
314 IPP_TAG_DOCUMENT }
315 };
316
317
318 /*
319 * Local functions...
320 */
321
322 static int compare_ipp_options(_ipp_option_t *a, _ipp_option_t *b);
323
324
325 /*
326 * '_cupsConvertOptions()' - Convert printer options to standard IPP attributes.
327 *
328 * This functions converts PPD and CUPS-specific options to their standard IPP
329 * attributes and values and adds them to the specified IPP request.
330 */
331
332 int /* O - New number of copies */
333 _cupsConvertOptions(ipp_t *request, /* I - IPP request */
334 ppd_file_t *ppd, /* I - PPD file */
335 _ppd_cache_t *pc, /* I - PPD cache info */
336 ipp_attribute_t *media_col_sup,
337 /* I - media-col-supported values */
338 ipp_attribute_t *doc_handling_sup,
339 /* I - multiple-document-handling-supported values */
340 ipp_attribute_t *print_color_mode_sup,
341 /* I - Printer supports print-color-mode */
342 const char *user, /* I - User info */
343 const char *format, /* I - document-format value */
344 int copies, /* I - Number of copies */
345 int num_options, /* I - Number of options */
346 cups_option_t *options) /* I - Options */
347 {
348 int i; /* Looping var */
349 const char *keyword; /* PWG keyword */
350 pwg_size_t *size; /* PWG media size */
351 ipp_t *media_col, /* media-col value */
352 *media_size; /* media-size value */
353 const char *media_source, /* media-source value */
354 *media_type, /* media-type value */
355 *collate_str, /* multiple-document-handling value */
356 *color_attr_name, /* Supported color attribute */
357 *mandatory; /* Mandatory attributes */
358 int num_finishings = 0, /* Number of finishing values */
359 finishings[10]; /* Finishing enum values */
360 ppd_choice_t *choice; /* Marked choice */
361
362
363 /*
364 * Send standard IPP attributes...
365 */
366
367 if (pc->password && (keyword = cupsGetOption("job-password", num_options, options)) != NULL)
368 {
369 ippAddOctetString(request, IPP_TAG_OPERATION, "job-password", keyword, (int)strlen(keyword));
370
371 if ((keyword = cupsGetOption("job-password-encryption", num_options, options)) == NULL)
372 keyword = "none";
373
374 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "job-password-encryption", NULL, keyword);
375 }
376
377 if (pc->account_id)
378 {
379 if ((keyword = cupsGetOption("job-account-id", num_options, options)) == NULL)
380 keyword = cupsGetOption("job-billing", num_options, options);
381
382 if (keyword)
383 ippAddString(request, IPP_TAG_JOB, IPP_TAG_NAME, "job-account-id", NULL, keyword);
384 }
385
386 if (pc->accounting_user_id)
387 {
388 if ((keyword = cupsGetOption("job-accounting-user-id", num_options, options)) == NULL)
389 keyword = user;
390
391 if (keyword)
392 ippAddString(request, IPP_TAG_JOB, IPP_TAG_NAME, "job-accounting-user-id", NULL, keyword);
393 }
394
395 for (mandatory = (const char *)cupsArrayFirst(pc->mandatory); mandatory; mandatory = (const char *)cupsArrayNext(pc->mandatory))
396 {
397 if (strcmp(mandatory, "copies") &&
398 strcmp(mandatory, "destination-uris") &&
399 strcmp(mandatory, "finishings") &&
400 strcmp(mandatory, "job-account-id") &&
401 strcmp(mandatory, "job-accounting-user-id") &&
402 strcmp(mandatory, "job-password") &&
403 strcmp(mandatory, "job-password-encryption") &&
404 strcmp(mandatory, "media") &&
405 strncmp(mandatory, "media-col", 9) &&
406 strcmp(mandatory, "multiple-document-handling") &&
407 strcmp(mandatory, "output-bin") &&
408 strcmp(mandatory, "print-color-mode") &&
409 strcmp(mandatory, "print-quality") &&
410 strcmp(mandatory, "sides") &&
411 (keyword = cupsGetOption(mandatory, num_options, options)) != NULL)
412 {
413 _ipp_option_t *opt = _ippFindOption(mandatory);
414 /* Option type */
415 ipp_tag_t value_tag = opt ? opt->value_tag : IPP_TAG_NAME;
416 /* Value type */
417
418 switch (value_tag)
419 {
420 case IPP_TAG_INTEGER :
421 case IPP_TAG_ENUM :
422 ippAddInteger(request, IPP_TAG_JOB, value_tag, mandatory, atoi(keyword));
423 break;
424 case IPP_TAG_BOOLEAN :
425 ippAddBoolean(request, IPP_TAG_JOB, mandatory, !_cups_strcasecmp(keyword, "true"));
426 break;
427 case IPP_TAG_RANGE :
428 {
429 int lower, upper; /* Range */
430
431 if (sscanf(keyword, "%d-%d", &lower, &upper) != 2)
432 lower = upper = atoi(keyword);
433
434 ippAddRange(request, IPP_TAG_JOB, mandatory, lower, upper);
435 }
436 break;
437 case IPP_TAG_STRING :
438 ippAddOctetString(request, IPP_TAG_JOB, mandatory, keyword, (int)strlen(keyword));
439 break;
440 default :
441 if (!strcmp(mandatory, "print-color-mode") && !strcmp(keyword, "monochrome"))
442 {
443 if (ippContainsString(print_color_mode_sup, "auto-monochrome"))
444 keyword = "auto-monochrome";
445 else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome"))
446 keyword = "process-monochrome";
447 }
448
449 ippAddString(request, IPP_TAG_JOB, value_tag, mandatory, NULL, keyword);
450 break;
451 }
452 }
453 }
454
455 if ((keyword = cupsGetOption("PageSize", num_options, options)) == NULL)
456 keyword = cupsGetOption("media", num_options, options);
457
458 if ((size = _ppdCacheGetSize(pc, keyword)) != NULL)
459 {
460 /*
461 * Add a media-col value...
462 */
463
464 media_size = ippNew();
465 ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER,
466 "x-dimension", size->width);
467 ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER,
468 "y-dimension", size->length);
469
470 media_col = ippNew();
471 ippAddCollection(media_col, IPP_TAG_ZERO, "media-size", media_size);
472
473 media_source = _ppdCacheGetSource(pc, cupsGetOption("InputSlot",
474 num_options,
475 options));
476 media_type = _ppdCacheGetType(pc, cupsGetOption("MediaType",
477 num_options,
478 options));
479
480 for (i = 0; i < media_col_sup->num_values; i ++)
481 {
482 if (!strcmp(media_col_sup->values[i].string.text, "media-left-margin"))
483 ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-left-margin", size->left);
484 else if (!strcmp(media_col_sup->values[i].string.text, "media-bottom-margin"))
485 ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-bottom-margin", size->bottom);
486 else if (!strcmp(media_col_sup->values[i].string.text, "media-right-margin"))
487 ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-right-margin", size->right);
488 else if (!strcmp(media_col_sup->values[i].string.text, "media-top-margin"))
489 ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER, "media-top-margin", size->top);
490 else if (!strcmp(media_col_sup->values[i].string.text, "media-source") && media_source)
491 ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD, "media-source", NULL, media_source);
492 else if (!strcmp(media_col_sup->values[i].string.text, "media-type") && media_type)
493 ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD, "media-type", NULL, media_type);
494 }
495
496 ippAddCollection(request, IPP_TAG_JOB, "media-col", media_col);
497 }
498
499 if ((keyword = cupsGetOption("output-bin", num_options, options)) == NULL)
500 {
501 if ((choice = ppdFindMarkedChoice(ppd, "OutputBin")) != NULL)
502 keyword = _ppdCacheGetBin(pc, choice->choice);
503 }
504
505 if (keyword)
506 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-bin", NULL, keyword);
507
508 color_attr_name = print_color_mode_sup ? "print-color-mode" : "output-mode";
509
510 if ((keyword = cupsGetOption("print-color-mode", num_options, options)) == NULL)
511 {
512 if ((choice = ppdFindMarkedChoice(ppd, "ColorModel")) != NULL)
513 {
514 if (!_cups_strcasecmp(choice->choice, "Gray"))
515 keyword = "monochrome";
516 else
517 keyword = "color";
518 }
519 }
520
521 if (keyword && !strcmp(keyword, "monochrome"))
522 {
523 if (ippContainsString(print_color_mode_sup, "auto-monochrome"))
524 keyword = "auto-monochrome";
525 else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome"))
526 keyword = "process-monochrome";
527 }
528
529 if (keyword)
530 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, color_attr_name, NULL, keyword);
531
532 if ((keyword = cupsGetOption("print-quality", num_options, options)) != NULL)
533 ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", atoi(keyword));
534 else if ((choice = ppdFindMarkedChoice(ppd, "cupsPrintQuality")) != NULL)
535 {
536 if (!_cups_strcasecmp(choice->choice, "draft"))
537 ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_DRAFT);
538 else if (!_cups_strcasecmp(choice->choice, "normal"))
539 ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_NORMAL);
540 else if (!_cups_strcasecmp(choice->choice, "high"))
541 ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality", IPP_QUALITY_HIGH);
542 }
543
544 if ((keyword = cupsGetOption("sides", num_options, options)) != NULL)
545 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, keyword);
546 else if (pc->sides_option && (choice = ppdFindMarkedChoice(ppd, pc->sides_option)) != NULL)
547 {
548 if (!_cups_strcasecmp(choice->choice, pc->sides_1sided))
549 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "one-sided");
550 else if (!_cups_strcasecmp(choice->choice, pc->sides_2sided_long))
551 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "two-sided-long-edge");
552 if (!_cups_strcasecmp(choice->choice, pc->sides_2sided_short))
553 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides", NULL, "two-sided-short-edge");
554 }
555
556 /*
557 * Copies...
558 */
559
560 if ((keyword = cupsGetOption("multiple-document-handling", num_options, options)) != NULL)
561 {
562 if (strstr(keyword, "uncollated"))
563 keyword = "false";
564 else
565 keyword = "true";
566 }
567 else if ((keyword = cupsGetOption("collate", num_options, options)) == NULL)
568 keyword = "true";
569
570 if (format)
571 {
572 if (!_cups_strcasecmp(format, "image/gif") ||
573 !_cups_strcasecmp(format, "image/jp2") ||
574 !_cups_strcasecmp(format, "image/jpeg") ||
575 !_cups_strcasecmp(format, "image/png") ||
576 !_cups_strcasecmp(format, "image/tiff") ||
577 !_cups_strncasecmp(format, "image/x-", 8))
578 {
579 /*
580 * Collation makes no sense for single page image formats...
581 */
582
583 keyword = "false";
584 }
585 else if (!_cups_strncasecmp(format, "image/", 6) ||
586 !_cups_strcasecmp(format, "application/vnd.cups-raster"))
587 {
588 /*
589 * Multi-page image formats will have copies applied by the upstream
590 * filters...
591 */
592
593 copies = 1;
594 }
595 }
596
597 if (doc_handling_sup)
598 {
599 if (!_cups_strcasecmp(keyword, "true"))
600 collate_str = "separate-documents-collated-copies";
601 else
602 collate_str = "separate-documents-uncollated-copies";
603
604 for (i = 0; i < doc_handling_sup->num_values; i ++)
605 {
606 if (!strcmp(doc_handling_sup->values[i].string.text, collate_str))
607 {
608 ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "multiple-document-handling", NULL, collate_str);
609 break;
610 }
611 }
612
613 if (i >= doc_handling_sup->num_values)
614 copies = 1;
615 }
616
617 /*
618 * Map finishing options...
619 */
620
621 num_finishings = _ppdCacheGetFinishingValues(pc, num_options, options, (int)(sizeof(finishings) / sizeof(finishings[0])), finishings);
622 if (num_finishings > 0)
623 {
624 ippAddIntegers(request, IPP_TAG_JOB, IPP_TAG_ENUM, "finishings", num_finishings, finishings);
625
626 if (copies > 1 && (keyword = cupsGetOption("job-impressions", num_options, options)) != NULL)
627 {
628 /*
629 * Send job-pages-per-set attribute to apply finishings correctly...
630 */
631
632 ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-pages-per-set", atoi(keyword) / copies);
633 }
634 }
635
636 return (copies);
637 }
638
639
640 /*
641 * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
642 *
643 * This function adds operation, job, and then subscription attributes,
644 * in that order. Use the cupsEncodeOptions2() function to add attributes
645 * for a single group.
646 */
647
648 void
649 cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */
650 int num_options, /* I - Number of options */
651 cups_option_t *options) /* I - Options */
652 {
653 DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)", ipp, num_options, options));
654
655 /*
656 * Add the options in the proper groups & order...
657 */
658
659 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_OPERATION);
660 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_JOB);
661 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_SUBSCRIPTION);
662 }
663
664
665 /*
666 * 'cupsEncodeOptions2()' - Encode printer options into IPP attributes for a group.
667 *
668 * This function only adds attributes for a single group. Call this
669 * function multiple times for each group, or use cupsEncodeOptions()
670 * to add the standard groups.
671 *
672 * @since CUPS 1.2/OS X 10.5@
673 */
674
675 void
676 cupsEncodeOptions2(
677 ipp_t *ipp, /* I - Request to add to */
678 int num_options, /* I - Number of options */
679 cups_option_t *options, /* I - Options */
680 ipp_tag_t group_tag) /* I - Group to encode */
681 {
682 int i, j; /* Looping vars */
683 int count; /* Number of values */
684 char *s, /* Pointer into option value */
685 *val, /* Pointer to option value */
686 *copy, /* Copy of option value */
687 *sep, /* Option separator */
688 quote; /* Quote character */
689 ipp_attribute_t *attr; /* IPP attribute */
690 ipp_tag_t value_tag; /* IPP value tag */
691 cups_option_t *option; /* Current option */
692 ipp_t *collection; /* Collection value */
693 int num_cols; /* Number of collection values */
694 cups_option_t *cols; /* Collection values */
695 ipp_op_t op; /* Operation for this request */
696 const ipp_op_t *ops; /* List of allowed operations */
697
698
699 DEBUG_printf(("cupsEncodeOptions2(ipp=%p(%s), num_options=%d, options=%p, "
700 "group_tag=%x)", ipp,
701 ipp ? ippOpString(ippGetOperation(ipp)) : "", num_options,
702 options, group_tag));
703
704 /*
705 * Range check input...
706 */
707
708 if (!ipp || num_options < 1 || !options)
709 return;
710
711 /*
712 * Do special handling for the document-format/raw options...
713 */
714
715 op = ippGetOperation(ipp);
716
717 if (group_tag == IPP_TAG_OPERATION &&
718 (op == IPP_OP_PRINT_JOB || op == IPP_OP_PRINT_URI ||
719 op == IPP_OP_SEND_DOCUMENT || op == IPP_OP_SEND_URI))
720 {
721 /*
722 * Handle the document format stuff first...
723 */
724
725 if ((val = (char *)cupsGetOption("document-format", num_options,
726 options)) != NULL)
727 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
728 NULL, val);
729 else if (cupsGetOption("raw", num_options, options))
730 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
731 NULL, "application/vnd.cups-raw");
732 else
733 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
734 NULL, "application/octet-stream");
735 }
736
737 /*
738 * Then loop through the options...
739 */
740
741 for (i = num_options, option = options; i > 0; i --, option ++)
742 {
743 _ipp_option_t *match; /* Matching attribute */
744
745
746 /*
747 * Skip document format options that are handled above...
748 */
749
750 if (!_cups_strcasecmp(option->name, "raw") ||
751 !_cups_strcasecmp(option->name, "document-format") ||
752 !option->name[0])
753 continue;
754
755 /*
756 * Figure out the proper value and group tags for this option...
757 */
758
759 if ((match = _ippFindOption(option->name)) != NULL)
760 {
761 if (match->group_tag != group_tag && match->alt_group_tag != group_tag)
762 continue;
763
764 value_tag = match->value_tag;
765
766 if (match->operations)
767 ops = match->operations;
768 else if (group_tag == IPP_TAG_JOB)
769 ops = ipp_job_creation;
770 else if (group_tag == IPP_TAG_DOCUMENT)
771 ops = ipp_doc_creation;
772 else if (group_tag == IPP_TAG_SUBSCRIPTION)
773 ops = ipp_sub_creation;
774 else if (group_tag == IPP_TAG_PRINTER)
775 ops = ipp_set_printer;
776 else
777 {
778 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
779 continue;
780 }
781 }
782 else
783 {
784 int namelen; /* Length of name */
785
786
787 namelen = (int)strlen(option->name);
788
789 if (namelen < 10 ||
790 (strcmp(option->name + namelen - 8, "-default") &&
791 strcmp(option->name + namelen - 10, "-supported")))
792 {
793 if (group_tag != IPP_TAG_JOB && group_tag != IPP_TAG_DOCUMENT)
794 {
795 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
796 continue;
797 }
798 }
799 else if (group_tag != IPP_TAG_PRINTER)
800 {
801 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
802 continue;
803 }
804
805 if (group_tag == IPP_TAG_JOB)
806 ops = ipp_job_creation;
807 else if (group_tag == IPP_TAG_DOCUMENT)
808 ops = ipp_doc_creation;
809 else
810 ops = ipp_set_printer;
811
812 if (!_cups_strcasecmp(option->value, "true") ||
813 !_cups_strcasecmp(option->value, "false"))
814 value_tag = IPP_TAG_BOOLEAN;
815 else
816 value_tag = IPP_TAG_NAME;
817 }
818
819 /*
820 * Verify that we send this attribute for this operation...
821 */
822
823 while (*ops != IPP_OP_CUPS_NONE)
824 if (op == *ops)
825 break;
826 else
827 ops ++;
828
829 if (*ops == IPP_OP_CUPS_NONE && op != IPP_OP_CUPS_NONE)
830 {
831 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
832 continue;
833 }
834
835 /*
836 * Count the number of values...
837 */
838
839 if (match && match->multivalue)
840 {
841 for (count = 1, sep = option->value, quote = 0; *sep; sep ++)
842 {
843 if (*sep == quote)
844 quote = 0;
845 else if (!quote && (*sep == '\'' || *sep == '\"'))
846 {
847 /*
848 * Skip quoted option value...
849 */
850
851 quote = *sep++;
852 }
853 else if (*sep == ',' && !quote)
854 count ++;
855 else if (*sep == '\\' && sep[1])
856 sep ++;
857 }
858 }
859 else
860 count = 1;
861
862 DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", count=%d",
863 option->name, count));
864
865 /*
866 * Allocate memory for the attribute values...
867 */
868
869 if ((attr = ippAddStrings(ipp, group_tag, value_tag, option->name, count,
870 NULL, NULL)) == NULL)
871 {
872 /*
873 * Ran out of memory!
874 */
875
876 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for attributes!");
877 return;
878 }
879
880 if (count > 1)
881 {
882 /*
883 * Make a copy of the value we can fiddle with...
884 */
885
886 if ((copy = strdup(option->value)) == NULL)
887 {
888 /*
889 * Ran out of memory!
890 */
891
892 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for value copy!");
893 ippDeleteAttribute(ipp, attr);
894 return;
895 }
896
897 val = copy;
898 }
899 else
900 {
901 /*
902 * Since we have a single value, use the value directly...
903 */
904
905 val = option->value;
906 copy = NULL;
907 }
908
909 /*
910 * Scan the value string for values...
911 */
912
913 for (j = 0, sep = val; j < count; val = sep, j ++)
914 {
915 /*
916 * Find the end of this value and mark it if needed...
917 */
918
919 if (count > 1)
920 {
921 for (quote = 0; *sep; sep ++)
922 {
923 if (*sep == quote)
924 {
925 /*
926 * Finish quoted value...
927 */
928
929 quote = 0;
930 }
931 else if (!quote && (*sep == '\'' || *sep == '\"'))
932 {
933 /*
934 * Handle quoted option value...
935 */
936
937 quote = *sep;
938 }
939 else if (*sep == ',' && count > 1)
940 break;
941 else if (*sep == '\\' && sep[1])
942 {
943 /*
944 * Skip quoted character...
945 */
946
947 sep ++;
948 }
949 }
950
951 if (*sep == ',')
952 *sep++ = '\0';
953 }
954
955 /*
956 * Copy the option value(s) over as needed by the type...
957 */
958
959 switch (attr->value_tag)
960 {
961 case IPP_TAG_INTEGER :
962 case IPP_TAG_ENUM :
963 /*
964 * Integer/enumeration value...
965 */
966
967 attr->values[j].integer = (int)strtol(val, &s, 10);
968
969 DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
970 "%d...", attr->values[j].integer));
971 break;
972
973 case IPP_TAG_BOOLEAN :
974 if (!_cups_strcasecmp(val, "true") ||
975 !_cups_strcasecmp(val, "on") ||
976 !_cups_strcasecmp(val, "yes"))
977 {
978 /*
979 * Boolean value - true...
980 */
981
982 attr->values[j].boolean = 1;
983
984 DEBUG_puts("2cupsEncodeOptions2: Added boolean true value...");
985 }
986 else
987 {
988 /*
989 * Boolean value - false...
990 */
991
992 attr->values[j].boolean = 0;
993
994 DEBUG_puts("2cupsEncodeOptions2: Added boolean false value...");
995 }
996 break;
997
998 case IPP_TAG_RANGE :
999 /*
1000 * Range...
1001 */
1002
1003 if (*val == '-')
1004 {
1005 attr->values[j].range.lower = 1;
1006 s = val;
1007 }
1008 else
1009 attr->values[j].range.lower = (int)strtol(val, &s, 10);
1010
1011 if (*s == '-')
1012 {
1013 if (s[1])
1014 attr->values[j].range.upper = (int)strtol(s + 1, NULL, 10);
1015 else
1016 attr->values[j].range.upper = 2147483647;
1017 }
1018 else
1019 attr->values[j].range.upper = attr->values[j].range.lower;
1020
1021 DEBUG_printf(("2cupsEncodeOptions2: Added range option value "
1022 "%d-%d...", attr->values[j].range.lower,
1023 attr->values[j].range.upper));
1024 break;
1025
1026 case IPP_TAG_RESOLUTION :
1027 /*
1028 * Resolution...
1029 */
1030
1031 attr->values[j].resolution.xres = (int)strtol(val, &s, 10);
1032
1033 if (*s == 'x')
1034 attr->values[j].resolution.yres = (int)strtol(s + 1, &s, 10);
1035 else
1036 attr->values[j].resolution.yres = attr->values[j].resolution.xres;
1037
1038 if (!_cups_strcasecmp(s, "dpc") ||
1039 !_cups_strcasecmp(s, "dpcm"))
1040 attr->values[j].resolution.units = IPP_RES_PER_CM;
1041 else
1042 attr->values[j].resolution.units = IPP_RES_PER_INCH;
1043
1044 DEBUG_printf(("2cupsEncodeOptions2: Added resolution option value "
1045 "%s...", val));
1046 break;
1047
1048 case IPP_TAG_STRING :
1049 /*
1050 * octet-string
1051 */
1052
1053 attr->values[j].unknown.length = (int)strlen(val);
1054 attr->values[j].unknown.data = strdup(val);
1055
1056 DEBUG_printf(("2cupsEncodeOptions2: Added octet-string value "
1057 "\"%s\"...", (char *)attr->values[j].unknown.data));
1058 break;
1059
1060 case IPP_TAG_BEGIN_COLLECTION :
1061 /*
1062 * Collection value
1063 */
1064
1065 num_cols = cupsParseOptions(val, 0, &cols);
1066 if ((collection = ippNew()) == NULL)
1067 {
1068 cupsFreeOptions(num_cols, cols);
1069
1070 if (copy)
1071 free(copy);
1072
1073 ippDeleteAttribute(ipp, attr);
1074 return;
1075 }
1076
1077 attr->values[j].collection = collection;
1078 cupsEncodeOptions2(collection, num_cols, cols, IPP_TAG_JOB);
1079 cupsFreeOptions(num_cols, cols);
1080 break;
1081
1082 default :
1083 if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
1084 {
1085 /*
1086 * Ran out of memory!
1087 */
1088
1089 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for string!");
1090
1091 if (copy)
1092 free(copy);
1093
1094 ippDeleteAttribute(ipp, attr);
1095 return;
1096 }
1097
1098 DEBUG_printf(("2cupsEncodeOptions2: Added string value \"%s\"...",
1099 val));
1100 break;
1101 }
1102 }
1103
1104 if (copy)
1105 free(copy);
1106 }
1107 }
1108
1109
1110 #ifdef DEBUG
1111 /*
1112 * '_ippCheckOptions()' - Validate that the option array is sorted properly.
1113 */
1114
1115 const char * /* O - First out-of-order option or NULL */
1116 _ippCheckOptions(void)
1117 {
1118 int i; /* Looping var */
1119
1120
1121 for (i = 0; i < (int)(sizeof(ipp_options) / sizeof(ipp_options[0]) - 1); i ++)
1122 if (strcmp(ipp_options[i].name, ipp_options[i + 1].name) >= 0)
1123 return (ipp_options[i + 1].name);
1124
1125 return (NULL);
1126 }
1127 #endif /* DEBUG */
1128
1129
1130 /*
1131 * '_ippFindOption()' - Find the attribute information for an option.
1132 */
1133
1134 _ipp_option_t * /* O - Attribute information */
1135 _ippFindOption(const char *name) /* I - Option/attribute name */
1136 {
1137 _ipp_option_t key; /* Search key */
1138
1139
1140 /*
1141 * Lookup the proper value and group tags for this option...
1142 */
1143
1144 key.name = name;
1145
1146 return ((_ipp_option_t *)bsearch(&key, ipp_options,
1147 sizeof(ipp_options) / sizeof(ipp_options[0]),
1148 sizeof(ipp_options[0]),
1149 (int (*)(const void *, const void *))
1150 compare_ipp_options));
1151 }
1152
1153
1154 /*
1155 * 'compare_ipp_options()' - Compare two IPP options.
1156 */
1157
1158 static int /* O - Result of comparison */
1159 compare_ipp_options(_ipp_option_t *a, /* I - First option */
1160 _ipp_option_t *b) /* I - Second option */
1161 {
1162 return (strcmp(a->name, b->name));
1163 }
1164
1165
1166 /*
1167 * End of "$Id$".
1168 */