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