/*
- * "$Id: encode.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $"
*
- * Option encoding routines for the Common UNIX Printing System (CUPS).
+ * Option encoding routines for CUPS.
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2012 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* Include necessary headers...
*/
-#include "cups.h"
-#include "ipp-private.h"
-#include <stdlib.h>
-#include <ctype.h>
-#include "string.h"
-#include "debug.h"
+#include "cups-private.h"
/*
{ 0, "brightness-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "columns", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "columns-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
- { 0, "copies", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 0, "compression", IPP_TAG_KEYWORD, IPP_TAG_OPERATION },
+ { 0, "copies", IPP_TAG_INTEGER, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "copies-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "device-uri", IPP_TAG_URI, IPP_TAG_PRINTER },
+ { 1, "document-copies", IPP_TAG_RANGE, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "document-format", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION },
{ 0, "document-format-default", IPP_TAG_MIMETYPE, IPP_TAG_PRINTER },
- { 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB },
+ { 1, "document-numbers", IPP_TAG_RANGE, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION },
+ { 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 1, "finishings-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
+ { 0, "fit-to-page", IPP_TAG_BOOLEAN, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "fit-to-page-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "fitplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 0, "fitplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "gamma", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "gamma-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "hue", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "hue-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
- { 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_JOB },
- { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION },
+ { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "job-priority", IPP_TAG_INTEGER, IPP_TAG_JOB },
- { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 0, "job-quota-period", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 1, "job-sheets", IPP_TAG_NAME, IPP_TAG_JOB },
+ { 1, "job-sheets-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
{ 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB },
{ 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
- { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB },
+ { 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 1, "marker-colors", IPP_TAG_NAME, IPP_TAG_PRINTER },
+ { 1, "marker-high-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 1, "marker-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 1, "marker-low-levels", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "marker-message", IPP_TAG_TEXT, IPP_TAG_PRINTER },
+ { 1, "marker-names", IPP_TAG_NAME, IPP_TAG_PRINTER },
+ { 1, "marker-types", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
+ { 1, "media", IPP_TAG_KEYWORD, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "media-col", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "media-col-default", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_PRINTER },
+ { 0, "media-color", IPP_TAG_KEYWORD, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 1, "media-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
+ { 0, "media-key", IPP_TAG_KEYWORD, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "media-size", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "media-type", IPP_TAG_KEYWORD, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "mirror", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 0, "mirror-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "natural-scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "notify-recipient-uri", IPP_TAG_URI, IPP_TAG_SUBSCRIPTION },
{ 0, "notify-time-interval", IPP_TAG_INTEGER, IPP_TAG_SUBSCRIPTION },
{ 0, "notify-user-data", IPP_TAG_STRING, IPP_TAG_SUBSCRIPTION },
- { 0, "number-up", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 0, "number-up", IPP_TAG_INTEGER, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "number-up-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
- { 0, "orientation-requested", IPP_TAG_ENUM, IPP_TAG_JOB },
+ { 0, "orientation-requested", IPP_TAG_ENUM, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "orientation-requested-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
+ { 1, "overrides", IPP_TAG_BEGIN_COLLECTION, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "page-bottom", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "page-bottom-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "page-left", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "page-left-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
- { 1, "page-ranges", IPP_TAG_RANGE, IPP_TAG_JOB },
+ { 1, "page-ranges", IPP_TAG_RANGE, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 1, "page-ranges-default", IPP_TAG_RANGE, IPP_TAG_PRINTER },
{ 0, "page-right", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "page-right-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "page-top", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "page-top-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 1, "pages", IPP_TAG_RANGE, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "penwidth", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "penwidth-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "port-monitor", IPP_TAG_NAME, IPP_TAG_PRINTER },
+ { 0, "ppd-name", IPP_TAG_NAME, IPP_TAG_PRINTER },
{ 0, "ppi", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "ppi-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "prettyprint", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 0, "prettyprint-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
- { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB },
+ { 0, "print-quality", IPP_TAG_ENUM, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "print-quality-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
+ { 1, "printer-commands", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
{ 0, "printer-error-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
{ 0, "printer-info", IPP_TAG_TEXT, IPP_TAG_PRINTER },
{ 0, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "printer-make-and-model", IPP_TAG_TEXT, IPP_TAG_PRINTER },
{ 0, "printer-more-info", IPP_TAG_URI, IPP_TAG_PRINTER },
{ 0, "printer-op-policy", IPP_TAG_NAME, IPP_TAG_PRINTER },
- { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
+ { 0, "printer-resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "printer-state", IPP_TAG_ENUM, IPP_TAG_PRINTER },
{ 0, "printer-state-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 1, "printer-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
{ 0, "printer-type", IPP_TAG_ENUM, IPP_TAG_PRINTER },
{ 0, "printer-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
+ { 1, "printer-uri-supported", IPP_TAG_URI, IPP_TAG_PRINTER },
{ 0, "queued-job-count", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "raw", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION },
+ { 1, "requested-attributes", IPP_TAG_NAME, IPP_TAG_OPERATION },
{ 1, "requesting-user-name-allowed", IPP_TAG_NAME, IPP_TAG_PRINTER },
{ 1, "requesting-user-name-denied", IPP_TAG_NAME, IPP_TAG_PRINTER },
{ 0, "resolution", IPP_TAG_RESOLUTION, IPP_TAG_JOB },
{ 0, "saturation-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 0, "scaling", IPP_TAG_INTEGER, IPP_TAG_JOB },
{ 0, "scaling-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
- { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB },
+ { 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
{ 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
{ 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
- { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER }
+ { 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
+ { 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT },
+ { 0, "y-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
+ IPP_TAG_DOCUMENT }
};
int num_options, /* I - Number of options */
cups_option_t *options) /* I - Options */
{
- DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)\n", ipp, num_options, options));
+ DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)", ipp, num_options, options));
/*
* Add the options in the proper groups & order...
* function multiple times for each group, or use cupsEncodeOptions()
* to add the standard groups.
*
- * @since CUPS 1.2@
+ * @since CUPS 1.2/Mac OS X 10.5@
*/
void
ipp_attribute_t *attr; /* IPP attribute */
ipp_tag_t value_tag; /* IPP value tag */
cups_option_t *option; /* Current option */
+ ipp_t *collection; /* Collection value */
+ int num_cols; /* Number of collection values */
+ cups_option_t *cols; /* Collection values */
DEBUG_printf(("cupsEncodeOptions2(ipp=%p, num_options=%d, options=%p, "
- "group_tag=%x)\n", ipp, num_options, options, group_tag));
+ "group_tag=%x)", ipp, num_options, options, group_tag));
/*
* Range check input...
* Skip document format options that are handled above...
*/
- if (!strcasecmp(option->name, "raw") ||
- !strcasecmp(option->name, "document-format") ||
+ if (!_cups_strcasecmp(option->name, "raw") ||
+ !_cups_strcasecmp(option->name, "document-format") ||
!option->name[0])
continue;
if ((match = _ippFindOption(option->name)) != NULL)
{
- if (match->group_tag != group_tag)
+ if (match->group_tag != group_tag && match->alt_group_tag != group_tag)
continue;
value_tag = match->value_tag;
namelen = (int)strlen(option->name);
- if (namelen < 9 || strcmp(option->name + namelen - 8, "-default"))
+ if (namelen < 10 ||
+ (strcmp(option->name + namelen - 8, "-default") &&
+ strcmp(option->name + namelen - 10, "-supported")))
{
- if (group_tag != IPP_TAG_JOB)
+ if (group_tag != IPP_TAG_JOB && group_tag != IPP_TAG_DOCUMENT)
continue;
}
else if (group_tag != IPP_TAG_PRINTER)
continue;
- if (!strcasecmp(option->value, "true") ||
- !strcasecmp(option->value, "false"))
+ if (!_cups_strcasecmp(option->value, "true") ||
+ !_cups_strcasecmp(option->value, "false"))
value_tag = IPP_TAG_BOOLEAN;
else
value_tag = IPP_TAG_NAME;
else
count = 1;
- DEBUG_printf(("cupsEncodeOptions2: option = \'%s\', count = %d\n",
+ DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", count=%d",
option->name, count));
/*
* Allocate memory for the attribute values...
*/
- if ((attr = _ippAddAttr(ipp, count)) == NULL)
+ if ((attr = ippAddStrings(ipp, group_tag, value_tag, option->name, count,
+ NULL, NULL)) == NULL)
{
/*
* Ran out of memory!
*/
- DEBUG_puts("cupsEncodeOptions2: Ran out of memory for attributes!");
- return;
- }
-
- /*
- * Now figure out what type of value we have...
- */
-
- attr->group_tag = group_tag;
- attr->value_tag = value_tag;
-
- /*
- * Copy the name over...
- */
-
- if ((attr->name = _cupsStrAlloc(option->name)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions2: Ran out of memory for name!");
+ DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for attributes!");
return;
}
* Ran out of memory!
*/
- DEBUG_puts("cupsEncodeOptions2: Ran out of memory for value copy!");
+ DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for value copy!");
+ ippDeleteAttribute(ipp, attr);
return;
}
attr->values[j].integer = strtol(val, &s, 10);
- DEBUG_printf(("cupsEncodeOptions2: Added integer option value %d...\n",
- attr->values[j].integer));
+ DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
+ "%d...", attr->values[j].integer));
break;
case IPP_TAG_BOOLEAN :
- if (!strcasecmp(val, "true") ||
- !strcasecmp(val, "on") ||
- !strcasecmp(val, "yes"))
+ if (!_cups_strcasecmp(val, "true") ||
+ !_cups_strcasecmp(val, "on") ||
+ !_cups_strcasecmp(val, "yes"))
{
/*
* Boolean value - true...
attr->values[j].boolean = 1;
- DEBUG_puts("cupsEncodeOptions2: Added boolean true value...");
+ DEBUG_puts("2cupsEncodeOptions2: Added boolean true value...");
}
else
{
attr->values[j].boolean = 0;
- DEBUG_puts("cupsEncodeOptions2: Added boolean false value...");
+ DEBUG_puts("2cupsEncodeOptions2: Added boolean false value...");
}
break;
else
attr->values[j].range.upper = attr->values[j].range.lower;
- DEBUG_printf(("cupsEncodeOptions2: Added range option value %d-%d...\n",
- attr->values[j].range.lower,
+ DEBUG_printf(("2cupsEncodeOptions2: Added range option value "
+ "%d-%d...", attr->values[j].range.lower,
attr->values[j].range.upper));
break;
else
attr->values[j].resolution.yres = attr->values[j].resolution.xres;
- if (!strcasecmp(s, "dpc"))
+ if (!_cups_strcasecmp(s, "dpc") ||
+ !_cups_strcasecmp(s, "dpcm"))
attr->values[j].resolution.units = IPP_RES_PER_CM;
else
attr->values[j].resolution.units = IPP_RES_PER_INCH;
- DEBUG_printf(("cupsEncodeOptions2: Added resolution option value %s...\n",
- val));
+ DEBUG_printf(("2cupsEncodeOptions2: Added resolution option value "
+ "%s...", val));
break;
case IPP_TAG_STRING :
attr->values[j].unknown.length = (int)strlen(val);
attr->values[j].unknown.data = strdup(val);
- DEBUG_printf(("cupsEncodeOptions2: Added octet-string value \"%s\"...\n",
- attr->values[j].unknown.data));
+ DEBUG_printf(("2cupsEncodeOptions2: Added octet-string value "
+ "\"%s\"...", (char *)attr->values[j].unknown.data));
break;
+ case IPP_TAG_BEGIN_COLLECTION :
+ /*
+ * Collection value
+ */
+
+ num_cols = cupsParseOptions(val, 0, &cols);
+ if ((collection = ippNew()) == NULL)
+ {
+ cupsFreeOptions(num_cols, cols);
+
+ if (copy)
+ free(copy);
+
+ ippDeleteAttribute(ipp, attr);
+ return;
+ }
+
+ attr->values[j].collection = collection;
+ cupsEncodeOptions2(collection, num_cols, cols, IPP_TAG_JOB);
+ cupsFreeOptions(num_cols, cols);
+ break;
+
default :
- if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
+ if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
{
/*
* Ran out of memory!
*/
- DEBUG_puts("cupsEncodeOptions2: Ran out of memory for string!");
+ DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for string!");
+
+ if (copy)
+ free(copy);
+
+ ippDeleteAttribute(ipp, attr);
return;
}
- DEBUG_printf(("cupsEncodeOptions2: Added string value \"%s\"...\n",
+ DEBUG_printf(("2cupsEncodeOptions2: Added string value \"%s\"...",
val));
break;
}
/*
- * End of "$Id: encode.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $".
*/