- /*
- * Count the number of values...
- */
-
- 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 ++;
- }
- }
- else
- count = 1;
-
- DEBUG_printf(("2cupsEncodeOptions2: option=\"%s\", count=%d",
- option->name, count));
-
- /*
- * Allocate memory for the attribute values...
- */
-
- if ((attr = ippAddStrings(ipp, group_tag, value_tag, option->name, count,
- NULL, NULL)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for attributes!");
- return;
- }
-
- if (count > 1)
- {
- /*
- * Make a copy of the value we can fiddle with...
- */
-
- if ((copy = strdup(option->value)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for value copy!");
- ippDeleteAttribute(ipp, attr);
- return;
- }
-
- val = copy;
- }
- else
- {
- /*
- * Since we have a single value, use the value directly...
- */
-
- val = option->value;
- copy = NULL;
- }
-
- /*
- * Scan the value string for values...
- */
-
- for (j = 0, sep = val; j < count; val = sep, j ++)
- {
- /*
- * Find the end of this value and mark it if needed...
- */
-
- 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...
- */
-
- switch (attr->value_tag)
- {
- case IPP_TAG_INTEGER :
- case IPP_TAG_ENUM :
- /*
- * Integer/enumeration value...
- */
-
- attr->values[j].integer = (int)strtol(val, &s, 10);
-
- DEBUG_printf(("2cupsEncodeOptions2: Added integer option value "
- "%d...", attr->values[j].integer));
- break;
-
- case IPP_TAG_BOOLEAN :
- if (!_cups_strcasecmp(val, "true") ||
- !_cups_strcasecmp(val, "on") ||
- !_cups_strcasecmp(val, "yes"))
- {
- /*
- * Boolean value - true...
- */
-
- attr->values[j].boolean = 1;
-
- DEBUG_puts("2cupsEncodeOptions2: Added boolean true value...");
- }
- else
- {
- /*
- * Boolean value - false...
- */
-
- attr->values[j].boolean = 0;
-
- DEBUG_puts("2cupsEncodeOptions2: Added boolean false value...");
- }
- break;
-
- case IPP_TAG_RANGE :
- /*
- * Range...
- */
-
- if (*val == '-')
- {
- attr->values[j].range.lower = 1;
- s = val;
- }
- else
- attr->values[j].range.lower = (int)strtol(val, &s, 10);
-
- if (*s == '-')
- {
- if (s[1])
- attr->values[j].range.upper = (int)strtol(s + 1, NULL, 10);
- else
- attr->values[j].range.upper = 2147483647;
- }
- else
- attr->values[j].range.upper = 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;
-
- case IPP_TAG_RESOLUTION :
- /*
- * Resolution...
- */
-
- attr->values[j].resolution.xres = (int)strtol(val, &s, 10);
-
- if (*s == 'x')
- attr->values[j].resolution.yres = (int)strtol(s + 1, &s, 10);
- else
- attr->values[j].resolution.yres = attr->values[j].resolution.xres;
-
- 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(("2cupsEncodeOptions2: Added resolution option value "
- "%s...", val));
- break;
-
- case IPP_TAG_STRING :
- /*
- * octet-string
- */
-
- attr->values[j].unknown.length = (int)strlen(val);
- attr->values[j].unknown.data = strdup(val);
-
- 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)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("1cupsEncodeOptions2: Ran out of memory for string!");
-
- if (copy)
- free(copy);
-
- ippDeleteAttribute(ipp, attr);
- return;
- }
-
- DEBUG_printf(("2cupsEncodeOptions2: Added string value \"%s\"...",
- val));
- break;
- }
- }
-
- if (copy)
- free(copy);