]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/encode.c
Update documentation for cupsd - "-s" option was not mentioned (STR #4772)
[thirdparty/cups.git] / cups / encode.c
1 /*
2 * "$Id$"
3 *
4 * Option encoding routines for CUPS.
5 *
6 * Copyright 2007-2016 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, "date-time-at-completed",IPP_TAG_DATE, IPP_TAG_ZERO }, /* never send as option */
121 { 0, "date-time-at-creation", IPP_TAG_DATE, IPP_TAG_ZERO }, /* never send as option */
122 { 0, "date-time-at-processing",IPP_TAG_DATE, IPP_TAG_ZERO }, /* never send as option */
123 { 0, "device-uri", IPP_TAG_URI, IPP_TAG_PRINTER },
124 { 1, "document-copies", IPP_TAG_RANGE, IPP_TAG_JOB,
125 IPP_TAG_DOCUMENT,
126 ipp_doc_creation },
127 { 0, "document-format", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION,
128 IPP_TAG_ZERO,
129 ipp_doc_creation },
130 { 0, "document-format-default", IPP_TAG_MIMETYPE, IPP_TAG_PRINTER },
131 { 1, "document-numbers", IPP_TAG_RANGE, IPP_TAG_JOB,
132 IPP_TAG_DOCUMENT,
133 ipp_all_print },
134 { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
135 IPP_TAG_ZERO,
136 cups_schemes },
137 { 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB,
138 IPP_TAG_DOCUMENT },
139 { 1, "finishings-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
140 { 0, "fit-to-page", IPP_TAG_BOOLEAN, IPP_TAG_JOB,
141 IPP_TAG_DOCUMENT },
142 { 0, "fit-to-page-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
143 { 0, "fitplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
144 { 0, "fitplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
145 { 0, "gamma", IPP_TAG_INTEGER, IPP_TAG_JOB },
146 { 0, "gamma-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
147 { 0, "hue", IPP_TAG_INTEGER, IPP_TAG_JOB },
148 { 0, "hue-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
149 { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
150 IPP_TAG_ZERO,
151 cups_schemes },
152 { 0, "job-account-id", IPP_TAG_NAME, IPP_TAG_JOB },
153 { 0, "job-account-id-default",IPP_TAG_NAME, IPP_TAG_PRINTER },
154 { 0, "job-accounting-user-id", IPP_TAG_NAME, IPP_TAG_JOB },
155 { 0, "job-accounting-user-id-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
156 { 0, "job-authorization-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
157 { 0, "job-cancel-after", IPP_TAG_INTEGER, IPP_TAG_JOB },
158 { 0, "job-cancel-after-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
159 { 0, "job-hold-until", IPP_TAG_KEYWORD, IPP_TAG_JOB },
160 { 0, "job-id", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
161 { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
162 { 0, "job-impressions-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
163 { 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
164 { 0, "job-k-octets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
165 { 0, "job-k-octets-completed",IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
166 { 0, "job-media-sheets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
167 { 0, "job-media-sheets-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
168 { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
169 { 0, "job-password", IPP_TAG_STRING, IPP_TAG_OPERATION,
170 IPP_TAG_ZERO,
171 ipp_job_creation },
172 { 0, "job-password-encryption", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
173 IPP_TAG_ZERO,
174 ipp_job_creation },
175 { 0, "job-priority", IPP_TAG_INTEGER, IPP_TAG_JOB },
176 { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
177 { 1, "job-sheets", IPP_TAG_NAME, IPP_TAG_JOB },
178 { 1, "job-sheets-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
179 { 0, "job-state", IPP_TAG_ENUM, IPP_TAG_ZERO }, /* never send as option */
180 { 0, "job-state-message", IPP_TAG_TEXT, IPP_TAG_ZERO }, /* never send as option */
181 { 0, "job-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_ZERO }, /* never send as option */
182 { 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB },
183 { 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
184 { 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
185 { 1, "marker-colors", IPP_TAG_NAME, IPP_TAG_PRINTER },
186 { 1, "marker-high-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
187 { 1, "marker-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
188 { 1, "marker-low-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
189 { 0, "marker-message", IPP_TAG_TEXT, IPP_TAG_PRINTER },
190 { 1, "marker-names", IPP_TAG_NAME, IPP_TAG_PRINTER },
191 { 1, "marker-types", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
192 { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB,
193 IPP_TAG_DOCUMENT },
194 { 0, "media-col", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
195 IPP_TAG_DOCUMENT },
196 { 0, "media-col-default", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_PRINTER },
197 { 0, "media-color", IPP_TAG_KEYWORD, IPP_TAG_JOB,
198 IPP_TAG_DOCUMENT },
199 { 1, "media-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
200 { 0, "media-key", IPP_TAG_KEYWORD, IPP_TAG_JOB,
201 IPP_TAG_DOCUMENT },
202 { 0, "media-size", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
203 IPP_TAG_DOCUMENT },
204 { 0, "media-type", IPP_TAG_KEYWORD, IPP_TAG_JOB,
205 IPP_TAG_DOCUMENT },
206 { 0, "mirror", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
207 { 0, "mirror-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
208 { 0, "natural-scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
209 { 0, "natural-scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
210 { 0, "notify-charset", IPP_TAG_CHARSET, IPP_TAG_SUBSCRIPTION },
211 { 1, "notify-events", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION },
212 { 1, "notify-events-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
213 { 0, "notify-lease-duration", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION },
214 { 0, "notify-lease-duration-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
215 { 0, "notify-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_SUBSCRIPTION },
216 { 0, "notify-pull-method", IPP_TAG_KEYWORD, IPP_TAG_SUBSCRIPTION },
217 { 0, "notify-recipient-uri", IPP_TAG_URI, IPP_TAG_SUBSCRIPTION },
218 { 0, "notify-time-interval", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION },
219 { 0, "notify-user-data", IPP_TAG_STRING, IPP_TAG_SUBSCRIPTION },
220 { 0, "number-up", IPP_TAG_INTEGER, IPP_TAG_JOB,
221 IPP_TAG_DOCUMENT },
222 { 0, "number-up-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
223 { 0, "orientation-requested", IPP_TAG_ENUM, IPP_TAG_JOB,
224 IPP_TAG_DOCUMENT },
225 { 0, "orientation-requested-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
226 { 1, "overrides", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
227 IPP_TAG_DOCUMENT },
228 { 0, "page-bottom", IPP_TAG_INTEGER, IPP_TAG_JOB },
229 { 0, "page-bottom-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
230 { 0, "page-left", IPP_TAG_INTEGER, IPP_TAG_JOB },
231 { 0, "page-left-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
232 { 1, "page-ranges", IPP_TAG_RANGE, IPP_TAG_JOB,
233 IPP_TAG_DOCUMENT },
234 { 1, "page-ranges-default", IPP_TAG_RANGE, IPP_TAG_PRINTER },
235 { 0, "page-right", IPP_TAG_INTEGER, IPP_TAG_JOB },
236 { 0, "page-right-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
237 { 0, "page-top", IPP_TAG_INTEGER, IPP_TAG_JOB },
238 { 0, "page-top-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
239 { 1, "pages", IPP_TAG_RANGE, IPP_TAG_JOB,
240 IPP_TAG_DOCUMENT },
241 { 0, "penwidth", IPP_TAG_INTEGER, IPP_TAG_JOB },
242 { 0, "penwidth-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
243 { 0, "port-monitor", IPP_TAG_NAME, IPP_TAG_PRINTER },
244 { 0, "ppd-device-id", IPP_TAG_TEXT, IPP_TAG_OPERATION,
245 IPP_TAG_ZERO,
246 cups_get_ppds },
247 { 0, "ppd-make", IPP_TAG_TEXT, IPP_TAG_OPERATION,
248 IPP_TAG_ZERO,
249 cups_get_ppds },
250 { 0, "ppd-make-and-model", IPP_TAG_TEXT, IPP_TAG_OPERATION,
251 IPP_TAG_ZERO,
252 cups_get_ppds },
253 { 0, "ppd-model-number", IPP_TAG_INTEGER, IPP_TAG_OPERATION,
254 IPP_TAG_ZERO,
255 cups_get_ppds },
256 { 0, "ppd-name", IPP_TAG_NAME, IPP_TAG_OPERATION,
257 IPP_TAG_ZERO,
258 cups_ppd_name },
259 { 0, "ppd-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_OPERATION,
260 IPP_TAG_ZERO,
261 cups_get_ppds },
262 { 0, "ppd-product", IPP_TAG_TEXT, IPP_TAG_OPERATION,
263 IPP_TAG_ZERO,
264 cups_get_ppds },
265 { 0, "ppd-psversion", IPP_TAG_TEXT, IPP_TAG_OPERATION,
266 IPP_TAG_ZERO,
267 cups_get_ppds },
268 { 0, "ppd-type", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
269 IPP_TAG_ZERO,
270 cups_get_ppds },
271 { 0, "ppi", IPP_TAG_INTEGER, IPP_TAG_JOB },
272 { 0, "ppi-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
273 { 0, "prettyprint", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
274 { 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
275 { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB,
276 IPP_TAG_DOCUMENT },
277 { 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
278 { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
279 { 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
280 { 0, "printer-geo-location", IPP_TAG_URI, IPP_TAG_PRINTER },
281 { 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER },
282 { 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
283 { 0, "printer-is-shared", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
284 { 0, "printer-location", IPP_TAG_TEXT, IPP_TAG_PRINTER },
285 { 0, "printer-make-and-model", IPP_TAG_TEXT, IPP_TAG_PRINTER },
286 { 0, "printer-more-info", IPP_TAG_URI, IPP_TAG_PRINTER },
287 { 0, "printer-op-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
288 { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB,
289 IPP_TAG_DOCUMENT },
290 { 0, "printer-state", IPP_TAG_ENUM, IPP_TAG_PRINTER },
291 { 0, "printer-state-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
292 { 1, "printer-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
293 { 0, "printer-type", IPP_TAG_ENUM, IPP_TAG_PRINTER },
294 { 0, "printer-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
295 { 1, "printer-uri-supported", IPP_TAG_URI, IPP_TAG_PRINTER },
296 { 0, "queued-job-count", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
297 { 0, "raw", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION },
298 { 1, "requested-attributes", IPP_TAG_NAME, IPP_TAG_OPERATION },
299 { 1, "requesting-user-name-allowed", IPP_TAG_NAME, IPP_TAG_PRINTER },
300 { 1, "requesting-user-name-denied", IPP_TAG_NAME, IPP_TAG_PRINTER },
301 { 0, "resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
302 { 0, "resolution-default", IPP_TAG_RESOLUTION, IPP_TAG_PRINTER },
303 { 0, "saturation", IPP_TAG_INTEGER, IPP_TAG_JOB },
304 { 0, "saturation-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
305 { 0, "scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
306 { 0, "scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
307 { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB,
308 IPP_TAG_DOCUMENT },
309 { 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
310 { 0, "time-at-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
311 { 0, "time-at-creation", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
312 { 0, "time-at-processing", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
313 { 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
314 { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
315 { 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
316 IPP_TAG_DOCUMENT },
317 { 0, "y-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
318 IPP_TAG_DOCUMENT }
319 };
320
321
322 /*
323 * Local functions...
324 */
325
326 static int compare_ipp_options(_ipp_option_t *a, _ipp_option_t *b);
327
328
329 /*
330 * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
331 *
332 * This function adds operation, job, and then subscription attributes,
333 * in that order. Use the cupsEncodeOptions2() function to add attributes
334 * for a single group.
335 */
336
337 void
338 cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */
339 int num_options, /* I - Number of options */
340 cups_option_t *options) /* I - Options */
341 {
342 DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)", ipp, num_options, options));
343
344 /*
345 * Add the options in the proper groups & order...
346 */
347
348 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_OPERATION);
349 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_JOB);
350 cupsEncodeOptions2(ipp, num_options, options, IPP_TAG_SUBSCRIPTION);
351 }
352
353
354 /*
355 * 'cupsEncodeOptions2()' - Encode printer options into IPP attributes for a group.
356 *
357 * This function only adds attributes for a single group. Call this
358 * function multiple times for each group, or use cupsEncodeOptions()
359 * to add the standard groups.
360 *
361 * @since CUPS 1.2/OS X 10.5@
362 */
363
364 void
365 cupsEncodeOptions2(
366 ipp_t *ipp, /* I - Request to add to */
367 int num_options, /* I - Number of options */
368 cups_option_t *options, /* I - Options */
369 ipp_tag_t group_tag) /* I - Group to encode */
370 {
371 int i, j; /* Looping vars */
372 int count; /* Number of values */
373 char *s, /* Pointer into option value */
374 *val, /* Pointer to option value */
375 *copy, /* Copy of option value */
376 *sep, /* Option separator */
377 quote; /* Quote character */
378 ipp_attribute_t *attr; /* IPP attribute */
379 ipp_tag_t value_tag; /* IPP value tag */
380 cups_option_t *option; /* Current option */
381 ipp_t *collection; /* Collection value */
382 int num_cols; /* Number of collection values */
383 cups_option_t *cols; /* Collection values */
384 ipp_op_t op; /* Operation for this request */
385 const ipp_op_t *ops; /* List of allowed operations */
386
387
388 DEBUG_printf(("cupsEncodeOptions2(ipp=%p(%s), num_options=%d, options=%p, "
389 "group_tag=%x)", ipp,
390 ipp ? ippOpString(ippGetOperation(ipp)) : "", num_options,
391 options, group_tag));
392
393 /*
394 * Range check input...
395 */
396
397 if (!ipp || num_options < 1 || !options)
398 return;
399
400 /*
401 * Do special handling for the document-format/raw options...
402 */
403
404 op = ippGetOperation(ipp);
405
406 if (group_tag == IPP_TAG_OPERATION &&
407 (op == IPP_OP_PRINT_JOB || op == IPP_OP_PRINT_URI ||
408 op == IPP_OP_SEND_DOCUMENT || op == IPP_OP_SEND_URI))
409 {
410 /*
411 * Handle the document format stuff first...
412 */
413
414 if ((val = (char *)cupsGetOption("document-format", num_options,
415 options)) != NULL)
416 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
417 NULL, val);
418 else if (cupsGetOption("raw", num_options, options))
419 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
420 NULL, "application/vnd.cups-raw");
421 else
422 ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
423 NULL, "application/octet-stream");
424 }
425
426 /*
427 * Then loop through the options...
428 */
429
430 for (i = num_options, option = options; i > 0; i --, option ++)
431 {
432 _ipp_option_t *match; /* Matching attribute */
433
434
435 /*
436 * Skip document format options that are handled above...
437 */
438
439 if (!_cups_strcasecmp(option->name, "raw") ||
440 !_cups_strcasecmp(option->name, "document-format") ||
441 !option->name[0])
442 continue;
443
444 /*
445 * Figure out the proper value and group tags for this option...
446 */
447
448 if ((match = _ippFindOption(option->name)) != NULL)
449 {
450 if (match->group_tag != group_tag && match->alt_group_tag != group_tag)
451 continue;
452
453 value_tag = match->value_tag;
454
455 if (match->operations)
456 ops = match->operations;
457 else if (group_tag == IPP_TAG_JOB)
458 ops = ipp_job_creation;
459 else if (group_tag == IPP_TAG_DOCUMENT)
460 ops = ipp_doc_creation;
461 else if (group_tag == IPP_TAG_SUBSCRIPTION)
462 ops = ipp_sub_creation;
463 else if (group_tag == IPP_TAG_PRINTER)
464 ops = ipp_set_printer;
465 else
466 {
467 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
468 continue;
469 }
470 }
471 else
472 {
473 int namelen; /* Length of name */
474
475
476 namelen = (int)strlen(option->name);
477
478 if (namelen < 10 ||
479 (strcmp(option->name + namelen - 8, "-default") &&
480 strcmp(option->name + namelen - 10, "-supported")))
481 {
482 if (group_tag != IPP_TAG_JOB && group_tag != IPP_TAG_DOCUMENT)
483 {
484 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
485 continue;
486 }
487 }
488 else if (group_tag != IPP_TAG_PRINTER)
489 {
490 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
491 continue;
492 }
493
494 if (group_tag == IPP_TAG_JOB)
495 ops = ipp_job_creation;
496 else if (group_tag == IPP_TAG_DOCUMENT)
497 ops = ipp_doc_creation;
498 else
499 ops = ipp_set_printer;
500
501 if (!_cups_strcasecmp(option->value, "true") ||
502 !_cups_strcasecmp(option->value, "false"))
503 value_tag = IPP_TAG_BOOLEAN;
504 else
505 value_tag = IPP_TAG_NAME;
506 }
507
508 /*
509 * Verify that we send this attribute for this operation...
510 */
511
512 while (*ops != IPP_OP_CUPS_NONE)
513 if (op == *ops)
514 break;
515 else
516 ops ++;
517
518 if (*ops == IPP_OP_CUPS_NONE && op != IPP_OP_CUPS_NONE)
519 {
520 DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
521 continue;
522 }
523
524 /*
525 * Count the number of values...
526 */
527
528 if (match && match->multivalue)
529 {
530 for (count = 1, sep = option->value, quote = 0; *sep; sep ++)
531 {
532 if (*sep == quote)
533 quote = 0;
534 else if (!quote && (*sep == '\'' || *sep == '\"'))
535 {
536 /*
537 * Skip quoted option value...
538 */
539
540 quote = *sep++;
541 }
542 else if (*sep == ',' && !quote)
543 count ++;
544 else if (*sep == '\\' && sep[1])
545 sep += 2;
546 }
547 }
548 else
549 count = 1;
550
551 DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", value=\"%s\", count=%d", option->name, option->value, count));
552
553 /*
554 * Allocate memory for the attribute values...
555 */
556
557 if ((attr = ippAddStrings(ipp, group_tag, value_tag, option->name, count,
558 NULL, NULL)) == NULL)
559 {
560 /*
561 * Ran out of memory!
562 */
563
564 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for attributes!");
565 return;
566 }
567
568 if (count > 1)
569 {
570 /*
571 * Make a copy of the value we can fiddle with...
572 */
573
574 if ((copy = strdup(option->value)) == NULL)
575 {
576 /*
577 * Ran out of memory!
578 */
579
580 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for value copy!");
581 ippDeleteAttribute(ipp, attr);
582 return;
583 }
584
585 val = copy;
586 }
587 else
588 {
589 /*
590 * Since we have a single value, use the value directly...
591 */
592
593 val = option->value;
594 copy = NULL;
595 }
596
597 /*
598 * Scan the value string for values...
599 */
600
601 for (j = 0, sep = val; j < count; val = sep, j ++)
602 {
603 /*
604 * Find the end of this value and mark it if needed...
605 */
606
607 if (count > 1)
608 {
609 for (quote = 0; *sep; sep ++)
610 {
611 if (*sep == quote)
612 {
613 /*
614 * Finish quoted value...
615 */
616
617 quote = 0;
618 }
619 else if (!quote && (*sep == '\'' || *sep == '\"'))
620 {
621 /*
622 * Handle quoted option value...
623 */
624
625 quote = *sep;
626 }
627 else if (*sep == ',' && count > 1)
628 break;
629 else if (*sep == '\\' && sep[1])
630 {
631 /*
632 * Skip quoted character...
633 */
634
635 memmove(sep, sep + 1, strlen(sep));
636 sep ++;
637 }
638 }
639
640 if (*sep == ',')
641 *sep++ = '\0';
642 }
643
644 /*
645 * Copy the option value(s) over as needed by the type...
646 */
647
648 switch (attr->value_tag)
649 {
650 case IPP_TAG_INTEGER :
651 case IPP_TAG_ENUM :
652 /*
653 * Integer/enumeration value...
654 */
655
656 attr->values[j].integer = (int)strtol(val, &s, 10);
657
658 DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
659 "%d...", attr->values[j].integer));
660 break;
661
662 case IPP_TAG_BOOLEAN :
663 if (!_cups_strcasecmp(val, "true") ||
664 !_cups_strcasecmp(val, "on") ||
665 !_cups_strcasecmp(val, "yes"))
666 {
667 /*
668 * Boolean value - true...
669 */
670
671 attr->values[j].boolean = 1;
672
673 DEBUG_puts("2cupsEncodeOptions2: Added boolean true value...");
674 }
675 else
676 {
677 /*
678 * Boolean value - false...
679 */
680
681 attr->values[j].boolean = 0;
682
683 DEBUG_puts("2cupsEncodeOptions2: Added boolean false value...");
684 }
685 break;
686
687 case IPP_TAG_RANGE :
688 /*
689 * Range...
690 */
691
692 if (*val == '-')
693 {
694 attr->values[j].range.lower = 1;
695 s = val;
696 }
697 else
698 attr->values[j].range.lower = (int)strtol(val, &s, 10);
699
700 if (*s == '-')
701 {
702 if (s[1])
703 attr->values[j].range.upper = (int)strtol(s + 1, NULL, 10);
704 else
705 attr->values[j].range.upper = 2147483647;
706 }
707 else
708 attr->values[j].range.upper = attr->values[j].range.lower;
709
710 DEBUG_printf(("2cupsEncodeOptions2: Added range option value "
711 "%d-%d...", attr->values[j].range.lower,
712 attr->values[j].range.upper));
713 break;
714
715 case IPP_TAG_RESOLUTION :
716 /*
717 * Resolution...
718 */
719
720 attr->values[j].resolution.xres = (int)strtol(val, &s, 10);
721
722 if (*s == 'x')
723 attr->values[j].resolution.yres = (int)strtol(s + 1, &s, 10);
724 else
725 attr->values[j].resolution.yres = attr->values[j].resolution.xres;
726
727 if (!_cups_strcasecmp(s, "dpc") ||
728 !_cups_strcasecmp(s, "dpcm"))
729 attr->values[j].resolution.units = IPP_RES_PER_CM;
730 else
731 attr->values[j].resolution.units = IPP_RES_PER_INCH;
732
733 DEBUG_printf(("2cupsEncodeOptions2: Added resolution option value "
734 "%s...", val));
735 break;
736
737 case IPP_TAG_STRING :
738 /*
739 * octet-string
740 */
741
742 attr->values[j].unknown.length = (int)strlen(val);
743 attr->values[j].unknown.data = strdup(val);
744
745 DEBUG_printf(("2cupsEncodeOptions2: Added octet-string value "
746 "\"%s\"...", (char *)attr->values[j].unknown.data));
747 break;
748
749 case IPP_TAG_BEGIN_COLLECTION :
750 /*
751 * Collection value
752 */
753
754 num_cols = cupsParseOptions(val, 0, &cols);
755 if ((collection = ippNew()) == NULL)
756 {
757 cupsFreeOptions(num_cols, cols);
758
759 if (copy)
760 free(copy);
761
762 ippDeleteAttribute(ipp, attr);
763 return;
764 }
765
766 attr->values[j].collection = collection;
767 cupsEncodeOptions2(collection, num_cols, cols, IPP_TAG_JOB);
768 cupsFreeOptions(num_cols, cols);
769 break;
770
771 default :
772 if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
773 {
774 /*
775 * Ran out of memory!
776 */
777
778 DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for string!");
779
780 if (copy)
781 free(copy);
782
783 ippDeleteAttribute(ipp, attr);
784 return;
785 }
786
787 DEBUG_printf(("2cupsEncodeOptions2: Added string value \"%s\"...",
788 val));
789 break;
790 }
791 }
792
793 if (copy)
794 free(copy);
795 }
796 }
797
798
799 #ifdef DEBUG
800 /*
801 * '_ippCheckOptions()' - Validate that the option array is sorted properly.
802 */
803
804 const char * /* O - First out-of-order option or NULL */
805 _ippCheckOptions(void)
806 {
807 int i; /* Looping var */
808
809
810 for (i = 0; i < (int)(sizeof(ipp_options) / sizeof(ipp_options[0]) - 1); i ++)
811 if (strcmp(ipp_options[i].name, ipp_options[i + 1].name) >= 0)
812 return (ipp_options[i + 1].name);
813
814 return (NULL);
815 }
816 #endif /* DEBUG */
817
818
819 /*
820 * '_ippFindOption()' - Find the attribute information for an option.
821 */
822
823 _ipp_option_t * /* O - Attribute information */
824 _ippFindOption(const char *name) /* I - Option/attribute name */
825 {
826 _ipp_option_t key; /* Search key */
827
828
829 /*
830 * Lookup the proper value and group tags for this option...
831 */
832
833 key.name = name;
834
835 return ((_ipp_option_t *)bsearch(&key, ipp_options,
836 sizeof(ipp_options) / sizeof(ipp_options[0]),
837 sizeof(ipp_options[0]),
838 (int (*)(const void *, const void *))
839 compare_ipp_options));
840 }
841
842
843 /*
844 * 'compare_ipp_options()' - Compare two IPP options.
845 */
846
847 static int /* O - Result of comparison */
848 compare_ipp_options(_ipp_option_t *a, /* I - First option */
849 _ipp_option_t *b) /* I - Second option */
850 {
851 return (strcmp(a->name, b->name));
852 }
853
854
855 /*
856 * End of "$Id$".
857 */