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