- var->name = strdup(name);
- var->value = strdup(value);
-
- cupsArrayAdd(vars->vars, var);
- }
-}
-
-
-/*
- * 'timeout_cb()' - Handle HTTP timeouts.
- */
-
-static int /* O - 1 to continue, 0 to cancel */
-timeout_cb(http_t *http, /* I - Connection to server (unused) */
- void *user_data) /* I - User data (unused) */
-{
- (void)http;
- (void)user_data;
-
- return (0);
-}
-
-
-/*
- * 'usage()' - Show program usage.
- */
-
-static void
-usage(void)
-{
- _cupsLangPuts(stderr, _("Usage: ipptool [options] URI filename [ ... "
- "filenameN ]"));
- _cupsLangPuts(stderr, _("Options:"));
- _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 TLS "
- "encryption."));
- _cupsLangPuts(stderr, _(" -I Ignore errors."));
- _cupsLangPuts(stderr, _(" -L Send requests using "
- "content-length."));
- _cupsLangPuts(stderr, _(" -S Test with SSL "
- "encryption."));
- _cupsLangPuts(stderr, _(" -T 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, _(" -d name=value Set named variable to "
- "value."));
- _cupsLangPuts(stderr, _(" -f filename Set default request "
- "filename."));
- _cupsLangPuts(stderr, _(" -i seconds Repeat the last file with "
- "the given time interval."));
- _cupsLangPuts(stderr, _(" -n count Repeat the last file the "
- "given number of times."));
- _cupsLangPuts(stderr, _(" -q Be quiet - no output "
- "except errors."));
- _cupsLangPuts(stderr, _(" -t Produce a test report."));
- _cupsLangPuts(stderr, _(" -v Show all attributes sent "
- "and received."));
-
- exit(1);
-}
-
-
-/*
- * 'validate_attr()' - Determine whether an attribute is valid.
- */
-
-static int /* O - 1 if valid, 0 otherwise */
-validate_attr(ipp_attribute_t *attr, /* I - Attribute to validate */
- int print) /* I - 1 = report issues to stdout */
-{
- int i; /* Looping var */
- char scheme[64], /* Scheme from URI */
- userpass[256], /* Username/password from URI */
- hostname[256], /* Hostname from URI */
- resource[1024]; /* Resource from URI */
- int port, /* Port number from URI */
- uri_status, /* URI separation status */
- valid = 1; /* Is the attribute valid? */
- const char *ptr; /* Pointer into string */
- ipp_attribute_t *colattr; /* Collection attribute */
- regex_t re; /* Regular expression */
- ipp_uchar_t *date; /* Current date value */
-
-
- /*
- * Skip separators.
- */
-
- if (!attr->name)
- return (1);
-
- /*
- * Validate the attribute name.
- */
-
- for (ptr = attr->name; *ptr; ptr ++)
- if (!isalnum(*ptr & 255) && *ptr != '-' && *ptr != '.' && *ptr != '_')
- break;
-
- if (*ptr || ptr == attr->name)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad attribute name - invalid character (RFC "
- "2911 section 4.1.3).", attr->name);
- }
-
- if ((ptr - attr->name) > 255)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad attribute name - bad length (RFC 2911 "
- "section 4.1.3).", attr->name);
- }
-
- switch (attr->value_tag)
- {
- case IPP_TAG_INTEGER :
- break;
-
- case IPP_TAG_BOOLEAN :
- for (i = 0; i < attr->num_values; i ++)
- {
- if (attr->values[i].boolean != 0 &&
- attr->values[i].boolean != 1)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad boolen value %d (RFC 2911 section "
- "4.1.10).", attr->name, attr->values[i].boolean);
- else
- break;
- }
- }
- break;
-
- case IPP_TAG_ENUM :
- for (i = 0; i < attr->num_values; i ++)
- {
- if (attr->values[i].integer < 1)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad enum value %d - out of range "
- "(RFC 2911 section 4.1.4).", attr->name,
- attr->values[i].integer);
- else
- break;
- }
- }
- break;
-
- case IPP_TAG_STRING :
- for (i = 0; i < attr->num_values; i ++)
- {
- if (attr->values[i].unknown.length > 1023)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad octetString value - bad length %d "
- "(RFC 2911 section 4.1.10).", attr->name,
- attr->values[i].unknown.length);
- else
- break;
- }
- }
- break;
-
- case IPP_TAG_DATE :
- for (i = 0; i < attr->num_values; i ++)
- {
- date = attr->values[i].date;
-
- if (date[2] < 1 || date[2] > 12)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad dateTime month %u (RFC 2911 "
- "section 4.1.13).", attr->name, date[2]);
- else
- break;
- }
-
- if (date[3] < 1 || date[3] > 31)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad dateTime day %u (RFC 2911 "
- "section 4.1.13).", attr->name, date[3]);
- else
- break;
- }
-
- if (date[4] > 23)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad dateTime hours %u (RFC 2911 "
- "section 4.1.13).", attr->name, date[4]);
- else
- break;
- }
-
- if (date[5] > 59)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad dateTime minutes %u (RFC 2911 "
- "section 4.1.13).", attr->name, date[5]);
- else
- break;
- }
-
- if (date[6] > 60)
- {
- valid = 0;
-
- if (print)
- print_test_error("\"%s\": Bad dateTime seconds %u (RFC 2911 "
- "section 4.1.13).", attr->name, date[6]);
- else
- break;
- }
-
- if (date[7] > 9)
- {
- valid = 0;