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