cups_file_t *outfile; /* Output file */
int show_header, /* Show the test header? */
xml_header; /* 1 if XML plist header was written */
- int test_count, /* Number of tests (total) */
+ int pass, /* Have we passed all tests? */
+ test_count, /* Number of tests (total) */
pass_count, /* Number of tests that passed */
fail_count, /* Number of tests that failed */
skip_count; /* Number of tests that were skipped */
/* Per-Test State */
cups_array_t *errors; /* Errors array */
- int pass, /* Did we pass the current test? */
- prev_pass, /* Did we pass the previous test? */
- skip_previous, /* Skip on previous test failure? */
- repeat_test; /* Repeat a test? */
+ int prev_pass, /* Result of previous test */
+ skip_previous; /* Skip on previous test failure? */
char compression[16]; /* COMPRESSION value */
useconds_t delay; /* Initial delay */
int num_displayed; /* Number of displayed attributes */
_cups_expect_t expects[200], /* Expected attributes */
*expect, /* Current expected attribute */
*last_expect; /* Last EXPECT (for predicates) */
- char file_id[1024], /* File identifier */
- filename[1024]; /* Data filename */
+ char file[1024], /* Data filename */
+ file_id[1024]; /* File identifier */
int ignore_errors; /* Ignore test failures? */
char name[1024]; /* Test name */
- int repeat_count; /* Repeat count */
useconds_t repeat_interval; /* Repeat interval (delay) */
int request_id; /* Current request ID */
char resource[512]; /* Resource for request */
static void add_stringf(cups_array_t *a, const char *s, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
static int compare_uris(const char *a, const char *b);
-static int do_test(_cups_testdata_t *data, _ipp_vars_t *vars, _ipp_file_t *f);
-static int do_tests(_cups_testdata_t *data, _ipp_vars_t *vars, const char *testfile);
+static int do_test(_ipp_file_t *f, _ipp_vars_t *vars, _cups_testdata_t *data);
+static int do_tests(const char *testfile, _ipp_vars_t *vars, _cups_testdata_t *data);
static int error_cb(_ipp_file_t *f, _cups_testdata_t *data, const char *error);
static int expect_matches(_cups_expect_t *expect, ipp_tag_t value_tag);
static char *get_filename(const char *testfile, char *dst, const char *src, size_t dstsize);
static void init_data(_cups_testdata_t *data);
static char *iso_date(const ipp_uchar_t *date);
static void pause_message(const char *message);
-static void print_attr(_cups_testdata_t *data, ipp_attribute_t *attr, ipp_tag_t *group);
+static void print_attr(cups_file_t *outfile, int output, ipp_attribute_t *attr, ipp_tag_t *group);
static void print_csv(_cups_testdata_t *data, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
static void print_fatal_error(_cups_testdata_t *data, const char *s, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
static void print_ippserver_attr(_cups_testdata_t *data, ipp_attribute_t *attr, int indent);
static void print_ippserver_string(_cups_testdata_t *data, const char *s, size_t len);
static void print_line(_cups_testdata_t *data, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
static void print_xml_header(_cups_testdata_t *data);
-static void print_xml_string(_cups_testdata_t *data, const char *element, const char *s);
+static void print_xml_string(cups_file_t *outfile, const char *element, const char *s);
static void print_xml_trailer(_cups_testdata_t *data, int success, const char *message);
#ifndef WIN32
static void sigterm_handler(int sig);
static int timeout_cb(http_t *http, void *user_data);
static int token_cb(_ipp_file_t *f, _ipp_vars_t *vars, _cups_testdata_t *data, const char *token);
static void usage(void) __attribute__((noreturn));
-static int validate_attr(cups_file_t *outfile, cups_array_t *errors, ipp_attribute_t *attr);
+static int validate_attr(_cups_testdata_t *data, cups_array_t *errors, ipp_attribute_t *attr);
static const char *with_flags_string(int flags);
-static int with_value(cups_file_t *outfile, cups_array_t *errors, char *value, int flags, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
+static int with_value(_cups_testdata_t *data, cups_array_t *errors, char *value, int flags, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
static int with_value_from(cups_array_t *errors, ipp_attribute_t *fromattr, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
name[1024], /* Name/value buffer */
*value, /* Pointer to value */
filename[1024], /* Real filename */
- testname[1024], /* Real test filename */
- uri[1024]; /* Copy of printer URI */
+ testname[1024]; /* Real test filename */
const char *ext, /* Extension on filename */
*testfile; /* Test file to use */
int interval, /* Test interval in microseconds */
repeat; /* Repeat count */
_cups_testdata_t data; /* Test data */
_ipp_vars_t vars; /* Variables */
- http_uri_status_t uri_status; /* URI separation status */
_cups_globals_t *cg = _cupsGlobals();
/* Global data */
}
else if (!strcmp(argv[i], "--stop-after-include-error"))
{
- StopAfterIncludeError = 1;
+ data.stop_after_include_error = 1;
}
else if (!strcmp(argv[i], "--version"))
{
#endif /* AF_INET6 */
case 'C' : /* Enable HTTP chunking */
- Transfer = _CUPS_TRANSFER_CHUNKED;
+ data.def_transfer = _CUPS_TRANSFER_CHUNKED;
break;
case 'E' : /* Encrypt with TLS */
break;
case 'I' : /* Ignore errors */
- IgnoreErrors = 1;
+ data.def_ignore_errors = 1;
break;
case 'L' : /* Disable HTTP chunking */
- Transfer = _CUPS_TRANSFER_LENGTH;
+ data.def_transfer = _CUPS_TRANSFER_LENGTH;
break;
case 'P' : /* Output to plist file */
}
if (!strcmp(argv[i], "1.0"))
- Version = 10;
+ {
+ data.def_version = 10;
+ }
else if (!strcmp(argv[i], "1.1"))
- Version = 11;
+ {
+ data.def_version = 11;
+ }
else if (!strcmp(argv[i], "2.0"))
- Version = 20;
+ {
+ data.def_version = 20;
+ }
else if (!strcmp(argv[i], "2.1"))
- Version = 21;
+ {
+ data.def_version = 21;
+ }
else if (!strcmp(argv[i], "2.2"))
- Version = 22;
+ {
+ data.def_version = 22;
+ }
else
{
- _cupsLangPrintf(stderr,
- _("%s: Bad version %s for \"-V\"."),
- "ipptool", argv[i]);
+ _cupsLangPrintf(stderr, _("%s: Bad version %s for \"-V\"."), "ipptool", argv[i]);
usage();
}
break;
usage();
}
- if (data.filename)
- {
- free(data.filename);
- data.filename = NULL;
- }
-
if (access(argv[i], 0))
{
/*
#endif /* WIN32 */
)
{
- snprintf(filename, sizeof(filename), "%s/ipptool/%s",
- cg->cups_datadir, argv[i]);
+ snprintf(filename, sizeof(filename), "%s/ipptool/%s", cg->cups_datadir, argv[i]);
if (access(filename, 0))
{
- snprintf(filename, sizeof(filename), "%s/ipptool/%s.gz",
- cg->cups_datadir, argv[i]);
+ snprintf(filename, sizeof(filename), "%s/ipptool/%s.gz", cg->cups_datadir, argv[i]);
if (access(filename, 0))
- data.filename = strdup(argv[i]);
- else
- data.filename = strdup(filename);
+ strlcpy(filename, argv[i], sizeof(filename));
}
- else
- data.filename = strdup(filename);
}
- else
- data.filename = strdup(filename);
}
else
- data.filename = strdup(argv[i]);
+ strlcpy(filename, argv[i], sizeof(filename));
+
+ _ippVarsSet(&vars, "filename", filename);
- if ((ext = strrchr(data.filename, '.')) != NULL)
+ if ((ext = strrchr(filename, '.')) != NULL)
{
/*
* Guess the MIME media type based on the extension...
break;
case 'h' : /* Validate response headers */
- ValidateHeaders = 1;
+ data.validate_headers = 1;
break;
case 'i' : /* Test every N seconds */
if (i >= argc)
{
- _cupsLangPuts(stderr,
- _("ipptool: Missing seconds for \"-i\"."));
+ _cupsLangPuts(stderr, _("ipptool: Missing seconds for \"-i\"."));
usage();
}
else
{
- interval = (int)(_cupsStrScand(argv[i], NULL, localeconv()) *
- 1000000.0);
+ interval = (int)(_cupsStrScand(argv[i], NULL, localeconv()) * 1000000.0);
if (interval <= 0)
{
- _cupsLangPuts(stderr,
- _("ipptool: Invalid seconds for \"-i\"."));
+ _cupsLangPuts(stderr, _("ipptool: Invalid seconds for \"-i\"."));
usage();
}
}
if (i >= argc)
{
- _cupsLangPuts(stderr,
- _("ipptool: Missing count for \"-n\"."));
+ _cupsLangPuts(stderr, _("ipptool: Missing count for \"-n\"."));
usage();
}
else
break;
case 'v' : /* Be verbose */
- Verbosity ++;
+ data.verbosity ++;
break;
default :
#endif /* WIN32 */
)
{
- snprintf(testname, sizeof(testname), "%s/ipptool/%s", cg->cups_datadir,
- argv[i]);
+ snprintf(testname, sizeof(testname), "%s/ipptool/%s", cg->cups_datadir, argv[i]);
if (access(testname, 0))
testfile = argv[i];
else
else
testfile = argv[i];
- if (!do_tests(&data, &vars, testfile))
+ if (!do_tests(testfile, &vars, &data))
status = 1;
}
}
*/
if (data.output == _CUPS_OUTPUT_PLIST)
- print_xml_trailer(data->outfile, !status, NULL);
+ print_xml_trailer(&data, !status, NULL);
else if (interval > 0 && repeat > 0)
{
while (repeat > 1)
{
usleep((useconds_t)interval);
- do_tests(data->outfile, &vars, testfile);
+ do_tests(testfile, &vars, &data);
repeat --;
}
}
for (;;)
{
usleep((useconds_t)interval);
- do_tests(data->outfile, &vars, testfile);
+ do_tests(testfile, &vars, &data);
}
}
- if ((Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile)) && TestCount > 1)
+ if ((data.output == _CUPS_OUTPUT_TEST || (data.output == _CUPS_OUTPUT_PLIST && data.outfile)) && data.test_count > 1)
{
/*
* Show a summary report if there were multiple tests...
*/
- cupsFilePrintf(cupsFileStdout(), "\nSummary: %d tests, %d passed, %d failed, %d skipped\nScore: %d%%\n", TestCount, PassCount, FailCount, SkipCount, 100 * (PassCount + SkipCount) / TestCount);
+ cupsFilePrintf(cupsFileStdout(), "\nSummary: %d tests, %d passed, %d failed, %d skipped\nScore: %d%%\n", data.test_count, data.pass_count, data.fail_count, data.skip_count, 100 * (data.pass_count + data.skip_count) / data.test_count);
}
- cupsFileClose(data->outfile);
+ cupsFileClose(data.outfile);
/*
* Exit...
*/
static int /* O - 1 on success, 0 on failure */
-do_test(_cups_testdata_t *data, /* I - Test data */
+do_test(_ipp_file_t *f, /* I - IPP data file */
_ipp_vars_t *vars, /* I - IPP variables */
- _ipp_file_t *f) /* I - IPP data file */
-{
- return (0);
-}
-
-
-/*
- * 'do_tests()' - Do tests as specified in the test file.
- */
+ _cups_testdata_t *data) /* I - Test data */
-static int /* O - 1 on success, 0 on failure */
-do_tests(_cups_testdata_t *data, /* I - Test data */
- _cups_vars_t *vars, /* I - Variables */
- const char *testfile) /* I - Test file to use */
{
- int i, /* Looping var */
- linenum, /* Current line number */
- pass, /* Did we pass the test? */
- prev_pass = 1, /* Did we pass the previous test? */
- request_id, /* Current request ID */
- show_header = 1, /* Show the test header? */
- ignore_errors, /* Ignore test failures? */
- skip_previous = 0, /* Skip on previous test failure? */
- repeat_count, /* Repeat count */
- repeat_test; /* Repeat a test? */
- useconds_t delay, /* Initial delay */
- repeat_interval; /* Repeat interval (delay) */
- http_t *http = NULL; /* HTTP connection to server */
- cups_file_t *fp = NULL; /* Test file */
- char resource[512], /* Resource for request */
- token[1024], /* Token from file */
- *tokenptr, /* Pointer into token */
- temp[1024], /* Temporary string */
- buffer[131072], /* Copy buffer */
- compression[16]; /* COMPRESSION value */
- ipp_t *request = NULL, /* IPP request */
- *response = NULL; /* IPP response */
+ int i, /* Looping var */
+ status_ok, /* Did we get a matching status? */
+ repeat_count = 0, /* Repeat count */
+ repeat_test; /* Repeat the test? */
+ _cups_expect_t *expect; /* Current expected attribute */
+ ipp_t *request, /* IPP request */
+ *response; /* IPP response */
size_t length; /* Length of IPP request */
http_status_t status; /* HTTP status */
- cups_file_t *reqfile; /* File to send */
- ssize_t bytes; /* Bytes read/written */
- char attr[128]; /* Attribute name */
- ipp_op_t op; /* Operation */
+ cups_array_t *a; /* Duplicate attribute array */
ipp_tag_t group; /* Current group */
- ipp_tag_t value; /* Current value type */
ipp_attribute_t *attrptr, /* Attribute pointer */
- *found, /* Found attribute */
- *lastcol = NULL; /* Last collection attribute */
- char name[1024], /* Name of test */
- file_id[1024], /* File identifier */
- test_id[1024]; /* Test identifier */
- char filename[1024]; /* Filename */
- _cups_transfer_t transfer; /* To chunk or not to chunk */
- int version, /* IPP version number to use */
- skip_test; /* Skip this test? */
- int num_statuses = 0; /* Number of valid status codes */
- _cups_status_t statuses[100], /* Valid status codes */
- *last_status; /* Last STATUS (for predicates) */
- int status_ok, /* Did we get a matching status? */
- num_expects = 0; /* Number of expected attributes */
- _cups_expect_t expects[200], /* Expected attributes */
- *expect, /* Current expected attribute */
- *last_expect; /* Last EXPECT (for predicates) */
- int num_displayed = 0; /* Number of displayed attributes */
- char *displayed[200]; /* Displayed attributes */
+ *found; /* Found attribute */
+ char temp[1024]; /* Temporary string */
+ cups_file_t *reqfile; /* File to send */
+ ssize_t bytes; /* Bytes read/written */
+ char buffer[131072]; /* Copy buffer */
size_t widths[200]; /* Width of columns */
- cups_array_t *a, /* Duplicate attribute array */
- *errors = NULL; /* Errors array */
const char *error; /* Current error */
+ if (Cancel)
+ return (0);
+
/*
- * Open the test file...
+ * Take over control of the attributes in the request...
*/
- if ((fp = cupsFileOpen(testfile, "r")) == NULL)
- {
- print_fatal_error(data, "Unable to open test file %s - %s", testfile,
- strerror(errno));
- pass = 0;
- goto test_exit;
- }
+ request = f->attrs;
+ f->attrs = NULL;
/*
- * Connect to the server...
+ * Submit the IPP request...
*/
- if ((http = httpConnect2(vars->hostname, vars->port, NULL, vars->family,
- vars->encryption, 1, 30000, NULL)) == NULL)
- {
- print_fatal_error(data, "Unable to connect to %s on port %d - %s", vars->hostname,
- vars->port, cupsLastErrorString());
- pass = 0;
- goto test_exit;
- }
+ data->test_count ++;
-#ifdef HAVE_LIBZ
- httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING,
- "deflate, gzip, identity");
-#else
- httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING, "identity");
-#endif /* HAVE_LIBZ */
+ ippSetVersion(request, data->version / 10, data->version % 10);
+ ippSetRequestId(request, data->request_id);
- if (vars->timeout > 0.0)
- httpSetTimeout(http, vars->timeout, timeout_cb, NULL);
+ if (data->output == _CUPS_OUTPUT_PLIST)
+ {
+ cupsFilePuts(data->outfile, "<dict>\n");
+ cupsFilePuts(data->outfile, "<key>Name</key>\n");
+ print_xml_string(data->outfile, "string", data->name);
+ if (data->file_id[0])
+ {
+ cupsFilePuts(data->outfile, "<key>FileId</key>\n");
+ print_xml_string(data->outfile, "string", data->file_id);
+ }
+ if (data->test_id[0])
+ {
+ cupsFilePuts(data->outfile, "<key>TestId</key>\n");
+ print_xml_string(data->outfile, "string", data->test_id);
+ }
+ cupsFilePuts(data->outfile, "<key>Version</key>\n");
+ cupsFilePrintf(data->outfile, "<string>%d.%d</string>\n", data->version / 10, data->version % 10);
+ cupsFilePuts(data->outfile, "<key>Operation</key>\n");
+ print_xml_string(data->outfile, "string", ippOpString(ippGetOperation(request)));
+ cupsFilePuts(data->outfile, "<key>RequestId</key>\n");
+ cupsFilePrintf(data->outfile, "<integer>%d</integer>\n", data->request_id);
+ cupsFilePuts(data->outfile, "<key>RequestAttributes</key>\n");
+ cupsFilePuts(data->outfile, "<array>\n");
+ if (request->attrs)
+ {
+ cupsFilePuts(data->outfile, "<dict>\n");
+ for (attrptr = ippFirstAttribute(request), group = ippGetGroupTag(attrptr); attrptr; attrptr = ippNextAttribute(request))
+ print_attr(data->outfile, data->output, attrptr, &group);
+ cupsFilePuts(data->outfile, "</dict>\n");
+ }
+ cupsFilePuts(data->outfile, "</array>\n");
+ }
- /*
- * Loop on tests...
- */
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
+ {
+ if (data->verbosity)
+ {
+ cupsFilePrintf(cupsFileStdout(), " %s:\n", ippOpString(ippGetOperation(request)));
- CUPS_SRAND((unsigned)time(NULL));
+ for (attrptr = ippFirstAttribute(request); attrptr; attrptr = ippNextAttribute(request))
+ print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
+ }
- errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup,
- (cups_afree_func_t)free);
- file_id[0] = '\0';
- pass = 1;
- linenum = 0;
- request_id = (CUPS_RAND() % 1000) * 137 + 1;
+ cupsFilePrintf(cupsFileStdout(), " %-68.68s [", data->name);
+ }
- while (!Cancel && get_token(fp, token, sizeof(token), &linenum) != NULL)
+ if ((data->skip_previous && !data->prev_pass) || data->skip_test)
{
- /*
- * Expect an open brace...
- */
+ data->skip_count ++;
+
+ ippDelete(request);
+ request = NULL;
+ response = NULL;
- if (!strcmp(token, "DEFINE"))
+ if (data->output == _CUPS_OUTPUT_PLIST)
{
- /*
- * DEFINE name value
- */
+ cupsFilePuts(data->outfile, "<key>Successful</key>\n");
+ cupsFilePuts(data->outfile, "<true />\n");
+ cupsFilePuts(data->outfile, "<key>Skipped</key>\n");
+ cupsFilePuts(data->outfile, "<true />\n");
+ cupsFilePuts(data->outfile, "<key>StatusCode</key>\n");
+ print_xml_string(data->outfile, "string", "skip");
+ cupsFilePuts(data->outfile, "<key>ResponseAttributes</key>\n");
+ cupsFilePuts(data->outfile, "<dict />\n");
+ }
- if (_ippFileReadToken(f, name, sizeof(name)) &&
- _ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- _ippVarsSet(vars, attr, token);
- }
- else
- {
- print_fatal_error(data, "Missing DEFINE name and/or value on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
+ cupsFilePuts(cupsFileStdout(), "SKIP]\n");
- continue;
- }
- else if (!strcmp(token, "DEFINE-DEFAULT"))
- {
- /*
- * DEFINE-DEFAULT name value
- */
+ goto skip_error;
+ }
- if (_ippFileReadToken(f, name, sizeof(name)) &&
- _ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- if (!_ippVarsGet(vars, attr))
- _ippVarsSet(vars, attr, token);
- }
- else
- {
- print_fatal_error(data, "Missing DEFINE-DEFAULT name and/or value on line "
- "%d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
+ vars->password_tries = 0;
- continue;
- }
- else if (!strcmp(token, "FILE-ID"))
- {
- /*
- * FILE-ID "string"
- */
+ do
+ {
+ if (data->delay > 0)
+ usleep(data->delay);
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, file_id, temp, sizeof(file_id));
- }
- else
- {
- print_fatal_error(data, "Missing FILE-ID value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
+ data->delay = data->repeat_interval;
+ repeat_count ++;
- continue;
- }
- else if (!strcmp(token, "IGNORE-ERRORS"))
+ status = HTTP_STATUS_OK;
+
+ if (data->transfer == _CUPS_TRANSFER_CHUNKED || (data->transfer == _CUPS_TRANSFER_AUTO && data->file[0]))
{
/*
- * IGNORE-ERRORS yes
- * IGNORE-ERRORS no
+ * Send request using chunking - a 0 length means "chunk".
*/
- if (_ippFileReadToken(f, temp, sizeof(temp)) &&
- (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
- {
- IgnoreErrors = !_cups_strcasecmp(temp, "yes");
- }
- else
- {
- print_fatal_error(data, "Missing IGNORE-ERRORS value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
+ length = 0;
}
- else if (!strcmp(token, "INCLUDE"))
+ else
{
/*
- * INCLUDE "filename"
- * INCLUDE <filename>
+ * Send request using content length...
*/
- if (_ippFileReadToken(f, temp, sizeof(temp)))
+ length = ippLength(request);
+
+ if (data->file[0] && (reqfile = cupsFileOpen(data->file, "r")) != NULL)
{
/*
- * Map the filename to and then run the tests...
+ * Read the file to get the uncompressed file size...
*/
- if (!do_tests(data->outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
- {
- pass = 0;
+ while ((bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
+ length += (size_t)bytes;
- if (StopAfterIncludeError)
- goto test_exit;
- }
- }
- else
- {
- print_fatal_error(data, "Missing INCLUDE filename on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ cupsFileClose(reqfile);
}
-
- show_header = 1;
- continue;
}
- else if (!strcmp(token, "INCLUDE-IF-DEFINED"))
- {
- /*
- * INCLUDE-IF-DEFINED name "filename"
- * INCLUDE-IF-DEFINED name <filename>
- */
- if (_ippFileReadToken(f, name, sizeof(name)) &&
- _ippFileReadToken(f, temp, sizeof(temp)))
+ /*
+ * Send the request...
+ */
+
+ data->prev_pass = 1;
+ repeat_test = 0;
+ response = NULL;
+
+ if (status != HTTP_STATUS_ERROR)
+ {
+ while (!response && !Cancel && data->prev_pass)
{
+ status = cupsSendRequest(data->http, request, data->resource, length);
+
+#ifdef HAVE_LIBZ
+ if (data->compression[0])
+ httpSetField(data->http, HTTP_FIELD_CONTENT_ENCODING, data->compression);
+#endif /* HAVE_LIBZ */
+
+ if (!Cancel && status == HTTP_STATUS_CONTINUE && ippGetState(request) == IPP_DATA && data->file[0])
+ {
+ if ((reqfile = cupsFileOpen(data->file, "r")) != NULL)
+ {
+ while (!Cancel && (bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
+ {
+ if ((status = cupsWriteRequestData(data->http, buffer, (size_t)bytes)) != HTTP_STATUS_CONTINUE)
+ break;
+ }
+
+ cupsFileClose(reqfile);
+ }
+ else
+ {
+ snprintf(buffer, sizeof(buffer), "%s: %s", data->file, strerror(errno));
+ _cupsSetError(IPP_INTERNAL_ERROR, buffer, 0);
+
+ status = HTTP_STATUS_ERROR;
+ }
+ }
+
/*
- * Map the filename to and then run the tests...
+ * Get the server's response...
*/
- if (_ippVarsGet(vars, attr) &&
- !do_tests(data->outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
+ if (!Cancel && status != HTTP_STATUS_ERROR)
{
- pass = 0;
+ response = cupsGetResponse(data->http, data->resource);
+ status = httpGetStatus(data->http);
+ }
- if (StopAfterIncludeError)
- goto test_exit;
+ if (!Cancel && status == HTTP_STATUS_ERROR && httpError(data->http) != EINVAL &&
+#ifdef WIN32
+ httpError(data->http) != WSAETIMEDOUT)
+#else
+ httpError(data->http) != ETIMEDOUT)
+#endif /* WIN32 */
+ {
+ if (httpReconnect2(data->http, 30000, NULL))
+ data->prev_pass = 0;
+ }
+ else if (status == HTTP_STATUS_ERROR || status == HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED)
+ {
+ data->prev_pass = 0;
+ break;
+ }
+ else if (status != HTTP_STATUS_OK)
+ {
+ httpFlush(data->http);
+
+ if (status == HTTP_STATUS_UNAUTHORIZED)
+ continue;
+
+ break;
}
}
- else
- {
- print_fatal_error(data, "Missing INCLUDE-IF-DEFINED name or filename on line "
- "%d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
+ }
- show_header = 1;
- continue;
+ if (!Cancel && status == HTTP_STATUS_ERROR && httpError(data->http) != EINVAL &&
+#ifdef WIN32
+ httpError(data->http) != WSAETIMEDOUT)
+#else
+ httpError(data->http) != ETIMEDOUT)
+#endif /* WIN32 */
+ {
+ if (httpReconnect2(data->http, 30000, NULL))
+ data->prev_pass = 0;
}
- else if (!strcmp(token, "INCLUDE-IF-NOT-DEFINED"))
+ else if (status == HTTP_STATUS_ERROR)
{
- /*
- * INCLUDE-IF-NOT-DEFINED name "filename"
- * INCLUDE-IF-NOT-DEFINED name <filename>
- */
+ if (!Cancel)
+ httpReconnect2(data->http, 30000, NULL);
- if (_ippFileReadToken(f, name, sizeof(name)) &&
- _ippFileReadToken(f, temp, sizeof(temp)))
- {
- /*
- * Map the filename to and then run the tests...
- */
+ data->prev_pass = 0;
+ }
+ else if (status != HTTP_STATUS_OK)
+ {
+ httpFlush(data->http);
+ data->prev_pass = 0;
+ }
- if (!_ippVarsGet(vars, attr) &&
- !do_tests(data->outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
- {
- pass = 0;
+ /*
+ * Check results of request...
+ */
- if (StopAfterIncludeError)
- goto test_exit;
- }
- }
- else
- {
- print_fatal_error(data, "Missing INCLUDE-IF-NOT-DEFINED name or filename on "
- "line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
+ cupsArrayClear(data->errors);
+
+ if (httpGetVersion(data->http) != HTTP_1_1)
+ {
+ int version = httpGetVersion(data->http);
- show_header = 1;
- continue;
+ add_stringf(data->errors, "Bad HTTP version (%d.%d)", version / 100, version % 100);
}
- else if (!strcmp(token, "SKIP-IF-DEFINED"))
+
+ if (data->validate_headers)
{
- /*
- * SKIP-IF-DEFINED variable
- */
+ const char *header; /* HTTP header value */
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (_ippVarsGet(vars, temp))
- goto test_exit;
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-IF-DEFINED variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
+ if ((header = httpGetField(data->http, HTTP_FIELD_CONTENT_TYPE)) == NULL || _cups_strcasecmp(header, "application/ipp"))
+ add_stringf(data->errors, "Bad HTTP Content-Type in response (%s)", header && *header ? header : "<missing>");
+
+ if ((header = httpGetField(data->http, HTTP_FIELD_DATE)) != NULL && *header && httpGetDateTime(header) == 0)
+ add_stringf(data->errors, "Bad HTTP Date in response (%s)", header);
}
- else if (!strcmp(token, "SKIP-IF-NOT-DEFINED"))
+
+ if (!response)
{
/*
- * SKIP-IF-NOT-DEFINED variable
+ * No response, log error...
*/
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (!_ippVarsGet(vars, temp))
- goto test_exit;
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-IF-NOT-DEFINED variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
+ add_stringf(data->errors, "IPP request failed with status %s (%s)", ippErrorString(cupsLastError()), cupsLastErrorString());
}
- else if (!strcmp(token, "STOP-AFTER-INCLUDE-ERROR"))
+ else
{
/*
- * STOP-AFTER-INCLUDE-ERROR yes
- * STOP-AFTER-INCLUDE-ERROR no
+ * Collect common attribute values...
*/
- if (_ippFileReadToken(f, temp, sizeof(temp)) &&
- (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+ if ((attrptr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) != NULL)
{
- StopAfterIncludeError = !_cups_strcasecmp(temp, "yes");
+ snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
+ _ippVarsSet(vars, "job-id", temp);
}
- else
+
+ if ((attrptr = ippFindAttribute(response, "job-uri",
+ IPP_TAG_URI)) != NULL)
+ _ippVarsSet(vars, "job-uri", attrptr->values[0].string.text);
+
+ if ((attrptr = ippFindAttribute(response, "notify-subscription-id",
+ IPP_TAG_INTEGER)) != NULL)
{
- print_fatal_error(data, "Missing STOP-AFTER-INCLUDE-ERROR value on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
+ _ippVarsSet(vars, "notify-subscription-id", temp);
}
- continue;
- }
- else if (!strcmp(token, "TRANSFER"))
- {
/*
- * TRANSFER auto
- * TRANSFER chunked
- * TRANSFER length
+ * Check response, validating groups and attributes and logging errors
+ * as needed...
*/
- if (_ippFileReadToken(f, temp, sizeof(temp)))
+ if (ippGetState(response) != IPP_DATA)
+ add_stringf(data->errors, "Missing end-of-attributes-tag in response (RFC 2910 section 3.5.1)");
+
+ if (data->version)
{
- if (!strcmp(temp, "auto"))
- Transfer = _CUPS_TRANSFER_AUTO;
- else if (!strcmp(temp, "chunked"))
- Transfer = _CUPS_TRANSFER_CHUNKED;
- else if (!strcmp(temp, "length"))
- Transfer = _CUPS_TRANSFER_LENGTH;
- else
- {
- print_fatal_error(data, "Bad TRANSFER value \"%s\" on line %d of \"%s\".", temp,
- linenum);
- pass = 0;
- goto test_exit;
- }
+ int major, minor; /* IPP version */
+
+ major = ippGetVersion(response, &minor);
+
+ if (major != (data->version / 10) || minor != (data->version % 10))
+ add_stringf(data->errors, "Bad version %d.%d in response - expected %d.%d (RFC 2911 section 3.1.8).", major, minor, data->version / 10, data->version % 10);
}
- else
+
+ if (ippGetRequestId(response) != data->request_id)
+ add_stringf(data->errors, "Bad request ID %d in response - expected %d (RFC 2911 section 3.1.1)", ippGetRequestId(response), data->request_id);
+
+ attrptr = ippFirstAttribute(response);
+ if (!attrptr)
{
- print_fatal_error(data, "Missing TRANSFER value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
- }
- else if (!strcmp(token, "VERSION"))
- {
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (!strcmp(temp, "1.0"))
- Version = 10;
- else if (!strcmp(temp, "1.1"))
- Version = 11;
- else if (!strcmp(temp, "2.0"))
- Version = 20;
- else if (!strcmp(temp, "2.1"))
- Version = 21;
- else if (!strcmp(temp, "2.2"))
- Version = 22;
- else
- {
- print_fatal_error(data, "Bad VERSION \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else
- {
- print_fatal_error(data, "Missing VERSION number on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
- }
- else if (strcmp(token, "{"))
- {
- print_fatal_error(data, "Unexpected token %s seen on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- /*
- * Initialize things...
- */
-
- if (show_header)
- {
- if (Output == _CUPS_OUTPUT_PLIST)
- print_xml_header(data->outfile);
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- cupsFilePrintf(cupsFileStdout(), "\"%s\":\n", testfile);
-
- show_header = 0;
- }
-
- strlcpy(resource, vars->resource, sizeof(resource));
-
- request_id ++;
- request = ippNew();
- op = (ipp_op_t)0;
- group = IPP_TAG_ZERO;
- ignore_errors = IgnoreErrors;
- last_expect = NULL;
- last_status = NULL;
- filename[0] = '\0';
- skip_previous = 0;
- skip_test = 0;
- test_id[0] = '\0';
- version = Version;
- transfer = Transfer;
- compression[0] = '\0';
- delay = 0;
- repeat_count = 0;
- repeat_interval = 5000000;
-
- strlcpy(name, testfile, sizeof(name));
- if (strrchr(name, '.') != NULL)
- *strrchr(name, '.') = '\0';
-
- /*
- * Parse until we see a close brace...
- */
-
- while (get_token(fp, token, sizeof(token), &linenum) != NULL)
- {
- if (_cups_strcasecmp(token, "COUNT") &&
- _cups_strcasecmp(token, "DEFINE-MATCH") &&
- _cups_strcasecmp(token, "DEFINE-NO-MATCH") &&
- _cups_strcasecmp(token, "DEFINE-VALUE") &&
- _cups_strcasecmp(token, "IF-DEFINED") &&
- _cups_strcasecmp(token, "IF-NOT-DEFINED") &&
- _cups_strcasecmp(token, "IN-GROUP") &&
- _cups_strcasecmp(token, "OF-TYPE") &&
- _cups_strcasecmp(token, "REPEAT-LIMIT") &&
- _cups_strcasecmp(token, "REPEAT-MATCH") &&
- _cups_strcasecmp(token, "REPEAT-NO-MATCH") &&
- _cups_strcasecmp(token, "SAME-COUNT-AS") &&
- _cups_strcasecmp(token, "WITH-ALL-VALUES") &&
- _cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") &&
- _cups_strcasecmp(token, "WITH-ALL-RESOURCES") &&
- _cups_strcasecmp(token, "WITH-ALL-SCHEMES") &&
- _cups_strcasecmp(token, "WITH-HOSTNAME") &&
- _cups_strcasecmp(token, "WITH-RESOURCE") &&
- _cups_strcasecmp(token, "WITH-SCHEME") &&
- _cups_strcasecmp(token, "WITH-VALUE") &&
- _cups_strcasecmp(token, "WITH-VALUE-FROM"))
- last_expect = NULL;
-
- if (_cups_strcasecmp(token, "DEFINE-MATCH") &&
- _cups_strcasecmp(token, "DEFINE-NO-MATCH") &&
- _cups_strcasecmp(token, "IF-DEFINED") &&
- _cups_strcasecmp(token, "IF-NOT-DEFINED") &&
- _cups_strcasecmp(token, "REPEAT-LIMIT") &&
- _cups_strcasecmp(token, "REPEAT-MATCH") &&
- _cups_strcasecmp(token, "REPEAT-NO-MATCH"))
- last_status = NULL;
-
- if (!strcmp(token, "}"))
- break;
- else if (!strcmp(token, "{") && lastcol)
- {
- /*
- * Another collection value
- */
-
- ipp_t *col = get_collection(data->outfile, vars, fp, &linenum);
- /* Collection value */
-
- if (col)
- {
- ippSetCollection(request, &lastcol, ippGetCount(lastcol), col);
- }
- else
- {
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "COMPRESSION"))
- {
- /*
- * COMPRESSION none
- * COMPRESSION deflate
- * COMPRESSION gzip
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, compression, temp, sizeof(compression));
-#ifdef HAVE_LIBZ
- if (strcmp(compression, "none") && strcmp(compression, "deflate") &&
- strcmp(compression, "gzip"))
-#else
- if (strcmp(compression, "none"))
-#endif /* HAVE_LIBZ */
- {
- print_fatal_error(data, "Unsupported COMPRESSION value '%s' on line %d of \"%s\".",
- compression, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (!strcmp(compression, "none"))
- compression[0] = '\0';
- }
- else
- {
- print_fatal_error(data, "Missing COMPRESSION value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "DEFINE"))
- {
- /*
- * DEFINE name value
- */
-
- if (_ippFileReadToken(f, name, sizeof(name)) &&
- _ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- _ippVarsSet(vars, attr, token);
- }
- else
- {
- print_fatal_error(data, "Missing DEFINE name and/or value on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "IGNORE-ERRORS"))
- {
- /*
- * IGNORE-ERRORS yes
- * IGNORE-ERRORS no
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)) &&
- (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
- {
- ignore_errors = !_cups_strcasecmp(temp, "yes");
- }
- else
- {
- print_fatal_error(data, "Missing IGNORE-ERRORS value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
- }
- else if (!_cups_strcasecmp(token, "NAME"))
- {
- /*
- * Name of test...
- */
-
- _ippFileReadToken(f, temp, sizeof(temp));
- _ippVarsExpand(vars, name, temp, sizeof(name));
- }
- else if (!_cups_strcasecmp(token, "PAUSE"))
- {
- /*
- * Pause with a message...
- */
-
- get_token(fp, token, sizeof(token), &linenum);
- pause_message(token);
- }
- else if (!strcmp(token, "REQUEST-ID"))
- {
- /*
- * REQUEST-ID #
- * REQUEST-ID random
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (isdigit(temp[0] & 255))
- request_id = atoi(temp);
- else if (!_cups_strcasecmp(temp, "random"))
- request_id = (CUPS_RAND() % 1000) * 137 + 1;
- else
- {
- print_fatal_error(data, "Bad REQUEST-ID value \"%s\" on line %d of \"%s\".", temp,
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else
- {
- print_fatal_error(data, "Missing REQUEST-ID value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "SKIP-IF-DEFINED"))
- {
- /*
- * SKIP-IF-DEFINED variable
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (_ippVarsGet(vars, temp))
- skip_test = 1;
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-IF-DEFINED value on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "SKIP-IF-MISSING"))
- {
- /*
- * SKIP-IF-MISSING filename
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- get_filename(testfile, filename, token, sizeof(filename));
-
- if (access(filename, R_OK))
- skip_test = 1;
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-IF-MISSING filename on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "SKIP-IF-NOT-DEFINED"))
- {
- /*
- * SKIP-IF-NOT-DEFINED variable
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (!_ippVarsGet(vars, temp))
- skip_test = 1;
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-IF-NOT-DEFINED value on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!strcmp(token, "SKIP-PREVIOUS-ERROR"))
- {
- /*
- * SKIP-PREVIOUS-ERROR yes
- * SKIP-PREVIOUS-ERROR no
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)) &&
- (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
- {
- skip_previous = !_cups_strcasecmp(temp, "yes");
- }
- else
- {
- print_fatal_error(data, "Missing SKIP-PREVIOUS-ERROR value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
- }
- else if (!strcmp(token, "TEST-ID"))
- {
- /*
- * TEST-ID "string"
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- _ippVarsExpand(vars, test_id, temp, sizeof(test_id));
- }
- else
- {
- print_fatal_error(data, "Missing TEST-ID value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- continue;
- }
- else if (!strcmp(token, "TRANSFER"))
- {
- /*
- * TRANSFER auto
- * TRANSFER chunked
- * TRANSFER length
- */
-
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (!strcmp(temp, "auto"))
- transfer = _CUPS_TRANSFER_AUTO;
- else if (!strcmp(temp, "chunked"))
- transfer = _CUPS_TRANSFER_CHUNKED;
- else if (!strcmp(temp, "length"))
- transfer = _CUPS_TRANSFER_LENGTH;
- else
- {
- print_fatal_error(data, "Bad TRANSFER value \"%s\" on line %d of \"%s\".", temp,
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else
- {
- print_fatal_error(data, "Missing TRANSFER value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "VERSION"))
- {
- if (_ippFileReadToken(f, temp, sizeof(temp)))
- {
- if (!strcmp(temp, "0.0"))
- version = 0;
- else if (!strcmp(temp, "1.0"))
- version = 10;
- else if (!strcmp(temp, "1.1"))
- version = 11;
- else if (!strcmp(temp, "2.0"))
- version = 20;
- else if (!strcmp(temp, "2.1"))
- version = 21;
- else if (!strcmp(temp, "2.2"))
- version = 22;
- else
- {
- print_fatal_error(data, "Bad VERSION \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
- return (0);
- }
- }
- else
- {
- print_fatal_error(data, "Missing VERSION number on line %d of \"%s\".", f->linenum, f->filename);
- return (0);
- }
- }
- else if (!_cups_strcasecmp(token, "RESOURCE"))
- {
- /*
- * Resource name...
- */
-
- if (!get_token(fp, data->resource, sizeof(data->resource), &linenum))
- {
- print_fatal_error(data, "Missing RESOURCE path on line %d of \"%s\".", f->linenum, f->filename);
- return (0);
- }
- }
- else if (!_cups_strcasecmp(token, "OPERATION"))
- {
- /*
- * Operation...
- */
-
- ipp_op_t op; /* Operation code */
-
- if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing OPERATION code on line %d of \"%s\".", f->linenum, f->filename);
- return (0);
- }
-
- _ippVarsExpand(vars, value, temp, sizeof(value));
-
- if ((op = ippOpValue(value)) == (ipp_op_t)-1 && (op = (ipp_op_t)strtol(token, NULL, 0)) == 0)
- {
- print_fatal_error(data, "Bad OPERATION code \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- return (0);
- }
- }
- else if (!_cups_strcasecmp(token, "GROUP"))
- {
- /*
- * Attribute group...
- */
-
- ipp_tag_t group_tag; /* Group tag */
-
- if (!get_token(fp, temp, sizeof(temp), &linenum))
- {
- print_fatal_error(data, "Missing GROUP tag on line %d of \"%s\".", f->linenum, f->filename);
- return (0);
- }
-
- if ((group_tag = ippTagValue(token)) == IPP_TAG_ZERO || group_tag >= IPP_TAG_UNSUPPORTED_VALUE)
- {
- print_fatal_error(data, "Bad GROUP tag \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- return (0);
- }
-
- if (group_tag == f->group_tag)
- ippAddSeparator(f->attrs);
-
- f->group_tag = group_tag;
- }
- else if (!_cups_strcasecmp(token, "DELAY"))
- {
- /*
- * Delay before operation...
- */
-
- double dval; /* Delay value */
-
- if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing DELAY value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- _ippVarsExpand(vars, token, temp, sizeof(token));
-
- if ((dval = _cupsStrScand(token, &tokenptr, localeconv())) < 0.0 || (*tokenptr && *tokenptr != ','))
- {
- print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- delay = (useconds_t)(1000000.0 * dval);
-
- if (*tokenptr == ',')
- {
- if ((dval = _cupsStrScand(tokenptr + 1, &tokenptr, localeconv())) <= 0.0 || *tokenptr)
- {
- print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- repeat_interval = (useconds_t)(1000000.0 * dval);
- }
- else
- repeat_interval = delay;
- }
- else if (!_cups_strcasecmp(token, "ATTR"))
- {
- /*
- * Attribute...
- */
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing ATTR value tag on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if ((value = ippTagValue(token)) < IPP_TAG_UNSUPPORTED_VALUE)
- {
- print_fatal_error(data, "Bad ATTR value tag \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- if (!_ippFileReadToken(f, name, sizeof(name)))
- {
- print_fatal_error(data, "Missing ATTR name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (value < IPP_TAG_INTEGER)
- {
- /*
- * Add out-of-band value - no value string needed...
- */
-
- token[0] = '\0';
- }
- else if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing ATTR value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- else
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- }
-
- attrptr = NULL;
-
- switch (value)
- {
- default :
- if (value < IPP_TAG_INTEGER)
- {
- /*
- * Add out-of-band value...
- */
-
- attrptr = ippAddOutOfBand(request, group, value, attr);
- }
- else
- {
- print_fatal_error(data, "Unsupported ATTR value tag %s for \"%s\" on line %d of \"%s\".", ippTagString(value), attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- break;
-
- case IPP_TAG_BOOLEAN :
- if (!_cups_strcasecmp(token, "true"))
- attrptr = ippAddBoolean(request, group, attr, 1);
- else
- attrptr = ippAddBoolean(request, group, attr, (char)atoi(token));
- break;
-
- case IPP_TAG_INTEGER :
- case IPP_TAG_ENUM :
- if (!strchr(token, ','))
- {
- if (isdigit(token[0] & 255) || token[0] == '-')
- attrptr = ippAddInteger(request, group, value, attr, (int)strtol(token, &tokenptr, 0));
- else
- {
- tokenptr = token;
- if ((i = ippEnumValue(attr, tokenptr)) >= 0)
- {
- attrptr = ippAddInteger(request, group, value, attr, i);
- tokenptr += strlen(tokenptr);
- }
- }
- }
- else
- {
- int values[100], /* Values */
- num_values = 1; /* Number of values */
-
- if (!isdigit(token[0] & 255) && token[0] != '-' && value == IPP_TAG_ENUM)
- {
- char *ptr; /* Pointer to next terminator */
-
- if ((ptr = strchr(token, ',')) != NULL)
- *ptr++ = '\0';
- else
- ptr = token + strlen(token);
-
- if ((i = ippEnumValue(attr, token)) < 0)
- tokenptr = NULL;
- else
- tokenptr = ptr;
- }
- else
- i = (int)strtol(token, &tokenptr, 0);
-
- values[0] = i;
-
- while (tokenptr && *tokenptr &&
- num_values < (int)(sizeof(values) / sizeof(values[0])))
- {
- if (*tokenptr == ',')
- tokenptr ++;
-
- if (!isdigit(*tokenptr & 255) && *tokenptr != '-')
- {
- char *ptr; /* Pointer to next terminator */
-
- if (value != IPP_TAG_ENUM)
- break;
-
- if ((ptr = strchr(tokenptr, ',')) != NULL)
- *ptr++ = '\0';
- else
- ptr = tokenptr + strlen(tokenptr);
-
- if ((i = ippEnumValue(attr, tokenptr)) < 0)
- break;
-
- tokenptr = ptr;
- }
- else
- i = (int)strtol(tokenptr, &tokenptr, 0);
-
- values[num_values ++] = i;
- }
-
- attrptr = ippAddIntegers(request, group, value, attr, num_values, values);
- }
-
- if ((!token[0] || !tokenptr || *tokenptr) && !skip_test)
- {
- print_fatal_error(data, "Bad %s value \'%s\' for \"%s\" on line %d of \"%s\".",
- ippTagString(value), token, attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- break;
-
- case IPP_TAG_RESOLUTION :
- {
- int xres, /* X resolution */
- yres; /* Y resolution */
- char *ptr; /* Pointer into value */
-
- xres = yres = (int)strtol(token, (char **)&ptr, 10);
- if (ptr > token && xres > 0)
- {
- if (*ptr == 'x')
- yres = (int)strtol(ptr + 1, (char **)&ptr, 10);
- }
-
- if (ptr <= token || xres <= 0 || yres <= 0 || !ptr ||
- (_cups_strcasecmp(ptr, "dpi") &&
- _cups_strcasecmp(ptr, "dpc") &&
- _cups_strcasecmp(ptr, "dpcm") &&
- _cups_strcasecmp(ptr, "other")))
- {
- if (skip_test)
- break;
-
- print_fatal_error(data, "Bad resolution value \'%s\' for \"%s\" on line %d of \"%s\".", token, attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (!_cups_strcasecmp(ptr, "dpi"))
- attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_INCH, xres, yres);
- else if (!_cups_strcasecmp(ptr, "dpc") ||
- !_cups_strcasecmp(ptr, "dpcm"))
- attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_CM, xres, yres);
- else
- attrptr = ippAddResolution(request, group, attr, (ipp_res_t)0, xres, yres);
- }
- break;
-
- case IPP_TAG_RANGE :
- {
- int lowers[4], /* Lower value */
- uppers[4], /* Upper values */
- num_vals; /* Number of values */
-
-
- num_vals = sscanf(token, "%d-%d,%d-%d,%d-%d,%d-%d",
- lowers + 0, uppers + 0,
- lowers + 1, uppers + 1,
- lowers + 2, uppers + 2,
- lowers + 3, uppers + 3);
-
- if ((num_vals & 1) || num_vals == 0)
- {
- if (skip_test)
- break;
-
- print_fatal_error(data, "Bad rangeOfInteger value \'%s\' for \"%s\" on line %d of \"%s\".", token, attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- attrptr = ippAddRanges(request, group, attr, num_vals / 2, lowers,
- uppers);
- }
- break;
-
- case IPP_TAG_BEGIN_COLLECTION :
- if (!strcmp(token, "{"))
- {
- ipp_t *col = get_collection(data->outfile, vars, fp, &linenum);
- /* Collection value */
-
- if (col)
- {
- attrptr = lastcol = ippAddCollection(request, group, attr, col);
- ippDelete(col);
- }
- else
- {
- pass = 0;
- goto test_exit;
- }
- }
- else if (skip_test)
- break;
- else
- {
- print_fatal_error(data, "Bad ATTR collection value for \"%s\" on line %d of \"%s\".", attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- do
- {
- ipp_t *col; /* Collection value */
- off_t savepos = cupsFileTell(fp); /* Save position of file */
- int savelinenum = linenum; /* Save line number */
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- break;
-
- if (strcmp(token, ","))
- {
- cupsFileSeek(fp, savepos);
- linenum = savelinenum;
- break;
- }
-
- if (!get_token(fp, token, sizeof(token), &linenum) || strcmp(token, "{"))
- {
- print_fatal_error(data, "Unexpected \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- break;
- }
-
- if ((col = get_collection(data->outfile, vars, fp, &linenum)) == NULL)
- break;
-
- ippSetCollection(request, &attrptr, ippGetCount(attrptr), col);
- lastcol = attrptr;
- }
- while (!strcmp(token, "{"));
- break;
-
- case IPP_TAG_STRING :
- attrptr = ippAddOctetString(request, group, attr, token, (int)strlen(token));
- break;
-
- case IPP_TAG_TEXTLANG :
- case IPP_TAG_NAMELANG :
- case IPP_TAG_TEXT :
- case IPP_TAG_NAME :
- case IPP_TAG_KEYWORD :
- case IPP_TAG_URI :
- case IPP_TAG_URISCHEME :
- case IPP_TAG_CHARSET :
- case IPP_TAG_LANGUAGE :
- case IPP_TAG_MIMETYPE :
- if (!strchr(token, ','))
- attrptr = ippAddString(request, group, value, attr, NULL, token);
- else
- {
- /*
- * Multiple string values...
- */
-
- int num_values; /* Number of values */
- char *values[100], /* Values */
- *ptr; /* Pointer to next value */
-
-
- values[0] = token;
- num_values = 1;
-
- for (ptr = strchr(token, ','); ptr; ptr = strchr(ptr, ','))
- {
- if (ptr > token && ptr[-1] == '\\')
- _cups_strcpy(ptr - 1, ptr);
- else
- {
- *ptr++ = '\0';
- values[num_values] = ptr;
- num_values ++;
- }
- }
-
- attrptr = ippAddStrings(request, group, value, attr, num_values,
- NULL, (const char **)values);
- }
- break;
- }
-
- if (!attrptr && !skip_test)
- {
- print_fatal_error(data, "Unable to add attribute \"%s\" on line %d of \"%s\".", attr, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "FILE"))
- {
- /*
- * File...
- */
-
- if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing FILE filename on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- _ippVarsExpand(vars, token, temp, sizeof(token));
- get_filename(testfile, filename, token, sizeof(filename));
-
- if (access(filename, R_OK))
- {
- print_fatal_error(data, "Filename \"%s\" on line %d cannot be read.",
- temp, f->linenum, f->filename);
- print_fatal_error(data, "Filename mapped to \"%s\".", filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "STATUS"))
- {
- /*
- * Status...
- */
-
- if (num_statuses >= (int)(sizeof(statuses) / sizeof(statuses[0])))
- {
- print_fatal_error(data, "Too many STATUS's on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing STATUS code on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if ((statuses[num_statuses].status = ippErrorValue(token))
- == (ipp_status_t)-1 &&
- (statuses[num_statuses].status = (ipp_status_t)strtol(token, NULL, 0)) == 0)
- {
- print_fatal_error(data, "Bad STATUS code \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- last_status = statuses + num_statuses;
- num_statuses ++;
-
- last_status->define_match = NULL;
- last_status->define_no_match = NULL;
- last_status->if_defined = NULL;
- last_status->if_not_defined = NULL;
- last_status->repeat_limit = 1000;
- last_status->repeat_match = 0;
- last_status->repeat_no_match = 0;
- }
- else if (!_cups_strcasecmp(token, "EXPECT") || !_cups_strcasecmp(token, "EXPECT-ALL"))
- {
- /*
- * Expected attributes...
- */
-
- int expect_all = !_cups_strcasecmp(token, "EXPECT-ALL");
-
- if (num_expects >= (int)(sizeof(expects) / sizeof(expects[0])))
- {
- print_fatal_error(data, "Too many EXPECT's on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing EXPECT name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- last_expect = expects + num_expects;
- num_expects ++;
-
- memset(last_expect, 0, sizeof(_cups_expect_t));
- last_expect->repeat_limit = 1000;
- last_expect->expect_all = expect_all;
-
- if (token[0] == '!')
- {
- last_expect->not_expect = 1;
- last_expect->name = strdup(token + 1);
- }
- else if (token[0] == '?')
- {
- last_expect->optional = 1;
- last_expect->name = strdup(token + 1);
- }
- else
- last_expect->name = strdup(token);
- }
- else if (!_cups_strcasecmp(token, "COUNT"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing COUNT number on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if ((i = atoi(token)) <= 0)
- {
- print_fatal_error(data, "Bad COUNT \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->count = i;
- else
- {
- print_fatal_error(data, "COUNT without a preceding EXPECT on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "DEFINE-MATCH"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing DEFINE-MATCH variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->define_match = strdup(token);
- else if (last_status)
- last_status->define_match = strdup(token);
- else
- {
- print_fatal_error(data, "DEFINE-MATCH without a preceding EXPECT or STATUS "
- "on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "DEFINE-NO-MATCH"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing DEFINE-NO-MATCH variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->define_no_match = strdup(token);
- else if (last_status)
- last_status->define_no_match = strdup(token);
- else
- {
- print_fatal_error(data, "DEFINE-NO-MATCH without a preceding EXPECT or "
- "STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "DEFINE-VALUE"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing DEFINE-VALUE variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->define_value = strdup(token);
- else
- {
- print_fatal_error(data, "DEFINE-VALUE without a preceding EXPECT on "
- "line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "OF-TYPE"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing OF-TYPE value tag(s) on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->of_type = strdup(token);
- else
- {
- print_fatal_error(data, "OF-TYPE without a preceding EXPECT on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "IN-GROUP"))
- {
- ipp_tag_t in_group; /* IN-GROUP value */
-
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing IN-GROUP group tag on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if ((in_group = ippTagValue(token)) == IPP_TAG_ZERO || in_group >= IPP_TAG_UNSUPPORTED_VALUE)
- {
- print_fatal_error(data, "Bad IN-GROUP group tag \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- else if (last_expect)
- last_expect->in_group = in_group;
- else
- {
- print_fatal_error(data, "IN-GROUP without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "REPEAT-LIMIT"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing REPEAT-LIMIT value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- else if (atoi(token) <= 0)
- {
- print_fatal_error(data, "Bad REPEAT-LIMIT value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_status)
- last_status->repeat_limit = atoi(token);
- else if (last_expect)
- last_expect->repeat_limit = atoi(token);
- else
- {
- print_fatal_error(data, "REPEAT-LIMIT without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "REPEAT-MATCH"))
- {
- if (last_status)
- last_status->repeat_match = 1;
- else if (last_expect)
- last_expect->repeat_match = 1;
- else
- {
- print_fatal_error(data, "REPEAT-MATCH without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "REPEAT-NO-MATCH"))
- {
- if (last_status)
- last_status->repeat_no_match = 1;
- else if (last_expect)
- last_expect->repeat_no_match = 1;
- else
- {
- print_fatal_error(data, "REPEAT-NO-MATCH without a preceding EXPECT or STATUS on ine %d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "SAME-COUNT-AS"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing SAME-COUNT-AS name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->same_count_as = strdup(token);
- else
- {
- print_fatal_error(data, "SAME-COUNT-AS without a preceding EXPECT on line "
- "%d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "IF-DEFINED"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing IF-DEFINED name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->if_defined = strdup(token);
- else if (last_status)
- last_status->if_defined = strdup(token);
- else
- {
- print_fatal_error(data, "IF-DEFINED without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "IF-NOT-DEFINED"))
- {
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing IF-NOT-DEFINED name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- last_expect->if_not_defined = strdup(token);
- else if (last_status)
- last_status->if_not_defined = strdup(token);
- else
- {
- print_fatal_error(data, "IF-NOT-DEFINED without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") ||
- !_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
- !_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
- !_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
- !_cups_strcasecmp(token, "WITH-HOSTNAME") ||
- !_cups_strcasecmp(token, "WITH-RESOURCE") ||
- !_cups_strcasecmp(token, "WITH-SCHEME") ||
- !_cups_strcasecmp(token, "WITH-VALUE"))
- {
- if (last_expect)
- {
- if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
- !_cups_strcasecmp(token, "WITH-HOSTNAME"))
- last_expect->with_flags = _CUPS_WITH_HOSTNAME;
- else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
- !_cups_strcasecmp(token, "WITH-RESOURCE"))
- last_expect->with_flags = _CUPS_WITH_RESOURCE;
- else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
- !_cups_strcasecmp(token, "WITH-SCHEME"))
- last_expect->with_flags = _CUPS_WITH_SCHEME;
-
- if (!_cups_strncasecmp(token, "WITH-ALL-", 9))
- last_expect->with_flags |= _CUPS_WITH_ALL;
- }
-
- if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing %s value on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- {
- /*
- * Expand any variables in the value and then save it.
- */
-
- _ippVarsExpand(vars, token, temp, sizeof(token));
-
- tokenptr = token + strlen(token) - 1;
-
- if (token[0] == '/' && tokenptr > token && *tokenptr == '/')
- {
- /*
- * WITH-VALUE is a POSIX extended regular expression.
- */
-
- last_expect->with_value = calloc(1, (size_t)(tokenptr - token));
- last_expect->with_flags |= _CUPS_WITH_REGEX;
-
- if (last_expect->with_value)
- memcpy(last_expect->with_value, token + 1, (size_t)(tokenptr - token - 1));
- }
- else
- {
- /*
- * WITH-VALUE is a literal value...
- */
-
- char *ptr; /* Pointer into value */
-
- for (ptr = token; *ptr; ptr ++)
- {
- if (*ptr == '\\' && ptr[1])
- {
- /*
- * Remove \ from \foo...
- */
-
- _cups_strcpy(ptr, ptr + 1);
- }
- }
-
- last_expect->with_value = strdup(token);
- last_expect->with_flags |= _CUPS_WITH_LITERAL;
- }
- }
- else
- {
- print_fatal_error(data, "%s without a preceding EXPECT on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "WITH-VALUE-FROM"))
- {
- if (!_ippFileReadToken(f, temp, sizeof(temp)))
- {
- print_fatal_error(data, "Missing %s value on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (last_expect)
- {
- /*
- * Expand any variables in the value and then save it.
- */
-
- _ippVarsExpand(vars, token, temp, sizeof(token));
-
- last_expect->with_value_from = strdup(token);
- last_expect->with_flags = _CUPS_WITH_LITERAL;
- }
- else
- {
- print_fatal_error(data, "%s without a preceding EXPECT on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
- else if (!_cups_strcasecmp(token, "DISPLAY"))
- {
- /*
- * Display attributes...
- */
-
- if (num_displayed >= (int)(sizeof(displayed) / sizeof(displayed[0])))
- {
- print_fatal_error(data, "Too many DISPLAY's on line %d", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- if (!get_token(fp, token, sizeof(token), &linenum))
- {
- print_fatal_error(data, "Missing DISPLAY name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
-
- displayed[num_displayed] = strdup(token);
- num_displayed ++;
- }
- else
- {
- print_fatal_error(data, "Unexpected token %s seen on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
- }
- }
-
- /*
- * Submit the IPP request...
- */
-
- TestCount ++;
-
- ippSetVersion(request, version / 10, version % 10);
- ippSetOperation(request, op);
- ippSetRequestId(request, request_id);
-
- if (Output == _CUPS_OUTPUT_PLIST)
- {
- cupsFilePuts(data->outfile, "<dict>\n");
- cupsFilePuts(data->outfile, "<key>Name</key>\n");
- print_xml_string(data->outfile, "string", name);
- if (file_id[0])
- {
- cupsFilePuts(data->outfile, "<key>FileId</key>\n");
- print_xml_string(data->outfile, "string", file_id);
- }
- if (test_id[0])
- {
- cupsFilePuts(data->outfile, "<key>TestId</key>\n");
- print_xml_string(data->outfile, "string", test_id);
- }
- cupsFilePuts(data->outfile, "<key>Version</key>\n");
- cupsFilePrintf(data->outfile, "<string>%d.%d</string>\n", version / 10, version % 10);
- cupsFilePuts(data->outfile, "<key>Operation</key>\n");
- print_xml_string(data->outfile, "string", ippOpString(op));
- cupsFilePuts(data->outfile, "<key>RequestId</key>\n");
- cupsFilePrintf(data->outfile, "<integer>%d</integer>\n", request_id);
- cupsFilePuts(data->outfile, "<key>RequestAttributes</key>\n");
- cupsFilePuts(data->outfile, "<array>\n");
- if (request->attrs)
- {
- cupsFilePuts(data->outfile, "<dict>\n");
- for (attrptr = request->attrs,
- group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
- attrptr;
- attrptr = attrptr->next)
- print_attr(data->outfile, Output, attrptr, &group);
- cupsFilePuts(data->outfile, "</dict>\n");
- }
- cupsFilePuts(data->outfile, "</array>\n");
- }
-
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- {
- if (Verbosity)
- {
- cupsFilePrintf(cupsFileStdout(), " %s:\n", ippOpString(op));
-
- for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
- print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
- }
-
- cupsFilePrintf(cupsFileStdout(), " %-68.68s [", name);
- }
-
- if ((skip_previous && !prev_pass) || skip_test)
- {
- SkipCount ++;
-
- ippDelete(request);
- request = NULL;
-
- if (Output == _CUPS_OUTPUT_PLIST)
- {
- cupsFilePuts(data->outfile, "<key>Successful</key>\n");
- cupsFilePuts(data->outfile, "<true />\n");
- cupsFilePuts(data->outfile, "<key>Skipped</key>\n");
- cupsFilePuts(data->outfile, "<true />\n");
- cupsFilePuts(data->outfile, "<key>StatusCode</key>\n");
- print_xml_string(data->outfile, "string", "skip");
- cupsFilePuts(data->outfile, "<key>ResponseAttributes</key>\n");
- cupsFilePuts(data->outfile, "<dict />\n");
- }
-
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- cupsFilePuts(cupsFileStdout(), "SKIP]\n");
-
- goto skip_error;
- }
-
- PasswordTries = 0;
-
- do
- {
- if (delay > 0)
- usleep(delay);
-
- delay = repeat_interval;
- repeat_count ++;
-
- status = HTTP_STATUS_OK;
-
- if (transfer == _CUPS_TRANSFER_CHUNKED ||
- (transfer == _CUPS_TRANSFER_AUTO && filename[0]))
- {
- /*
- * Send request using chunking - a 0 length means "chunk".
- */
-
- length = 0;
+ add_stringf(data->errors, "Missing first attribute \"attributes-charset (charset)\" in group operation-attributes-tag (RFC 2911 section 3.1.4).");
}
else
{
- /*
- * Send request using content length...
- */
-
- length = ippLength(request);
-
- if (filename[0] && (reqfile = cupsFileOpen(filename, "r")) != NULL)
- {
- /*
- * Read the file to get the uncompressed file size...
- */
-
- while ((bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
- length += (size_t)bytes;
-
- cupsFileClose(reqfile);
- }
- }
-
- /*
- * Send the request...
- */
-
- response = NULL;
- repeat_test = 0;
- prev_pass = 1;
+ if (!ippGetName(attrptr) || ippGetValueTag(attrptr) != IPP_TAG_CHARSET || ippGetGroupTag(attrptr) != IPP_TAG_OPERATION || ippGetCount(attrptr) != 1 ||strcmp(ippGetName(attrptr), "attributes-charset"))
+ add_stringf(data->errors, "Bad first attribute \"%s (%s%s)\" in group %s, expected \"attributes-charset (charset)\" in group operation-attributes-tag (RFC 2911 section 3.1.4).", ippGetName(attrptr) ? ippGetName(attrptr) : "(null)", ippGetCount(attrptr) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attrptr)), ippTagString(ippGetGroupTag(attrptr)));
- if (status != HTTP_STATUS_ERROR)
+ attrptr = ippNextAttribute(response);
+ if (!attrptr)
+ add_stringf(data->errors, "Missing second attribute \"attributes-natural-language (naturalLanguage)\" in group operation-attributes-tag (RFC 2911 section 3.1.4).");
+ else if (!ippGetName(attrptr) || ippGetValueTag(attrptr) != IPP_TAG_LANGUAGE || ippGetGroupTag(attrptr) != IPP_TAG_OPERATION || ippGetCount(attrptr) != 1 || strcmp(ippGetName(attrptr), "attributes-natural-language"))
+ add_stringf(data->errors, "Bad first attribute \"%s (%s%s)\" in group %s, expected \"attributes-natural-language (naturalLanguage)\" in group operation-attributes-tag (RFC 2911 section 3.1.4).", ippGetName(attrptr) ? ippGetName(attrptr) : "(null)", ippGetCount(attrptr) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attrptr)), ippTagString(ippGetGroupTag(attrptr)));
+ }
+
+ if ((attrptr = ippFindAttribute(response, "status-message", IPP_TAG_ZERO)) != NULL)
+ {
+ if (attrptr->value_tag != IPP_TAG_TEXT)
+ add_stringf(data->errors, "status-message (text(255)) has wrong value tag %s (RFC 2911 section 3.1.6.2).", ippTagString(attrptr->value_tag));
+ if (attrptr->group_tag != IPP_TAG_OPERATION)
+ add_stringf(data->errors, "status-message (text(255)) has wrong group tag %s (RFC 2911 section 3.1.6.2).", ippTagString(attrptr->group_tag));
+ if (attrptr->num_values != 1)
+ add_stringf(data->errors, "status-message (text(255)) has %d values (RFC 2911 section 3.1.6.2).", attrptr->num_values);
+ if (attrptr->value_tag == IPP_TAG_TEXT && strlen(attrptr->values[0].string.text) > 255)
+ add_stringf(data->errors, "status-message (text(255)) has bad length %d (RFC 2911 section 3.1.6.2).", (int)strlen(attrptr->values[0].string.text));
+ }
+
+ if ((attrptr = ippFindAttribute(response, "detailed-status-message",
+ IPP_TAG_ZERO)) != NULL)
+ {
+ if (attrptr->value_tag != IPP_TAG_TEXT)
+ add_stringf(data->errors,
+ "detailed-status-message (text(MAX)) has wrong "
+ "value tag %s (RFC 2911 section 3.1.6.3).",
+ ippTagString(attrptr->value_tag));
+ if (attrptr->group_tag != IPP_TAG_OPERATION)
+ add_stringf(data->errors,
+ "detailed-status-message (text(MAX)) has wrong "
+ "group tag %s (RFC 2911 section 3.1.6.3).",
+ ippTagString(attrptr->group_tag));
+ if (attrptr->num_values != 1)
+ add_stringf(data->errors,
+ "detailed-status-message (text(MAX)) has %d values"
+ " (RFC 2911 section 3.1.6.3).",
+ attrptr->num_values);
+ if (attrptr->value_tag == IPP_TAG_TEXT &&
+ strlen(attrptr->values[0].string.text) > 1023)
+ add_stringf(data->errors,
+ "detailed-status-message (text(MAX)) has bad "
+ "length %d (RFC 2911 section 3.1.6.3).",
+ (int)strlen(attrptr->values[0].string.text));
+ }
+
+ a = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+
+ for (attrptr = response->attrs,
+ group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
+ attrptr;
+ attrptr = attrptr->next)
{
- while (!response && !Cancel && prev_pass)
+ if (attrptr->group_tag != group)
{
- status = cupsSendRequest(http, request, resource, length);
-
-#ifdef HAVE_LIBZ
- if (compression[0])
- httpSetField(http, HTTP_FIELD_CONTENT_ENCODING, compression);
-#endif /* HAVE_LIBZ */
+ int out_of_order = 0; /* Are attribute groups out-of-order? */
+ cupsArrayClear(a);
- if (!Cancel && status == HTTP_STATUS_CONTINUE &&
- request->state == IPP_DATA && filename[0])
+ switch (attrptr->group_tag)
{
- if ((reqfile = cupsFileOpen(filename, "r")) != NULL)
- {
- while (!Cancel &&
- (bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
- if ((status = cupsWriteRequestData(http, buffer, (size_t)bytes)) != HTTP_STATUS_CONTINUE)
- break;
+ case IPP_TAG_ZERO :
+ break;
- cupsFileClose(reqfile);
- }
- else
- {
- snprintf(buffer, sizeof(buffer), "%s: %s", filename,
- strerror(errno));
- _cupsSetError(IPP_INTERNAL_ERROR, buffer, 0);
+ case IPP_TAG_OPERATION :
+ out_of_order = 1;
+ break;
- status = HTTP_STATUS_ERROR;
- }
- }
+ case IPP_TAG_UNSUPPORTED_GROUP :
+ if (group != IPP_TAG_OPERATION)
+ out_of_order = 1;
+ break;
- /*
- * Get the server's response...
- */
+ case IPP_TAG_JOB :
+ case IPP_TAG_PRINTER :
+ if (group != IPP_TAG_OPERATION &&
+ group != IPP_TAG_UNSUPPORTED_GROUP)
+ out_of_order = 1;
+ break;
- if (!Cancel && status != HTTP_STATUS_ERROR)
- {
- response = cupsGetResponse(http, resource);
- status = httpGetStatus(http);
- }
+ case IPP_TAG_SUBSCRIPTION :
+ if (group > attrptr->group_tag &&
+ group != IPP_TAG_DOCUMENT)
+ out_of_order = 1;
+ break;
- if (!Cancel && status == HTTP_STATUS_ERROR && http->error != EINVAL &&
-#ifdef WIN32
- http->error != WSAETIMEDOUT)
-#else
- http->error != ETIMEDOUT)
-#endif /* WIN32 */
- {
- if (httpReconnect2(http, 30000, NULL))
- prev_pass = 0;
- }
- else if (status == HTTP_STATUS_ERROR || status == HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED)
- {
- prev_pass = 0;
- break;
+ default :
+ if (group > attrptr->group_tag)
+ out_of_order = 1;
+ break;
}
- else if (status != HTTP_STATUS_OK)
- {
- httpFlush(http);
- if (status == HTTP_STATUS_UNAUTHORIZED)
- continue;
+ if (out_of_order)
+ add_stringf(data->errors, "Attribute groups out of order (%s < %s)",
+ ippTagString(attrptr->group_tag),
+ ippTagString(group));
- break;
- }
+ if (attrptr->group_tag != IPP_TAG_ZERO)
+ group = attrptr->group_tag;
}
- }
- if (!Cancel && status == HTTP_STATUS_ERROR && http->error != EINVAL &&
-#ifdef WIN32
- http->error != WSAETIMEDOUT)
-#else
- http->error != ETIMEDOUT)
-#endif /* WIN32 */
- {
- if (httpReconnect2(http, 30000, NULL))
- prev_pass = 0;
- }
- else if (status == HTTP_STATUS_ERROR)
- {
- if (!Cancel)
- httpReconnect2(http, 30000, NULL);
+ validate_attr(data, data->errors, attrptr);
- prev_pass = 0;
- }
- else if (status != HTTP_STATUS_OK)
- {
- httpFlush(http);
- prev_pass = 0;
+ if (attrptr->name)
+ {
+ if (cupsArrayFind(a, attrptr->name))
+ add_stringf(data->errors, "Duplicate \"%s\" attribute in %s group",
+ attrptr->name, ippTagString(group));
+
+ cupsArrayAdd(a, attrptr->name);
+ }
}
+ cupsArrayDelete(a);
+
/*
- * Check results of request...
+ * Now check the test-defined expected status-code and attribute
+ * values...
*/
- cupsArrayClear(errors);
-
- if (http->version != HTTP_1_1)
- add_stringf(errors, "Bad HTTP version (%d.%d)", http->version / 100,
- http->version % 100);
-
- if (ValidateHeaders)
- {
- const char *header; /* HTTP header value */
-
- if ((header = httpGetField(http, HTTP_FIELD_CONTENT_TYPE)) == NULL || _cups_strcasecmp(header, "application/ipp"))
- add_stringf(errors, "Bad HTTP Content-Type in response (%s)", header && *header ? header : "<missing>");
-
- if ((header = httpGetField(http, HTTP_FIELD_DATE)) != NULL && *header && httpGetDateTime(header) == 0)
- add_stringf(errors, "Bad HTTP Date in response (%s)", header);
- }
-
- if (!response)
+ for (i = 0, status_ok = 0; i < data->num_statuses; i ++)
{
- /*
- * No response, log error...
- */
+ if (data->statuses[i].if_defined &&
+ !_ippVarsGet(vars, data->statuses[i].if_defined))
+ continue;
- add_stringf(errors, "IPP request failed with status %s (%s)",
- ippErrorString(cupsLastError()),
- cupsLastErrorString());
- }
- else
- {
- /*
- * Collect common attribute values...
- */
+ if (data->statuses[i].if_not_defined &&
+ _ippVarsGet(vars, data->statuses[i].if_not_defined))
+ continue;
- if ((attrptr = ippFindAttribute(response, "job-id",
- IPP_TAG_INTEGER)) != NULL)
+ if (ippGetStatusCode(response) == data->statuses[i].status)
{
- snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
- _ippVarsSet(vars, "job-id", temp);
- }
+ status_ok = 1;
- if ((attrptr = ippFindAttribute(response, "job-uri",
- IPP_TAG_URI)) != NULL)
- _ippVarsSet(vars, "job-uri", attrptr->values[0].string.text);
+ if (data->statuses[i].repeat_match && repeat_count < data->statuses[i].repeat_limit)
+ repeat_test = 1;
- if ((attrptr = ippFindAttribute(response, "notify-subscription-id",
- IPP_TAG_INTEGER)) != NULL)
- {
- snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
- _ippVarsSet(vars, "notify-subscription-id", temp);
+ if (data->statuses[i].define_match)
+ _ippVarsSet(vars, data->statuses[i].define_match, "1");
}
-
- /*
- * Check response, validating groups and attributes and logging errors
- * as needed...
- */
-
- if (response->state != IPP_DATA)
- add_stringf(errors,
- "Missing end-of-attributes-tag in response "
- "(RFC 2910 section 3.5.1)");
-
- if (version &&
- (response->request.status.version[0] != (version / 10) ||
- response->request.status.version[1] != (version % 10)))
- add_stringf(errors,
- "Bad version %d.%d in response - expected %d.%d "
- "(RFC 2911 section 3.1.8).",
- response->request.status.version[0],
- response->request.status.version[1],
- version / 10, version % 10);
-
- if (response->request.status.request_id != request_id)
- add_stringf(errors,
- "Bad request ID %d in response - expected %d "
- "(RFC 2911 section 3.1.1)",
- response->request.status.request_id, request_id);
-
- attrptr = response->attrs;
- if (!attrptr)
- add_stringf(errors,
- "Missing first attribute \"attributes-charset "
- "(charset)\" in group operation-attributes-tag "
- "(RFC 2911 section 3.1.4).");
else
{
- if (!attrptr->name ||
- attrptr->value_tag != IPP_TAG_CHARSET ||
- attrptr->group_tag != IPP_TAG_OPERATION ||
- attrptr->num_values != 1 ||
- strcmp(attrptr->name, "attributes-charset"))
- add_stringf(errors,
- "Bad first attribute \"%s (%s%s)\" in group %s, "
- "expected \"attributes-charset (charset)\" in "
- "group operation-attributes-tag (RFC 2911 section "
- "3.1.4).",
- attrptr->name ? attrptr->name : "(null)",
- attrptr->num_values > 1 ? "1setOf " : "",
- ippTagString(attrptr->value_tag),
- ippTagString(attrptr->group_tag));
-
- attrptr = attrptr->next;
- if (!attrptr)
- add_stringf(errors,
- "Missing second attribute \"attributes-natural-"
- "language (naturalLanguage)\" in group "
- "operation-attributes-tag (RFC 2911 section "
- "3.1.4).");
- else if (!attrptr->name ||
- attrptr->value_tag != IPP_TAG_LANGUAGE ||
- attrptr->group_tag != IPP_TAG_OPERATION ||
- attrptr->num_values != 1 ||
- strcmp(attrptr->name, "attributes-natural-language"))
- add_stringf(errors,
- "Bad first attribute \"%s (%s%s)\" in group %s, "
- "expected \"attributes-natural-language "
- "(naturalLanguage)\" in group "
- "operation-attributes-tag (RFC 2911 section "
- "3.1.4).",
- attrptr->name ? attrptr->name : "(null)",
- attrptr->num_values > 1 ? "1setOf " : "",
- ippTagString(attrptr->value_tag),
- ippTagString(attrptr->group_tag));
- }
-
- if ((attrptr = ippFindAttribute(response, "status-message",
- IPP_TAG_ZERO)) != NULL)
- {
- if (attrptr->value_tag != IPP_TAG_TEXT)
- add_stringf(errors,
- "status-message (text(255)) has wrong value tag "
- "%s (RFC 2911 section 3.1.6.2).",
- ippTagString(attrptr->value_tag));
- if (attrptr->group_tag != IPP_TAG_OPERATION)
- add_stringf(errors,
- "status-message (text(255)) has wrong group tag "
- "%s (RFC 2911 section 3.1.6.2).",
- ippTagString(attrptr->group_tag));
- if (attrptr->num_values != 1)
- add_stringf(errors,
- "status-message (text(255)) has %d values "
- "(RFC 2911 section 3.1.6.2).",
- attrptr->num_values);
- if (attrptr->value_tag == IPP_TAG_TEXT &&
- strlen(attrptr->values[0].string.text) > 255)
- add_stringf(errors,
- "status-message (text(255)) has bad length %d"
- " (RFC 2911 section 3.1.6.2).",
- (int)strlen(attrptr->values[0].string.text));
- }
-
- if ((attrptr = ippFindAttribute(response, "detailed-status-message",
- IPP_TAG_ZERO)) != NULL)
- {
- if (attrptr->value_tag != IPP_TAG_TEXT)
- add_stringf(errors,
- "detailed-status-message (text(MAX)) has wrong "
- "value tag %s (RFC 2911 section 3.1.6.3).",
- ippTagString(attrptr->value_tag));
- if (attrptr->group_tag != IPP_TAG_OPERATION)
- add_stringf(errors,
- "detailed-status-message (text(MAX)) has wrong "
- "group tag %s (RFC 2911 section 3.1.6.3).",
- ippTagString(attrptr->group_tag));
- if (attrptr->num_values != 1)
- add_stringf(errors,
- "detailed-status-message (text(MAX)) has %d values"
- " (RFC 2911 section 3.1.6.3).",
- attrptr->num_values);
- if (attrptr->value_tag == IPP_TAG_TEXT &&
- strlen(attrptr->values[0].string.text) > 1023)
- add_stringf(errors,
- "detailed-status-message (text(MAX)) has bad "
- "length %d (RFC 2911 section 3.1.6.3).",
- (int)strlen(attrptr->values[0].string.text));
- }
+ if (data->statuses[i].repeat_no_match && repeat_count < data->statuses[i].repeat_limit)
+ repeat_test = 1;
- a = cupsArrayNew((cups_array_func_t)strcmp, NULL);
-
- for (attrptr = response->attrs,
- group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
- attrptr;
- attrptr = attrptr->next)
- {
- if (attrptr->group_tag != group)
+ if (data->statuses[i].define_no_match)
{
- int out_of_order = 0; /* Are attribute groups out-of-order? */
- cupsArrayClear(a);
-
- switch (attrptr->group_tag)
- {
- case IPP_TAG_ZERO :
- break;
-
- case IPP_TAG_OPERATION :
- out_of_order = 1;
- break;
-
- case IPP_TAG_UNSUPPORTED_GROUP :
- if (group != IPP_TAG_OPERATION)
- out_of_order = 1;
- break;
-
- case IPP_TAG_JOB :
- case IPP_TAG_PRINTER :
- if (group != IPP_TAG_OPERATION &&
- group != IPP_TAG_UNSUPPORTED_GROUP)
- out_of_order = 1;
- break;
-
- case IPP_TAG_SUBSCRIPTION :
- if (group > attrptr->group_tag &&
- group != IPP_TAG_DOCUMENT)
- out_of_order = 1;
- break;
-
- default :
- if (group > attrptr->group_tag)
- out_of_order = 1;
- break;
- }
-
- if (out_of_order)
- add_stringf(errors, "Attribute groups out of order (%s < %s)",
- ippTagString(attrptr->group_tag),
- ippTagString(group));
-
- if (attrptr->group_tag != IPP_TAG_ZERO)
- group = attrptr->group_tag;
+ _ippVarsSet(vars, data->statuses[i].define_no_match, "1");
+ status_ok = 1;
}
-
- validate_attr(data->outfile, errors, attrptr);
-
- if (attrptr->name)
- {
- if (cupsArrayFind(a, attrptr->name))
- add_stringf(errors, "Duplicate \"%s\" attribute in %s group",
- attrptr->name, ippTagString(group));
-
- cupsArrayAdd(a, attrptr->name);
- }
}
+ }
- cupsArrayDelete(a);
-
- /*
- * Now check the test-defined expected status-code and attribute
- * values...
- */
-
- for (i = 0, status_ok = 0; i < num_statuses; i ++)
+ if (!status_ok && data->num_statuses > 0)
+ {
+ for (i = 0; i < data->num_statuses; i ++)
{
- if (statuses[i].if_defined &&
- !_ippVarsGet(vars, statuses[i].if_defined))
+ if (data->statuses[i].if_defined &&
+ !_ippVarsGet(vars, data->statuses[i].if_defined))
continue;
- if (statuses[i].if_not_defined &&
- _ippVarsGet(vars, statuses[i].if_not_defined))
+ if (data->statuses[i].if_not_defined &&
+ _ippVarsGet(vars, data->statuses[i].if_not_defined))
continue;
- if (ippGetStatusCode(response) == statuses[i].status)
- {
- status_ok = 1;
+ if (!data->statuses[i].repeat_match || repeat_count >= data->statuses[i].repeat_limit)
+ add_stringf(data->errors, "EXPECTED: STATUS %s (got %s)",
+ ippErrorString(data->statuses[i].status),
+ ippErrorString(cupsLastError()));
+ }
- if (statuses[i].repeat_match && repeat_count < statuses[i].repeat_limit)
- repeat_test = 1;
+ if ((attrptr = ippFindAttribute(response, "status-message",
+ IPP_TAG_TEXT)) != NULL)
+ add_stringf(data->errors, "status-message=\"%s\"",
+ attrptr->values[0].string.text);
+ }
- if (statuses[i].define_match)
- _ippVarsSet(vars, statuses[i].define_match, "1");
- }
- else
- {
- if (statuses[i].repeat_no_match && repeat_count < statuses[i].repeat_limit)
- repeat_test = 1;
+ for (i = data->num_expects, expect = data->expects; i > 0; i --, expect ++)
+ {
+ if (expect->if_defined && !_ippVarsGet(vars, expect->if_defined))
+ continue;
- if (statuses[i].define_no_match)
- {
- _ippVarsSet(vars, statuses[i].define_no_match, "1");
- status_ok = 1;
- }
- }
- }
+ if (expect->if_not_defined &&
+ _ippVarsGet(vars, expect->if_not_defined))
+ continue;
- if (!status_ok && num_statuses > 0)
+ found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+
+ do
{
- for (i = 0; i < num_statuses; i ++)
+ if ((found && expect->not_expect) ||
+ (!found && !(expect->not_expect || expect->optional)) ||
+ (found && !expect_matches(expect, found->value_tag)) ||
+ (found && expect->in_group &&
+ found->group_tag != expect->in_group))
{
- if (statuses[i].if_defined &&
- !_ippVarsGet(vars, statuses[i].if_defined))
- continue;
-
- if (statuses[i].if_not_defined &&
- _ippVarsGet(vars, statuses[i].if_not_defined))
- continue;
-
- if (!statuses[i].repeat_match || repeat_count >= statuses[i].repeat_limit)
- add_stringf(errors, "EXPECTED: STATUS %s (got %s)",
- ippErrorString(statuses[i].status),
- ippErrorString(cupsLastError()));
- }
-
- if ((attrptr = ippFindAttribute(response, "status-message",
- IPP_TAG_TEXT)) != NULL)
- add_stringf(errors, "status-message=\"%s\"",
- attrptr->values[0].string.text);
- }
+ if (expect->define_no_match)
+ _ippVarsSet(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value)
+ {
+ if (found && expect->not_expect)
+ add_stringf(data->errors, "NOT EXPECTED: %s", expect->name);
+ else if (!found && !(expect->not_expect || expect->optional))
+ add_stringf(data->errors, "EXPECTED: %s", expect->name);
+ else if (found)
+ {
+ if (!expect_matches(expect, found->value_tag))
+ add_stringf(data->errors, "EXPECTED: %s OF-TYPE %s (got %s)",
+ expect->name, expect->of_type,
+ ippTagString(found->value_tag));
+
+ if (expect->in_group && found->group_tag != expect->in_group)
+ add_stringf(data->errors, "EXPECTED: %s IN-GROUP %s (got %s).",
+ expect->name, ippTagString(expect->in_group),
+ ippTagString(found->group_tag));
+ }
+ }
- for (i = num_expects, expect = expects; i > 0; i --, expect ++)
- {
- if (expect->if_defined && !_ippVarsGet(vars, expect->if_defined))
- continue;
+ if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
+ repeat_test = 1;
- if (expect->if_not_defined &&
- _ippVarsGet(vars, expect->if_not_defined))
- continue;
+ break;
+ }
- found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+ if (found)
+ ippAttributeString(found, buffer, sizeof(buffer));
- do
- {
- if ((found && expect->not_expect) ||
- (!found && !(expect->not_expect || expect->optional)) ||
- (found && !expect_matches(expect, found->value_tag)) ||
- (found && expect->in_group &&
- found->group_tag != expect->in_group))
+ if (found && expect->with_value_from && !with_value_from(NULL, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, buffer, sizeof(buffer)))
+ {
+ if (expect->define_no_match)
+ _ippVarsSet(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value && ((!expect->repeat_match && !expect->repeat_no_match) || repeat_count >= expect->repeat_limit))
{
- if (expect->define_no_match)
- _ippVarsSet(vars, expect->define_no_match, "1");
- else if (!expect->define_match && !expect->define_value)
- {
- if (found && expect->not_expect)
- add_stringf(errors, "NOT EXPECTED: %s", expect->name);
- else if (!found && !(expect->not_expect || expect->optional))
- add_stringf(errors, "EXPECTED: %s", expect->name);
- else if (found)
- {
- if (!expect_matches(expect, found->value_tag))
- add_stringf(errors, "EXPECTED: %s OF-TYPE %s (got %s)",
- expect->name, expect->of_type,
- ippTagString(found->value_tag));
-
- if (expect->in_group && found->group_tag != expect->in_group)
- add_stringf(errors, "EXPECTED: %s IN-GROUP %s (got %s).",
- expect->name, ippTagString(expect->in_group),
- ippTagString(found->group_tag));
- }
- }
-
- if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
- repeat_test = 1;
+ add_stringf(data->errors, "EXPECTED: %s WITH-VALUES-FROM %s", expect->name, expect->with_value_from);
- break;
+ with_value_from(data->errors, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, buffer, sizeof(buffer));
}
- if (found)
- ippAttributeString(found, buffer, sizeof(buffer));
+ if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
+ repeat_test = 1;
- if (found && expect->with_value_from && !with_value_from(NULL, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, buffer, sizeof(buffer)))
+ break;
+ }
+ else if (found && !with_value(data, NULL, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer)))
+ {
+ if (expect->define_no_match)
+ _ippVarsSet(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value &&
+ !expect->repeat_match && (!expect->repeat_no_match || repeat_count >= expect->repeat_limit))
{
- if (expect->define_no_match)
- _ippVarsSet(vars, expect->define_no_match, "1");
- else if (!expect->define_match && !expect->define_value && ((!expect->repeat_match && !expect->repeat_no_match) || repeat_count >= expect->repeat_limit))
- {
- add_stringf(errors, "EXPECTED: %s WITH-VALUES-FROM %s", expect->name, expect->with_value_from);
+ if (expect->with_flags & _CUPS_WITH_REGEX)
+ add_stringf(data->errors, "EXPECTED: %s %s /%s/", expect->name, with_flags_string(expect->with_flags), expect->with_value);
+ else
+ add_stringf(data->errors, "EXPECTED: %s %s \"%s\"", expect->name, with_flags_string(expect->with_flags), expect->with_value);
- with_value_from(errors, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, buffer, sizeof(buffer));
- }
+ with_value(data, data->errors, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer));
+ }
- if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
- repeat_test = 1;
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
- break;
- }
- else if (found && !with_value(data->outfile, NULL, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer)))
+ break;
+ }
+
+ if (found && expect->count > 0 &&
+ found->num_values != expect->count)
+ {
+ if (expect->define_no_match)
+ _ippVarsSet(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value)
{
- if (expect->define_no_match)
- _ippVarsSet(vars, expect->define_no_match, "1");
- else if (!expect->define_match && !expect->define_value &&
- !expect->repeat_match && (!expect->repeat_no_match || repeat_count >= expect->repeat_limit))
- {
- if (expect->with_flags & _CUPS_WITH_REGEX)
- add_stringf(errors, "EXPECTED: %s %s /%s/", expect->name, with_flags_string(expect->with_flags), expect->with_value);
- else
- add_stringf(errors, "EXPECTED: %s %s \"%s\"", expect->name, with_flags_string(expect->with_flags), expect->with_value);
+ add_stringf(data->errors, "EXPECTED: %s COUNT %d (got %d)", expect->name,
+ expect->count, found->num_values);
+ }
- with_value(data->outfile, errors, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer));
- }
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
- if (expect->repeat_no_match &&
- repeat_count < expect->repeat_limit)
- repeat_test = 1;
+ break;
+ }
- break;
- }
+ if (found && expect->same_count_as)
+ {
+ attrptr = ippFindAttribute(response, expect->same_count_as,
+ IPP_TAG_ZERO);
- if (found && expect->count > 0 &&
- found->num_values != expect->count)
+ if (!attrptr || attrptr->num_values != found->num_values)
{
if (expect->define_no_match)
_ippVarsSet(vars, expect->define_no_match, "1");
else if (!expect->define_match && !expect->define_value)
{
- add_stringf(errors, "EXPECTED: %s COUNT %d (got %d)", expect->name,
- expect->count, found->num_values);
+ if (!attrptr)
+ add_stringf(data->errors,
+ "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
+ "(not returned)", expect->name,
+ found->num_values, expect->same_count_as);
+ else if (attrptr->num_values != found->num_values)
+ add_stringf(data->errors,
+ "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
+ "(%d values)", expect->name, found->num_values,
+ expect->same_count_as, attrptr->num_values);
}
if (expect->repeat_no_match &&
break;
}
+ }
- if (found && expect->same_count_as)
+ if (found && expect->define_match)
+ _ippVarsSet(vars, expect->define_match, "1");
+
+ if (found && expect->define_value)
+ {
+ if (!expect->with_value)
{
- attrptr = ippFindAttribute(response, expect->same_count_as,
- IPP_TAG_ZERO);
+ int last = ippGetCount(found) - 1;
+ /* Last element in attribute */
- if (!attrptr || attrptr->num_values != found->num_values)
+ switch (ippGetValueTag(found))
{
- if (expect->define_no_match)
- _ippVarsSet(vars, expect->define_no_match, "1");
- else if (!expect->define_match && !expect->define_value)
- {
- if (!attrptr)
- add_stringf(errors,
- "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
- "(not returned)", expect->name,
- found->num_values, expect->same_count_as);
- else if (attrptr->num_values != found->num_values)
- add_stringf(errors,
- "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
- "(%d values)", expect->name, found->num_values,
- expect->same_count_as, attrptr->num_values);
- }
-
- if (expect->repeat_no_match &&
- repeat_count < expect->repeat_limit)
- repeat_test = 1;
+ case IPP_TAG_ENUM :
+ case IPP_TAG_INTEGER :
+ snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(found, last));
+ break;
- break;
- }
- }
+ case IPP_TAG_BOOLEAN :
+ if (ippGetBoolean(found, last))
+ strlcpy(buffer, "true", sizeof(buffer));
+ else
+ strlcpy(buffer, "false", sizeof(buffer));
+ break;
- if (found && expect->define_match)
- _ippVarsSet(vars, expect->define_match, "1");
+ case IPP_TAG_RESOLUTION :
+ {
+ int xres, /* Horizontal resolution */
+ yres; /* Vertical resolution */
+ ipp_res_t units; /* Resolution units */
- if (found && expect->define_value)
- {
- if (!expect->with_value)
- {
- int last = ippGetCount(found) - 1;
- /* Last element in attribute */
+ xres = ippGetResolution(found, last, &yres, &units);
- switch (ippGetValueTag(found))
- {
- case IPP_TAG_ENUM :
- case IPP_TAG_INTEGER :
- snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(found, last));
- break;
-
- case IPP_TAG_BOOLEAN :
- if (ippGetBoolean(found, last))
- strlcpy(buffer, "true", sizeof(buffer));
+ if (xres == yres)
+ snprintf(buffer, sizeof(buffer), "%d%s", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
else
- strlcpy(buffer, "false", sizeof(buffer));
- break;
-
- case IPP_TAG_RESOLUTION :
- {
- int xres, /* Horizontal resolution */
- yres; /* Vertical resolution */
- ipp_res_t units; /* Resolution units */
-
- xres = ippGetResolution(found, last, &yres, &units);
-
- if (xres == yres)
- snprintf(buffer, sizeof(buffer), "%d%s", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
- else
- snprintf(buffer, sizeof(buffer), "%dx%d%s", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
- }
- break;
-
- case IPP_TAG_CHARSET :
- case IPP_TAG_KEYWORD :
- case IPP_TAG_LANGUAGE :
- case IPP_TAG_MIMETYPE :
- case IPP_TAG_NAME :
- case IPP_TAG_NAMELANG :
- case IPP_TAG_TEXT :
- case IPP_TAG_TEXTLANG :
- case IPP_TAG_URI :
- case IPP_TAG_URISCHEME :
- strlcpy(buffer, ippGetString(found, last, NULL), sizeof(buffer));
- break;
-
- default :
- ippAttributeString(found, buffer, sizeof(buffer));
- break;
- }
- }
+ snprintf(buffer, sizeof(buffer), "%dx%d%s", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+ }
+ break;
+
+ case IPP_TAG_CHARSET :
+ case IPP_TAG_KEYWORD :
+ case IPP_TAG_LANGUAGE :
+ case IPP_TAG_MIMETYPE :
+ case IPP_TAG_NAME :
+ case IPP_TAG_NAMELANG :
+ case IPP_TAG_TEXT :
+ case IPP_TAG_TEXTLANG :
+ case IPP_TAG_URI :
+ case IPP_TAG_URISCHEME :
+ strlcpy(buffer, ippGetString(found, last, NULL), sizeof(buffer));
+ break;
- _ippVarsSet(vars, expect->define_value, buffer);
+ default :
+ ippAttributeString(found, buffer, sizeof(buffer));
+ break;
+ }
}
- if (found && expect->repeat_match &&
- repeat_count < expect->repeat_limit)
- repeat_test = 1;
- }
- while (expect->expect_all && (found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL);
+ _ippVarsSet(vars, expect->define_value, buffer);
+ }
+
+ if (found && expect->repeat_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
}
+ while (expect->expect_all && (found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL);
}
+ }
- /*
- * If we are going to repeat this test, display intermediate results...
- */
+ /*
+ * If we are going to repeat this test, display intermediate results...
+ */
- if (repeat_test)
+ if (repeat_test)
+ {
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
{
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- {
- cupsFilePrintf(cupsFileStdout(), "%04d]\n", repeat_count);
+ cupsFilePrintf(cupsFileStdout(), "%04d]\n", repeat_count);
\
- if (num_displayed > 0)
+ if (data->num_displayed > 0)
+ {
+ for (attrptr = ippFirstAttribute(response); attrptr; attrptr = ippNextAttribute(response))
{
- for (attrptr = ippFirstAttribute(response); attrptr; attrptr = ippNextAttribute(response))
+ const char *attrname = ippGetName(attrptr);
+ if (attrname)
{
- const char *attrname = ippGetName(attrptr);
- if (attrname)
+ for (i = 0; i < data->num_displayed; i ++)
{
- for (i = 0; i < num_displayed; i ++)
+ if (!strcmp(data->displayed[i], attrname))
{
- if (!strcmp(displayed[i], attrname))
- {
- print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
- break;
- }
+ print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
+ break;
}
}
}
}
- }
-
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- {
- cupsFilePrintf(cupsFileStdout(), " %-68.68s [", name);
}
+ }
- ippDelete(response);
- response = NULL;
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
+ {
+ cupsFilePrintf(cupsFileStdout(), " %-68.68s [", data->name);
}
+
+ ippDelete(response);
+ response = NULL;
}
- while (repeat_test);
+ }
+ while (repeat_test);
- ippDelete(request);
+ ippDelete(request);
- request = NULL;
+ request = NULL;
- if (cupsArrayCount(errors) > 0)
- prev_pass = pass = 0;
+ if (cupsArrayCount(data->errors) > 0)
+ data->prev_pass = data->pass = 0;
- if (prev_pass)
- PassCount ++;
- else
- FailCount ++;
+ if (data->prev_pass)
+ data->pass_count ++;
+ else
+ data->fail_count ++;
- if (Output == _CUPS_OUTPUT_PLIST)
- {
- cupsFilePuts(data->outfile, "<key>Successful</key>\n");
- cupsFilePuts(data->outfile, prev_pass ? "<true />\n" : "<false />\n");
- cupsFilePuts(data->outfile, "<key>StatusCode</key>\n");
- print_xml_string(data->outfile, "string", ippErrorString(cupsLastError()));
- cupsFilePuts(data->outfile, "<key>ResponseAttributes</key>\n");
- cupsFilePuts(data->outfile, "<array>\n");
- cupsFilePuts(data->outfile, "<dict>\n");
- for (attrptr = response ? response->attrs : NULL,
- group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
- attrptr;
- attrptr = attrptr->next)
- print_attr(data->outfile, Output, attrptr, &group);
- cupsFilePuts(data->outfile, "</dict>\n");
- cupsFilePuts(data->outfile, "</array>\n");
- }
- else if (Output == _CUPS_OUTPUT_IPPSERVER && response)
+ if (data->output == _CUPS_OUTPUT_PLIST)
+ {
+ cupsFilePuts(data->outfile, "<key>Successful</key>\n");
+ cupsFilePuts(data->outfile, data->prev_pass ? "<true />\n" : "<false />\n");
+ cupsFilePuts(data->outfile, "<key>StatusCode</key>\n");
+ print_xml_string(data->outfile, "string", ippErrorString(cupsLastError()));
+ cupsFilePuts(data->outfile, "<key>ResponseAttributes</key>\n");
+ cupsFilePuts(data->outfile, "<array>\n");
+ cupsFilePuts(data->outfile, "<dict>\n");
+ for (attrptr = response ? response->attrs : NULL,
+ group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
+ attrptr;
+ attrptr = attrptr->next)
+ print_attr(data->outfile, data->output, attrptr, &group);
+ cupsFilePuts(data->outfile, "</dict>\n");
+ cupsFilePuts(data->outfile, "</array>\n");
+ }
+ else if (data->output == _CUPS_OUTPUT_IPPSERVER && response)
+ {
+ for (attrptr = ippFirstAttribute(response), group = IPP_TAG_ZERO; attrptr; attrptr = ippNextAttribute(response))
{
- for (attrptr = ippFirstAttribute(response), group = IPP_TAG_ZERO; attrptr; attrptr = ippNextAttribute(response))
- {
- if (!ippGetName(attrptr) || ippGetGroupTag(attrptr) != IPP_TAG_PRINTER)
- continue;
+ if (!ippGetName(attrptr) || ippGetGroupTag(attrptr) != IPP_TAG_PRINTER)
+ continue;
- print_ippserver_attr(data->outfile, attrptr, 0);
- }
+ print_ippserver_attr(data, attrptr, 0);
}
+ }
+
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
+ {
+ cupsFilePuts(cupsFileStdout(), data->prev_pass ? "PASS]\n" : "FAIL]\n");
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
+ if (!data->prev_pass || (data->verbosity && response))
{
- cupsFilePuts(cupsFileStdout(), prev_pass ? "PASS]\n" : "FAIL]\n");
+ cupsFilePrintf(cupsFileStdout(), " RECEIVED: %lu bytes in response\n", (unsigned long)ippLength(response));
+ cupsFilePrintf(cupsFileStdout(), " status-code = %s (%s)\n", ippErrorString(cupsLastError()), cupsLastErrorString());
- if (!prev_pass || (Verbosity && response))
+ if (data->verbosity && response)
{
- cupsFilePrintf(cupsFileStdout(), " RECEIVED: %lu bytes in response\n", (unsigned long)ippLength(response));
- cupsFilePrintf(cupsFileStdout(), " status-code = %s (%s)\n", ippErrorString(cupsLastError()), cupsLastErrorString());
-
- if (Verbosity && response)
- {
- for (attrptr = response->attrs;
- attrptr != NULL;
- attrptr = attrptr->next)
- print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
- }
+ for (attrptr = response->attrs;
+ attrptr != NULL;
+ attrptr = attrptr->next)
+ print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
}
}
- else if (!prev_pass && Output != _CUPS_OUTPUT_QUIET)
- fprintf(stderr, "%s\n", cupsLastErrorString());
+ }
+ else if (!data->prev_pass && data->output != _CUPS_OUTPUT_QUIET)
+ fprintf(stderr, "%s\n", cupsLastErrorString());
+
+ if (data->prev_pass && data->output >= _CUPS_OUTPUT_LIST && !data->verbosity && data->num_displayed > 0)
+ {
+ size_t width; /* Length of value */
- if (prev_pass && Output >= _CUPS_OUTPUT_LIST && !Verbosity &&
- num_displayed > 0)
+ for (i = 0; i < data->num_displayed; i ++)
{
- size_t width; /* Length of value */
+ widths[i] = strlen(data->displayed[i]);
- for (i = 0; i < num_displayed; i ++)
+ for (attrptr = ippFindAttribute(response, data->displayed[i], IPP_TAG_ZERO);
+ attrptr;
+ attrptr = ippFindNextAttribute(response, data->displayed[i], IPP_TAG_ZERO))
{
- widths[i] = strlen(displayed[i]);
-
- for (attrptr = ippFindAttribute(response, displayed[i], IPP_TAG_ZERO);
- attrptr;
- attrptr = ippFindNextAttribute(response, displayed[i],
- IPP_TAG_ZERO))
- {
- width = ippAttributeString(attrptr, NULL, 0);
- if (width > widths[i])
- widths[i] = width;
- }
+ width = ippAttributeString(attrptr, NULL, 0);
+ if (width > widths[i])
+ widths[i] = width;
}
+ }
- if (Output == _CUPS_OUTPUT_CSV)
- print_csv(data->outfile, NULL, num_displayed, displayed, widths);
- else
- print_line(data->outfile, NULL, num_displayed, displayed, widths);
+ if (data->output == _CUPS_OUTPUT_CSV)
+ print_csv(data, NULL, data->num_displayed, data->displayed, widths);
+ else
+ print_line(data, NULL, data->num_displayed, data->displayed, widths);
- attrptr = response->attrs;
+ attrptr = response->attrs;
- while (attrptr)
- {
- while (attrptr && attrptr->group_tag <= IPP_TAG_OPERATION)
- attrptr = attrptr->next;
+ while (attrptr)
+ {
+ while (attrptr && attrptr->group_tag <= IPP_TAG_OPERATION)
+ attrptr = attrptr->next;
- if (attrptr)
- {
- if (Output == _CUPS_OUTPUT_CSV)
- print_csv(data->outfile, attrptr, num_displayed, displayed, widths);
- else
- print_line(data->outfile, attrptr, num_displayed, displayed, widths);
+ if (attrptr)
+ {
+ if (data->output == _CUPS_OUTPUT_CSV)
+ print_csv(data, attrptr, data->num_displayed, data->displayed, widths);
+ else
+ print_line(data, attrptr, data->num_displayed, data->displayed, widths);
- while (attrptr && attrptr->group_tag > IPP_TAG_OPERATION)
- attrptr = attrptr->next;
- }
+ while (attrptr && attrptr->group_tag > IPP_TAG_OPERATION)
+ attrptr = attrptr->next;
}
}
- else if (!prev_pass)
+ }
+ else if (!data->prev_pass)
+ {
+ if (data->output == _CUPS_OUTPUT_PLIST)
{
- if (Output == _CUPS_OUTPUT_PLIST)
- {
- cupsFilePuts(data->outfile, "<key>Errors</key>\n");
- cupsFilePuts(data->outfile, "<array>\n");
+ cupsFilePuts(data->outfile, "<key>Errors</key>\n");
+ cupsFilePuts(data->outfile, "<array>\n");
- for (error = (char *)cupsArrayFirst(errors);
- error;
- error = (char *)cupsArrayNext(errors))
- print_xml_string(data->outfile, "string", error);
+ for (error = (char *)cupsArrayFirst(data->errors);
+ error;
+ error = (char *)cupsArrayNext(data->errors))
+ print_xml_string(data->outfile, "string", error);
- cupsFilePuts(data->outfile, "</array>\n");
- }
+ cupsFilePuts(data->outfile, "</array>\n");
+ }
- if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
- {
- for (error = (char *)cupsArrayFirst(errors);
- error;
- error = (char *)cupsArrayNext(errors))
- cupsFilePrintf(cupsFileStdout(), " %s\n", error);
- }
+ if (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout()))
+ {
+ for (error = (char *)cupsArrayFirst(data->errors);
+ error;
+ error = (char *)cupsArrayNext(data->errors))
+ cupsFilePrintf(cupsFileStdout(), " %s\n", error);
}
+ }
- if (num_displayed > 0 && !Verbosity && response && (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout())))
+ if (data->num_displayed > 0 && !data->verbosity && response && (data->output == _CUPS_OUTPUT_TEST || (data->output == _CUPS_OUTPUT_PLIST && data->outfile != cupsFileStdout())))
+ {
+ for (attrptr = response->attrs;
+ attrptr != NULL;
+ attrptr = attrptr->next)
{
- for (attrptr = response->attrs;
- attrptr != NULL;
- attrptr = attrptr->next)
+ if (attrptr->name)
{
- if (attrptr->name)
+ for (i = 0; i < data->num_displayed; i ++)
{
- for (i = 0; i < num_displayed; i ++)
+ if (!strcmp(data->displayed[i], attrptr->name))
{
- if (!strcmp(displayed[i], attrptr->name))
- {
- print_attr(data->outfile, Output, attrptr, NULL);
- break;
- }
+ print_attr(data->outfile, data->output, attrptr, NULL);
+ break;
}
}
}
}
-
- skip_error:
-
- if (Output == _CUPS_OUTPUT_PLIST)
- cupsFilePuts(data->outfile, "</dict>\n");
-
- ippDelete(response);
- response = NULL;
-
- for (i = 0; i < num_statuses; i ++)
- {
- if (statuses[i].if_defined)
- free(statuses[i].if_defined);
- if (statuses[i].if_not_defined)
- free(statuses[i].if_not_defined);
- if (statuses[i].define_match)
- free(statuses[i].define_match);
- if (statuses[i].define_no_match)
- free(statuses[i].define_no_match);
- }
- num_statuses = 0;
-
- for (i = num_expects, expect = expects; i > 0; i --, expect ++)
- {
- free(expect->name);
- if (expect->of_type)
- free(expect->of_type);
- if (expect->same_count_as)
- free(expect->same_count_as);
- if (expect->if_defined)
- free(expect->if_defined);
- if (expect->if_not_defined)
- free(expect->if_not_defined);
- if (expect->with_value)
- free(expect->with_value);
- if (expect->define_match)
- free(expect->define_match);
- if (expect->define_no_match)
- free(expect->define_no_match);
- if (expect->define_value)
- free(expect->define_value);
- }
- num_expects = 0;
-
- for (i = 0; i < num_displayed; i ++)
- free(displayed[i]);
- num_displayed = 0;
-
- if (!ignore_errors && !prev_pass)
- break;
}
- test_exit:
-
- cupsArrayDelete(errors);
+ skip_error:
- if (fp)
- cupsFileClose(fp);
+ if (data->output == _CUPS_OUTPUT_PLIST)
+ cupsFilePuts(data->outfile, "</dict>\n");
- httpClose(http);
- ippDelete(request);
ippDelete(response);
+ response = NULL;
- for (i = 0; i < num_statuses; i ++)
+ for (i = 0; i < data->num_statuses; i ++)
{
- if (statuses[i].if_defined)
- free(statuses[i].if_defined);
- if (statuses[i].if_not_defined)
- free(statuses[i].if_not_defined);
- if (statuses[i].define_match)
- free(statuses[i].define_match);
- if (statuses[i].define_no_match)
- free(statuses[i].define_no_match);
+ if (data->statuses[i].if_defined)
+ free(data->statuses[i].if_defined);
+ if (data->statuses[i].if_not_defined)
+ free(data->statuses[i].if_not_defined);
+ if (data->statuses[i].define_match)
+ free(data->statuses[i].define_match);
+ if (data->statuses[i].define_no_match)
+ free(data->statuses[i].define_no_match);
}
+ data->num_statuses = 0;
- for (i = num_expects, expect = expects; i > 0; i --, expect ++)
+ for (i = data->num_expects, expect = data->expects; i > 0; i --, expect ++)
{
free(expect->name);
if (expect->of_type)
if (expect->define_value)
free(expect->define_value);
}
+ data->num_expects = 0;
+
+ for (i = 0; i < data->num_displayed; i ++)
+ free(data->displayed[i]);
+ data->num_displayed = 0;
+
+ return (data->ignore_errors || data->prev_pass);
+}
+
+
+/*
+ * 'do_tests()' - Do tests as specified in the test file.
+ */
+
+static int /* O - 1 on success, 0 on failure */
+do_tests(const char *testfile, /* I - Test file to use */
+ _ipp_vars_t *vars, /* I - Variables */
+ _cups_testdata_t *data) /* I - Test data */
+{
+ http_encryption_t encryption; /* Encryption mode */
+
+
+ /*
+ * Connect to the printer/server...
+ */
+
+ if (!_cups_strcasecmp(vars->scheme, "https") || !_cups_strcasecmp(vars->scheme, "ipps"))
+ encryption = HTTP_ENCRYPTION_ALWAYS;
+ else
+ encryption = data->encryption;
+
+ if ((data->http = httpConnect2(vars->host, vars->port, NULL, data->family, encryption, 1, 30000, NULL)) == NULL)
+ {
+ print_fatal_error(data, "Unable to connect to \"%s\" on port %d - %s", vars->host, vars->port, cupsLastErrorString());
+ return (0);
+ }
+
+#ifdef HAVE_LIBZ
+ httpSetDefaultField(data->http, HTTP_FIELD_ACCEPT_ENCODING, "deflate, gzip, identity");
+#else
+ httpSetDefaultField(data->http, HTTP_FIELD_ACCEPT_ENCODING, "identity");
+#endif /* HAVE_LIBZ */
- for (i = 0; i < num_displayed; i ++)
- free(displayed[i]);
+ if (data->timeout > 0.0)
+ httpSetTimeout(data->http, data->timeout, timeout_cb, NULL);
- return (pass);
+ /*
+ * Run tests...
+ */
+
+ _ippFileParse(vars, testfile, (_ipp_ftoken_cb_t)token_cb, (_ipp_ferror_cb_t)error_cb, (void *)data);
+
+ /*
+ * Close connection and return...
+ */
+
+ httpClose(data->http);
+ data->http = NULL;
+
+ return (data->pass);
}
_cups_testdata_t *data, /* I - Test data */
const char *error) /* I - Error message */
{
+ (void)f;
+
+ print_fatal_error(data, "%s", error);
+
return (1);
}
if (!expect->of_type)
return (1);
- /*
- * Parse the "of_type" value since the string can contain multiple attribute
- * types separated by "," or "|"...
- */
-
- for (of_type = expect->of_type, match = 0; !match && *of_type; of_type = next)
- {
- /*
- * Find the next separator, and set it (temporarily) to nul if present.
- */
-
- for (next = of_type; *next && *next != '|' && *next != ','; next ++);
-
- if ((sep = *next) != '\0')
- *next = '\0';
-
- /*
- * Support some meta-types to make it easier to write the test file.
- */
-
- if (!strcmp(of_type, "text"))
- match = value_tag == IPP_TAG_TEXTLANG || value_tag == IPP_TAG_TEXT;
- else if (!strcmp(of_type, "name"))
- match = value_tag == IPP_TAG_NAMELANG || value_tag == IPP_TAG_NAME;
- else if (!strcmp(of_type, "collection"))
- match = value_tag == IPP_TAG_BEGIN_COLLECTION;
- else
- match = value_tag == ippTagValue(of_type);
-
- /*
- * Restore the separator if we have one...
- */
-
- if (sep)
- *next++ = sep;
- }
-
- return (match);
-}
-
-
-/*
- * 'get_collection()' - Get a collection value from the current test file.
- */
-
-static ipp_t * /* O - Collection value */
-get_collection(cups_file_t *outfile, /* I - Output file */
- _cups_vars_t *vars, /* I - Variables */
- cups_file_t *fp, /* I - File to read from */
- int *linenum) /* IO - Line number */
-{
- char token[1024], /* Token from file */
- temp[1024], /* Temporary string */
- attr[128]; /* Attribute name */
- ipp_tag_t value; /* Current value type */
- ipp_t *col = ippNew(); /* Collection value */
- ipp_attribute_t *lastcol = NULL; /* Last collection attribute */
-
-
- while (get_token(fp, token, sizeof(token), f->linenum, f->filename) != NULL)
- {
- if (!strcmp(token, "}"))
- break;
- else if (!strcmp(token, "{") && lastcol)
- {
- /*
- * Another collection value
- */
-
- ipp_t *subcol = get_collection(data->outfile, vars, fp, f->linenum, f->filename);
- /* Collection value */
-
- if (subcol)
- ippSetCollection(col, &lastcol, ippGetCount(lastcol), subcol);
- else
- goto col_error;
- }
- else if (!_cups_strcasecmp(token, "MEMBER"))
- {
- /*
- * Attribute...
- */
-
- lastcol = NULL;
-
- if (!get_token(fp, token, sizeof(token), f->linenum, f->filename))
- {
- print_fatal_error(data, "Missing MEMBER value tag on line %d of \"%s\".", *linenum);
- goto col_error;
- }
-
- if ((value = ippTagValue(token)) < IPP_TAG_UNSUPPORTED_VALUE)
- {
- print_fatal_error(data, "Bad MEMBER value tag \"%s\" on line %d of \"%s\".", token,
- *linenum);
- goto col_error;
- }
-
- if (!get_token(fp, attr, sizeof(attr), f->linenum, f->filename))
- {
- print_fatal_error(data, "Missing MEMBER name on line %d of \"%s\".", *linenum);
- goto col_error;
- }
-
- if (value < IPP_TAG_INTEGER)
- {
- /*
- * Out-of-band member attributes have no value...
- */
-
- token[0] = '\0';
- }
- else if (!get_token(fp, temp, sizeof(temp), f->linenum, f->filename))
- {
- print_fatal_error(data, "Missing MEMBER value on line %d of \"%s\".", *linenum);
- goto col_error;
- }
- else
- {
- _ippVarsExpand(vars, token, temp, sizeof(token));
- }
-
- switch (value)
- {
- default :
- if (value < IPP_TAG_INTEGER)
- {
- /*
- * Add out-of-band value...
- */
-
- ippAddOutOfBand(col, IPP_TAG_ZERO, value, attr);
- }
- else
- {
- print_fatal_error(data, "Unsupported MEMBER value tag %s for \"%s\" on line %d of \"%s\".", ippTagString(value), attr, *linenum);
- goto col_error;
- }
- break;
-
- case IPP_TAG_BOOLEAN :
- if (!_cups_strcasecmp(token, "true"))
- ippAddBoolean(col, IPP_TAG_ZERO, attr, 1);
- else
- ippAddBoolean(col, IPP_TAG_ZERO, attr, (char)atoi(token));
- break;
-
- case IPP_TAG_INTEGER :
- case IPP_TAG_ENUM :
- ippAddInteger(col, IPP_TAG_ZERO, value, attr, atoi(token));
- break;
-
- case IPP_TAG_RESOLUTION :
- {
- int xres, /* X resolution */
- yres; /* Y resolution */
- char units[6]; /* Units */
-
- if (sscanf(token, "%dx%d%5s", &xres, &yres, units) != 3 ||
- (_cups_strcasecmp(units, "dpi") &&
- _cups_strcasecmp(units, "dpc") &&
- _cups_strcasecmp(units, "dpcm") &&
- _cups_strcasecmp(units, "other")))
- {
- print_fatal_error(data, "Bad resolution value \"%s\" on line %d of \"%s\".",
- token, *linenum);
- goto col_error;
- }
-
- if (!_cups_strcasecmp(units, "dpi"))
- ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_INCH, xres, yres);
- else if (!_cups_strcasecmp(units, "dpc") ||
- !_cups_strcasecmp(units, "dpcm"))
- ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_CM, xres, yres);
- else
- ippAddResolution(col, IPP_TAG_ZERO, attr, (ipp_res_t)0, xres, yres);
- }
- break;
-
- case IPP_TAG_RANGE :
- {
- int lowers[4], /* Lower value */
- uppers[4], /* Upper values */
- num_vals; /* Number of values */
-
-
- num_vals = sscanf(token, "%d-%d,%d-%d,%d-%d,%d-%d",
- lowers + 0, uppers + 0,
- lowers + 1, uppers + 1,
- lowers + 2, uppers + 2,
- lowers + 3, uppers + 3);
-
- if ((num_vals & 1) || num_vals == 0)
- {
- print_fatal_error(data, "Bad rangeOfInteger value \"%s\" on line %d of \"%s\".",
- token, *linenum);
- goto col_error;
- }
-
- ippAddRanges(col, IPP_TAG_ZERO, attr, num_vals / 2, lowers,
- uppers);
- }
- break;
-
- case IPP_TAG_BEGIN_COLLECTION :
- if (!strcmp(token, "{"))
- {
- ipp_t *subcol = get_collection(data->outfile, vars, fp, f->linenum, f->filename);
- /* Collection value */
-
- if (subcol)
- {
- lastcol = ippAddCollection(col, IPP_TAG_ZERO, attr, subcol);
- ippDelete(subcol);
- }
- else
- goto col_error;
- }
- else
- {
- print_fatal_error(data, "Bad collection value on line %d of \"%s\".", *linenum);
- goto col_error;
- }
- break;
-
- case IPP_TAG_STRING :
- ippAddOctetString(col, IPP_TAG_ZERO, attr, token, (int)strlen(token));
- break;
-
- case IPP_TAG_TEXTLANG :
- case IPP_TAG_NAMELANG :
- case IPP_TAG_TEXT :
- case IPP_TAG_NAME :
- case IPP_TAG_KEYWORD :
- case IPP_TAG_URI :
- case IPP_TAG_URISCHEME :
- case IPP_TAG_CHARSET :
- case IPP_TAG_LANGUAGE :
- case IPP_TAG_MIMETYPE :
- if (!strchr(token, ','))
- ippAddString(col, IPP_TAG_ZERO, value, attr, NULL, token);
- else
- {
- /*
- * Multiple string values...
- */
-
- int num_values; /* Number of values */
- char *values[100], /* Values */
- *ptr; /* Pointer to next value */
-
+ /*
+ * Parse the "of_type" value since the string can contain multiple attribute
+ * types separated by "," or "|"...
+ */
- values[0] = token;
- num_values = 1;
+ for (of_type = expect->of_type, match = 0; !match && *of_type; of_type = next)
+ {
+ /*
+ * Find the next separator, and set it (temporarily) to nul if present.
+ */
- for (ptr = strchr(token, ','); ptr; ptr = strchr(ptr, ','))
- {
- if (ptr > token && ptr[-1] == '\\')
- _cups_strcpy(ptr - 1, ptr);
- else
- {
- *ptr++ = '\0';
- values[num_values] = ptr;
- num_values ++;
- }
- }
+ for (next = of_type; *next && *next != '|' && *next != ','; next ++);
- ippAddStrings(col, IPP_TAG_ZERO, value, attr, num_values,
- NULL, (const char **)values);
- }
- break;
- }
- }
- else
- {
- print_fatal_error(data, "Unexpected token %s seen on line %d of \"%s\".", token, *linenum);
- goto col_error;
- }
- }
+ if ((sep = *next) != '\0')
+ *next = '\0';
- return (col);
+ /*
+ * Support some meta-types to make it easier to write the test file.
+ */
- /*
- * If we get here there was a parse error; free memory and return.
- */
+ if (!strcmp(of_type, "text"))
+ match = value_tag == IPP_TAG_TEXTLANG || value_tag == IPP_TAG_TEXT;
+ else if (!strcmp(of_type, "name"))
+ match = value_tag == IPP_TAG_NAMELANG || value_tag == IPP_TAG_NAME;
+ else if (!strcmp(of_type, "collection"))
+ match = value_tag == IPP_TAG_BEGIN_COLLECTION;
+ else
+ match = value_tag == ippTagValue(of_type);
- col_error:
+ /*
+ * Restore the separator if we have one...
+ */
- ippDelete(col);
+ if (sep)
+ *next++ = sep;
+ }
- return (NULL);
+ return (match);
}
if (*dstptr == '>')
*dstptr = '\0';
}
- else if (*src == '/' || !strchr(testfile, '/')
+ else if (!access(src, R_OK) || *src == '/'
#ifdef WIN32
|| (isalpha(*src & 255) && src[1] == ':')
#endif /* WIN32 */
}
-/*
- * 'get_token()' - Get a token from a file.
- */
-
-static char * /* O - Token from file or NULL on EOF */
-get_token(cups_file_t *fp, /* I - File to read from */
- char *buf, /* I - Buffer to read into */
- int buflen, /* I - Length of buffer */
- int *linenum) /* IO - Current line number */
-{
- int ch, /* Character from file */
- quote; /* Quoting character */
- char *bufptr, /* Pointer into buffer */
- *bufend; /* End of buffer */
-
-
- for (;;)
- {
- /*
- * Skip whitespace...
- */
-
- while (isspace(ch = cupsFileGetChar(fp)))
- {
- if (ch == '\n')
- (*linenum) ++;
- }
-
- /*
- * Read a token...
- */
-
- if (ch == EOF)
- return (NULL);
- else if (ch == '\'' || ch == '\"')
- {
- /*
- * Quoted text or regular expression...
- */
-
- quote = ch;
- bufptr = buf;
- bufend = buf + buflen - 1;
-
- while ((ch = cupsFileGetChar(fp)) != EOF)
- {
- if (ch == '\\')
- {
- /*
- * Escape next character...
- */
-
- if (bufptr < bufend)
- *bufptr++ = (char)ch;
-
- if ((ch = cupsFileGetChar(fp)) != EOF && bufptr < bufend)
- *bufptr++ = (char)ch;
- }
- else if (ch == quote)
- break;
- else if (bufptr < bufend)
- *bufptr++ = (char)ch;
- }
-
- *bufptr = '\0';
-
- return (buf);
- }
- else if (ch == '#')
- {
- /*
- * Comment...
- */
-
- while ((ch = cupsFileGetChar(fp)) != EOF)
- if (ch == '\n')
- break;
-
- (*linenum) ++;
- }
- else if (ch == '{' || ch == '}' || ch == ',')
- {
- buf[0] = (char)ch;
- buf[1] = '\0';
-
- return (buf);
- }
- else
- {
- /*
- * Whitespace delimited text...
- */
-
- cupsFileSeek(fp, cupsFileTell(fp) - 1);
-
- bufptr = buf;
- bufend = buf + buflen - 1;
-
- while ((ch = cupsFileGetChar(fp)) != EOF)
- if (isspace(ch) || ch == '#')
- break;
- else if (bufptr < bufend)
- *bufptr++ = (char)ch;
-
- if (ch == '#')
- cupsFileSeek(fp, cupsFileTell(fp) - 1);
- else if (ch == '\n')
- (*linenum) ++;
-
- *bufptr = '\0';
-
- return (buf);
- }
- }
-}
-
-
/*
* 'init_data()' - Initialize test data.
*/
data->family = AF_UNSPEC;
data->def_transfer = _CUPS_TRANSFER_AUTO;
data->def_version = 11;
+ data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free);
+ data->pass = 1;
data->prev_pass = 1;
+ data->request_id = (CUPS_RAND() % 1000) * 137 + 1;
data->show_header = 1;
}
*/
static void
-print_attr(_cups_testdata_t *data, /* I - Test data */
+print_attr(cups_file_t *outfile, /* I - Output file */
+ int output, /* I - Output format */
ipp_attribute_t *attr, /* I - Attribute to print */
ipp_tag_t *group) /* IO - Current group */
{
ipp_attribute_t *colattr; /* Collection attribute */
- if (format == _CUPS_OUTPUT_PLIST)
+ if (output == _CUPS_OUTPUT_PLIST)
{
if (!attr->name || (group && *group != attr->group_tag))
{
if (attr->group_tag != IPP_TAG_ZERO)
{
- cupsFilePuts(data->outfile, "</dict>\n");
- cupsFilePuts(data->outfile, "<dict>\n");
+ cupsFilePuts(outfile, "</dict>\n");
+ cupsFilePuts(outfile, "<dict>\n");
}
if (group)
if (!attr->name)
return;
- print_xml_string(data->outfile, "key", attr->name);
+ print_xml_string(outfile, "key", attr->name);
if (attr->num_values > 1)
- cupsFilePuts(data->outfile, "<array>\n");
+ cupsFilePuts(outfile, "<array>\n");
switch (attr->value_tag)
{
case IPP_TAG_INTEGER :
case IPP_TAG_ENUM :
for (i = 0; i < attr->num_values; i ++)
- cupsFilePrintf(data->outfile, "<integer>%d</integer>\n", attr->values[i].integer);
+ cupsFilePrintf(outfile, "<integer>%d</integer>\n", attr->values[i].integer);
break;
case IPP_TAG_BOOLEAN :
for (i = 0; i < attr->num_values; i ++)
- cupsFilePuts(data->outfile, attr->values[i].boolean ? "<true />\n" : "<false />\n");
+ cupsFilePuts(outfile, attr->values[i].boolean ? "<true />\n" : "<false />\n");
break;
case IPP_TAG_RANGE :
for (i = 0; i < attr->num_values; i ++)
- cupsFilePrintf(data->outfile, "<dict><key>lower</key><integer>%d</integer>"
+ cupsFilePrintf(outfile, "<dict><key>lower</key><integer>%d</integer>"
"<key>upper</key><integer>%d</integer></dict>\n",
attr->values[i].range.lower, attr->values[i].range.upper);
break;
case IPP_TAG_RESOLUTION :
for (i = 0; i < attr->num_values; i ++)
- cupsFilePrintf(data->outfile, "<dict><key>xres</key><integer>%d</integer>"
+ cupsFilePrintf(outfile, "<dict><key>xres</key><integer>%d</integer>"
"<key>yres</key><integer>%d</integer>"
"<key>units</key><string>%s</string></dict>\n",
attr->values[i].resolution.xres,
case IPP_TAG_DATE :
for (i = 0; i < attr->num_values; i ++)
- cupsFilePrintf(data->outfile, "<date>%s</date>\n", iso_date(attr->values[i].date));
+ cupsFilePrintf(outfile, "<date>%s</date>\n", iso_date(attr->values[i].date));
break;
case IPP_TAG_STRING :
char buffer[IPP_MAX_LENGTH * 5 / 4 + 1];
/* Output buffer */
- cupsFilePrintf(data->outfile, "<data>%s</data>\n",
+ cupsFilePrintf(outfile, "<data>%s</data>\n",
httpEncode64_2(buffer, sizeof(buffer),
attr->values[i].unknown.data,
attr->values[i].unknown.length));
case IPP_TAG_LANGUAGE :
case IPP_TAG_MIMETYPE :
for (i = 0; i < attr->num_values; i ++)
- print_xml_string(data->outfile, "string", attr->values[i].string.text);
+ print_xml_string(outfile, "string", attr->values[i].string.text);
break;
case IPP_TAG_TEXTLANG :
case IPP_TAG_NAMELANG :
for (i = 0; i < attr->num_values; i ++)
{
- cupsFilePuts(data->outfile, "<dict><key>language</key><string>");
- print_xml_string(data->outfile, NULL, attr->values[i].string.language);
- cupsFilePuts(data->outfile, "</string><key>string</key><string>");
- print_xml_string(data->outfile, NULL, attr->values[i].string.text);
- cupsFilePuts(data->outfile, "</string></dict>\n");
+ cupsFilePuts(outfile, "<dict><key>language</key><string>");
+ print_xml_string(outfile, NULL, attr->values[i].string.language);
+ cupsFilePuts(outfile, "</string><key>string</key><string>");
+ print_xml_string(outfile, NULL, attr->values[i].string.text);
+ cupsFilePuts(outfile, "</string></dict>\n");
}
break;
case IPP_TAG_BEGIN_COLLECTION :
for (i = 0; i < attr->num_values; i ++)
{
- cupsFilePuts(data->outfile, "<dict>\n");
+ cupsFilePuts(outfile, "<dict>\n");
for (colattr = attr->values[i].collection->attrs;
colattr;
colattr = colattr->next)
- print_attr(data->outfile, format, colattr, NULL);
- cupsFilePuts(data->outfile, "</dict>\n");
+ print_attr(outfile, output, colattr, NULL);
+ cupsFilePuts(outfile, "</dict>\n");
}
break;
default :
- cupsFilePrintf(data->outfile, "<string><<%s>></string>\n", ippTagString(attr->value_tag));
+ cupsFilePrintf(outfile, "<string><<%s>></string>\n", ippTagString(attr->value_tag));
break;
}
if (attr->num_values > 1)
- cupsFilePuts(data->outfile, "</array>\n");
+ cupsFilePuts(outfile, "</array>\n");
}
else
{
char buffer[131072]; /* Value buffer */
- if (format == _CUPS_OUTPUT_TEST)
+ if (output == _CUPS_OUTPUT_TEST)
{
if (!attr->name)
{
- cupsFilePuts(data->outfile, " -- separator --\n");
+ cupsFilePuts(outfile, " -- separator --\n");
return;
}
- cupsFilePrintf(data->outfile, " %s (%s%s) = ", attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag));
+ cupsFilePrintf(outfile, " %s (%s%s) = ", attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag));
}
ippAttributeString(attr, buffer, sizeof(buffer));
- cupsFilePrintf(data->outfile, "%s\n", buffer);
+ cupsFilePrintf(outfile, "%s\n", buffer);
}
}
* Then output it...
*/
- if (Output == _CUPS_OUTPUT_PLIST)
+ if (data->output == _CUPS_OUTPUT_PLIST)
{
- print_xml_header(data->outfile);
- print_xml_trailer(data->outfile, 0, buffer);
+ print_xml_header(data);
+ print_xml_trailer(data, 0, buffer);
}
_cupsLangPrintf(stderr, "ipptool: %s", buffer);
const char *s = (const char *)ippGetOctetString(attr, i, &len);
cupsFilePuts(data->outfile, i ? "," : " ");
- print_ippserver_string(data->outfile, s, (size_t)len);
+ print_ippserver_string(data, s, (size_t)len);
}
break;
const char *s = ippGetString(attr, i, NULL);
cupsFilePuts(data->outfile, i ? "," : " ");
- print_ippserver_string(data->outfile, s, strlen(s));
+ print_ippserver_string(data, s, strlen(s));
}
break;
cupsFilePuts(data->outfile, i ? ",{\n" : " {\n");
for (colattr = ippFirstAttribute(col); colattr; colattr = ippNextAttribute(col))
- print_ippserver_attr(data->outfile, colattr, indent + 4);
+ print_ippserver_attr(data, colattr, indent + 4);
cupsFilePrintf(data->outfile, "%*s}", indent, "");
}
break;
if (!data->xml_header)
{
cupsFilePuts(data->outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- cupsFilePuts(data->outfile, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
- "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
+ cupsFilePuts(data->outfile, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
cupsFilePuts(data->outfile, "<plist version=\"1.0\">\n");
cupsFilePuts(data->outfile, "<dict>\n");
cupsFilePuts(data->outfile, "<key>ipptoolVersion</key>\n");
cupsFilePuts(data->outfile, "<string>" CUPS_SVERSION "</string>\n");
cupsFilePuts(data->outfile, "<key>Transfer</key>\n");
- cupsFilePrintf(data->outfile, "<string>%s</string>\n",
- Transfer == _CUPS_TRANSFER_AUTO ? "auto" :
- Transfer == _CUPS_TRANSFER_CHUNKED ? "chunked" : "length");
+ cupsFilePrintf(data->outfile, "<string>%s</string>\n", data->transfer == _CUPS_TRANSFER_AUTO ? "auto" : data->transfer == _CUPS_TRANSFER_CHUNKED ? "chunked" : "length");
cupsFilePuts(data->outfile, "<key>Tests</key>\n");
cupsFilePuts(data->outfile, "<array>\n");
*/
static void
-print_xml_string(
- _cups_testdata_t *data, /* I - Test data */
- const char *element, /* I - Element name or NULL */
- const char *s) /* I - String to print */
+print_xml_string(cups_file_t *outfile, /* I - Test data */
+ const char *element, /* I - Element name or NULL */
+ const char *s) /* I - String to print */
{
if (element)
- cupsFilePrintf(data->outfile, "<%s>", element);
+ cupsFilePrintf(outfile, "<%s>", element);
while (*s)
{
if (*s == '&')
- cupsFilePuts(data->outfile, "&");
+ cupsFilePuts(outfile, "&");
else if (*s == '<')
- cupsFilePuts(data->outfile, "<");
+ cupsFilePuts(outfile, "<");
else if (*s == '>')
- cupsFilePuts(data->outfile, ">");
+ cupsFilePuts(outfile, ">");
else if ((*s & 0xe0) == 0xc0)
{
/*
if ((s[1] & 0xc0) != 0x80)
{
- cupsFilePutChar(data->outfile, '?');
+ cupsFilePutChar(outfile, '?');
s ++;
}
else
{
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s);
}
}
else if ((*s & 0xf0) == 0xe0)
if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80)
{
- cupsFilePutChar(data->outfile, '?');
+ cupsFilePutChar(outfile, '?');
s += 2;
}
else
{
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s);
}
}
else if ((*s & 0xf8) == 0xf0)
if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 ||
(s[3] & 0xc0) != 0x80)
{
- cupsFilePutChar(data->outfile, '?');
+ cupsFilePutChar(outfile, '?');
s += 3;
}
else
{
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s++);
- cupsFilePutChar(data->outfile, *s);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s++);
+ cupsFilePutChar(outfile, *s);
}
}
else if ((*s & 0x80) || (*s < ' ' && !isspace(*s & 255)))
* Invalid control character...
*/
- cupsFilePutChar(data->outfile, '?');
+ cupsFilePutChar(outfile, '?');
}
else
- cupsFilePutChar(data->outfile, *s);
+ cupsFilePutChar(outfile, *s);
s ++;
}
if (element)
- cupsFilePrintf(data->outfile, "</%s>\n", element);
+ cupsFilePrintf(outfile, "</%s>\n", element);
}
{
char name[1024], /* Name string */
temp[1024], /* Temporary string */
- value[1024]; /* Value string */
+ value[1024], /* Value string */
+ *ptr; /* Pointer into value */
+
+ if (!token)
+ {
+ /*
+ * Initialize state as needed (nothing for now...)
+ */
- if (f->attrs)
+ return (1);
+ }
+ else if (f->attrs)
{
/*
* Parse until we see a close brace...
if (!strcmp(token, "}"))
{
- /*
- * TODO: Call do_test and return...
- */
-
+ return (do_test(f, vars, data));
}
else if (!strcmp(token, "COMPRESSION"))
{
return (0);
}
- if (!strcmp(compression, "none"))
+ if (!strcmp(data->compression, "none"))
data->compression[0] = '\0';
}
else
else
{
print_fatal_error(data, "Missing VERSION number on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "RESOURCE"))
* Resource name...
*/
- if (!get_token(fp, resource, sizeof(resource), &linenum))
+ if (!_ippFileReadToken(f, data->resource, sizeof(data->resource)))
{
print_fatal_error(data, "Missing RESOURCE path on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "OPERATION"))
* Operation...
*/
+ ipp_op_t op; /* Operation code */
+
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing OPERATION code on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- _ippVarsExpand(vars, token, temp, sizeof(token));
+ _ippVarsExpand(vars, value, temp, sizeof(value));
- if ((op = ippOpValue(token)) == (ipp_op_t)-1 &&
- (op = (ipp_op_t)strtol(token, NULL, 0)) == 0)
+ if ((op = ippOpValue(value)) == (ipp_op_t)-1 && (op = (ipp_op_t)strtol(value, NULL, 0)) == 0)
{
- print_fatal_error(data, "Bad OPERATION code \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad OPERATION code \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
+ return (0);
}
+
+ ippSetOperation(f->attrs, op);
}
else if (!_cups_strcasecmp(token, "GROUP"))
{
* Attribute group...
*/
- if (!get_token(fp, token, sizeof(token), &linenum))
+ ipp_tag_t group_tag; /* Group tag */
+
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing GROUP tag on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if ((value = ippTagValue(token)) == IPP_TAG_ZERO || value >= IPP_TAG_UNSUPPORTED_VALUE)
+ if ((group_tag = ippTagValue(temp)) == IPP_TAG_ZERO || group_tag >= IPP_TAG_UNSUPPORTED_VALUE)
{
- print_fatal_error(data, "Bad GROUP tag \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad GROUP tag \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
+ return (0);
}
- if (value == group)
- ippAddSeparator(request);
+ if (group_tag == f->group_tag)
+ ippAddSeparator(f->attrs);
- group = value;
+ f->group_tag = group_tag;
}
else if (!_cups_strcasecmp(token, "DELAY"))
{
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing DELAY value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- _ippVarsExpand(vars, token, temp, sizeof(token));
+ _ippVarsExpand(vars, value, temp, sizeof(value));
- if ((dval = _cupsStrScand(token, &tokenptr, localeconv())) < 0.0 || (*tokenptr && *tokenptr != ','))
+ if ((dval = _cupsStrScand(value, &ptr, localeconv())) < 0.0 || (*ptr && *ptr != ','))
{
- print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
+ return (0);
}
- delay = (useconds_t)(1000000.0 * dval);
+ data->delay = (useconds_t)(1000000.0 * dval);
- if (*tokenptr == ',')
+ if (*ptr == ',')
{
- if ((dval = _cupsStrScand(tokenptr + 1, &tokenptr, localeconv())) <= 0.0 || *tokenptr)
+ if ((dval = _cupsStrScand(ptr + 1, &ptr, localeconv())) <= 0.0 || *ptr)
{
- print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad DELAY value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
+ return (0);
}
- repeat_interval = (useconds_t)(1000000.0 * dval);
+ data->repeat_interval = (useconds_t)(1000000.0 * dval);
}
else
- repeat_interval = delay;
+ data->repeat_interval = data->delay;
}
else if (!_cups_strcasecmp(token, "FILE"))
{
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing FILE filename on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- _ippVarsExpand(vars, token, temp, sizeof(token));
- get_filename(testfile, filename, token, sizeof(filename));
+ _ippVarsExpand(vars, value, temp, sizeof(value));
+ get_filename(f->filename, data->file, value, sizeof(data->file));
- if (access(filename, R_OK))
+ if (access(data->file, R_OK))
{
- print_fatal_error(data, "Filename \"%s\" on line %d cannot be read.",
- temp, f->linenum, f->filename);
- print_fatal_error(data, "Filename mapped to \"%s\".", filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Filename \"%s\" (mapped to \"%s\") on line %d of \"%s\" cannot be read.", value, data->file, f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "STATUS"))
* Status...
*/
- if (num_statuses >= (int)(sizeof(statuses) / sizeof(statuses[0])))
+ if (data->num_statuses >= (int)(sizeof(data->statuses) / sizeof(data->statuses[0])))
{
print_fatal_error(data, "Too many STATUS's on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing STATUS code on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if ((statuses[num_statuses].status = ippErrorValue(token))
- == (ipp_status_t)-1 &&
- (statuses[num_statuses].status = (ipp_status_t)strtol(token, NULL, 0)) == 0)
+ if ((data->statuses[data->num_statuses].status = ippErrorValue(temp)) == (ipp_status_t)-1 && (data->statuses[data->num_statuses].status = (ipp_status_t)strtol(temp, NULL, 0)) == 0)
{
- print_fatal_error(data, "Bad STATUS code \"%s\" on line %d of \"%s\".", token,
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad STATUS code \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
+ return (0);
}
- last_status = statuses + num_statuses;
- num_statuses ++;
+ data->last_status = data->statuses + data->num_statuses;
+ data->num_statuses ++;
- last_status->define_match = NULL;
- last_status->define_no_match = NULL;
- last_status->if_defined = NULL;
- last_status->if_not_defined = NULL;
- last_status->repeat_limit = 1000;
- last_status->repeat_match = 0;
- last_status->repeat_no_match = 0;
+ data->last_status->define_match = NULL;
+ data->last_status->define_no_match = NULL;
+ data->last_status->if_defined = NULL;
+ data->last_status->if_not_defined = NULL;
+ data->last_status->repeat_limit = 1000;
+ data->last_status->repeat_match = 0;
+ data->last_status->repeat_no_match = 0;
}
else if (!_cups_strcasecmp(token, "EXPECT") || !_cups_strcasecmp(token, "EXPECT-ALL"))
{
int expect_all = !_cups_strcasecmp(token, "EXPECT-ALL");
- if (num_expects >= (int)(sizeof(expects) / sizeof(expects[0])))
+ if (data->num_expects >= (int)(sizeof(data->expects) / sizeof(data->expects[0])))
{
print_fatal_error(data, "Too many EXPECT's on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, name, sizeof(name)))
{
print_fatal_error(data, "Missing EXPECT name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- last_expect = expects + num_expects;
- num_expects ++;
+ data->last_expect = data->expects + data->num_expects;
+ data->num_expects ++;
- memset(last_expect, 0, sizeof(_cups_expect_t));
- last_expect->repeat_limit = 1000;
- last_expect->expect_all = expect_all;
+ memset(data->last_expect, 0, sizeof(_cups_expect_t));
+ data->last_expect->repeat_limit = 1000;
+ data->last_expect->expect_all = expect_all;
- if (token[0] == '!')
+ if (name[0] == '!')
{
- last_expect->not_expect = 1;
- last_expect->name = strdup(token + 1);
+ data->last_expect->not_expect = 1;
+ data->last_expect->name = strdup(name + 1);
}
- else if (token[0] == '?')
+ else if (name[0] == '?')
{
- last_expect->optional = 1;
- last_expect->name = strdup(token + 1);
+ data->last_expect->optional = 1;
+ data->last_expect->name = strdup(name + 1);
}
else
- last_expect->name = strdup(token);
+ data->last_expect->name = strdup(name);
}
else if (!_cups_strcasecmp(token, "COUNT"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ int count; /* Count value */
+
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing COUNT number on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if ((i = atoi(token)) <= 0)
+ if ((count = atoi(temp)) <= 0)
{
- print_fatal_error(data, "Bad COUNT \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Bad COUNT \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
+ return (0);
}
- if (last_expect)
- last_expect->count = i;
+ if (data->last_expect)
+ {
+ data->last_expect->count = count;
+ }
else
{
- print_fatal_error(data, "COUNT without a preceding EXPECT on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "COUNT without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "DEFINE-MATCH"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
- print_fatal_error(data, "Missing DEFINE-MATCH variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Missing DEFINE-MATCH variable on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
- if (last_expect)
- last_expect->define_match = strdup(token);
- else if (last_status)
- last_status->define_match = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->define_match = strdup(temp);
+ }
+ else if (data->last_status)
+ {
+ data->last_status->define_match = strdup(temp);
+ }
else
{
- print_fatal_error(data, "DEFINE-MATCH without a preceding EXPECT or STATUS "
- "on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "DEFINE-MATCH without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "DEFINE-NO-MATCH"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
- print_fatal_error(data, "Missing DEFINE-NO-MATCH variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Missing DEFINE-NO-MATCH variable on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
- if (last_expect)
- last_expect->define_no_match = strdup(token);
- else if (last_status)
- last_status->define_no_match = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->define_no_match = strdup(temp);
+ }
+ else if (data->last_status)
+ {
+ data->last_status->define_no_match = strdup(temp);
+ }
else
{
- print_fatal_error(data, "DEFINE-NO-MATCH without a preceding EXPECT or "
- "STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "DEFINE-NO-MATCH without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "DEFINE-VALUE"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
- print_fatal_error(data, "Missing DEFINE-VALUE variable on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Missing DEFINE-VALUE variable on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
- if (last_expect)
- last_expect->define_value = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->define_value = strdup(temp);
+ }
else
{
- print_fatal_error(data, "DEFINE-VALUE without a preceding EXPECT on "
- "line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "DEFINE-VALUE without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "OF-TYPE"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
- print_fatal_error(data, "Missing OF-TYPE value tag(s) on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Missing OF-TYPE value tag(s) on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
- if (last_expect)
- last_expect->of_type = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->of_type = strdup(temp);
+ }
else
{
- print_fatal_error(data, "OF-TYPE without a preceding EXPECT on line %d of \"%s\".",
- linenum);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "OF-TYPE without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "IN-GROUP"))
{
- ipp_tag_t in_group; /* IN-GROUP value */
+ ipp_tag_t in_group; /* IN-GROUP value */
-
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing IN-GROUP group tag on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if ((in_group = ippTagValue(token)) == IPP_TAG_ZERO || in_group >= IPP_TAG_UNSUPPORTED_VALUE)
+ if ((in_group = ippTagValue(temp)) == IPP_TAG_ZERO || in_group >= IPP_TAG_UNSUPPORTED_VALUE)
+ {
+ print_fatal_error(data, "Bad IN-GROUP group tag \"%s\" on line %d of \"%s\".", temp, f->linenum, f->filename);
+ return (0);
+ }
+ else if (data->last_expect)
{
- print_fatal_error(data, "Bad IN-GROUP group tag \"%s\" on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ data->last_expect->in_group = in_group;
}
- else if (last_expect)
- last_expect->in_group = in_group;
else
{
print_fatal_error(data, "IN-GROUP without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "REPEAT-LIMIT"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing REPEAT-LIMIT value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- else if (atoi(token) <= 0)
+ else if (atoi(temp) <= 0)
{
print_fatal_error(data, "Bad REPEAT-LIMIT value on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (last_status)
- last_status->repeat_limit = atoi(token);
- else if (last_expect)
- last_expect->repeat_limit = atoi(token);
+ if (data->last_status)
+ {
+ data->last_status->repeat_limit = atoi(temp);
+ }
+ else if (data->last_expect)
+ {
+ data->last_expect->repeat_limit = atoi(temp);
+ }
else
{
print_fatal_error(data, "REPEAT-LIMIT without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "REPEAT-MATCH"))
{
- if (last_status)
- last_status->repeat_match = 1;
- else if (last_expect)
- last_expect->repeat_match = 1;
+ if (data->last_status)
+ {
+ data->last_status->repeat_match = 1;
+ }
+ else if (data->last_expect)
+ {
+ data->last_expect->repeat_match = 1;
+ }
else
{
print_fatal_error(data, "REPEAT-MATCH without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "REPEAT-NO-MATCH"))
{
- if (last_status)
- last_status->repeat_no_match = 1;
- else if (last_expect)
- last_expect->repeat_no_match = 1;
+ if (data->last_status)
+ {
+ data->last_status->repeat_no_match = 1;
+ }
+ else if (data->last_expect)
+ {
+ data->last_expect->repeat_no_match = 1;
+ }
else
{
- print_fatal_error(data, "REPEAT-NO-MATCH without a preceding EXPECT or STATUS on ine %d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "REPEAT-NO-MATCH without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "SAME-COUNT-AS"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing SAME-COUNT-AS name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (last_expect)
- last_expect->same_count_as = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->same_count_as = strdup(temp);
+ }
else
{
- print_fatal_error(data, "SAME-COUNT-AS without a preceding EXPECT on line "
- "%d.", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "SAME-COUNT-AS without a preceding EXPECT on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "IF-DEFINED"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing IF-DEFINED name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (last_expect)
- last_expect->if_defined = strdup(token);
- else if (last_status)
- last_status->if_defined = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->if_defined = strdup(temp);
+ }
+ else if (data->last_status)
+ {
+ data->last_status->if_defined = strdup(temp);
+ }
else
{
print_fatal_error(data, "IF-DEFINED without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "IF-NOT-DEFINED"))
{
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing IF-NOT-DEFINED name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (last_expect)
- last_expect->if_not_defined = strdup(token);
- else if (last_status)
- last_status->if_not_defined = strdup(token);
+ if (data->last_expect)
+ {
+ data->last_expect->if_not_defined = strdup(temp);
+ }
+ else if (data->last_status)
+ {
+ data->last_status->if_not_defined = strdup(temp);
+ }
else
{
print_fatal_error(data, "IF-NOT-DEFINED without a preceding EXPECT or STATUS on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") ||
!_cups_strcasecmp(token, "WITH-SCHEME") ||
!_cups_strcasecmp(token, "WITH-VALUE"))
{
- if (last_expect)
- {
- if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
- !_cups_strcasecmp(token, "WITH-HOSTNAME"))
- last_expect->with_flags = _CUPS_WITH_HOSTNAME;
- else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
- !_cups_strcasecmp(token, "WITH-RESOURCE"))
- last_expect->with_flags = _CUPS_WITH_RESOURCE;
- else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
- !_cups_strcasecmp(token, "WITH-SCHEME"))
- last_expect->with_flags = _CUPS_WITH_SCHEME;
+ off_t lastpos; /* Last file position */
+
+ if (data->last_expect)
+ {
+ if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") || !_cups_strcasecmp(token, "WITH-HOSTNAME"))
+ data->last_expect->with_flags = _CUPS_WITH_HOSTNAME;
+ else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") || !_cups_strcasecmp(token, "WITH-RESOURCE"))
+ data->last_expect->with_flags = _CUPS_WITH_RESOURCE;
+ else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") || !_cups_strcasecmp(token, "WITH-SCHEME"))
+ data->last_expect->with_flags = _CUPS_WITH_SCHEME;
if (!_cups_strncasecmp(token, "WITH-ALL-", 9))
- last_expect->with_flags |= _CUPS_WITH_ALL;
+ data->last_expect->with_flags |= _CUPS_WITH_ALL;
}
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing %s value on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
+ }
+
+ /*
+ * Read additional comma-delimited values - needed since legacy test files
+ * will have unquoted WITH-VALUE values with commas...
+ */
+
+ ptr = temp + strlen(temp);
+
+ for (;;)
+ {
+ lastpos = cupsFileTell(f->fp);
+ ptr += strlen(ptr);
+
+ if (!_ippFileReadToken(f, ptr, (sizeof(temp) - (size_t)(ptr - temp))))
+ break;
+
+ if (!strcmp(ptr, ","))
+ {
+ /*
+ * Append a value...
+ */
+
+ ptr += strlen(ptr);
+
+ if (!_ippFileReadToken(f, ptr, (sizeof(temp) - (size_t)(ptr - temp))))
+ break;
+ }
+ else
+ {
+ /*
+ * Not another value, stop here...
+ */
+
+ cupsFileSeek(f->fp, lastpos);
+ *ptr = '\0';
+ break;
+ }
}
- if (last_expect)
+ if (data->last_expect)
{
/*
* Expand any variables in the value and then save it.
*/
- _ippVarsExpand(vars, token, temp, sizeof(token));
+ _ippVarsExpand(vars, value, temp, sizeof(value));
- tokenptr = token + strlen(token) - 1;
+ ptr = value + strlen(value) - 1;
- if (token[0] == '/' && tokenptr > token && *tokenptr == '/')
+ if (value[0] == '/' && ptr > value && *ptr == '/')
{
/*
* WITH-VALUE is a POSIX extended regular expression.
*/
- last_expect->with_value = calloc(1, (size_t)(tokenptr - token));
- last_expect->with_flags |= _CUPS_WITH_REGEX;
+ data->last_expect->with_value = calloc(1, (size_t)(ptr - value));
+ data->last_expect->with_flags |= _CUPS_WITH_REGEX;
- if (last_expect->with_value)
- memcpy(last_expect->with_value, token + 1, (size_t)(tokenptr - token - 1));
+ if (data->last_expect->with_value)
+ memcpy(data->last_expect->with_value, value + 1, (size_t)(ptr - value - 1));
}
else
{
* WITH-VALUE is a literal value...
*/
- char *ptr; /* Pointer into value */
-
- for (ptr = token; *ptr; ptr ++)
+ for (ptr = value; *ptr; ptr ++)
{
if (*ptr == '\\' && ptr[1])
{
}
}
- last_expect->with_value = strdup(token);
- last_expect->with_flags |= _CUPS_WITH_LITERAL;
+ data->last_expect->with_value = strdup(value);
+ data->last_expect->with_flags |= _CUPS_WITH_LITERAL;
}
}
else
{
print_fatal_error(data, "%s without a preceding EXPECT on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "WITH-VALUE-FROM"))
if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing %s value on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- if (last_expect)
+ if (data->last_expect)
{
/*
* Expand any variables in the value and then save it.
*/
- _ippVarsExpand(vars, token, temp, sizeof(token));
+ _ippVarsExpand(vars, value, temp, sizeof(value));
- last_expect->with_value_from = strdup(token);
- last_expect->with_flags = _CUPS_WITH_LITERAL;
+ data->last_expect->with_value_from = strdup(value);
+ data->last_expect->with_flags = _CUPS_WITH_LITERAL;
}
else
{
print_fatal_error(data, "%s without a preceding EXPECT on line %d of \"%s\".", token, f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
}
else if (!_cups_strcasecmp(token, "DISPLAY"))
* Display attributes...
*/
- if (num_displayed >= (int)(sizeof(displayed) / sizeof(displayed[0])))
+ if (data->num_displayed >= (int)(sizeof(data->displayed) / sizeof(data->displayed[0])))
{
- print_fatal_error(data, "Too many DISPLAY's on line %d", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ print_fatal_error(data, "Too many DISPLAY's on line %d of \"%s\".", f->linenum, f->filename);
+ return (0);
}
- if (!get_token(fp, token, sizeof(token), &linenum))
+ if (!_ippFileReadToken(f, temp, sizeof(temp)))
{
print_fatal_error(data, "Missing DISPLAY name on line %d of \"%s\".", f->linenum, f->filename);
- pass = 0;
- goto test_exit;
+ return (0);
}
- displayed[num_displayed] = strdup(token);
- num_displayed ++;
+ data->displayed[data->num_displayed] = strdup(temp);
+ data->num_displayed ++;
}
else
{
* Start new test...
*/
- char *ptr; /* Pointer into string */
-
if (data->show_header)
{
if (data->output == _CUPS_OUTPUT_PLIST)
data->compression[0] = '\0';
data->delay = 0;
- data->num_expect = 0;
+ data->num_expects = 0;
data->last_expect = NULL;
- data->filename[0] = '\0';
+ data->file[0] = '\0';
data->ignore_errors = data->def_ignore_errors;
strlcpy(data->name, f->filename, sizeof(data->name));
if ((ptr = strrchr(data->name, '.')) != NULL)
*ptr = '\0';
- data->repeat_count = 0;
data->repeat_interval = 5000000;
data->request_id ++;
strlcpy(data->resource, vars->resource, sizeof(data->resource));
data->skip_previous = 0;
data->skip_test = 0;
- data->num_status = 0;
+ data->num_statuses = 0;
data->last_status = NULL;
data->test_id[0] = '\0';
data->transfer = data->def_transfer;
* Map the filename to and then run the tests...
*/
- char filename[1024], /* Mapped filename */
- save_file_id[1024]; /* Saved FILE-ID value */
+ _cups_testdata_t inc_data; /* Data for included file */
+ char filename[1024]; /* Mapped filename */
- strlcpy(save_file_id, data->file_id, sizeof(save_file_id));
- data->file_id[0] = '\0';
+ memcpy(&inc_data, data, sizeof(inc_data));
+ inc_data.http = NULL;
+ inc_data.pass = 1;
+ inc_data.prev_pass = 1;
+ inc_data.show_header = 1;
- if (!do_tests(data, vars, get_filename(f->filename, filename, temp, sizeof(filename))) && data->stop_after_include_error)
+ if (!do_tests(get_filename(f->filename, filename, temp, sizeof(filename)), vars, &inc_data) && data->stop_after_include_error)
+ {
+ data->pass = data->prev_pass = 0;
return (0);
-
- strlcpy(data->file_id, save_file_id, sizeof(data->file_id));
+ }
}
else
{
* Map the filename to and then run the tests...
*/
- char filename[1024], /* Mapped filename */
- save_file_id[1024]; /* Saved FILE-ID value */
+ _cups_testdata_t inc_data; /* Data for included file */
+ char filename[1024]; /* Mapped filename */
- strlcpy(save_file_id, data->file_id, sizeof(save_file_id));
- data->file_id[0] = '\0';
+ memcpy(&inc_data, data, sizeof(inc_data));
+ inc_data.http = NULL;
+ inc_data.pass = 1;
+ inc_data.prev_pass = 1;
+ inc_data.show_header = 1;
- if (_ippVarsGet(vars, name) && !do_tests(data, vars, get_filename(f->filename, filename, temp, sizeof(filename))) && data->stop_after_include_error)
+ if (!do_tests(get_filename(f->filename, filename, temp, sizeof(filename)), vars, &inc_data) && data->stop_after_include_error)
+ {
+ data->pass = data->prev_pass = 0;
return (0);
-
- strlcpy(data->file_id, save_file_id, sizeof(data->file_id));
+ }
}
else
{
* Map the filename to and then run the tests...
*/
- char filename[1024], /* Mapped filename */
- save_file_id[1024]; /* Saved FILE-ID value */
+ _cups_testdata_t inc_data; /* Data for included file */
+ char filename[1024]; /* Mapped filename */
- strlcpy(save_file_id, data->file_id, sizeof(save_file_id));
- data->file_id[0] = '\0';
+ memcpy(&inc_data, data, sizeof(inc_data));
+ inc_data.http = NULL;
+ inc_data.pass = 1;
+ inc_data.prev_pass = 1;
+ inc_data.show_header = 1;
- if (!_ippVarsGet(vars, name) && !do_tests(data, vars, get_filename(f->filename, filename, temp, sizeof(filename))) && data->stop_after_include_error)
+ if (!do_tests(get_filename(f->filename, filename, temp, sizeof(filename)), vars, &inc_data) && data->stop_after_include_error)
+ {
+ data->pass = data->prev_pass = 0;
return (0);
-
- strlcpy(data->file_id, save_file_id, sizeof(data->file_id));
+ }
}
else
{
*/
static int /* O - 1 if valid, 0 otherwise */
-validate_attr(cups_file_t *outfile, /* I - Output file */
- cups_array_t *errors, /* I - Errors array */
- ipp_attribute_t *attr) /* I - Attribute to validate */
+validate_attr(_cups_testdata_t *data, /* I - Test data */
+ cups_array_t *errors, /* I - Errors array */
+ ipp_attribute_t *attr) /* I - Attribute to validate */
{
int i; /* Looping var */
char scheme[64], /* Scheme from URI */
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad attribute name - invalid character "
"(RFC 2911 section 4.1.3).", attr->name);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad attribute name - bad length "
"(RFC 2911 section 4.1.3).", attr->name);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad boolen value %d "
"(RFC 2911 section 4.1.11).", attr->name,
attr->values[i].boolean);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad enum value %d - out of range "
"(RFC 2911 section 4.1.4).", attr->name,
attr->values[i].integer);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad octetString value - bad length %d "
"(RFC 2911 section 4.1.10).", attr->name,
attr->values[i].unknown.length);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime month %u "
"(RFC 2911 section 4.1.14).", attr->name, date[2]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime day %u "
"(RFC 2911 section 4.1.14).", attr->name, date[3]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime hours %u "
"(RFC 2911 section 4.1.14).", attr->name, date[4]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime minutes %u "
"(RFC 2911 section 4.1.14).", attr->name, date[5]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime seconds %u "
"(RFC 2911 section 4.1.14).", attr->name, date[6]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime deciseconds %u "
"(RFC 2911 section 4.1.14).", attr->name, date[7]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime UTC sign '%c' "
"(RFC 2911 section 4.1.14).", attr->name, date[8]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime UTC hours %u "
"(RFC 2911 section 4.1.14).", attr->name, date[9]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad dateTime UTC minutes %u "
"(RFC 2911 section 4.1.14).", attr->name, date[10]);
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad resolution value %dx%d%s - cross "
"feed resolution must be positive "
"(RFC 2911 section 4.1.15).", attr->name,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad resolution value %dx%d%s - feed "
"resolution must be positive "
"(RFC 2911 section 4.1.15).", attr->name,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad resolution value %dx%d%s - bad "
"units value (RFC 2911 section 4.1.15).",
attr->name, attr->values[i].resolution.xres,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad rangeOfInteger value %d-%d - lower "
"greater than upper (RFC 2911 section 4.1.13).",
attr->name, attr->values[i].range.lower,
colattr;
colattr = colattr->next)
{
- if (!validate_attr(data->outfile, NULL, colattr))
+ if (!validate_attr(data, NULL, colattr))
{
valid = 0;
break;
if (colattr && errors)
{
- add_stringf(errors, "\"%s\": Bad collection value.", attr->name);
+ add_stringf(data->errors, "\"%s\": Bad collection value.", attr->name);
while (colattr)
{
- validate_attr(data->outfile, errors, colattr);
+ validate_attr(data, errors, colattr);
colattr = colattr->next;
}
}
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad text value \"%s\" - bad UTF-8 "
"sequence (RFC 2911 section 4.1.1).", attr->name,
attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad text value \"%s\" - bad length %d "
"(RFC 2911 section 4.1.1).", attr->name,
attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad name value \"%s\" - bad UTF-8 "
"sequence (RFC 2911 section 4.1.2).", attr->name,
attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad name value \"%s\" - bad length %d "
"(RFC 2911 section 4.1.2).", attr->name,
attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad keyword value \"%s\" - invalid "
"character (RFC 2911 section 4.1.3).",
attr->name, attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad keyword value \"%s\" - bad "
"length %d (RFC 2911 section 4.1.3).",
attr->name, attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad URI value \"%s\" - %s "
"(RFC 2911 section 4.1.5).", attr->name,
attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad URI value \"%s\" - bad length %d "
"(RFC 2911 section 4.1.5).", attr->name,
attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad uriScheme value \"%s\" - bad "
"characters (RFC 2911 section 4.1.6).",
attr->name, attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad uriScheme value \"%s\" - bad "
"length %d (RFC 2911 section 4.1.6).",
attr->name, attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad charset value \"%s\" - bad "
"characters (RFC 2911 section 4.1.7).",
attr->name, attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad charset value \"%s\" - bad "
"length %d (RFC 2911 section 4.1.7).",
attr->name, attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad naturalLanguage value \"%s\" - bad "
"characters (RFC 2911 section 4.1.8).",
attr->name, attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad naturalLanguage value \"%s\" - bad "
"length %d (RFC 2911 section 4.1.8).",
attr->name, attr->values[i].string.text,
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad mimeMediaType value \"%s\" - bad "
"characters (RFC 2911 section 4.1.9).",
attr->name, attr->values[i].string.text);
{
valid = 0;
- add_stringf(errors,
+ add_stringf(data->errors,
"\"%s\": Bad mimeMediaType value \"%s\" - bad "
"length %d (RFC 2911 section 4.1.9).",
attr->name, attr->values[i].string.text,
*/
static int /* O - 1 on match, 0 on non-match */
-with_value(cups_file_t *outfile, /* I - Output file */
- cups_array_t *errors, /* I - Errors array */
- char *value, /* I - Value string */
- int flags, /* I - Flags for match */
- ipp_attribute_t *attr, /* I - Attribute to compare */
- char *matchbuf, /* I - Buffer to hold matching value */
- size_t matchlen) /* I - Length of match buffer */
+with_value(_cups_testdata_t *data, /* I - Test data */
+ cups_array_t *errors, /* I - Errors array */
+ char *value, /* I - Value string */
+ int flags, /* I - Flags for match */
+ ipp_attribute_t *attr, /* I - Attribute to compare */
+ char *matchbuf, /* I - Buffer to hold matching value */
+ size_t matchlen) /* I - Length of match buffer */
{
int i, /* Looping var */
match; /* Match? */
if (!match && errors)
{
for (i = 0; i < attr->num_values; i ++)
- add_stringf(errors, "GOT: %s=%d", attr->name,
+ add_stringf(data->errors, "GOT: %s=%d", attr->name,
attr->values[i].integer);
}
break;
if (!match && errors)
{
for (i = 0; i < attr->num_values; i ++)
- add_stringf(errors, "GOT: %s=%d-%d", attr->name,
+ add_stringf(data->errors, "GOT: %s=%d-%d", attr->name,
attr->values[i].range.lower,
attr->values[i].range.upper);
}
if (!match && errors)
{
for (i = 0; i < attr->num_values; i ++)
- add_stringf(errors, "GOT: %s=%s", attr->name,
+ add_stringf(data->errors, "GOT: %s=%s", attr->name,
attr->values[i].boolean ? "true" : "false");
}
break;
"dpi" : "dpcm");
if (strcmp(value, temp))
- add_stringf(errors, "GOT: %s=%s", attr->name, temp);
+ add_stringf(data->errors, "GOT: %s=%s", attr->name, temp);
}
}
break;
if (!match && errors)
{
for (i = 0; i < attr->num_values; i ++)
- add_stringf(errors, "GOT: %s=\"%s\"", attr->name,
+ add_stringf(data->errors, "GOT: %s=\"%s\"", attr->name,
attr->values[i].string.text);
}
break;