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