/*
- * "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $"
+ * "$Id$"
*
- * Option encoding routines for CUPS.
+ * Option encoding routines for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * cupsEncodeOptions() - Encode printer options into IPP attributes.
- * cupsEncodeOptions2() - Encode printer options into IPP attributes for
- * a group.
- * _ippFindOption() - Find the attribute information for an option.
- * compare_ipp_options() - Compare two IPP options.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
/*
- * Local list of option names and the value tags they should use...
+ * Local list of option names, the value tags they should use, and the list of
+ * supported operations...
*
- * **** THIS LIST MUST BE SORTED ****
+ * **** THIS LIST MUST BE SORTED BY ATTRIBUTE NAME ****
*/
+static const ipp_op_t ipp_job_creation[] =
+{
+ IPP_OP_PRINT_JOB,
+ IPP_OP_PRINT_URI,
+ IPP_OP_VALIDATE_JOB,
+ IPP_OP_CREATE_JOB,
+ IPP_OP_HOLD_JOB,
+ IPP_OP_SET_JOB_ATTRIBUTES,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t ipp_doc_creation[] =
+{
+ IPP_OP_PRINT_JOB,
+ IPP_OP_PRINT_URI,
+ IPP_OP_SEND_DOCUMENT,
+ IPP_OP_SEND_URI,
+ IPP_OP_SET_JOB_ATTRIBUTES,
+ IPP_OP_SET_DOCUMENT_ATTRIBUTES,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t ipp_sub_creation[] =
+{
+ IPP_OP_PRINT_JOB,
+ IPP_OP_PRINT_URI,
+ IPP_OP_CREATE_JOB,
+ IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS,
+ IPP_OP_CREATE_JOB_SUBSCRIPTIONS,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t ipp_all_print[] =
+{
+ IPP_OP_PRINT_JOB,
+ IPP_OP_PRINT_URI,
+ IPP_OP_VALIDATE_JOB,
+ IPP_OP_CREATE_JOB,
+ IPP_OP_SEND_DOCUMENT,
+ IPP_OP_SEND_URI,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t ipp_set_printer[] =
+{
+ IPP_OP_SET_PRINTER_ATTRIBUTES,
+ IPP_OP_CUPS_ADD_MODIFY_PRINTER,
+ IPP_OP_CUPS_ADD_MODIFY_CLASS,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t cups_schemes[] =
+{
+ IPP_OP_CUPS_GET_DEVICES,
+ IPP_OP_CUPS_GET_PPDS,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t cups_get_ppds[] =
+{
+ IPP_OP_CUPS_GET_PPDS,
+ IPP_OP_CUPS_NONE
+};
+
+static const ipp_op_t cups_ppd_name[] =
+{
+ IPP_OP_CUPS_ADD_MODIFY_PRINTER,
+ IPP_OP_CUPS_GET_PPD,
+ IPP_OP_CUPS_NONE
+};
+
static const _ipp_option_t ipp_options[] =
{
{ 1, "auth-info", IPP_TAG_TEXT, IPP_TAG_JOB },
+ { 1, "auth-info-default", IPP_TAG_TEXT, IPP_TAG_PRINTER },
{ 1, "auth-info-required", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
{ 0, "blackplot", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 0, "blackplot-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 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, "compression", IPP_TAG_KEYWORD, IPP_TAG_OPERATION },
+ { 0, "compression", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ ipp_doc_creation },
{ 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 },
+ IPP_TAG_DOCUMENT,
+ ipp_doc_creation },
+ { 0, "document-format", IPP_TAG_MIMETYPE, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ ipp_doc_creation },
{ 0, "document-format-default", IPP_TAG_MIMETYPE, IPP_TAG_PRINTER },
{ 1, "document-numbers", IPP_TAG_RANGE, IPP_TAG_JOB,
- IPP_TAG_DOCUMENT },
- { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION },
+ IPP_TAG_DOCUMENT,
+ ipp_all_print },
+ { 1, "exclude-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_schemes },
{ 1, "finishings", IPP_TAG_ENUM, IPP_TAG_JOB,
IPP_TAG_DOCUMENT },
{ 1, "finishings-default", IPP_TAG_ENUM, IPP_TAG_PRINTER },
{ 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 },
- { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION },
- { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 1, "include-schemes", IPP_TAG_NAME, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_schemes },
+ { 0, "job-account-id", IPP_TAG_NAME, IPP_TAG_JOB },
+ { 0, "job-account-id-default",IPP_TAG_NAME, IPP_TAG_PRINTER },
+ { 0, "job-accounting-user-id", IPP_TAG_NAME, IPP_TAG_JOB },
+ { 0, "job-accounting-user-id-default", IPP_TAG_NAME, IPP_TAG_PRINTER },
+ { 0, "job-authorization-uri", IPP_TAG_URI, IPP_TAG_OPERATION },
+ { 0, "job-cancel-after", IPP_TAG_INTEGER, IPP_TAG_JOB },
+ { 0, "job-cancel-after-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "job-hold-until", IPP_TAG_KEYWORD, IPP_TAG_JOB },
+ { 0, "job-id", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-impressions", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-impressions-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
{ 0, "job-k-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "job-k-octets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-k-octets-completed",IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-media-sheets", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-media-sheets-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
{ 0, "job-page-limit", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+ { 0, "job-password", IPP_TAG_STRING, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ ipp_job_creation },
+ { 0, "job-password-encryption", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ ipp_job_creation },
{ 0, "job-priority", 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-state", IPP_TAG_ENUM, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-state-message", IPP_TAG_TEXT, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "job-state-reasons", IPP_TAG_KEYWORD, IPP_TAG_ZERO }, /* never send as option */
{ 0, "job-uuid", IPP_TAG_URI, IPP_TAG_JOB },
{ 0, "landscape", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 1, "marker-change-time", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
{ 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, "ppd-device-id", IPP_TAG_TEXT, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-make", IPP_TAG_TEXT, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-make-and-model", IPP_TAG_TEXT, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-model-number", IPP_TAG_INTEGER, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-name", IPP_TAG_NAME, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_ppd_name },
+ { 0, "ppd-natural-language", IPP_TAG_LANGUAGE, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-product", IPP_TAG_TEXT, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-psversion", IPP_TAG_TEXT, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
+ { 0, "ppd-type", IPP_TAG_KEYWORD, IPP_TAG_OPERATION,
+ IPP_TAG_ZERO,
+ cups_get_ppds },
{ 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, "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-geo-location", IPP_TAG_URI, 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-is-shared", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "sides", IPP_TAG_KEYWORD, IPP_TAG_JOB,
IPP_TAG_DOCUMENT },
{ 0, "sides-default", IPP_TAG_KEYWORD, IPP_TAG_PRINTER },
+ { 0, "time-at-completed", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "time-at-creation", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
+ { 0, "time-at-processing", IPP_TAG_INTEGER, IPP_TAG_ZERO }, /* never send as option */
{ 0, "wrap", IPP_TAG_BOOLEAN, IPP_TAG_JOB },
{ 0, "wrap-default", IPP_TAG_BOOLEAN, IPP_TAG_PRINTER },
{ 0, "x-dimension", IPP_TAG_INTEGER, IPP_TAG_JOB,
cups_option_t *options, /* I - Options */
ipp_tag_t group_tag) /* I - Group to encode */
{
- int i, j; /* Looping vars */
- int count; /* Number of values */
- char *s, /* Pointer into option value */
- *val, /* Pointer to option value */
- *copy, /* Copy of option value */
- *sep, /* Option separator */
- quote; /* Quote character */
- 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)", ipp, num_options, options, group_tag));
+ int i, j; /* Looping vars */
+ int count; /* Number of values */
+ char *s, /* Pointer into option value */
+ *val, /* Pointer to option value */
+ *copy, /* Copy of option value */
+ *sep, /* Option separator */
+ quote; /* Quote character */
+ 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 */
+ ipp_op_t op; /* Operation for this request */
+ const ipp_op_t *ops; /* List of allowed operations */
+
+
+ DEBUG_printf(("cupsEncodeOptions2(ipp=%p(%s), num_options=%d, options=%p, "
+ "group_tag=%x)", ipp,
+ ipp ? ippOpString(ippGetOperation(ipp)) : "", num_options,
+ options, group_tag));
/*
* Range check input...
* Do special handling for the document-format/raw options...
*/
- if (group_tag == IPP_TAG_OPERATION)
+ op = ippGetOperation(ipp);
+
+ 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))
{
/*
* Handle the document format stuff first...
*/
- if ((val = (char *)cupsGetOption("document-format", num_options, options)) != NULL)
+ if ((val = (char *)cupsGetOption("document-format", num_options,
+ options)) != NULL)
ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
NULL, val);
else if (cupsGetOption("raw", num_options, options))
continue;
value_tag = match->value_tag;
+
+ if (match->operations)
+ ops = match->operations;
+ else if (group_tag == IPP_TAG_JOB)
+ ops = ipp_job_creation;
+ else if (group_tag == IPP_TAG_DOCUMENT)
+ ops = ipp_doc_creation;
+ else if (group_tag == IPP_TAG_SUBSCRIPTION)
+ ops = ipp_sub_creation;
+ else if (group_tag == IPP_TAG_PRINTER)
+ ops = ipp_set_printer;
+ else
+ {
+ DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
+ continue;
+ }
}
else
{
strcmp(option->name + namelen - 10, "-supported")))
{
if (group_tag != IPP_TAG_JOB && group_tag != IPP_TAG_DOCUMENT)
+ {
+ DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
continue;
+ }
}
else if (group_tag != IPP_TAG_PRINTER)
+ {
+ DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
continue;
+ }
+
+ if (group_tag == IPP_TAG_JOB)
+ ops = ipp_job_creation;
+ else if (group_tag == IPP_TAG_DOCUMENT)
+ ops = ipp_doc_creation;
+ else
+ ops = ipp_set_printer;
if (!_cups_strcasecmp(option->value, "true") ||
!_cups_strcasecmp(option->value, "false"))
value_tag = IPP_TAG_NAME;
}
+ /*
+ * Verify that we send this attribute for this operation...
+ */
+
+ while (*ops != IPP_OP_CUPS_NONE)
+ if (op == *ops)
+ break;
+ else
+ ops ++;
+
+ if (*ops == IPP_OP_CUPS_NONE && op != IPP_OP_CUPS_NONE)
+ {
+ DEBUG_printf(("2cupsEncodeOptions2: Skipping \"%s\".", option->name));
+ continue;
+ }
+
/*
* Count the number of values...
*/
* Integer/enumeration value...
*/
- attr->values[j].integer = strtol(val, &s, 10);
+ attr->values[j].integer = (int)strtol(val, &s, 10);
DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
"%d...", attr->values[j].integer));
s = val;
}
else
- attr->values[j].range.lower = strtol(val, &s, 10);
+ attr->values[j].range.lower = (int)strtol(val, &s, 10);
if (*s == '-')
{
if (s[1])
- attr->values[j].range.upper = strtol(s + 1, NULL, 10);
+ attr->values[j].range.upper = (int)strtol(s + 1, NULL, 10);
else
attr->values[j].range.upper = 2147483647;
}
* Resolution...
*/
- attr->values[j].resolution.xres = strtol(val, &s, 10);
+ attr->values[j].resolution.xres = (int)strtol(val, &s, 10);
if (*s == 'x')
- attr->values[j].resolution.yres = strtol(s + 1, &s, 10);
+ attr->values[j].resolution.yres = (int)strtol(s + 1, &s, 10);
else
attr->values[j].resolution.yres = attr->values[j].resolution.xres;
}
+#ifdef DEBUG
+/*
+ * '_ippCheckOptions()' - Validate that the option array is sorted properly.
+ */
+
+const char * /* O - First out-of-order option or NULL */
+_ippCheckOptions(void)
+{
+ int i; /* Looping var */
+
+
+ for (i = 0; i < (int)(sizeof(ipp_options) / sizeof(ipp_options[0]) - 1); i ++)
+ if (strcmp(ipp_options[i].name, ipp_options[i + 1].name) >= 0)
+ return (ipp_options[i + 1].name);
+
+ return (NULL);
+}
+#endif /* DEBUG */
+
+
/*
* '_ippFindOption()' - Find the attribute information for an option.
*/
/*
- * End of "$Id: encode.c 7696 2008-06-26 00:54:42Z mike $".
+ * End of "$Id$".
*/