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