]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/encode.c
2 * "$Id: encode.c,v 1.1.2.10 2003/01/07 18:26:24 mike Exp $"
4 * Option encoding routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * cupsEncodeOptions() - Encode printer options into IPP attributes.
32 * Include necessary headers...
43 * Local list of option names and the value tags they should use...
52 static ipp_option_t ipp_options
[] =
54 { "blackplot", IPP_TAG_BOOLEAN
},
55 { "brightness", IPP_TAG_INTEGER
},
56 { "columns", IPP_TAG_INTEGER
},
57 { "copies", IPP_TAG_INTEGER
},
58 { "finishings", IPP_TAG_ENUM
},
59 { "fitplot", IPP_TAG_BOOLEAN
},
60 { "gamma", IPP_TAG_INTEGER
},
61 { "hue", IPP_TAG_INTEGER
},
62 { "job-k-limit", IPP_TAG_INTEGER
},
63 { "job-page-limit", IPP_TAG_INTEGER
},
64 { "job-priority", IPP_TAG_INTEGER
},
65 { "job-quota-period", IPP_TAG_INTEGER
},
66 { "landscape", IPP_TAG_BOOLEAN
},
67 { "mirror", IPP_TAG_BOOLEAN
},
68 { "natural-scaling", IPP_TAG_INTEGER
},
69 { "number-up", IPP_TAG_INTEGER
},
70 { "orientation-requested", IPP_TAG_ENUM
},
71 { "page-bottom", IPP_TAG_INTEGER
},
72 { "page-left", IPP_TAG_INTEGER
},
73 { "page-ranges", IPP_TAG_RANGE
},
74 { "page-right", IPP_TAG_INTEGER
},
75 { "page-top", IPP_TAG_INTEGER
},
76 { "penwidth", IPP_TAG_INTEGER
},
77 { "ppi", IPP_TAG_INTEGER
},
78 { "prettyprint", IPP_TAG_BOOLEAN
},
79 { "printer-resolution", IPP_TAG_RESOLUTION
},
80 { "print-quality", IPP_TAG_ENUM
},
81 { "saturation", IPP_TAG_INTEGER
},
82 { "scaling", IPP_TAG_INTEGER
},
83 { "wrap", IPP_TAG_BOOLEAN
}
88 * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
92 cupsEncodeOptions(ipp_t
*ipp
, /* I - Request to add to */
93 int num_options
, /* I - Number of options */
94 cups_option_t
*options
) /* I - Options */
96 int i
, j
; /* Looping vars */
97 int count
; /* Number of values */
98 char *s
, /* Pointer into option value */
99 *val
, /* Pointer to option value */
100 *copy
, /* Copy of option value */
101 *sep
; /* Option separator */
102 ipp_attribute_t
*attr
; /* IPP job-id attribute */
105 DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)\n", ipp
, num_options
, options
));
107 if (ipp
== NULL
|| num_options
< 1 || options
== NULL
)
111 * Handle the document format stuff first...
114 if ((val
= (char *)cupsGetOption("document-format", num_options
, options
)) != NULL
)
115 ippAddString(ipp
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
, "document-format",
117 else if (cupsGetOption("raw", num_options
, options
))
118 ippAddString(ipp
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
, "document-format",
119 NULL
, "application/vnd.cups-raw");
121 ippAddString(ipp
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
, "document-format",
122 NULL
, "application/octet-stream");
125 * Then add all other options...
128 for (i
= 0; i
< num_options
; i
++)
131 * Skip document format options - handled above...
134 if (strcasecmp(options
[i
].name
, "raw") == 0 ||
135 strcasecmp(options
[i
].name
, "document-format") == 0 ||
140 * Count the number of values...
143 for (count
= 1, sep
= options
[i
].value
; *sep
; sep
++)
148 * Skip quoted option value...
153 while (*sep
&& *sep
!= '\'')
159 else if (*sep
== '\"')
162 * Skip quoted option value...
167 while (*sep
&& *sep
!= '\"')
173 else if (*sep
== ',')
175 else if (*sep
== '\\' && sep
[1])
179 DEBUG_printf(("cupsEncodeOptions: option = \'%s\', count = %d\n",
180 options
[i
].name
, count
));
183 * Allocate memory for the attribute values...
186 if ((attr
= _ipp_add_attr(ipp
, count
)) == NULL
)
192 DEBUG_puts("cupsEncodeOptions: Ran out of memory for attributes!");
197 * Now figure out what type of value we have...
200 attr
->group_tag
= IPP_TAG_JOB
;
202 if (strcasecmp(options
[i
].value
, "true") == 0 ||
203 strcasecmp(options
[i
].value
, "false") == 0)
204 attr
->value_tag
= IPP_TAG_BOOLEAN
;
206 attr
->value_tag
= IPP_TAG_NAME
;
208 for (j
= 0; j
< (int)(sizeof(ipp_options
) / sizeof(ipp_options
[0])); j
++)
209 if (strcasecmp(options
[i
].name
, ipp_options
[j
].name
) == 0)
211 attr
->value_tag
= ipp_options
[j
].value_tag
;
216 * Copy the name over...
219 if ((attr
->name
= strdup(options
[i
].name
)) == NULL
)
225 DEBUG_puts("cupsEncodeOptions: Ran out of memory for name!");
232 * Make a copy of the value we can fiddle with...
235 if ((copy
= strdup(options
[i
].value
)) == NULL
)
241 DEBUG_puts("cupsEncodeOptions: Ran out of memory for value copy!");
250 * Since we have a single value, use the value directly...
253 val
= options
[i
].value
;
258 * Scan the value string for values...
261 for (j
= 0; *val
!= '\0' || j
== 0; val
= sep
, j
++)
264 * Find the end of this value and mark it if needed...
267 if ((sep
= strchr(val
, ',')) != NULL
)
270 sep
= val
+ strlen(val
);
273 * Copy the option value(s) over as needed by the type...
276 switch (attr
->value_tag
)
278 case IPP_TAG_INTEGER
:
281 * Integer/enumeration value...
284 attr
->values
[j
].integer
= strtol(val
, &s
, 0);
286 DEBUG_printf(("cupsEncodeOptions: Adding integer option value %d...\n",
287 attr
->values
[j
].integer
));
290 case IPP_TAG_BOOLEAN
:
291 if (strcasecmp(val
, "true") == 0)
294 * Boolean value - true...
297 attr
->values
[j
].boolean
= 1;
299 DEBUG_puts("cupsEncodeOptions: Added boolean true value...");
304 * Boolean value - false...
307 attr
->values
[j
].boolean
= 0;
309 DEBUG_puts("cupsEncodeOptions: Added boolean false value...");
320 attr
->values
[j
].range
.lower
= 1;
324 attr
->values
[j
].range
.lower
= strtol(val
, &s
, 0);
329 attr
->values
[j
].range
.upper
= strtol(s
+ 1, NULL
, 0);
331 attr
->values
[j
].range
.upper
= 2147483647;
334 attr
->values
[j
].range
.upper
= attr
->values
[j
].range
.lower
;
336 DEBUG_printf(("cupsEncodeOptions: Added range option value %d-%d...\n",
337 attr
->values
[j
].range
.lower
,
338 attr
->values
[j
].range
.upper
));
341 case IPP_TAG_RESOLUTION
:
346 attr
->values
[j
].resolution
.xres
= strtol(val
, &s
, 0);
349 attr
->values
[j
].resolution
.yres
= strtol(s
+ 1, &s
, 0);
351 attr
->values
[j
].resolution
.yres
= attr
->values
[j
].resolution
.xres
;
353 if (strcasecmp(s
, "dpc") == 0)
354 attr
->values
[j
].resolution
.units
= IPP_RES_PER_CM
;
356 attr
->values
[j
].resolution
.units
= IPP_RES_PER_INCH
;
358 DEBUG_printf(("cupsEncodeOptions: Adding resolution option value %s...\n",
363 if ((attr
->values
[j
].string
.text
= strdup(val
)) == NULL
)
369 DEBUG_puts("cupsEncodeOptions: Ran out of memory for string!");
373 DEBUG_printf(("cupsEncodeOptions: Added string value \'%s\'...\n",
383 * End of "$Id: encode.c,v 1.1.2.10 2003/01/07 18:26:24 mike Exp $".