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