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