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