/*
* ipptool command for CUPS.
*
- * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
if (*dataptr < 0x20 || *dataptr >= 0x7f)
break;
- if (*dataptr)
+ if (dataptr < dataend)
{
/*
* Yes, encode as hex...
{
_cupsLangPuts(stderr, _("Usage: ipptool [options] URI filename [ ... filenameN ]"));
_cupsLangPuts(stderr, _("Options:"));
- _cupsLangPuts(stderr, _(" --help Show help."));
- _cupsLangPuts(stderr, _(" --ippserver filename Produce ippserver attribute file."));
- _cupsLangPuts(stderr, _(" --stop-after-include-error\n"
- " Stop tests after a failed INCLUDE."));
- _cupsLangPuts(stderr, _(" --version Show version."));
- _cupsLangPuts(stderr, _(" -4 Connect using IPv4."));
- _cupsLangPuts(stderr, _(" -6 Connect using IPv6."));
- _cupsLangPuts(stderr, _(" -C Send requests using "
- "chunking (default)."));
- _cupsLangPuts(stderr, _(" -E Test with encryption using HTTP Upgrade to TLS."));
- _cupsLangPuts(stderr, _(" -I Ignore errors."));
- _cupsLangPuts(stderr, _(" -L Send requests using content-length."));
- _cupsLangPuts(stderr, _(" -P filename.plist Produce XML plist to a file and test report to standard output."));
- _cupsLangPuts(stderr, _(" -S Test with encryption using HTTPS."));
- _cupsLangPuts(stderr, _(" -T seconds Set the receive/send timeout in seconds."));
- _cupsLangPuts(stderr, _(" -V version Set default IPP version."));
- _cupsLangPuts(stderr, _(" -X Produce XML plist instead of plain text."));
- _cupsLangPuts(stderr, _(" -c Produce CSV output."));
- _cupsLangPuts(stderr, _(" -d name=value Set named variable to value."));
- _cupsLangPuts(stderr, _(" -f filename Set default request filename."));
- _cupsLangPuts(stderr, _(" -h Validate HTTP response headers."));
- _cupsLangPuts(stderr, _(" -i seconds Repeat the last file with the given time interval."));
- _cupsLangPuts(stderr, _(" -l Produce plain text output."));
- _cupsLangPuts(stderr, _(" -n count Repeat the last file the given number of times."));
- _cupsLangPuts(stderr, _(" -q Run silently."));
- _cupsLangPuts(stderr, _(" -t Produce a test report."));
- _cupsLangPuts(stderr, _(" -v Be verbose."));
+ _cupsLangPuts(stderr, _("--ippserver filename Produce ippserver attribute file"));
+ _cupsLangPuts(stderr, _("--stop-after-include-error\n"
+ " Stop tests after a failed INCLUDE"));
+ _cupsLangPuts(stderr, _("--version Show version"));
+ _cupsLangPuts(stderr, _("-4 Connect using IPv4"));
+ _cupsLangPuts(stderr, _("-6 Connect using IPv6"));
+ _cupsLangPuts(stderr, _("-C Send requests using chunking (default)"));
+ _cupsLangPuts(stderr, _("-E Test with encryption using HTTP Upgrade to TLS"));
+ _cupsLangPuts(stderr, _("-I Ignore errors"));
+ _cupsLangPuts(stderr, _("-L Send requests using content-length"));
+ _cupsLangPuts(stderr, _("-P filename.plist Produce XML plist to a file and test report to standard output"));
+ _cupsLangPuts(stderr, _("-S Test with encryption using HTTPS"));
+ _cupsLangPuts(stderr, _("-T seconds Set the receive/send timeout in seconds"));
+ _cupsLangPuts(stderr, _("-V version Set default IPP version"));
+ _cupsLangPuts(stderr, _("-X Produce XML plist instead of plain text"));
+ _cupsLangPuts(stderr, _("-c Produce CSV output"));
+ _cupsLangPuts(stderr, _("-d name=value Set named variable to value"));
+ _cupsLangPuts(stderr, _("-f filename Set default request filename"));
+ _cupsLangPuts(stderr, _("-h Validate HTTP response headers"));
+ _cupsLangPuts(stderr, _("-i seconds Repeat the last file with the given time interval"));
+ _cupsLangPuts(stderr, _("-l Produce plain text output"));
+ _cupsLangPuts(stderr, _("-n count Repeat the last file the given number of times"));
+ _cupsLangPuts(stderr, _("-q Run silently"));
+ _cupsLangPuts(stderr, _("-t Produce a test report"));
+ _cupsLangPuts(stderr, _("-v Be verbose"));
exit(1);
}
case IPP_TAG_BOOLEAN :
for (i = 0; i < count; i ++)
{
- if ((!strcmp(value, "true")) == ippGetBoolean(attr, i))
+ if ((!strcmp(value, "true") || !strcmp(value, "1")) == ippGetBoolean(attr, i))
{
if (!matchbuf[0])
strlcpy(matchbuf, value, matchlen);
break;
case IPP_TAG_STRING :
+ if (flags & _CUPS_WITH_REGEX)
+ {
+ /*
+ * Value is an extended, case-sensitive POSIX regular expression...
+ */
+
+ regex_t re; /* Regular expression */
+
+ if ((i = regcomp(&re, value, REG_EXTENDED | REG_NOSUB)) != 0)
+ {
+ regerror(i, &re, temp, sizeof(temp));
+
+ print_fatal_error(data, "Unable to compile WITH-VALUE regular expression \"%s\" - %s", value, temp);
+ return (0);
+ }
+
+ /*
+ * See if ALL of the values match the given regular expression.
+ */
+
+ for (i = 0; i < count; i ++)
+ {
+ void *data; /* Pointer to octetString data */
+ int datalen; /* Length of octetString */
+
+ if ((data = ippGetOctetString(attr, i, &datalen)) == NULL || datalen >= (int)sizeof(temp))
+ {
+ match = 0;
+ break;
+ }
+ memcpy(temp, data, (size_t)datalen);
+ temp[datalen] = '\0';
+
+ if (!regexec(&re, temp, 0, NULL, 0))
+ {
+ if (!matchbuf[0])
+ strlcpy(matchbuf, temp, matchlen);
+
+ if (!(flags & _CUPS_WITH_ALL))
+ {
+ match = 1;
+ break;
+ }
+ }
+ else if (flags & _CUPS_WITH_ALL)
+ {
+ match = 0;
+ break;
+ }
+ }
+
+ regfree(&re);
+
+ if (!match && errors)
+ {
+ for (i = 0; i < count; i ++)
+ {
+ int adatalen;
+ void *adata = ippGetOctetString(attr, i, &adatalen);
+
+ copy_hex_string(temp, adata, adatalen, sizeof(temp));
+ add_stringf(data->errors, "GOT: %s=\"%s\"", name, temp);
+ }
+ }
+ }
+ else
{
+ /*
+ * Value is a literal or hex-encoded string...
+ */
+
unsigned char withdata[1023], /* WITH-VALUE data */
*adata; /* Pointer to octetString data */
int withlen, /* Length of WITH-VALUE data */
if (withlen == adatalen && !memcmp(withdata, adata, (size_t)withlen))
{
if (!matchbuf[0])
- copy_hex_string(matchbuf, adata, adatalen, matchlen);
+ copy_hex_string(matchbuf, adata, adatalen, matchlen);
if (!(flags & _CUPS_WITH_ALL))
{