-/*
- * 'get_variable()' - Get the value of a variable.
- */
-
-static char * /* O - Value or NULL */
-get_variable(_cups_vars_t *vars, /* I - Variables */
- const char *name) /* I - Variable name */
-{
- _cups_var_t key, /* Search key */
- *match; /* Matching variable, if any */
-
-
- key.name = (char *)name;
- match = cupsArrayFind(vars->vars, &key);
-
- return (match ? match->value : NULL);
-}
-
-
-/*
- * 'iso_date()' - Return an ISO 8601 date/time string for the given IPP dateTime
- * value.
- */
-
-static char * /* O - ISO 8601 date/time string */
-iso_date(ipp_uchar_t *date) /* I - IPP (RFC 1903) date/time value */
-{
- time_t utctime; /* UTC time since 1970 */
- struct tm *utcdate; /* UTC date/time */
- static char buffer[255]; /* String buffer */
-
-
- utctime = ippDateToTime(date);
- utcdate = gmtime(&utctime);
-
- snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ",
- utcdate->tm_year + 1900, utcdate->tm_mon + 1, utcdate->tm_mday,
- utcdate->tm_hour, utcdate->tm_min, utcdate->tm_sec);
-
- return (buffer);
-}
-
-
-/*
- * 'password_cb()' - Password callback for authenticated tests.
- */
-
-static const char * /* O - Password */
-password_cb(const char *prompt) /* I - Prompt (unused) */
-{
- (void)prompt;
-
- if (PasswordTries < 3)
- {
- PasswordTries ++;
-
- cupsSetUser(Username);
-
- return (Password);
- }
- else
- return (NULL);
-}
-
-
-/*
- * 'pause_message()' - Display the message and pause until the user presses a key.
- */
-
-static void
-pause_message(const char *message) /* I - Message */
-{
-#ifdef WIN32
- HANDLE tty; /* Console handle */
- DWORD mode; /* Console mode */
- char key; /* Key press */
- DWORD bytes; /* Bytes read for key press */
-
-
- /*
- * Disable input echo and set raw input...
- */
-
- if ((tty = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE)
- return;
-
- if (!GetConsoleMode(tty, &mode))
- return;
-
- if (!SetConsoleMode(tty, 0))
- return;
-
-#else
- int tty; /* /dev/tty - never read from stdin */
- struct termios original, /* Original input mode */
- noecho; /* No echo input mode */
- char key; /* Current key press */
-
-
- /*
- * Disable input echo and set raw input...
- */
-
- if ((tty = open("/dev/tty", O_RDONLY)) < 0)
- return;
-
- if (tcgetattr(tty, &original))
- {
- close(tty);
- return;
- }
-
- noecho = original;
- noecho.c_lflag &= (tcflag_t)~(ICANON | ECHO | ECHOE | ISIG);
-
- if (tcsetattr(tty, TCSAFLUSH, &noecho))
- {
- close(tty);
- return;
- }
-#endif /* WIN32 */
-
- /*
- * Display the prompt...
- */
-
- printf("%s\n---- PRESS ANY KEY ----", message);
- fflush(stdout);
-
-#ifdef WIN32
- /*
- * Read a key...
- */
-
- ReadFile(tty, &key, 1, &bytes, NULL);
-
- /*
- * Cleanup...
- */
-
- SetConsoleMode(tty, mode);
-
-#else
- /*
- * Read a key...
- */
-
- read(tty, &key, 1);
-
- /*
- * Cleanup...
- */
-
- tcsetattr(tty, TCSAFLUSH, &original);
- close(tty);
-#endif /* WIN32 */
-
- /*
- * Erase the "press any key" prompt...
- */
-
- fputs("\r \r", stdout);
- fflush(stdout);
-}
-
-
-/*
- * 'print_attr()' - Print an attribute on the screen.
- */
-
-static void
-print_attr(FILE *outfile, /* I - Output file */
- int format, /* I - Output format */
- ipp_attribute_t *attr, /* I - Attribute to print */
- ipp_tag_t *group) /* IO - Current group */
-{
- int i; /* Looping var */
- ipp_attribute_t *colattr; /* Collection attribute */
-
-
- if (format == _CUPS_OUTPUT_PLIST)
- {
- if (!attr->name || (group && *group != attr->group_tag))
- {
- if (attr->group_tag != IPP_TAG_ZERO)
- {
- fputs("</dict>\n", outfile);
- fputs("<dict>\n", outfile);
- }
-
- if (group)
- *group = attr->group_tag;
- }
-
- if (!attr->name)
- return;
-
- print_xml_string(outfile, "key", attr->name);
- if (attr->num_values > 1)
- fputs("<array>\n", outfile);
-
- switch (attr->value_tag)
- {
- case IPP_TAG_INTEGER :
- case IPP_TAG_ENUM :
- for (i = 0; i < attr->num_values; i ++)
- fprintf(outfile, "<integer>%d</integer>\n", attr->values[i].integer);
- break;
-
- case IPP_TAG_BOOLEAN :
- for (i = 0; i < attr->num_values; i ++)
- fputs(attr->values[i].boolean ? "<true />\n" : "<false />\n", outfile);
- break;
-
- case IPP_TAG_RANGE :
- for (i = 0; i < attr->num_values; i ++)
- fprintf(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 ++)
- fprintf(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,
- attr->values[i].resolution.yres,
- attr->values[i].resolution.units == IPP_RES_PER_INCH ?
- "dpi" : "dpcm");
- break;
-
- case IPP_TAG_DATE :
- for (i = 0; i < attr->num_values; i ++)
- fprintf(outfile, "<date>%s</date>\n", iso_date(attr->values[i].date));
- break;
-
- case IPP_TAG_STRING :
- for (i = 0; i < attr->num_values; i ++)
- {
- char buffer[IPP_MAX_LENGTH * 5 / 4 + 1];
- /* Output buffer */
-
- fprintf(outfile, "<data>%s</data>\n",
- httpEncode64_2(buffer, sizeof(buffer),
- attr->values[i].unknown.data,
- attr->values[i].unknown.length));
- }
- break;
-
- 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 :
- for (i = 0; i < attr->num_values; i ++)
- 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 ++)
- {
- fputs("<dict><key>language</key><string>", outfile);
- print_xml_string(outfile, NULL, attr->values[i].string.language);
- fputs("</string><key>string</key><string>", outfile);
- print_xml_string(outfile, NULL, attr->values[i].string.text);
- fputs("</string></dict>\n", outfile);
- }
- break;
-
- case IPP_TAG_BEGIN_COLLECTION :
- for (i = 0; i < attr->num_values; i ++)
- {
- fputs("<dict>\n", outfile);
- for (colattr = attr->values[i].collection->attrs;
- colattr;
- colattr = colattr->next)
- print_attr(outfile, format, colattr, NULL);
- fputs("</dict>\n", outfile);
- }
- break;
-
- default :
- fprintf(outfile, "<string><<%s>></string>\n", ippTagString(attr->value_tag));
- break;
- }
-
- if (attr->num_values > 1)
- fputs("</array>\n", outfile);
- }
- else
- {
- char buffer[131072]; /* Value buffer */
-
- if (format == _CUPS_OUTPUT_TEST)
- {
- if (!attr->name)