]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/encode.c
Add missing files for test.
[thirdparty/cups.git] / cups / encode.c
index 071b29ea17d5062dec4bddf8833d879d06d3e602..506b87f0f9e7cf3ac5461efbb2fab68922b20aad 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: encode.c 5128 2006-02-17 18:59:03Z mike $"
+ * "$Id: encode.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   Option encoding routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products.
+ *   Copyright 2007 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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.
  *
@@ -28,6 +19,7 @@
  *   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 LIST MUST BE SORTED ****
  */
 
-typedef struct
-{
-  const char   *name;
-  ipp_tag_t    value_tag;
-  ipp_tag_t    group_tag;
-} _ipp_option_t;
-
 static const _ipp_option_t ipp_options[] =
 {
-  { "blackplot",               IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
-  { "brightness",              IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "columns",                 IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "copies",                  IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "document-format",         IPP_TAG_MIMETYPE,       IPP_TAG_OPERATION },
-  { "finishings",              IPP_TAG_ENUM,           IPP_TAG_JOB },
-  { "fitplot",                 IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
-  { "gamma",                   IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "hue",                     IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "job-k-limit",             IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "job-page-limit",          IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "job-priority",            IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "job-quota-period",                IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "job-uuid",                        IPP_TAG_URI,            IPP_TAG_JOB },
-  { "landscape",               IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
-  { "media",                   IPP_TAG_KEYWORD,        IPP_TAG_JOB },
-  { "mirror",                  IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
-  { "natural-scaling",         IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "notify-charset",          IPP_TAG_CHARSET,        IPP_TAG_SUBSCRIPTION },
-  { "notify-events",           IPP_TAG_KEYWORD,        IPP_TAG_SUBSCRIPTION },
-  { "notify-lease-time",       IPP_TAG_INTEGER,        IPP_TAG_SUBSCRIPTION },
-  { "notify-natural-language", IPP_TAG_LANGUAGE,       IPP_TAG_SUBSCRIPTION },
-  { "notify-pull-method",      IPP_TAG_KEYWORD,        IPP_TAG_SUBSCRIPTION },
-  { "notify-recipient",                IPP_TAG_URI,            IPP_TAG_SUBSCRIPTION },
-  { "notify-time-interval",    IPP_TAG_INTEGER,        IPP_TAG_SUBSCRIPTION },
-  { "notify-user-data",                IPP_TAG_STRING,         IPP_TAG_SUBSCRIPTION },
-  { "number-up",               IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "orientation-requested",   IPP_TAG_ENUM,           IPP_TAG_JOB },
-  { "page-bottom",             IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "page-left",               IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "page-ranges",             IPP_TAG_RANGE,          IPP_TAG_JOB },
-  { "page-right",              IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "page-top",                        IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "penwidth",                        IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "ppi",                     IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "prettyprint",             IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
-  { "printer-info",            IPP_TAG_TEXT,           IPP_TAG_PRINTER },
-  { "printer-is-accepting-jobs",IPP_TAG_BOOLEAN,       IPP_TAG_PRINTER },
-  { "printer-is-shared",       IPP_TAG_BOOLEAN,        IPP_TAG_PRINTER },
-  { "printer-make-and-model",  IPP_TAG_TEXT,           IPP_TAG_PRINTER },
-  { "printer-more-info",       IPP_TAG_URI,            IPP_TAG_PRINTER },
-  { "printer-resolution",      IPP_TAG_RESOLUTION,     IPP_TAG_JOB },
-  { "printer-state",           IPP_TAG_ENUM,           IPP_TAG_PRINTER },
-  { "printer-state-change-time",IPP_TAG_INTEGER,       IPP_TAG_PRINTER },
-  { "printer-state-reasons",   IPP_TAG_KEYWORD,        IPP_TAG_PRINTER },
-  { "printer-type",            IPP_TAG_ENUM,           IPP_TAG_PRINTER },
-  { "printer-uri",             IPP_TAG_URI,            IPP_TAG_OPERATION },
-  { "print-quality",           IPP_TAG_ENUM,           IPP_TAG_JOB },
-  { "queued-job-count",                IPP_TAG_INTEGER,        IPP_TAG_PRINTER },
-  { "raw",                     IPP_TAG_MIMETYPE,       IPP_TAG_OPERATION },
-  { "saturation",              IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "scaling",                 IPP_TAG_INTEGER,        IPP_TAG_JOB },
-  { "sides",                   IPP_TAG_KEYWORD,        IPP_TAG_JOB },
-  { "wrap",                    IPP_TAG_BOOLEAN,        IPP_TAG_JOB }
+  { 1, "auth-info",            IPP_TAG_TEXT,           IPP_TAG_JOB },
+  { 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",           IPP_TAG_INTEGER,        IPP_TAG_JOB },
+  { 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, "copies-default",       IPP_TAG_INTEGER,        IPP_TAG_PRINTER },
+  { 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, "finishings-default",   IPP_TAG_ENUM,           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 },
+  { 0, "job-priority",         IPP_TAG_INTEGER,        IPP_TAG_JOB },
+  { 0, "job-quota-period",     IPP_TAG_INTEGER,        IPP_TAG_JOB },
+  { 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 },
+  { 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, "natural-scaling-default", IPP_TAG_INTEGER,     IPP_TAG_PRINTER },
+  { 0, "notify-charset",       IPP_TAG_CHARSET,        IPP_TAG_SUBSCRIPTION },
+  { 1, "notify-events",                IPP_TAG_KEYWORD,        IPP_TAG_SUBSCRIPTION },
+  { 1, "notify-events-default",        IPP_TAG_KEYWORD,        IPP_TAG_PRINTER },
+  { 0, "notify-lease-duration",        IPP_TAG_INTEGER,        IPP_TAG_SUBSCRIPTION },
+  { 0, "notify-lease-duration-default", IPP_TAG_INTEGER, IPP_TAG_PRINTER },
+  { 0, "notify-natural-language", IPP_TAG_LANGUAGE,    IPP_TAG_SUBSCRIPTION },
+  { 0, "notify-pull-method",   IPP_TAG_KEYWORD,        IPP_TAG_SUBSCRIPTION },
+  { 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-default",    IPP_TAG_INTEGER,        IPP_TAG_PRINTER },
+  { 0, "orientation-requested",        IPP_TAG_ENUM,           IPP_TAG_JOB },
+  { 0, "orientation-requested-default", IPP_TAG_ENUM,  IPP_TAG_PRINTER },
+  { 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-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 },
+  { 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, "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-default",        IPP_TAG_ENUM,           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-is-shared",    IPP_TAG_BOOLEAN,        IPP_TAG_PRINTER },
+  { 0, "printer-location",     IPP_TAG_TEXT,           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-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 },
+  { 0, "queued-job-count",     IPP_TAG_INTEGER,        IPP_TAG_PRINTER },
+  { 0, "raw",                  IPP_TAG_MIMETYPE,       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, "resolution-default",   IPP_TAG_RESOLUTION,     IPP_TAG_PRINTER },
+  { 0, "saturation",           IPP_TAG_INTEGER,        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-default",                IPP_TAG_KEYWORD,        IPP_TAG_PRINTER },
+  { 0, "wrap",                 IPP_TAG_BOOLEAN,        IPP_TAG_JOB },
+  { 0, "wrap-default",         IPP_TAG_BOOLEAN,        IPP_TAG_PRINTER }
 };
 
 
@@ -169,19 +192,21 @@ cupsEncodeOptions2(
   char         *s,                     /* Pointer into option value */
                *val,                   /* Pointer to option value */
                *copy,                  /* Copy of option value */
-               *sep;                   /* Option separator */
+               *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 */
 
 
-  DEBUG_printf(("cupsEncodeOptions2(ipp=%p, num_options=%d, options=%p, group_tag=%x)\n",
-                ipp, num_options, options, group_tag));
+  DEBUG_printf(("cupsEncodeOptions2(ipp=%p, num_options=%d, options=%p, "
+                "group_tag=%x)\n", ipp, num_options, options, group_tag));
 
  /*
   * Range check input...
   */
 
-  if (ipp == NULL || num_options < 1 || options == NULL)
+  if (!ipp || num_options < 1 || !options)
     return;
 
  /*
@@ -209,97 +234,88 @@ cupsEncodeOptions2(
   * Then loop through the options...
   */
 
-  for (i = 0; i < num_options; i ++)
+  for (i = num_options, option = options; i > 0; i --, option ++)
   {
-    _ipp_option_t      key,            /* Search key */
-                       *match;         /* Matching attribute */
+    _ipp_option_t      *match;         /* Matching attribute */
 
 
    /*
     * Skip document format options that are handled above...
     */
 
-    if (!strcasecmp(options[i].name, "raw") ||
-        !strcasecmp(options[i].name, "document-format") ||
-       !options[i].name[0])
+    if (!strcasecmp(option->name, "raw") ||
+        !strcasecmp(option->name, "document-format") ||
+       !option->name[0])
       continue;
 
    /*
     * Figure out the proper value and group tags for this option...
     */
 
-    key.name = options[i].name;
-    match    = (_ipp_option_t *)bsearch(&key, ipp_options,
-                                        sizeof(ipp_options) /
-                                           sizeof(ipp_options[0]),
-                                       sizeof(ipp_options[0]),
-                                       (int (*)(const void *,
-                                                const void *))
-                                           compare_ipp_options);
-
-    if (match)
+    if ((match = _ippFindOption(option->name)) != NULL)
     {
       if (match->group_tag != group_tag)
         continue;
 
       value_tag = match->value_tag;
     }
-    else if (group_tag != IPP_TAG_JOB)
-      continue;
-    else if (!strcasecmp(options[i].value, "true") ||
-             !strcasecmp(options[i].value, "false"))
-      value_tag = IPP_TAG_BOOLEAN;
     else
-      value_tag = IPP_TAG_NAME;
-
-   /*
-    * Count the number of values...
-    */
-
-    for (count = 1, sep = options[i].value; *sep; sep ++)
     {
-      if (*sep == '\'')
-      {
-       /*
-        * Skip quoted option value...
-       */
+      int      namelen;                /* Length of name */
 
-        sep ++;
 
-        while (*sep && *sep != '\'')
-         sep ++;
+      namelen = (int)strlen(option->name);
 
-       if (!*sep)
-         sep --;
-      }
-      else if (*sep == '\"')
+      if (namelen < 9 || strcmp(option->name + namelen - 8, "-default"))
       {
-       /*
-        * Skip quoted option value...
-       */
+       if (group_tag != IPP_TAG_JOB)
+          continue;
+      }
+      else if (group_tag != IPP_TAG_PRINTER)
+        continue;
+
+      if (!strcasecmp(option->value, "true") ||
+          !strcasecmp(option->value, "false"))
+       value_tag = IPP_TAG_BOOLEAN;
+      else
+       value_tag = IPP_TAG_NAME;
+    }
 
-        sep ++;
+   /*
+    * Count the number of values...
+    */
 
-        while (*sep && *sep != '\"')
+    if (match && match->multivalue)
+    {
+      for (count = 1, sep = option->value, quote = 0; *sep; sep ++)
+      {
+       if (*sep == quote)
+         quote = 0;
+       else if (!quote && (*sep == '\'' || *sep == '\"'))
+       {
+        /*
+         * Skip quoted option value...
+         */
+
+         quote = *sep++;
+       }
+       else if (*sep == ',' && !quote)
+         count ++;
+       else if (*sep == '\\' && sep[1])
          sep ++;
-
-       if (!*sep)
-         sep --;
       }
-      else if (*sep == ',')
-        count ++;
-      else if (*sep == '\\' && sep[1])
-        sep ++;
     }
+    else
+      count = 1;
 
     DEBUG_printf(("cupsEncodeOptions2: option = \'%s\', count = %d\n",
-                  options[i].name, count));
+                  option->name, count));
 
    /*
     * Allocate memory for the attribute values...
     */
 
-    if ((attr = _ipp_add_attr(ipp, count)) == NULL)
+    if ((attr = _ippAddAttr(ipp, count)) == NULL)
     {
      /*
       * Ran out of memory!
@@ -320,7 +336,7 @@ cupsEncodeOptions2(
     * Copy the name over...
     */
 
-    if ((attr->name = strdup(options[i].name)) == NULL)
+    if ((attr->name = _cupsStrAlloc(option->name)) == NULL)
     {
      /*
       * Ran out of memory!
@@ -336,7 +352,7 @@ cupsEncodeOptions2(
       * Make a copy of the value we can fiddle with...
       */
 
-      if ((copy = strdup(options[i].value)) == NULL)
+      if ((copy = strdup(option->value)) == NULL)
       {
        /*
        * Ran out of memory!
@@ -354,7 +370,7 @@ cupsEncodeOptions2(
       * Since we have a single value, use the value directly...
       */
 
-      val  = options[i].value;
+      val  = option->value;
       copy = NULL;
     }
 
@@ -362,16 +378,47 @@ cupsEncodeOptions2(
     * Scan the value string for values...
     */
 
-    for (j = 0; j < count; val = sep, j ++)
+    for (j = 0, sep = val; j < count; val = sep, j ++)
     {
      /*
       * Find the end of this value and mark it if needed...
       */
 
-      if ((sep = strchr(val, ',')) != NULL)
-       *sep++ = '\0';
-      else
-       sep = val + strlen(val);
+      if (count > 1)
+      {
+       for (quote = 0; *sep; sep ++)
+       {
+         if (*sep == quote)
+         {
+          /*
+           * Finish quoted value...
+           */
+
+           quote = 0;
+         }
+         else if (!quote && (*sep == '\'' || *sep == '\"'))
+         {
+          /*
+           * Handle quoted option value...
+           */
+
+           quote = *sep;
+         }
+         else if (*sep == ',' && count > 1)
+           break;
+         else if (*sep == '\\' && sep[1])
+         {
+          /*
+           * Skip quoted character...
+           */
+
+           sep ++;
+         }
+       }
+
+       if (*sep == ',')
+         *sep++ = '\0';
+      }
 
      /*
       * Copy the option value(s) over as needed by the type...
@@ -385,7 +432,7 @@ cupsEncodeOptions2(
            * Integer/enumeration value...
            */
 
-            attr->values[j].integer = strtol(val, &s, 0);
+            attr->values[j].integer = strtol(val, &s, 10);
 
             DEBUG_printf(("cupsEncodeOptions2: Added integer option value %d...\n",
                          attr->values[j].integer));
@@ -427,12 +474,12 @@ cupsEncodeOptions2(
              s = val;
            }
            else
-             attr->values[j].range.lower = strtol(val, &s, 0);
+             attr->values[j].range.lower = strtol(val, &s, 10);
 
            if (*s == '-')
            {
              if (s[1])
-               attr->values[j].range.upper = strtol(s + 1, NULL, 0);
+               attr->values[j].range.upper = strtol(s + 1, NULL, 10);
              else
                attr->values[j].range.upper = 2147483647;
             }
@@ -449,14 +496,14 @@ cupsEncodeOptions2(
            * Resolution...
            */
 
-           attr->values[j].resolution.xres = strtol(val, &s, 0);
+           attr->values[j].resolution.xres = strtol(val, &s, 10);
 
            if (*s == 'x')
-             attr->values[j].resolution.yres = strtol(s + 1, &s, 0);
+             attr->values[j].resolution.yres = strtol(s + 1, &s, 10);
            else
              attr->values[j].resolution.yres = attr->values[j].resolution.xres;
 
-           if (strcasecmp(s, "dpc") == 0)
+           if (!strcasecmp(s, "dpc"))
               attr->values[j].resolution.units = IPP_RES_PER_CM;
             else
               attr->values[j].resolution.units = IPP_RES_PER_INCH;
@@ -470,7 +517,7 @@ cupsEncodeOptions2(
            * octet-string
            */
 
-            attr->values[j].unknown.length = strlen(val);
+            attr->values[j].unknown.length = (int)strlen(val);
            attr->values[j].unknown.data   = strdup(val);
 
             DEBUG_printf(("cupsEncodeOptions2: Added octet-string value \"%s\"...\n",
@@ -478,7 +525,7 @@ cupsEncodeOptions2(
             break;
 
        default :
-            if ((attr->values[j].string.text = strdup(val)) == NULL)
+            if ((attr->values[j].string.text = _cupsStrAlloc(val)) == NULL)
            {
             /*
              * Ran out of memory!
@@ -493,10 +540,37 @@ cupsEncodeOptions2(
             break;
       }
     }
+
+    if (copy)
+      free(copy);
   }
 }
 
 
+/*
+ * '_ippFindOption()' - Find the attribute information for an option.
+ */
+
+_ipp_option_t *                                /* O - Attribute information */
+_ippFindOption(const char *name)       /* I - Option/attribute name */
+{
+  _ipp_option_t        key;                    /* Search key */
+
+
+ /*
+  * Lookup the proper value and group tags for this option...
+  */
+
+  key.name = name;
+
+  return ((_ipp_option_t *)bsearch(&key, ipp_options,
+                                   sizeof(ipp_options) / sizeof(ipp_options[0]),
+                                  sizeof(ipp_options[0]),
+                                  (int (*)(const void *, const void *))
+                                      compare_ipp_options));
+}
+
+
 /*
  * 'compare_ipp_options()' - Compare two IPP options.
  */
@@ -510,5 +584,5 @@ compare_ipp_options(_ipp_option_t *a,       /* I - First option */
 
 
 /*
- * End of "$Id: encode.c 5128 2006-02-17 18:59:03Z mike $".
+ * End of "$Id: encode.c 6649 2007-07-11 21:46:42Z mike $".
  */