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