/*
- * "$Id: ipptest.c 5023 2006-01-29 14:39:44Z mike $"
+ * "$Id: ipptest.c 5414 2006-04-17 20:07:24Z mike $"
*
* IPP test command for the Common UNIX Printing System (CUPS).
*
*
* Contents:
*
- * main() - Parse options and do tests.
- * do_tests() - Do tests as specified in the test file.
- * get_tag() - Get an IPP value or group tag from a name...
- * get_token() - Get a token from a file.
- * print_attr() - Print an attribute on the screen.
+ * main() - Parse options and do tests.
+ * do_tests() - Do tests as specified in the test file.
+ * get_tag() - Get an IPP value or group tag from a name...
+ * get_token() - Get a token from a file.
+ * print_attr() - Print an attribute on the screen.
+ * usage() - Show program usage.
*/
/*
#include <cups/language.h>
+/*
+ * Globals...
+ */
+
+int Verbosity = 0; /* Show all attributes? */
+const char * const TagNames[] =
+ { /* Value/group tag names */
+ "zero", /* 0x00 */
+ "operation", /* 0x01 */
+ "job", /* 0x02 */
+ "end", /* 0x03 */
+ "printer", /* 0x04 */
+ "unsupported-group", /* 0x05 */
+ "subscription", /* 0x06 */
+ "event-notification", /* 0x07 */
+ "", "", "", "", "", "", "", "",
+ "unsupported-value", /* 0x10 */
+ "default", /* 0x11 */
+ "unknown", /* 0x12 */
+ "novalue", /* 0x13 */
+ "",
+ "notsettable", /* 0x15 */
+ "deleteattr", /* 0x16 */
+ "anyvalue", /* 0x17 */
+ "", "", "", "", "", "", "", "", "",
+ "integer", /* 0x21 */
+ "boolean", /* 0x22 */
+ "enum", /* 0x23 */
+ "", "", "", "", "", "", "", "", "", "", "", "",
+ "string", /* 0x30 */
+ "date", /* 0x31 */
+ "resolution", /* 0x32 */
+ "range", /* 0x33 */
+ "collection", /* 0x34 */
+ "textlang", /* 0x35 */
+ "namelang", /* 0x36 */
+ "", "", "", "", "", "", "", "", "", "",
+ "text", /* 0x41 */
+ "name", /* 0x42 */
+ "",
+ "keyword", /* 0x44 */
+ "uri", /* 0x45 */
+ "urischeme", /* 0x46 */
+ "charset", /* 0x47 */
+ "language", /* 0x48 */
+ "mimetype" /* 0x49 */
+ };
+
+
+
+
/*
* Local functions...
*/
ipp_op_t ippOpValue(const char *);
ipp_status_t ippErrorValue(const char *);
ipp_tag_t get_tag(const char *);
+const char *get_tag_string(ipp_tag_t tag);
char *get_token(FILE *, char *, int, int *linenum);
void print_attr(ipp_attribute_t *);
+void usage(const char *option);
/*
{
int i; /* Looping var */
int status; /* Status of tests... */
+ const char *uri; /* URI to use */
+ const char *testfile; /* Test file to use */
/*
* testipp URL testfile
*/
- if (argc < 3)
+ uri = NULL;
+ testfile = NULL;
+ status = 0;
+
+ for (i = 1; i < argc; i ++)
{
- fputs("Usage: ipptest URL testfile [ ... testfileN ]\n", stderr);
- return (1);
- }
+ if (argv[i][0] == '-')
+ {
+ if (!strcmp(argv[i], "-v"))
+ Verbosity ++;
+ else
+ usage(argv[i]);
+ }
+ else if (!strncmp(argv[i], "ipp://", 6) ||
+ !strncmp(argv[i], "http://", 7) ||
+ !strncmp(argv[i], "https://", 8))
+ {
+ /*
+ * Set URI...
+ */
- /*
- * Run tests...
- */
+ if (!testfile && uri)
+ usage(NULL);
+
+ uri = argv[i];
+ testfile = NULL;
+ }
+ else
+ {
+ /*
+ * Run test...
+ */
+
+ testfile = argv[i];
+
+ if (!do_tests(uri, testfile))
+ status ++;
+ }
+ }
- for (i = 2, status = 1; status && i < argc; i ++)
- status = status && do_tests(argv[1], argv[i]);
+ if (!uri || !testfile)
+ usage(NULL);
/*
* Exit...
*/
- return (!status);
+ return (status);
}
request->request.op.operation_id = op;
request->request.op.request_id = 1;
-#ifdef DEBUG
- for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
- print_attr(attrptr);
-#endif /* DEBUG */
+ if (Verbosity)
+ {
+ printf("%s:\n", ippOpString(op));
+
+ for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
+ print_attr(attrptr);
+ }
printf(" %-60.60s [", name);
fflush(stdout);
puts("FAIL]");
printf(" ERROR %04x (%s) @ %s\n", cupsLastError(),
- ippErrorString(cupsLastError()), ctime(&curtime));
+ cupsLastErrorString(), ctime(&curtime));
pass = 0;
}
else
printf(" RECEIVED: %lu bytes in response\n",
(unsigned long)ippLength(response));
- if (num_displayed > 0)
+ if (Verbosity)
+ {
+ for (attrptr = response->attrs; attrptr != NULL; attrptr = attrptr->next)
+ print_attr(attrptr);
+ }
+ else if (num_displayed > 0)
{
for (attrptr = response->attrs; attrptr != NULL; attrptr = attrptr->next)
if (attrptr->name)
puts(" BAD STATUS");
printf(" status-code = %04x (%s)\n",
- response->request.status.status_code,
- ippErrorString(response->request.status.status_code));
+ cupsLastError(), cupsLastErrorString());
for (i = 0; i < num_expects; i ++)
if (ippFindAttribute(response, expects[i], IPP_TAG_ZERO) == NULL)
get_tag(const char *name) /* I - Name of value/group tag */
{
int i; /* Looping var */
- static const char * const names[] =
- { /* Value/group tag names */
- "zero", "operation", "job", "end", "printer",
- "unsupported-group", "subscription", "event-notification",
- "", "", "", "", "",
- "", "", "", "unsupported-value", "default",
- "unknown", "novalue", "", "notsettable",
- "deleteattr", "anyvalue", "", "", "", "", "", "",
- "", "", "", "integer", "boolean", "enum", "", "",
- "", "", "", "", "", "", "", "", "", "", "string",
- "date", "resolution", "range", "collection",
- "textlang", "namelang", "", "", "", "", "", "", "",
- "", "", "", "text", "name", "", "keyword", "uri",
- "urischeme", "charset", "language", "mimetype"
- };
- for (i = 0; i < (sizeof(names) / sizeof(names[0])); i ++)
- if (!strcasecmp(name, names[i]))
+ for (i = 0; i < (sizeof(TagNames) / sizeof(TagNames[0])); i ++)
+ if (!strcasecmp(name, TagNames[i]))
return ((ipp_tag_t)i);
return (IPP_TAG_ZERO);
}
+/*
+ * 'get_tag_string()' - Get the string associated with a tag.
+ */
+
+const char * /* O - Tag name string */
+get_tag_string(ipp_tag_t tag) /* I - IPP tag */
+{
+ if (tag < (ipp_tag_t)(sizeof(TagNames) / sizeof(TagNames[0])))
+ return (TagNames[tag]);
+ else
+ return ("UNKNOWN");
+}
+
+
/*
* 'get_token()' - Get a token from a file.
*/
return;
}
- printf(" %s = ", attr->name);
+ printf(" %s (%s) = ", attr->name, get_tag_string(attr->value_tag));
switch (attr->value_tag)
{
/*
- * End of "$Id: ipptest.c 5023 2006-01-29 14:39:44Z mike $".
+ * 'usage()' - Show program usage.
+ */
+
+void
+usage(const char *option) /* I - Option string or NULL */
+{
+ if (option)
+ fprintf(stderr, "ipptest: Unknown option \"%s\"!\n", option);
+
+ fputs("Usage: ipptest [options] URL testfile [ ... testfileN ]\n", stderr);
+ fputs("Options:\n", stderr);
+ fputs("\n", stderr);
+ fputs("-v Show all attributes in response, even on success.\n", stderr);
+
+ exit(1);
+}
+
+
+/*
+ * End of "$Id: ipptest.c 5414 2006-04-17 20:07:24Z mike $".
*/