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