/*
- * "$Id: ipptest.c 5037 2006-02-01 15:19:59Z mike $"
+ * "$Id: ipptest.c 6649 2007-07-11 21:46:42Z mike $"
*
* IPP test command for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
* Globals...
*/
-int Verbosity = 0; /* Show all attributes? */
+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 */
+ };
+
+
/*
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 status; /* Status of tests... */
const char *uri; /* URI to use */
const char *testfile; /* Test file to use */
+ int interval; /* Test interval */
/*
uri = NULL;
testfile = NULL;
status = 0;
+ interval = 0;
for (i = 1; i < argc; i ++)
{
{
if (!strcmp(argv[i], "-v"))
Verbosity ++;
+ else if (!strcmp(argv[i], "-d"))
+ {
+ i ++;
+
+ if (i >= argc)
+ usage(NULL);
+ else
+ putenv(argv[i]);
+ }
+ else if (!strcmp(argv[i], "-i"))
+ {
+ i++;
+
+ if (i >= argc)
+ usage(NULL);
+ else
+ interval = atoi(argv[i]);
+ }
else
usage(argv[i]);
}
if (!uri || !testfile)
usage(NULL);
+ /*
+ * Loop if the interval is set...
+ */
+
+ if (interval)
+ {
+ for (;;)
+ {
+ sleep(interval);
+ do_tests(uri, testfile);
+ }
+ }
+
/*
* Exit...
*/
strlcpy(tokenptr, cupsUser(), sizeof(token) - (tokenptr - token));
tempptr += 5;
}
+ else if (!strncasecmp(tempptr + 1, "ENV[", 4))
+ {
+ char *end; /* End of $ENV[name] */
+
+
+ if ((end = strchr(tempptr + 5, ']')) != NULL)
+ {
+ *end++ = '\0';
+ strlcpy(tokenptr,
+ getenv(tempptr + 5) ? getenv(tempptr + 5) : tempptr + 5,
+ sizeof(token) - (tokenptr - token));
+ tempptr = end;
+ }
+ else
+ {
+ *tokenptr++ = *tempptr++;
+ *tokenptr = '\0';
+ }
+ }
else
{
- *tokenptr++ = *tempptr ++;
+ *tokenptr++ = *tempptr++;
*tokenptr = '\0';
}
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);
if (filename[0])
response = cupsDoFileRequest(http, request, resource, filename);
else
- response = cupsDoRequest(http, request, resource);
+ response = cupsDoIORequest(http, request, resource, -1,
+ Verbosity ? 1 : -1);
if (response == NULL)
{
puts("FAIL]");
printf(" ERROR %04x (%s) @ %s\n", cupsLastError(),
- ippErrorString(cupsLastError()), ctime(&curtime));
+ cupsLastErrorString(), ctime(&curtime));
pass = 0;
}
else
puts(" BAD STATUS");
printf(" status-code = %04x (%s)\n",
- response->request.status.status_code,
- ippErrorString(response->request.status.status_code));
+ cupsLastError(), ippErrorString(cupsLastError()));
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%s) = ", attr->name,
+ attr->num_values > 1 ? "1setOf " : "",
+ get_tag_string(attr->value_tag));
switch (attr->value_tag)
{
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);
+ fputs("-i N Repeat the last test file once every N seconds.\n", stderr);
+ fputs("-v Show all attributes in response, even on success.\n", stderr);
exit(1);
}
/*
- * End of "$Id: ipptest.c 5037 2006-02-01 15:19:59Z mike $".
+ * End of "$Id: ipptest.c 6649 2007-07-11 21:46:42Z mike $".
*/