]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptool.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / test / ipptool.c
index f3009b42fa0257f80dc823925577cb9d84782b08..20a2c9c8df6f5a0941d85fadde80cb7369524275 100644 (file)
@@ -1,18 +1,10 @@
 /*
- * "$Id$"
- *
  * ipptool command for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products.
  *
- * These coded instructions, statements, and computer programs are the
- * 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/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
 #include <regex.h>
 #include <sys/stat.h>
 #ifdef WIN32
-#  define R_OK 0
+#  include <windows.h>
+#  ifndef R_OK
+#    define R_OK 0
+#  endif /* !R_OK */
 #else
 #  include <signal.h>
+#  include <termios.h>
 #endif /* WIN32 */
 #ifndef O_BINARY
 #  define O_BINARY 0
@@ -49,6 +45,7 @@ typedef enum _cups_output_e           /**** Output mode ****/
   _CUPS_OUTPUT_QUIET,                  /* No output */
   _CUPS_OUTPUT_TEST,                   /* Traditional CUPS test output */
   _CUPS_OUTPUT_PLIST,                  /* XML plist test output */
+  _CUPS_OUTPUT_IPPSERVER,              /* ippserver attribute file output */
   _CUPS_OUTPUT_LIST,                   /* Tabular list output */
   _CUPS_OUTPUT_CSV                     /* Comma-separated values output */
 } _cups_output_t;
@@ -66,13 +63,15 @@ typedef enum _cups_with_e           /**** WITH flags ****/
 typedef struct _cups_expect_s          /**** Expected attribute info ****/
 {
   int          optional,               /* Optional attribute? */
-               not_expect;             /* Don't expect attribute? */
+               not_expect,             /* Don't expect attribute? */
+               expect_all;             /* Expect all attributes to match/not match */
   char         *name,                  /* Attribute name */
                *of_type,               /* Type name */
                *same_count_as,         /* Parallel attribute name */
                *if_defined,            /* Only required if variable defined */
                *if_not_defined,        /* Only required if variable is not defined */
                *with_value,            /* Attribute must include this value */
+               *with_value_from,       /* Attribute must have one of the values in this attribute */
                *define_match,          /* Variable to define on match */
                *define_no_match,       /* Variable to define on no-match */
                *define_value;          /* Variable to define with value */
@@ -131,7 +130,8 @@ static int  Cancel = 0,             /* Cancel test? */
                IgnoreErrors = 0,       /* Ignore errors? */
                StopAfterIncludeError = 0,
                                        /* Stop after include errors? */
-               Verbosity = 0,          /* Show all attributes? */
+               ValidateHeaders = 0,    /* Validate HTTP headers in response? */
+                Verbosity = 0,          /* Show all attributes? */
                Version = 11,           /* Default IPP version */
                XMLHeader = 0,          /* 1 if header is written */
                TestCount = 0,          /* Number of tests run */
@@ -147,45 +147,39 @@ static int        PasswordTries = 0;      /* Number of tries with password */
  * Local functions...
  */
 
-static void    add_stringf(cups_array_t *a, const char *s, ...)
-               __attribute__ ((__format__ (__printf__, 2, 3)));
+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     compare_vars(_cups_var_t *a, _cups_var_t *b);
-static int     do_tests(_cups_vars_t *vars, const char *testfile);
-static void    expand_variables(_cups_vars_t *vars, char *dst, const char *src,
-                                size_t dstsize) __attribute__((nonnull(1,2,3)));
+static int     do_tests(cups_file_t *outfile, _cups_vars_t *vars, const char *testfile);
+static void    expand_variables(_cups_vars_t *vars, char *dst, const char *src, size_t dstsize) __attribute__((nonnull(1,2,3)));
 static int      expect_matches(_cups_expect_t *expect, ipp_tag_t value_tag);
-static ipp_t   *get_collection(_cups_vars_t *vars, FILE *fp, int *linenum);
-static char    *get_filename(const char *testfile, char *dst, const char *src,
-                             size_t dstsize);
-static char    *get_string(ipp_attribute_t *attr, int element, int flags,
-                           char *buffer, size_t bufsize);
-static char    *get_token(FILE *fp, char *buf, int buflen,
-                          int *linenum);
+static ipp_t   *get_collection(cups_file_t *outfile, _cups_vars_t *vars, cups_file_t *fp, int *linenum);
+static char    *get_filename(const char *testfile, char *dst, const char *src, size_t dstsize);
+static const char *get_string(ipp_attribute_t *attr, int element, int flags, char *buffer, size_t bufsize);
+static char    *get_token(cups_file_t *fp, char *buf, int buflen, int *linenum);
 static char    *get_variable(_cups_vars_t *vars, const char *name);
-static char    *iso_date(ipp_uchar_t *date);
+static char    *iso_date(const ipp_uchar_t *date);
 static const char *password_cb(const char *prompt);
-static void    print_attr(ipp_attribute_t *attr, ipp_tag_t *group);
-static void    print_col(ipp_t *col);
-static void    print_csv(ipp_attribute_t *attr, int num_displayed,
-                         char **displayed, size_t *widths);
-static void    print_fatal_error(const char *s, ...)
-               __attribute__ ((__format__ (__printf__, 1, 2)));
-static void    print_line(ipp_attribute_t *attr, int num_displayed,
-                          char **displayed, size_t *widths);
-static void    print_xml_header(void);
-static void    print_xml_string(const char *element, const char *s);
-static void    print_xml_trailer(int success, const char *message);
-static void    set_variable(_cups_vars_t *vars, const char *name,
-                            const char *value);
+static void    pause_message(const char *message);
+static void    print_attr(cups_file_t *outfile, int format, ipp_attribute_t *attr, ipp_tag_t *group);
+static void    print_csv(cups_file_t *outfile, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
+static void    print_fatal_error(cups_file_t *outfile, const char *s, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+static void    print_ippserver_attr(cups_file_t *outfile, ipp_attribute_t *attr, int indent);
+static void    print_ippserver_string(cups_file_t *outfile, const char *s, size_t len);
+static void    print_line(cups_file_t *outfile, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
+static void    print_xml_header(cups_file_t *outfile);
+static void    print_xml_string(cups_file_t *outfile, const char *element, const char *s);
+static void    print_xml_trailer(cups_file_t *outfile, int success, const char *message);
+static void    set_variable(cups_file_t *outfile, _cups_vars_t *vars, const char *name, const char *value);
 #ifndef WIN32
 static void    sigterm_handler(int sig);
 #endif /* WIN32 */
 static int     timeout_cb(http_t *http, void *user_data);
 static void    usage(void) __attribute__((noreturn));
-static int     validate_attr(cups_array_t *errors, ipp_attribute_t *attr);
-static int      with_value(cups_array_t *errors, char *value, int flags,
-                          ipp_attribute_t *attr, char *matchbuf,
-                          size_t matchlen);
+static int     validate_attr(cups_file_t *outfile, 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_from(cups_array_t *errors, ipp_attribute_t *fromattr, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
 
 
 /*
@@ -198,6 +192,8 @@ main(int  argc,                             /* I - Number of command-line args */
 {
   int                  i;              /* Looping var */
   int                  status;         /* Status of tests... */
+  cups_file_t          *outfile = cupsFileStdout();
+                                        /* Output file */
   char                 *opt,           /* Current option */
                        name[1024],     /* Name/value buffer */
                        *value,         /* Pointer to value */
@@ -250,6 +246,27 @@ main(int  argc,                            /* I - Number of command-line args */
     {
       usage();
     }
+    else if (!strcmp(argv[i], "--ippserver"))
+    {
+      i ++;
+
+      if (i >= argc)
+      {
+       _cupsLangPuts(stderr, _("ipptool: Missing filename for \"--ippserver\"."));
+       usage();
+      }
+
+      if (outfile != cupsFileStdout())
+       usage();
+
+      if ((outfile = cupsFileOpen(argv[i], "w")) == NULL)
+      {
+       _cupsLangPrintf(stderr, _("%s: Unable to open \"%s\": %s"), "ipptool", argv[i], strerror(errno));
+       exit(1);
+      }
+
+      Output = _CUPS_OUTPUT_IPPSERVER;
+    }
     else if (!strcmp(argv[i], "--stop-after-include-error"))
     {
       StopAfterIncludeError = 1;
@@ -296,6 +313,33 @@ main(int  argc,                            /* I - Number of command-line args */
               Transfer = _CUPS_TRANSFER_LENGTH;
               break;
 
+          case 'P' : /* Output to plist file */
+             i ++;
+
+             if (i >= argc)
+             {
+               _cupsLangPrintf(stderr, _("%s: Missing filename for \"-P\"."), "ipptool");
+               usage();
+              }
+
+              if (outfile != cupsFileStdout())
+                usage();
+
+              if ((outfile = cupsFileOpen(argv[i], "w")) == NULL)
+              {
+                _cupsLangPrintf(stderr, _("%s: Unable to open \"%s\": %s"), "ipptool", argv[i], strerror(errno));
+                exit(1);
+              }
+
+             Output = _CUPS_OUTPUT_PLIST;
+
+              if (interval || repeat)
+             {
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
+               usage();
+             }
+              break;
+
          case 'S' : /* Encrypt with SSL */
 #ifdef HAVE_SSL
              vars.encryption = HTTP_ENCRYPT_ALWAYS;
@@ -354,8 +398,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
               if (interval || repeat)
              {
-               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
-                                       "incompatible with -X\"."));
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
                usage();
              }
              break;
@@ -380,7 +423,7 @@ main(int  argc,                             /* I - Number of command-line args */
              else
                value = name + strlen(name);
 
-             set_variable(&vars, name, value);
+             set_variable(outfile, &vars, name, value);
              break;
 
           case 'f' : /* Set the default test filename */
@@ -439,36 +482,43 @@ main(int  argc,                           /* I - Number of command-line args */
                 */
 
                 if (!_cups_strcasecmp(ext, ".gif"))
-                  set_variable(&vars, "filetype", "image/gif");
+                  set_variable(outfile, &vars, "filetype", "image/gif");
                 else if (!_cups_strcasecmp(ext, ".htm") ||
                          !_cups_strcasecmp(ext, ".htm.gz") ||
                          !_cups_strcasecmp(ext, ".html") ||
                          !_cups_strcasecmp(ext, ".html.gz"))
-                  set_variable(&vars, "filetype", "text/html");
-                else if (!_cups_strcasecmp(ext, ".jpg"))
-                  set_variable(&vars, "filetype", "image/jpeg");
+                  set_variable(outfile, &vars, "filetype", "text/html");
+                else if (!_cups_strcasecmp(ext, ".jpg") ||
+                         !_cups_strcasecmp(ext, ".jpeg"))
+                  set_variable(outfile, &vars, "filetype", "image/jpeg");
                 else if (!_cups_strcasecmp(ext, ".pcl") ||
                          !_cups_strcasecmp(ext, ".pcl.gz"))
-                  set_variable(&vars, "filetype", "application/vnd.hp-PCL");
+                  set_variable(outfile, &vars, "filetype", "application/vnd.hp-PCL");
                 else if (!_cups_strcasecmp(ext, ".pdf"))
-                  set_variable(&vars, "filetype", "application/pdf");
+                  set_variable(outfile, &vars, "filetype", "application/pdf");
                 else if (!_cups_strcasecmp(ext, ".png"))
-                  set_variable(&vars, "filetype", "image/png");
+                  set_variable(outfile, &vars, "filetype", "image/png");
                 else if (!_cups_strcasecmp(ext, ".ps") ||
                          !_cups_strcasecmp(ext, ".ps.gz"))
-                  set_variable(&vars, "filetype", "application/postscript");
+                  set_variable(outfile, &vars, "filetype", "application/postscript");
                 else if (!_cups_strcasecmp(ext, ".pwg") ||
                          !_cups_strcasecmp(ext, ".pwg.gz") ||
                          !_cups_strcasecmp(ext, ".ras") ||
                          !_cups_strcasecmp(ext, ".ras.gz"))
-                  set_variable(&vars, "filetype", "image/pwg-raster");
+                  set_variable(outfile, &vars, "filetype", "image/pwg-raster");
+                else if (!_cups_strcasecmp(ext, ".tif") ||
+                         !_cups_strcasecmp(ext, ".tiff"))
+                  set_variable(outfile, &vars, "filetype", "image/tiff");
                 else if (!_cups_strcasecmp(ext, ".txt") ||
                          !_cups_strcasecmp(ext, ".txt.gz"))
-                  set_variable(&vars, "filetype", "text/plain");
+                  set_variable(outfile, &vars, "filetype", "text/plain");
+                else if (!_cups_strcasecmp(ext, ".urf") ||
+                         !_cups_strcasecmp(ext, ".urf.gz"))
+                  set_variable(outfile, &vars, "filetype", "image/urf");
                 else if (!_cups_strcasecmp(ext, ".xps"))
-                  set_variable(&vars, "filetype", "application/openxps");
+                  set_variable(outfile, &vars, "filetype", "application/openxps");
                 else
-                 set_variable(&vars, "filetype", "application/octet-stream");
+                 set_variable(outfile, &vars, "filetype", "application/octet-stream");
               }
               else
               {
@@ -476,10 +526,14 @@ main(int  argc,                           /* I - Number of command-line args */
                 * Use the "auto-type" MIME media type...
                 */
 
-               set_variable(&vars, "filetype", "application/octet-stream");
+               set_variable(outfile, &vars, "filetype", "application/octet-stream");
               }
              break;
 
+          case 'h' : /* Validate response headers */
+              ValidateHeaders = 1;
+              break;
+
           case 'i' : /* Test every N seconds */
              i ++;
 
@@ -501,10 +555,9 @@ main(int  argc,                            /* I - Number of command-line args */
                }
               }
 
-              if (Output == _CUPS_OUTPUT_PLIST && interval)
+              if ((Output == _CUPS_OUTPUT_PLIST || Output == _CUPS_OUTPUT_IPPSERVER) && interval)
              {
-               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
-                                       "incompatible with -X\"."));
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are incompatible with \"--ippserver\", \"-P\", and \"-X\"."));
                usage();
              }
              break;
@@ -525,10 +578,9 @@ main(int  argc,                            /* I - Number of command-line args */
              else
                repeat = atoi(argv[i]);
 
-              if (Output == _CUPS_OUTPUT_PLIST && repeat)
+              if ((Output == _CUPS_OUTPUT_PLIST || Output == _CUPS_OUTPUT_IPPSERVER) && repeat)
              {
-               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
-                                       "incompatible with -X\"."));
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are incompatible with \"--ippserver\", \"-P\", and \"-X\"."));
                usage();
              }
              break;
@@ -595,7 +647,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
         Username = vars.userpass;
        cupsSetPasswordCB(password_cb);
-       set_variable(&vars, "uriuser", vars.userpass);
+       set_variable(outfile, &vars, "uriuser", vars.userpass);
       }
 
       httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri), vars.scheme, NULL,
@@ -611,6 +663,7 @@ main(int  argc,                             /* I - Number of command-line args */
       if (!vars.uri)
       {
         _cupsLangPuts(stderr, _("ipptool: URI required before test file."));
+        _cupsLangPuts(stderr, argv[i]);
        usage();
       }
 
@@ -630,7 +683,7 @@ main(int  argc,                             /* I - Number of command-line args */
       else
         testfile = argv[i];
 
-      if (!do_tests(&vars, testfile))
+      if (!do_tests(outfile, &vars, testfile))
         status = 1;
     }
   }
@@ -643,13 +696,13 @@ main(int  argc,                           /* I - Number of command-line args */
   */
 
   if (Output == _CUPS_OUTPUT_PLIST)
-    print_xml_trailer(!status, NULL);
+    print_xml_trailer(outfile, !status, NULL);
   else if (interval > 0 && repeat > 0)
   {
     while (repeat > 1)
     {
       usleep((useconds_t)interval);
-      do_tests(&vars, testfile);
+      do_tests(outfile, &vars, testfile);
       repeat --;
     }
   }
@@ -658,21 +711,22 @@ main(int  argc,                           /* I - Number of command-line args */
     for (;;)
     {
       usleep((useconds_t)interval);
-      do_tests(&vars, testfile);
+      do_tests(outfile, &vars, testfile);
     }
   }
-  else if (Output == _CUPS_OUTPUT_TEST && TestCount > 1)
+
+  if ((Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile)) && TestCount > 1)
   {
    /*
     * Show a summary report if there were multiple tests...
     */
 
-    printf("\nSummary: %d tests, %d passed, %d failed, %d skipped\n"
-           "Score: %d%%\n", TestCount, PassCount, FailCount, SkipCount,
-           100 * (PassCount + SkipCount) / TestCount);
+    cupsFilePrintf(cupsFileStdout(), "\nSummary: %d tests, %d passed, %d failed, %d skipped\nScore: %d%%\n", TestCount, PassCount, FailCount, SkipCount, 100 * (PassCount + SkipCount) / TestCount);
   }
 
- /*
+  cupsFileClose(outfile);
+
+/*
   * Exit...
   */
 
@@ -716,6 +770,71 @@ add_stringf(cups_array_t *a,               /* I - Array */
 }
 
 
+/*
+ * 'compare_uris()' - Compare two URIs...
+ */
+
+static int                              /* O - Result of comparison */
+compare_uris(const char *a,             /* I - First URI */
+             const char *b)             /* I - Second URI */
+{
+  char  ascheme[32],                    /* Components of first URI */
+        auserpass[256],
+        ahost[256],
+        aresource[256];
+  int   aport;
+  char  bscheme[32],                    /* Components of second URI */
+        buserpass[256],
+        bhost[256],
+        bresource[256];
+  int   bport;
+  char  *ptr;                           /* Pointer into string */
+  int   result;                         /* Result of comparison */
+
+
+ /*
+  * Separate the URIs into their components...
+  */
+
+  if (httpSeparateURI(HTTP_URI_CODING_ALL, a, ascheme, sizeof(ascheme), auserpass, sizeof(auserpass), ahost, sizeof(ahost), &aport, aresource, sizeof(aresource)) < HTTP_URI_STATUS_OK)
+    return (-1);
+
+  if (httpSeparateURI(HTTP_URI_CODING_ALL, b, bscheme, sizeof(bscheme), buserpass, sizeof(buserpass), bhost, sizeof(bhost), &bport, bresource, sizeof(bresource)) < HTTP_URI_STATUS_OK)
+    return (-1);
+
+ /*
+  * Strip trailing dots from the host components, if present...
+  */
+
+  if ((ptr = ahost + strlen(ahost) - 1) > ahost && *ptr == '.')
+    *ptr = '\0';
+
+  if ((ptr = bhost + strlen(bhost) - 1) > bhost && *ptr == '.')
+    *ptr = '\0';
+
+ /*
+  * Compare each component...
+  */
+
+  if ((result = _cups_strcasecmp(ascheme, bscheme)) != 0)
+    return (result);
+
+  if ((result = strcmp(auserpass, buserpass)) != 0)
+    return (result);
+
+  if ((result = _cups_strcasecmp(ahost, bhost)) != 0)
+    return (result);
+
+  if (aport != bport)
+    return (aport - bport);
+
+  if (!_cups_strcasecmp(ascheme, "mailto") || !_cups_strcasecmp(ascheme, "urn"))
+    return (_cups_strcasecmp(aresource, bresource));
+  else
+    return (strcmp(aresource, bresource));
+}
+
+
 /*
  * 'compare_vars()' - Compare two variables.
  */
@@ -733,7 +852,8 @@ compare_vars(_cups_var_t *a,                /* I - First variable */
  */
 
 static int                             /* 1 = success, 0 = failure */
-do_tests(_cups_vars_t *vars,           /* I - Variables */
+do_tests(cups_file_t  *outfile,                /* I - Output file */
+         _cups_vars_t *vars,           /* I - Variables */
          const char   *testfile)       /* I - Test file to use */
 {
   int          i,                      /* Looping var */
@@ -745,16 +865,16 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
                ignore_errors,          /* Ignore test failures? */
                skip_previous = 0,      /* Skip on previous test failure? */
                repeat_count,           /* Repeat count */
-               repeat_interval,        /* Repeat interval */
-               repeat_prev,            /* Previous repeat interval */
                repeat_test;            /* Repeat a test? */
+  useconds_t   delay,                  /* Initial delay */
+               repeat_interval;        /* Repeat interval (delay) */
   http_t       *http = NULL;           /* HTTP connection to server */
-  FILE         *fp = NULL;             /* Test file */
+  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[8192],           /* Copy buffer */
+               buffer[131072],         /* Copy buffer */
                compression[16];        /* COMPRESSION value */
   ipp_t                *request = NULL,        /* IPP request */
                *response = NULL;       /* IPP response */
@@ -779,7 +899,8 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   int          num_statuses = 0;       /* Number of valid status codes */
   _cups_status_t statuses[100],                /* Valid status codes */
                *last_status;           /* Last STATUS (for predicates) */
-  int          num_expects = 0;        /* Number of expected attributes */
+  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) */
@@ -795,9 +916,9 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   * Open the test file...
   */
 
-  if ((fp = fopen(testfile, "r")) == NULL)
+  if ((fp = cupsFileOpen(testfile, "r")) == NULL)
   {
-    print_fatal_error("Unable to open test file %s - %s", testfile,
+    print_fatal_error(outfile, "Unable to open test file %s - %s", testfile,
                       strerror(errno));
     pass = 0;
     goto test_exit;
@@ -810,7 +931,7 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   if ((http = httpConnect2(vars->hostname, vars->port, NULL, vars->family,
                            vars->encryption, 1, 30000, NULL)) == NULL)
   {
-    print_fatal_error("Unable to connect to %s on port %d - %s", vars->hostname,
+    print_fatal_error(outfile, "Unable to connect to %s on port %d - %s", vars->hostname,
                       vars->port, cupsLastErrorString());
     pass = 0;
     goto test_exit;
@@ -830,13 +951,13 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
   * Loop on tests...
   */
 
-  CUPS_SRAND(time(NULL));
+  CUPS_SRAND((unsigned)time(NULL));
 
   errors     = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup,
                              (cups_afree_func_t)free);
   file_id[0] = '\0';
   pass       = 1;
-  linenum    = 1;
+  linenum    = 0;
   request_id = (CUPS_RAND() % 1000) * 137 + 1;
 
   while (!Cancel && get_token(fp, token, sizeof(token), &linenum) != NULL)
@@ -855,11 +976,11 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
           get_token(fp, temp, sizeof(temp), &linenum))
       {
         expand_variables(vars, token, temp, sizeof(token));
-       set_variable(vars, attr, token);
+       set_variable(outfile, vars, attr, token);
       }
       else
       {
-        print_fatal_error("Missing DEFINE name and/or value on line %d.",
+        print_fatal_error(outfile, "Missing DEFINE name and/or value on line %d.",
                          linenum);
        pass = 0;
        goto test_exit;
@@ -878,11 +999,11 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
         expand_variables(vars, token, temp, sizeof(token));
        if (!get_variable(vars, attr))
-         set_variable(vars, attr, token);
+         set_variable(outfile, vars, attr, token);
       }
       else
       {
-        print_fatal_error("Missing DEFINE-DEFAULT name and/or value on line "
+        print_fatal_error(outfile, "Missing DEFINE-DEFAULT name and/or value on line "
                          "%d.", linenum);
        pass = 0;
        goto test_exit;
@@ -902,7 +1023,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing FILE-ID value on line %d.", linenum);
+        print_fatal_error(outfile, "Missing FILE-ID value on line %d.", linenum);
        pass = 0;
        goto test_exit;
       }
@@ -923,7 +1044,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing IGNORE-ERRORS value on line %d.", linenum);
+        print_fatal_error(outfile, "Missing IGNORE-ERRORS value on line %d.", linenum);
        pass = 0;
        goto test_exit;
       }
@@ -943,8 +1064,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
         * Map the filename to and then run the tests...
        */
 
-        if (!do_tests(vars, get_filename(testfile, filename, temp,
-                                        sizeof(filename))))
+        if (!do_tests(outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
        {
          pass = 0;
 
@@ -954,7 +1074,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing INCLUDE filename on line %d.", linenum);
+        print_fatal_error(outfile, "Missing INCLUDE filename on line %d.", linenum);
        pass = 0;
        goto test_exit;
       }
@@ -977,8 +1097,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
        */
 
         if (get_variable(vars, attr) &&
-           !do_tests(vars, get_filename(testfile, filename, temp,
-                                        sizeof(filename))))
+           !do_tests(outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
        {
          pass = 0;
 
@@ -988,7 +1107,7 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing INCLUDE-IF-DEFINED name or filename on line "
+        print_fatal_error(outfile, "Missing INCLUDE-IF-DEFINED name or filename on line "
                          "%d.", linenum);
        pass = 0;
        goto test_exit;
@@ -1012,8 +1131,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        */
 
         if (!get_variable(vars, attr) &&
-           !do_tests(vars, get_filename(testfile, filename, temp,
-                                        sizeof(filename))))
+           !do_tests(outfile, vars, get_filename(testfile, filename, temp, sizeof(filename))))
        {
          pass = 0;
 
@@ -1023,7 +1141,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing INCLUDE-IF-NOT-DEFINED name or filename on "
+        print_fatal_error(outfile, "Missing INCLUDE-IF-NOT-DEFINED name or filename on "
                          "line %d.", linenum);
        pass = 0;
        goto test_exit;
@@ -1045,7 +1163,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing SKIP-IF-DEFINED variable on line %d.",
+        print_fatal_error(outfile, "Missing SKIP-IF-DEFINED variable on line %d.",
                          linenum);
        pass = 0;
        goto test_exit;
@@ -1064,7 +1182,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing SKIP-IF-NOT-DEFINED variable on line %d.",
+        print_fatal_error(outfile, "Missing SKIP-IF-NOT-DEFINED variable on line %d.",
                          linenum);
        pass = 0;
        goto test_exit;
@@ -1084,7 +1202,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
+        print_fatal_error(outfile, "Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
                           linenum);
        pass = 0;
        goto test_exit;
@@ -1110,7 +1228,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          Transfer = _CUPS_TRANSFER_LENGTH;
        else
        {
-         print_fatal_error("Bad TRANSFER value \"%s\" on line %d.", temp,
+         print_fatal_error(outfile, "Bad TRANSFER value \"%s\" on line %d.", temp,
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1118,7 +1236,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-        print_fatal_error("Missing TRANSFER value on line %d.", linenum);
+        print_fatal_error(outfile, "Missing TRANSFER value on line %d.", linenum);
        pass = 0;
        goto test_exit;
       }
@@ -1141,14 +1259,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
          Version = 22;
        else
        {
-         print_fatal_error("Bad VERSION \"%s\" on line %d.", temp, linenum);
+         print_fatal_error(outfile, "Bad VERSION \"%s\" on line %d.", temp, linenum);
          pass = 0;
          goto test_exit;
        }
       }
       else
       {
-        print_fatal_error("Missing VERSION number on line %d.", linenum);
+        print_fatal_error(outfile, "Missing VERSION number on line %d.", linenum);
        pass = 0;
        goto test_exit;
       }
@@ -1157,7 +1275,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
     }
     else if (strcmp(token, "{"))
     {
-      print_fatal_error("Unexpected token %s seen on line %d.", token, linenum);
+      print_fatal_error(outfile, "Unexpected token %s seen on line %d.", token, linenum);
       pass = 0;
       goto test_exit;
     }
@@ -1169,9 +1287,9 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
     if (show_header)
     {
       if (Output == _CUPS_OUTPUT_PLIST)
-       print_xml_header();
-      else if (Output == _CUPS_OUTPUT_TEST)
-       printf("\"%s\":\n", testfile);
+       print_xml_header(outfile);
+      if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
+       cupsFilePrintf(cupsFileStdout(), "\"%s\":\n", testfile);
 
       show_header = 0;
     }
@@ -1179,19 +1297,22 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
     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';
+    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)
@@ -1222,7 +1343,8 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
           _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") &&
+          _cups_strcasecmp(token, "WITH-VALUE-FROM"))
         last_expect = NULL;
 
       if (_cups_strcasecmp(token, "DEFINE-MATCH") &&
@@ -1242,7 +1364,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        * Another collection value
        */
 
-       ipp_t   *col = get_collection(vars, fp, &linenum);
+       ipp_t   *col = get_collection(outfile, vars, fp, &linenum);
                                        /* Collection value */
 
        if (col)
@@ -1273,7 +1395,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          if (strcmp(compression, "none"))
 #endif /* HAVE_LIBZ */
           {
-           print_fatal_error("Unsupported COMPRESSION value '%s' on line %d.",
+           print_fatal_error(outfile, "Unsupported COMPRESSION value '%s' on line %d.",
                              compression, linenum);
            pass = 0;
            goto test_exit;
@@ -1284,7 +1406,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing COMPRESSION value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing COMPRESSION value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1299,11 +1421,11 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
            get_token(fp, temp, sizeof(temp), &linenum))
        {
          expand_variables(vars, token, temp, sizeof(token));
-         set_variable(vars, attr, token);
+         set_variable(outfile, vars, attr, token);
        }
        else
        {
-         print_fatal_error("Missing DEFINE name and/or value on line %d.",
+         print_fatal_error(outfile, "Missing DEFINE name and/or value on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1323,7 +1445,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing IGNORE-ERRORS value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing IGNORE-ERRORS value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1336,7 +1458,17 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
         * Name of test...
        */
 
-       get_token(fp, name, sizeof(name), &linenum);
+       get_token(fp, temp, sizeof(temp), &linenum);
+       expand_variables(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"))
       {
@@ -1353,7 +1485,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
            request_id = (CUPS_RAND() % 1000) * 137 + 1;
          else
          {
-           print_fatal_error("Bad REQUEST-ID value \"%s\" on line %d.", temp,
+           print_fatal_error(outfile, "Bad REQUEST-ID value \"%s\" on line %d.", temp,
                              linenum);
            pass = 0;
            goto test_exit;
@@ -1361,7 +1493,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing REQUEST-ID value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing REQUEST-ID value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1379,7 +1511,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing SKIP-IF-DEFINED value on line %d.",
+         print_fatal_error(outfile, "Missing SKIP-IF-DEFINED value on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1401,7 +1533,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing SKIP-IF-MISSING filename on line %d.",
+         print_fatal_error(outfile, "Missing SKIP-IF-MISSING filename on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1420,7 +1552,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing SKIP-IF-NOT-DEFINED value on line %d.",
+         print_fatal_error(outfile, "Missing SKIP-IF-NOT-DEFINED value on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1440,7 +1572,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing SKIP-PREVIOUS-ERROR value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing SKIP-PREVIOUS-ERROR value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1459,7 +1591,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing TEST-ID value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing TEST-ID value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1484,7 +1616,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
            transfer = _CUPS_TRANSFER_LENGTH;
          else
          {
-           print_fatal_error("Bad TRANSFER value \"%s\" on line %d.", temp,
+           print_fatal_error(outfile, "Bad TRANSFER value \"%s\" on line %d.", temp,
                              linenum);
            pass = 0;
            goto test_exit;
@@ -1492,7 +1624,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        }
        else
        {
-         print_fatal_error("Missing TRANSFER value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing TRANSFER value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1515,14 +1647,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
            version = 22;
          else
          {
-           print_fatal_error("Bad VERSION \"%s\" on line %d.", temp, linenum);
+           print_fatal_error(outfile, "Bad VERSION \"%s\" on line %d.", temp, linenum);
            pass = 0;
            goto test_exit;
          }
        }
        else
        {
-         print_fatal_error("Missing VERSION number on line %d.", linenum);
+         print_fatal_error(outfile, "Missing VERSION number on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1535,7 +1667,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        if (!get_token(fp, resource, sizeof(resource), &linenum))
        {
-         print_fatal_error("Missing RESOURCE path on line %d.", linenum);
+         print_fatal_error(outfile, "Missing RESOURCE path on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1548,7 +1680,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
-         print_fatal_error("Missing OPERATION code on line %d.", linenum);
+         print_fatal_error(outfile, "Missing OPERATION code on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1558,7 +1690,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        if ((op = ippOpValue(token)) == (ipp_op_t)-1 &&
            (op = (ipp_op_t)strtol(token, NULL, 0)) == 0)
        {
-         print_fatal_error("Bad OPERATION code \"%s\" on line %d.", token,
+         print_fatal_error(outfile, "Bad OPERATION code \"%s\" on line %d.", token,
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1572,14 +1704,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing GROUP tag on line %d.", linenum);
+         print_fatal_error(outfile, "Missing GROUP tag on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
-       if ((value = ippTagValue(token)) < 0)
+       if ((value = ippTagValue(token)) == IPP_TAG_ZERO || value >= IPP_TAG_UNSUPPORTED_VALUE)
        {
-         print_fatal_error("Bad GROUP tag \"%s\" on line %d.", token, linenum);
+         print_fatal_error(outfile, "Bad GROUP tag \"%s\" on line %d.", token, linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1595,31 +1727,41 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         * Delay before operation...
        */
 
-        double delay;
+        double dval;                    /* Delay value */
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
-         print_fatal_error("Missing DELAY value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing DELAY value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
        expand_variables(vars, token, temp, sizeof(token));
 
-       if ((delay = _cupsStrScand(token, NULL, localeconv())) <= 0.0)
+       if ((dval = _cupsStrScand(token, &tokenptr, localeconv())) < 0.0 || (*tokenptr && *tokenptr != ','))
        {
-         print_fatal_error("Bad DELAY value \"%s\" on line %d.", token,
+         print_fatal_error(outfile, "Bad DELAY value \"%s\" on line %d.", token,
                            linenum);
          pass = 0;
          goto test_exit;
        }
-       else
-       {
-         if (Output == _CUPS_OUTPUT_TEST)
-           printf("    [%g second delay]\n", delay);
 
-         usleep((useconds_t)(1000000.0 * delay));
-       }
+        delay = (useconds_t)(1000000.0 * dval);
+
+        if (*tokenptr == ',')
+        {
+          if ((dval = _cupsStrScand(tokenptr + 1, &tokenptr, localeconv())) <= 0.0 || *tokenptr)
+          {
+            print_fatal_error(outfile, "Bad DELAY value \"%s\" on line %d.", token,
+                              linenum);
+            pass = 0;
+            goto test_exit;
+          }
+
+          repeat_interval = (useconds_t)(1000000.0 * dval);
+        }
+        else
+          repeat_interval = delay;
       }
       else if (!_cups_strcasecmp(token, "ATTR"))
       {
@@ -1629,14 +1771,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing ATTR value tag on line %d.", linenum);
+         print_fatal_error(outfile, "Missing ATTR value tag on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
-       if ((value = ippTagValue(token)) == IPP_TAG_ZERO)
+       if ((value = ippTagValue(token)) < IPP_TAG_UNSUPPORTED_VALUE)
        {
-         print_fatal_error("Bad ATTR value tag \"%s\" on line %d.", token,
+         print_fatal_error(outfile, "Bad ATTR value tag \"%s\" on line %d.", token,
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1644,23 +1786,51 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (!get_token(fp, attr, sizeof(attr), &linenum))
        {
-         print_fatal_error("Missing ATTR name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing ATTR name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
-       if (!get_token(fp, temp, sizeof(temp), &linenum))
+        if (value < IPP_TAG_INTEGER)
+        {
+         /*
+          * Add out-of-band value - no value string needed...
+          */
+
+          token[0] = '\0';
+        }
+        else if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
-         print_fatal_error("Missing ATTR value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing ATTR value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
+       else
+       {
+          expand_variables(vars, token, temp, sizeof(token));
+        }
 
-        expand_variables(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(outfile, "Unsupported ATTR value tag %s for \"%s\" on line %d.", ippTagString(value), attr, linenum);
+                pass = 0;
+                goto test_exit;
+              }
+              break;
+
          case IPP_TAG_BOOLEAN :
              if (!_cups_strcasecmp(token, "true"))
                attrptr = ippAddBoolean(request, group, attr, 1);
@@ -1671,32 +1841,79 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
              if (!strchr(token, ','))
-               attrptr = ippAddInteger(request, group, value, attr, (int)strtol(token, &tokenptr, 0));
+             {
+               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 */
 
-               values[0] = (int)strtol(token, &tokenptr, 10);
+               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 ++;
-                 else if (!isdigit(*tokenptr & 255) && *tokenptr != '-')
-                   break;
 
-                 values[num_values] = (int)strtol(tokenptr, &tokenptr, 0);
-                 num_values ++;
+                 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 (!tokenptr || *tokenptr)
+             if ((!token[0] || !tokenptr || *tokenptr) && !skip_test)
              {
-               print_fatal_error("Bad %s value \"%s\" on line %d.",
-                                 ippTagString(value), token, linenum);
+               print_fatal_error(outfile, "Bad %s value \'%s\' for \"%s\" on line %d.",
+                                 ippTagString(value), token, attr, linenum);
                pass = 0;
                goto test_exit;
              }
@@ -1721,8 +1938,10 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
                     _cups_strcasecmp(ptr, "dpcm") &&
                     _cups_strcasecmp(ptr, "other")))
                {
-                 print_fatal_error("Bad resolution value \"%s\" on line %d.",
-                                   token, linenum);
+                 if (skip_test)
+                   break;
+
+                 print_fatal_error(outfile, "Bad resolution value \'%s\' for \"%s\" on line %d.", token, attr, linenum);
                  pass = 0;
                  goto test_exit;
                }
@@ -1752,8 +1971,10 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
                 if ((num_vals & 1) || num_vals == 0)
                {
-                 print_fatal_error("Bad rangeOfInteger value \"%s\" on line "
-                                   "%d.", token, linenum);
+                 if (skip_test)
+                   break;
+
+                 print_fatal_error(outfile, "Bad rangeOfInteger value \'%s\' for \"%s\" on line %d.", token, attr, linenum);
                  pass = 0;
                  goto test_exit;
                }
@@ -1766,7 +1987,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
           case IPP_TAG_BEGIN_COLLECTION :
              if (!strcmp(token, "{"))
              {
-               ipp_t   *col = get_collection(vars, fp, &linenum);
+               ipp_t   *col = get_collection(outfile, vars, fp, &linenum);
                                        /* Collection value */
 
                 if (col)
@@ -1780,37 +2001,40 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                  goto test_exit;
                }
               }
+              else if (skip_test)
+               break;
              else
              {
-               print_fatal_error("Bad ATTR collection value on line %d.",
-                                 linenum);
+               print_fatal_error(outfile, "Bad ATTR collection value for \"%s\" on line %d.", attr, linenum);
                pass = 0;
                goto test_exit;
              }
 
              do
              {
-               ipp_t   *col;                   /* Collection value */
-               long    pos = ftell(fp);        /* Save position of file */
+               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, ","))
                {
-                 fseek(fp, pos, SEEK_SET);
+                 cupsFileSeek(fp, savepos);
+                 linenum = savelinenum;
                  break;
                }
 
                if (!get_token(fp, token, sizeof(token), &linenum) || strcmp(token, "{"))
                {
-                 print_fatal_error("Unexpected \"%s\" on line %d.", token, linenum);
+                 print_fatal_error(outfile, "Unexpected \"%s\" on line %d.", token, linenum);
                  pass = 0;
                  goto test_exit;
                  break;
                }
 
-               if ((col = get_collection(vars, fp, &linenum)) == NULL)
+               if ((col = get_collection(outfile, vars, fp, &linenum)) == NULL)
                  break;
 
                ippSetCollection(request, &attrptr, ippGetCount(attrptr), col);
@@ -1823,12 +2047,6 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
               attrptr = ippAddOctetString(request, group, attr, token, (int)strlen(token));
              break;
 
-         default :
-             print_fatal_error("Unsupported ATTR value tag %s on line %d.",
-                               ippTagString(value), linenum);
-             pass = 0;
-             goto test_exit;
-
          case IPP_TAG_TEXTLANG :
          case IPP_TAG_NAMELANG :
          case IPP_TAG_TEXT :
@@ -1873,10 +2091,9 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
              break;
        }
 
-       if (!attrptr)
+       if (!attrptr && !skip_test)
        {
-         print_fatal_error("Unable to add attribute on line %d: %s", linenum,
-                           cupsLastErrorString());
+         print_fatal_error(outfile, "Unable to add attribute \"%s\" on line %d.", attr, linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1889,7 +2106,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
-         print_fatal_error("Missing FILE filename on line %d.", linenum);
+         print_fatal_error(outfile, "Missing FILE filename on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1899,9 +2116,9 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
         if (access(filename, R_OK))
         {
-         print_fatal_error("Filename \"%s\" on line %d cannot be read.",
+         print_fatal_error(outfile, "Filename \"%s\" on line %d cannot be read.",
                            temp, linenum);
-         print_fatal_error("Filename mapped to \"%s\".", filename);
+         print_fatal_error(outfile, "Filename mapped to \"%s\".", filename);
          pass = 0;
          goto test_exit;
         }
@@ -1914,14 +2131,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
         if (num_statuses >= (int)(sizeof(statuses) / sizeof(statuses[0])))
        {
-         print_fatal_error("Too many STATUS's on line %d.", linenum);
+         print_fatal_error(outfile, "Too many STATUS's on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing STATUS code on line %d.", linenum);
+         print_fatal_error(outfile, "Missing STATUS code on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1930,7 +2147,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
                == (ipp_status_t)-1 &&
            (statuses[num_statuses].status = (ipp_status_t)strtol(token, NULL, 0)) == 0)
        {
-         print_fatal_error("Bad STATUS code \"%s\" on line %d.", token,
+         print_fatal_error(outfile, "Bad STATUS code \"%s\" on line %d.", token,
                            linenum);
          pass = 0;
          goto test_exit;
@@ -1947,22 +2164,24 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        last_status->repeat_match    = 0;
        last_status->repeat_no_match = 0;
       }
-      else if (!_cups_strcasecmp(token, "EXPECT"))
+      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("Too many EXPECT's on line %d.", linenum);
+         print_fatal_error(outfile, "Too many EXPECT's on line %d.", linenum);
          pass = 0;
          goto test_exit;
         }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing EXPECT name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing EXPECT name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1972,6 +2191,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        memset(last_expect, 0, sizeof(_cups_expect_t));
        last_expect->repeat_limit = 1000;
+       last_expect->expect_all   = expect_all;
 
         if (token[0] == '!')
         {
@@ -1990,14 +2210,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing COUNT number on line %d.", linenum);
+         print_fatal_error(outfile, "Missing COUNT number on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
         if ((i = atoi(token)) <= 0)
        {
-         print_fatal_error("Bad COUNT \"%s\" on line %d.", token, linenum);
+         print_fatal_error(outfile, "Bad COUNT \"%s\" on line %d.", token, linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2006,7 +2226,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->count = i;
        else
        {
-         print_fatal_error("COUNT without a preceding EXPECT on line %d.",
+         print_fatal_error(outfile, "COUNT without a preceding EXPECT on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2016,7 +2236,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing DEFINE-MATCH variable on line %d.",
+         print_fatal_error(outfile, "Missing DEFINE-MATCH variable on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2028,7 +2248,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_status->define_match = strdup(token);
        else
        {
-         print_fatal_error("DEFINE-MATCH without a preceding EXPECT or STATUS "
+         print_fatal_error(outfile, "DEFINE-MATCH without a preceding EXPECT or STATUS "
                            "on line %d.", linenum);
          pass = 0;
          goto test_exit;
@@ -2038,7 +2258,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing DEFINE-NO-MATCH variable on line %d.",
+         print_fatal_error(outfile, "Missing DEFINE-NO-MATCH variable on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2050,7 +2270,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_status->define_no_match = strdup(token);
        else
        {
-         print_fatal_error("DEFINE-NO-MATCH without a preceding EXPECT or "
+         print_fatal_error(outfile, "DEFINE-NO-MATCH without a preceding EXPECT or "
                            "STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
@@ -2060,7 +2280,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing DEFINE-VALUE variable on line %d.",
+         print_fatal_error(outfile, "Missing DEFINE-VALUE variable on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2070,7 +2290,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->define_value = strdup(token);
        else
        {
-         print_fatal_error("DEFINE-VALUE without a preceding EXPECT on "
+         print_fatal_error(outfile, "DEFINE-VALUE without a preceding EXPECT on "
                            "line %d.", linenum);
          pass = 0;
          goto test_exit;
@@ -2080,7 +2300,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing OF-TYPE value tag(s) on line %d.",
+         print_fatal_error(outfile, "Missing OF-TYPE value tag(s) on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2090,7 +2310,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->of_type = strdup(token);
        else
        {
-         print_fatal_error("OF-TYPE without a preceding EXPECT on line %d.",
+         print_fatal_error(outfile, "OF-TYPE without a preceding EXPECT on line %d.",
                            linenum);
          pass = 0;
          goto test_exit;
@@ -2103,20 +2323,22 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing IN-GROUP group tag on line %d.", linenum);
+         print_fatal_error(outfile, "Missing IN-GROUP group tag on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
-        if ((in_group = ippTagValue(token)) == (ipp_tag_t)-1)
+        if ((in_group = ippTagValue(token)) == IPP_TAG_ZERO || in_group >= IPP_TAG_UNSUPPORTED_VALUE)
        {
+          print_fatal_error(outfile, "Bad IN-GROUP group tag \"%s\" on line %d.", token, linenum);
+          pass = 0;
+          goto test_exit;
        }
        else if (last_expect)
          last_expect->in_group = in_group;
        else
        {
-         print_fatal_error("IN-GROUP without a preceding EXPECT on line %d.",
-                           linenum);
+         print_fatal_error(outfile, "IN-GROUP without a preceding EXPECT on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2125,13 +2347,13 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing REPEAT-LIMIT value on line %d.", linenum);
+         print_fatal_error(outfile, "Missing REPEAT-LIMIT value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
        else if (atoi(token) <= 0)
        {
-         print_fatal_error("Bad REPEAT-LIMIT value on line %d.", linenum);
+         print_fatal_error(outfile, "Bad REPEAT-LIMIT value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2142,8 +2364,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->repeat_limit = atoi(token);
        else
        {
-         print_fatal_error("REPEAT-LIMIT without a preceding EXPECT or STATUS "
-                           "on line %d.", linenum);
+         print_fatal_error(outfile, "REPEAT-LIMIT without a preceding EXPECT or STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2156,8 +2377,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->repeat_match = 1;
        else
        {
-         print_fatal_error("REPEAT-MATCH without a preceding EXPECT or STATUS "
-                           "on line %d.", linenum);
+         print_fatal_error(outfile, "REPEAT-MATCH without a preceding EXPECT or STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2170,8 +2390,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->repeat_no_match = 1;
        else
        {
-         print_fatal_error("REPEAT-NO-MATCH without a preceding EXPECT or "
-                           "STATUS on ine %d.", linenum);
+         print_fatal_error(outfile, "REPEAT-NO-MATCH without a preceding EXPECT or STATUS on ine %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2180,7 +2399,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing SAME-COUNT-AS name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing SAME-COUNT-AS name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2189,7 +2408,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_expect->same_count_as = strdup(token);
        else
        {
-         print_fatal_error("SAME-COUNT-AS without a preceding EXPECT on line "
+         print_fatal_error(outfile, "SAME-COUNT-AS without a preceding EXPECT on line "
                            "%d.", linenum);
          pass = 0;
          goto test_exit;
@@ -2199,7 +2418,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing IF-DEFINED name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing IF-DEFINED name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2210,8 +2429,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_status->if_defined = strdup(token);
        else
        {
-         print_fatal_error("IF-DEFINED without a preceding EXPECT or STATUS "
-                           "on line %d.", linenum);
+         print_fatal_error(outfile, "IF-DEFINED without a preceding EXPECT or STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2220,7 +2438,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing IF-NOT-DEFINED name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing IF-NOT-DEFINED name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2231,8 +2449,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          last_status->if_not_defined = strdup(token);
        else
        {
-         print_fatal_error("IF-NOT-DEFINED without a preceding EXPECT or STATUS "
-                           "on line %d.", linenum);
+         print_fatal_error(outfile, "IF-NOT-DEFINED without a preceding EXPECT or STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2264,7 +2481,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
-         print_fatal_error("Missing %s value on line %d.", token, linenum);
+         print_fatal_error(outfile, "Missing %s value on line %d.", token, linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2317,8 +2534,34 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        }
        else
        {
-         print_fatal_error("%s without a preceding EXPECT on line %d.", token,
-                           linenum);
+         print_fatal_error(outfile, "%s without a preceding EXPECT on line %d.", token, linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "WITH-VALUE-FROM"))
+      {
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         print_fatal_error(outfile, "Missing %s value on line %d.", token, linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+        if (last_expect)
+       {
+        /*
+         * Expand any variables in the value and then save it.
+         */
+
+         expand_variables(vars, token, temp, sizeof(token));
+
+         last_expect->with_value_from = strdup(token);
+         last_expect->with_flags      = _CUPS_WITH_LITERAL;
+       }
+       else
+       {
+         print_fatal_error(outfile, "%s without a preceding EXPECT on line %d.", token, linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2331,14 +2574,14 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
         if (num_displayed >= (int)(sizeof(displayed) / sizeof(displayed[0])))
        {
-         print_fatal_error("Too many DISPLAY's on line %d", linenum);
+         print_fatal_error(outfile, "Too many DISPLAY's on line %d", linenum);
          pass = 0;
          goto test_exit;
        }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing DISPLAY name on line %d.", linenum);
+         print_fatal_error(outfile, "Missing DISPLAY name on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2348,8 +2591,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
       else
       {
-       print_fatal_error("Unexpected token %s seen on line %d.", token,
-                         linenum);
+       print_fatal_error(outfile, "Unexpected token %s seen on line %d.", token, linenum);
        pass = 0;
        goto test_exit;
       }
@@ -2367,51 +2609,51 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
     if (Output == _CUPS_OUTPUT_PLIST)
     {
-      puts("<dict>");
-      puts("<key>Name</key>");
-      print_xml_string("string", name);
+      cupsFilePuts(outfile, "<dict>\n");
+      cupsFilePuts(outfile, "<key>Name</key>\n");
+      print_xml_string(outfile, "string", name);
       if (file_id[0])
       {
-       puts("<key>FileId</key>");
-       print_xml_string("string", file_id);
+       cupsFilePuts(outfile, "<key>FileId</key>\n");
+       print_xml_string(outfile, "string", file_id);
       }
       if (test_id[0])
       {
-        puts("<key>TestId</key>");
-        print_xml_string("string", test_id);
+        cupsFilePuts(outfile, "<key>TestId</key>\n");
+        print_xml_string(outfile, "string", test_id);
       }
-      puts("<key>Version</key>");
-      printf("<string>%d.%d</string>\n", version / 10, version % 10);
-      puts("<key>Operation</key>");
-      print_xml_string("string", ippOpString(op));
-      puts("<key>RequestId</key>");
-      printf("<integer>%d</integer>\n", request_id);
-      puts("<key>RequestAttributes</key>");
-      puts("<array>");
+      cupsFilePuts(outfile, "<key>Version</key>\n");
+      cupsFilePrintf(outfile, "<string>%d.%d</string>\n", version / 10, version % 10);
+      cupsFilePuts(outfile, "<key>Operation</key>\n");
+      print_xml_string(outfile, "string", ippOpString(op));
+      cupsFilePuts(outfile, "<key>RequestId</key>\n");
+      cupsFilePrintf(outfile, "<integer>%d</integer>\n", request_id);
+      cupsFilePuts(outfile, "<key>RequestAttributes</key>\n");
+      cupsFilePuts(outfile, "<array>\n");
       if (request->attrs)
       {
-       puts("<dict>");
+       cupsFilePuts(outfile, "<dict>\n");
        for (attrptr = request->attrs,
                 group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
             attrptr;
             attrptr = attrptr->next)
-         print_attr(attrptr, &group);
-       puts("</dict>");
+         print_attr(outfile, Output, attrptr, &group);
+       cupsFilePuts(outfile, "</dict>\n");
       }
-      puts("</array>");
+      cupsFilePuts(outfile, "</array>\n");
     }
-    else if (Output == _CUPS_OUTPUT_TEST)
+
+    if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
     {
       if (Verbosity)
       {
-       printf("    %s:\n", ippOpString(op));
+       cupsFilePrintf(cupsFileStdout(), "    %s:\n", ippOpString(op));
 
        for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
-         print_attr(attrptr, NULL);
+         print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
       }
 
-      printf("    %-68.68s [", name);
-      fflush(stdout);
+      cupsFilePrintf(cupsFileStdout(), "    %-68.68s [", name);
     }
 
     if ((skip_previous && !prev_pass) || skip_test)
@@ -2423,26 +2665,30 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
       if (Output == _CUPS_OUTPUT_PLIST)
       {
-       puts("<key>Successful</key>");
-       puts("<true />");
-       puts("<key>StatusCode</key>");
-       print_xml_string("string", "skip");
-       puts("<key>ResponseAttributes</key>");
-       puts("<dict />");
+       cupsFilePuts(outfile, "<key>Successful</key>\n");
+       cupsFilePuts(outfile, "<true />\n");
+       cupsFilePuts(outfile, "<key>Skipped</key>\n");
+       cupsFilePuts(outfile, "<true />\n");
+       cupsFilePuts(outfile, "<key>StatusCode</key>\n");
+       print_xml_string(outfile, "string", "skip");
+       cupsFilePuts(outfile, "<key>ResponseAttributes</key>\n");
+       cupsFilePuts(outfile, "<dict />\n");
       }
-      else if (Output == _CUPS_OUTPUT_TEST)
-       puts("SKIP]");
+
+      if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
+       cupsFilePuts(cupsFileStdout(), "SKIP]\n");
 
       goto skip_error;
     }
 
     PasswordTries   = 0;
-    repeat_count    = 0;
-    repeat_interval = 1;
-    repeat_prev     = 1;
 
     do
     {
+      if (delay > 0)
+        usleep(delay);
+
+      delay = repeat_interval;
       repeat_count ++;
 
       status = HTTP_STATUS_OK;
@@ -2535,7 +2781,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
              http->error != ETIMEDOUT)
 #endif /* WIN32 */
          {
-           if (httpReconnect(http))
+           if (httpReconnect2(http, 30000, NULL))
              prev_pass = 0;
          }
          else if (status == HTTP_STATUS_ERROR || status == HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED)
@@ -2562,13 +2808,13 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
          http->error != ETIMEDOUT)
 #endif /* WIN32 */
       {
-       if (httpReconnect(http))
+       if (httpReconnect2(http, 30000, NULL))
          prev_pass = 0;
       }
       else if (status == HTTP_STATUS_ERROR)
       {
         if (!Cancel)
-          httpReconnect(http);
+          httpReconnect2(http, 30000, NULL);
 
        prev_pass = 0;
       }
@@ -2588,6 +2834,17 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        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)
       {
        /*
@@ -2608,18 +2865,18 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                                        IPP_TAG_INTEGER)) != NULL)
        {
          snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
-         set_variable(vars, "job-id", temp);
+         set_variable(outfile, vars, "job-id", temp);
        }
 
        if ((attrptr = ippFindAttribute(response, "job-uri",
                                        IPP_TAG_URI)) != NULL)
-         set_variable(vars, "job-uri", attrptr->values[0].string.text);
+         set_variable(outfile, vars, "job-uri", attrptr->values[0].string.text);
 
        if ((attrptr = ippFindAttribute(response, "notify-subscription-id",
                                        IPP_TAG_INTEGER)) != NULL)
        {
          snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
-         set_variable(vars, "notify-subscription-id", temp);
+         set_variable(outfile, vars, "notify-subscription-id", temp);
        }
 
        /*
@@ -2801,7 +3058,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
              group = attrptr->group_tag;
          }
 
-         validate_attr(errors, attrptr);
+         validate_attr(outfile, errors, attrptr);
 
           if (attrptr->name)
           {
@@ -2820,7 +3077,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
         * values...
         */
 
-       for (i = 0; i < num_statuses; i ++)
+       for (i = 0, status_ok = 0; i < num_statuses; i ++)
        {
          if (statuses[i].if_defined &&
              !get_variable(vars, statuses[i].if_defined))
@@ -2830,32 +3087,30 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
              get_variable(vars, statuses[i].if_not_defined))
            continue;
 
-         if (response->request.status.status_code == statuses[i].status)
+         if (ippGetStatusCode(response) == statuses[i].status)
          {
-           if (statuses[i].repeat_match &&
-               repeat_count < statuses[i].repeat_limit)
-             repeat_test = 1;
+            status_ok = 1;
 
-            if (statuses[i].define_match)
-              set_variable(vars, statuses[i].define_match, "1");
+            if (statuses[i].repeat_match && repeat_count < statuses[i].repeat_limit)
+              repeat_test = 1;
 
-            break;
+            if (statuses[i].define_match)
+              set_variable(outfile, vars, statuses[i].define_match, "1");
          }
          else
          {
-           if (statuses[i].repeat_no_match &&
-               repeat_count < statuses[i].repeat_limit)
-             repeat_test = 1;
+           if (statuses[i].repeat_no_match && repeat_count < statuses[i].repeat_limit)
+              repeat_test = 1;
 
             if (statuses[i].define_no_match)
             {
-              set_variable(vars, statuses[i].define_no_match, "1");
-              break;
+              set_variable(outfile, vars, statuses[i].define_no_match, "1");
+              status_ok = 1;
             }
           }
        }
 
-       if (i == num_statuses && num_statuses > 0)
+       if (!status_ok && num_statuses > 0)
        {
          for (i = 0; i < num_statuses; i ++)
          {
@@ -2867,7 +3122,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
                get_variable(vars, statuses[i].if_not_defined))
              continue;
 
-            if (!statuses[i].repeat_match)
+            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()));
@@ -2888,161 +3143,240 @@ do_tests(_cups_vars_t *vars,          /* I - Variables */
              get_variable(vars, expect->if_not_defined))
            continue;
 
-         found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+          found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
 
-         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 (expect->define_no_match)
-             set_variable(vars, expect->define_no_match, "1");
-           else if (!expect->define_match && !expect->define_value)
+          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->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->define_no_match)
+               set_variable(outfile, vars, expect->define_no_match, "1");
+             else if (!expect->define_match && !expect->define_value)
              {
-               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 (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;
+             if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
+                repeat_test = 1;
 
-           continue;
-         }
+             break;
+           }
 
-         if (found)
-           ippAttributeString(found, buffer, sizeof(buffer));
+           if (found)
+             ippAttributeString(found, buffer, sizeof(buffer));
 
-         if (found &&
-             !with_value(NULL, expect->with_value, expect->with_flags, found,
-                         buffer, sizeof(buffer)))
-         {
-           if (expect->define_no_match)
-             set_variable(vars, expect->define_no_match, "1");
-           else if (!expect->define_match && !expect->define_value &&
-                    !expect->repeat_match && !expect->repeat_no_match)
+            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->with_flags & _CUPS_WITH_REGEX)
-               add_stringf(errors, "EXPECTED: %s %s /%s/",
-                           expect->name,
-                           (expect->with_flags & _CUPS_WITH_ALL) ?
-                               "WITH-ALL-VALUES" : "WITH-VALUE",
-                           expect->with_value);
-             else
-               add_stringf(errors, "EXPECTED: %s %s \"%s\"",
-                           expect->name,
-                           (expect->with_flags & _CUPS_WITH_ALL) ?
-                               "WITH-ALL-VALUES" : "WITH-VALUE",
-                           expect->with_value);
-
-             with_value(errors, expect->with_value, expect->with_flags, found,
-                        buffer, sizeof(buffer));
-           }
+             if (expect->define_no_match)
+               set_variable(outfile, 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->repeat_no_match &&
-               repeat_count < expect->repeat_limit)
-             repeat_test = 1;
+               with_value_from(errors, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, buffer, sizeof(buffer));
+             }
 
-           continue;
-         }
+             if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
+               repeat_test = 1;
 
-         if (found && expect->count > 0 &&
-             found->num_values != expect->count)
-         {
-           if (expect->define_no_match)
-             set_variable(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);
+             break;
            }
+           else if (found && !with_value(outfile, NULL, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer)))
+           {
+             if (expect->define_no_match)
+               set_variable(outfile, 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);
 
-           if (expect->repeat_no_match &&
-               repeat_count < expect->repeat_limit)
-             repeat_test = 1;
+               with_value(outfile, errors, expect->with_value, expect->with_flags, found, buffer, sizeof(buffer));
+             }
 
-           continue;
-         }
+             if (expect->repeat_no_match &&
+                 repeat_count < expect->repeat_limit)
+               repeat_test = 1;
 
-         if (found && expect->same_count_as)
-         {
-           attrptr = ippFindAttribute(response, expect->same_count_as,
-                                      IPP_TAG_ZERO);
+             break;
+           }
 
-           if (!attrptr || attrptr->num_values != found->num_values)
+           if (found && expect->count > 0 &&
+               found->num_values != expect->count)
            {
              if (expect->define_no_match)
-               set_variable(vars, expect->define_no_match, "1");
+               set_variable(outfile, 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);
+               add_stringf(errors, "EXPECTED: %s COUNT %d (got %d)", expect->name,
+                           expect->count, found->num_values);
              }
 
              if (expect->repeat_no_match &&
-                 repeat_count < expect->repeat_limit)
+                 repeat_count < expect->repeat_limit)
                repeat_test = 1;
 
-             continue;
+             break;
            }
-         }
 
-         if (found && expect->define_match)
-           set_variable(vars, expect->define_match, "1");
+           if (found && expect->same_count_as)
+           {
+             attrptr = ippFindAttribute(response, expect->same_count_as,
+                                        IPP_TAG_ZERO);
+
+             if (!attrptr || attrptr->num_values != found->num_values)
+             {
+               if (expect->define_no_match)
+                 set_variable(outfile, 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;
+
+               break;
+             }
+           }
+
+           if (found && expect->define_match)
+             set_variable(outfile, vars, expect->define_match, "1");
+
+           if (found && expect->define_value)
+           {
+             if (!expect->with_value)
+             {
+               int last = ippGetCount(found) - 1;
+                                         /* Last element in attribute */
+
+               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));
+                     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;
+               }
+             }
 
-         if (found && expect->define_value)
-           set_variable(vars, expect->define_value, buffer);
+             set_variable(outfile, vars, expect->define_value, buffer);
+           }
 
-         if (found && expect->repeat_match &&
-             repeat_count < expect->repeat_limit)
-           repeat_test = 1;
+           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, sleep 1 second so we don't flood
-      * the printer with requests...
+      * If we are going to repeat this test, display intermediate results...
       */
 
       if (repeat_test)
       {
-       if (Output == _CUPS_OUTPUT_TEST)
+       if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
         {
-          printf("%04d]\n", repeat_count);
-          fflush(stdout);
+          cupsFilePrintf(cupsFileStdout(), "%04d]\n", repeat_count);
+\
+         if (num_displayed > 0)
+         {
+           for (attrptr = ippFirstAttribute(response); attrptr; attrptr = ippNextAttribute(response))
+           {
+             const char *attrname = ippGetName(attrptr);
+             if (attrname)
+             {
+               for (i = 0; i < num_displayed; i ++)
+               {
+                 if (!strcmp(displayed[i], attrname))
+                 {
+                   print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
+                   break;
+                 }
+               }
+             }
+           }
+         }
         }
 
-        sleep((unsigned)repeat_interval);
-        repeat_interval = _cupsNextDelay(repeat_interval, &repeat_prev);
-
-       if (Output == _CUPS_OUTPUT_TEST)
+       if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
        {
-         printf("    %-68.68s [", name);
-         fflush(stdout);
+         cupsFilePrintf(cupsFileStdout(), "    %-68.68s [", name);
        }
+
+        ippDelete(response);
+        response = NULL;
       }
     }
     while (repeat_test);
@@ -3061,42 +3395,51 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
     if (Output == _CUPS_OUTPUT_PLIST)
     {
-      puts("<key>Successful</key>");
-      puts(prev_pass ? "<true />" : "<false />");
-      puts("<key>StatusCode</key>");
-      print_xml_string("string", ippErrorString(cupsLastError()));
-      puts("<key>ResponseAttributes</key>");
-      puts("<array>");
-      puts("<dict>");
+      cupsFilePuts(outfile, "<key>Successful</key>\n");
+      cupsFilePuts(outfile, prev_pass ? "<true />\n" : "<false />\n");
+      cupsFilePuts(outfile, "<key>StatusCode</key>\n");
+      print_xml_string(outfile, "string", ippErrorString(cupsLastError()));
+      cupsFilePuts(outfile, "<key>ResponseAttributes</key>\n");
+      cupsFilePuts(outfile, "<array>\n");
+      cupsFilePuts(outfile, "<dict>\n");
       for (attrptr = response ? response->attrs : NULL,
                group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
           attrptr;
           attrptr = attrptr->next)
-       print_attr(attrptr, &group);
-      puts("</dict>");
-      puts("</array>");
+       print_attr(outfile, Output, attrptr, &group);
+      cupsFilePuts(outfile, "</dict>\n");
+      cupsFilePuts(outfile, "</array>\n");
     }
-    else if (Output == _CUPS_OUTPUT_TEST)
+    else if (Output == _CUPS_OUTPUT_IPPSERVER && response)
     {
-      puts(prev_pass ? "PASS]" : "FAIL]");
-
-      if (!prev_pass || (Verbosity && response))
+      for (attrptr = ippFirstAttribute(response), group = IPP_TAG_ZERO; attrptr; attrptr = ippNextAttribute(response))
       {
-       printf("        RECEIVED: %lu bytes in response\n",
-              (unsigned long)ippLength(response));
-       printf("        status-code = %s (%s)\n", ippErrorString(cupsLastError()),
-              cupsLastErrorString());
+        if (!ippGetName(attrptr) || ippGetGroupTag(attrptr) != IPP_TAG_PRINTER)
+          continue;
 
-        if (response)
-        {
+        print_ippserver_attr(outfile, attrptr, 0);
+      }
+    }
+
+    if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
+    {
+      cupsFilePuts(cupsFileStdout(), prev_pass ? "PASS]\n" : "FAIL]\n");
+
+      if (!prev_pass || (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(attrptr, NULL);
+           print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST, attrptr, NULL);
        }
       }
     }
-    else if (!prev_pass)
+    else if (!prev_pass && Output != _CUPS_OUTPUT_QUIET)
       fprintf(stderr, "%s\n", cupsLastErrorString());
 
     if (prev_pass && Output >= _CUPS_OUTPUT_LIST && !Verbosity &&
@@ -3120,9 +3463,9 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       }
 
       if (Output == _CUPS_OUTPUT_CSV)
-       print_csv(NULL, num_displayed, displayed, widths);
+       print_csv(outfile, NULL, num_displayed, displayed, widths);
       else
-       print_line(NULL, num_displayed, displayed, widths);
+       print_line(outfile, NULL, num_displayed, displayed, widths);
 
       attrptr = response->attrs;
 
@@ -3134,9 +3477,9 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        if (attrptr)
        {
          if (Output == _CUPS_OUTPUT_CSV)
-           print_csv(attrptr, num_displayed, displayed, widths);
+           print_csv(outfile, attrptr, num_displayed, displayed, widths);
          else
-           print_line(attrptr, num_displayed, displayed, widths);
+           print_line(outfile, attrptr, num_displayed, displayed, widths);
 
          while (attrptr && attrptr->group_tag > IPP_TAG_OPERATION)
            attrptr = attrptr->next;
@@ -3147,27 +3490,27 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
     {
       if (Output == _CUPS_OUTPUT_PLIST)
       {
-       puts("<key>Errors</key>");
-       puts("<array>");
+       cupsFilePuts(outfile, "<key>Errors</key>\n");
+       cupsFilePuts(outfile, "<array>\n");
 
        for (error = (char *)cupsArrayFirst(errors);
             error;
             error = (char *)cupsArrayNext(errors))
-         print_xml_string("string", error);
+         print_xml_string(outfile, "string", error);
 
-       puts("</array>");
+       cupsFilePuts(outfile, "</array>\n");
       }
-      else
+
+      if (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout()))
       {
        for (error = (char *)cupsArrayFirst(errors);
             error;
             error = (char *)cupsArrayNext(errors))
-         printf("        %s\n", error);
+         cupsFilePrintf(cupsFileStdout(), "        %s\n", error);
       }
     }
 
-    if (num_displayed > 0 && !Verbosity && response &&
-        Output == _CUPS_OUTPUT_TEST)
+    if (num_displayed > 0 && !Verbosity && response && (Output == _CUPS_OUTPUT_TEST || (Output == _CUPS_OUTPUT_PLIST && outfile != cupsFileStdout())))
     {
       for (attrptr = response->attrs;
           attrptr != NULL;
@@ -3179,7 +3522,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          {
            if (!strcmp(displayed[i], attrptr->name))
            {
-             print_attr(attrptr, NULL);
+             print_attr(outfile, Output, attrptr, NULL);
              break;
            }
          }
@@ -3190,9 +3533,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
     skip_error:
 
     if (Output == _CUPS_OUTPUT_PLIST)
-      puts("</dict>");
-
-    fflush(stdout);
+      cupsFilePuts(outfile, "</dict>\n");
 
     ippDelete(response);
     response = NULL;
@@ -3245,7 +3586,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
   cupsArrayDelete(errors);
 
   if (fp)
-    fclose(fp);
+    cupsFileClose(fp);
 
   httpClose(http);
   ippDelete(request);
@@ -3257,10 +3598,10 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
       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 (statuses[i].define_match)
+      free(statuses[i].define_match);
+    if (statuses[i].define_no_match)
+      free(statuses[i].define_no_match);
   }
 
   for (i = num_expects, expect = expects; i > 0; i --, expect ++)
@@ -3338,16 +3679,28 @@ expand_variables(_cups_vars_t *vars,    /* I - Variables */
        value = getenv(temp);
         src   += tempptr - temp + 5;
       }
-      else if (vars)
+      else
       {
-       strlcpy(temp, src + 1, sizeof(temp));
+        if (src[1] == '{')
+       {
+         src += 2;
+         strlcpy(temp, src, sizeof(temp));
+         if ((tempptr = strchr(temp, '}')) != NULL)
+           *tempptr = '\0';
+         else
+           tempptr = temp + strlen(temp);
+       }
+       else
+       {
+         strlcpy(temp, src + 1, sizeof(temp));
 
-       for (tempptr = temp; *tempptr; tempptr ++)
-         if (!isalnum(*tempptr & 255) && *tempptr != '-' && *tempptr != '_')
-           break;
+         for (tempptr = temp; *tempptr; tempptr ++)
+           if (!isalnum(*tempptr & 255) && *tempptr != '-' && *tempptr != '_')
+             break;
 
-        if (*tempptr)
-         *tempptr = '\0';
+         if (*tempptr)
+           *tempptr = '\0';
+        }
 
        if (!strcmp(temp, "uri"))
          value = vars->uri;
@@ -3373,11 +3726,6 @@ expand_variables(_cups_vars_t *vars,     /* I - Variables */
 
         src += tempptr - temp + 1;
       }
-      else
-      {
-        value = "$";
-       src ++;
-      }
 
       if (value)
       {
@@ -3461,8 +3809,9 @@ expect_matches(
  */
 
 static ipp_t *                         /* O  - Collection value */
-get_collection(_cups_vars_t *vars,     /* I  - Variables */
-               FILE         *fp,       /* I  - File to read from */
+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 */
@@ -3483,7 +3832,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
       * Another collection value
       */
 
-      ipp_t    *subcol = get_collection(vars, fp, linenum);
+      ipp_t    *subcol = get_collection(outfile, vars, fp, linenum);
                                        /* Collection value */
 
       if (subcol)
@@ -3501,34 +3850,60 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
 
       if (!get_token(fp, token, sizeof(token), linenum))
       {
-       print_fatal_error("Missing MEMBER value tag on line %d.", *linenum);
+       print_fatal_error(outfile, "Missing MEMBER value tag on line %d.", *linenum);
        goto col_error;
       }
 
-      if ((value = ippTagValue(token)) == IPP_TAG_ZERO)
+      if ((value = ippTagValue(token)) < IPP_TAG_UNSUPPORTED_VALUE)
       {
-       print_fatal_error("Bad MEMBER value tag \"%s\" on line %d.", token,
+       print_fatal_error(outfile, "Bad MEMBER value tag \"%s\" on line %d.", token,
                          *linenum);
        goto col_error;
       }
 
       if (!get_token(fp, attr, sizeof(attr), linenum))
       {
-       print_fatal_error("Missing MEMBER name on line %d.", *linenum);
+       print_fatal_error(outfile, "Missing MEMBER name on line %d.", *linenum);
        goto col_error;
       }
 
-      if (!get_token(fp, temp, sizeof(temp), linenum))
+      if (value < IPP_TAG_INTEGER)
+      {
+       /*
+        * Out-of-band member attributes have no value...
+        */
+
+        token[0] = '\0';
+      }
+      else if (!get_token(fp, temp, sizeof(temp), linenum))
       {
-       print_fatal_error("Missing MEMBER value on line %d.", *linenum);
+       print_fatal_error(outfile, "Missing MEMBER value on line %d.", *linenum);
        goto col_error;
       }
-
-      expand_variables(vars, token, temp, sizeof(token));
+      else
+      {
+        expand_variables(vars, token, temp, sizeof(token));
+      }
 
       switch (value)
       {
-       case IPP_TAG_BOOLEAN :
+        default :
+              if (value < IPP_TAG_INTEGER)
+              {
+               /*
+                * Add out-of-band value...
+                */
+
+                ippAddOutOfBand(col, IPP_TAG_ZERO, value, attr);
+              }
+              else
+              {
+                print_fatal_error(outfile, "Unsupported MEMBER value tag %s for \"%s\" on line %d.", 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
@@ -3552,7 +3927,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
                   _cups_strcasecmp(units, "dpcm") &&
                   _cups_strcasecmp(units, "other")))
              {
-               print_fatal_error("Bad resolution value \"%s\" on line %d.",
+               print_fatal_error(outfile, "Bad resolution value \"%s\" on line %d.",
                                  token, *linenum);
                goto col_error;
              }
@@ -3582,7 +3957,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
 
              if ((num_vals & 1) || num_vals == 0)
              {
-               print_fatal_error("Bad rangeOfInteger value \"%s\" on line %d.",
+               print_fatal_error(outfile, "Bad rangeOfInteger value \"%s\" on line %d.",
                                  token, *linenum);
                goto col_error;
              }
@@ -3595,7 +3970,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
        case IPP_TAG_BEGIN_COLLECTION :
            if (!strcmp(token, "{"))
            {
-             ipp_t     *subcol = get_collection(vars, fp, linenum);
+             ipp_t     *subcol = get_collection(outfile, vars, fp, linenum);
                                      /* Collection value */
 
              if (subcol)
@@ -3608,15 +3983,25 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
            }
            else
            {
-             print_fatal_error("Bad collection value on line %d.", *linenum);
+             print_fatal_error(outfile, "Bad collection value on line %d.", *linenum);
              goto col_error;
            }
            break;
-       case IPP_TAG_STRING :
+
+        case IPP_TAG_STRING :
            ippAddOctetString(col, IPP_TAG_ZERO, attr, token, (int)strlen(token));
            break;
 
-       default :
+        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
@@ -3635,9 +4020,14 @@ get_collection(_cups_vars_t *vars,       /* I  - Variables */
 
              for (ptr = strchr(token, ','); ptr; ptr = strchr(ptr, ','))
              {
-               *ptr++ = '\0';
-               values[num_values] = ptr;
-               num_values ++;
+                if (ptr > token && ptr[-1] == '\\')
+                  _cups_strcpy(ptr - 1, ptr);
+                else
+                {
+                  *ptr++ = '\0';
+                  values[num_values] = ptr;
+                  num_values ++;
+                }
              }
 
              ippAddStrings(col, IPP_TAG_ZERO, value, attr, num_values,
@@ -3646,6 +4036,11 @@ get_collection(_cups_vars_t *vars,       /* I  - Variables */
            break;
       }
     }
+    else
+    {
+      print_fatal_error(outfile, "Unexpected token %s seen on line %d.", token, *linenum);
+      goto col_error;
+    }
   }
 
   return (col);
@@ -3723,46 +4118,77 @@ get_filename(const char *testfile,      /* I - Current test file */
  * 'get_string()' - Get a pointer to a string value or the portion of interest.
  */
 
-static char *                          /* O - Pointer to string */
+static const char *                    /* O - Pointer to string */
 get_string(ipp_attribute_t *attr,      /* I - IPP attribute */
            int             element,    /* I - Element to fetch */
            int             flags,      /* I - Value ("with") flags */
            char            *buffer,    /* I - Temporary buffer */
           size_t          bufsize)     /* I - Size of temporary buffer */
 {
-  char *ptr,                           /* Value */
-       scheme[256],                    /* URI scheme */
-       userpass[256],                  /* Username/password */
-       hostname[256],                  /* Hostname */
-       resource[1024];                 /* Resource */
-  int  port;                           /* Port number */
+  const char   *value;                 /* Value */
+  char         *ptr,                   /* Pointer into value */
+               scheme[256],            /* URI scheme */
+               userpass[256],          /* Username/password */
+               hostname[256],          /* Hostname */
+               resource[1024];         /* Resource */
+  int          port;                   /* Port number */
 
 
-  ptr = attr->values[element].string.text;
+  value = ippGetString(attr, element, NULL);
 
   if (flags & _CUPS_WITH_HOSTNAME)
   {
-    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme), userpass, sizeof(userpass), buffer, (int)bufsize, &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, value, scheme, sizeof(scheme), userpass, sizeof(userpass), buffer, (int)bufsize, &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
       buffer[0] = '\0';
 
+    ptr = buffer + strlen(buffer) - 1;
+    if (ptr >= buffer && *ptr == '.')
+      *ptr = '\0';                     /* Drop trailing "." */
+
     return (buffer);
   }
   else if (flags & _CUPS_WITH_RESOURCE)
   {
-    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, buffer, (int)bufsize) < HTTP_URI_STATUS_OK)
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, value, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, buffer, (int)bufsize) < HTTP_URI_STATUS_OK)
       buffer[0] = '\0';
 
     return (buffer);
   }
   else if (flags & _CUPS_WITH_SCHEME)
   {
-    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, buffer, (int)bufsize, userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, value, buffer, (int)bufsize, userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+      buffer[0] = '\0';
+
+    return (buffer);
+  }
+  else if (ippGetValueTag(attr) == IPP_TAG_URI && (!strncmp(value, "ipp://", 6) || !strncmp(value, "http://", 7) || !strncmp(value, "ipps://", 7) || !strncmp(value, "https://", 8)))
+  {
+    http_uri_status_t status = httpSeparateURI(HTTP_URI_CODING_ALL, value, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, sizeof(resource));
+
+    if (status < HTTP_URI_STATUS_OK)
+    {
+     /*
+      * Bad URI...
+      */
+
       buffer[0] = '\0';
+    }
+    else
+    {
+     /*
+      * Normalize URI with no trailing dot...
+      */
+
+      if ((ptr = hostname + strlen(hostname) - 1) >= hostname && *ptr == '.')
+       *ptr = '\0';
+
+      httpAssembleURI(HTTP_URI_CODING_ALL, buffer, (int)bufsize, scheme, userpass, hostname, port, resource);
+    }
 
     return (buffer);
   }
   else
-    return (ptr);
+    return (value);
 }
 
 
@@ -3771,10 +4197,10 @@ get_string(ipp_attribute_t *attr,       /* I - IPP attribute */
  */
 
 static char *                          /* O  - Token from file or NULL on EOF */
-get_token(FILE *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 */
+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 */
@@ -3788,7 +4214,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
     * Skip whitespace...
     */
 
-    while (isspace(ch = getc(fp)))
+    while (isspace(ch = cupsFileGetChar(fp)))
     {
       if (ch == '\n')
         (*linenum) ++;
@@ -3810,7 +4236,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
       bufptr = buf;
       bufend = buf + buflen - 1;
 
-      while ((ch = getc(fp)) != EOF)
+      while ((ch = cupsFileGetChar(fp)) != EOF)
       {
         if (ch == '\\')
        {
@@ -3821,7 +4247,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
          if (bufptr < bufend)
            *bufptr++ = (char)ch;
 
-         if ((ch = getc(fp)) != EOF && bufptr < bufend)
+         if ((ch = cupsFileGetChar(fp)) != EOF && bufptr < bufend)
            *bufptr++ = (char)ch;
        }
        else if (ch == quote)
@@ -3840,7 +4266,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
       * Comment...
       */
 
-      while ((ch = getc(fp)) != EOF)
+      while ((ch = cupsFileGetChar(fp)) != EOF)
        if (ch == '\n')
           break;
 
@@ -3859,19 +4285,19 @@ get_token(FILE *fp,                     /* I  - File to read from */
       * Whitespace delimited text...
       */
 
-      ungetc(ch, fp);
+      cupsFileSeek(fp, cupsFileTell(fp) - 1);
 
       bufptr = buf;
       bufend = buf + buflen - 1;
 
-      while ((ch = getc(fp)) != EOF)
+      while ((ch = cupsFileGetChar(fp)) != EOF)
        if (isspace(ch) || ch == '#')
           break;
        else if (bufptr < bufend)
           *bufptr++ = (char)ch;
 
       if (ch == '#')
-        ungetc(ch, fp);
+        cupsFileSeek(fp, cupsFileTell(fp) - 1);
       else if (ch == '\n')
         (*linenum) ++;
 
@@ -3908,7 +4334,7 @@ get_variable(_cups_vars_t *vars,  /* I - Variables */
  */
 
 static char *                          /* O - ISO 8601 date/time string */
-iso_date(ipp_uchar_t *date)            /* I - IPP (RFC 1903) date/time value */
+iso_date(const ipp_uchar_t *date)      /* I - IPP (RFC 1903) date/time value */
 {
   time_t       utctime;                /* UTC time since 1970 */
   struct tm    *utcdate;               /* UTC date/time */
@@ -3948,26 +4374,127 @@ password_cb(const char *prompt)                /* I - Prompt (unused) */
 }
 
 
+/*
+ * '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...
+  */
+
+  cupsFilePrintf(cupsFileStdout(), "%s\n---- PRESS ANY KEY ----", message);
+
+#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...
+  */
+
+  cupsFilePuts(cupsFileStdout(), "\r                       \r");
+}
+
+
 /*
  * 'print_attr()' - Print an attribute on the screen.
  */
 
 static void
-print_attr(ipp_attribute_t *attr,      /* I  - Attribute to print */
+print_attr(cups_file_t     *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 (Output == _CUPS_OUTPUT_PLIST)
+  if (format == _CUPS_OUTPUT_PLIST)
   {
     if (!attr->name || (group && *group != attr->group_tag))
     {
       if (attr->group_tag != IPP_TAG_ZERO)
       {
-       puts("</dict>");
-       puts("<dict>");
+       cupsFilePuts(outfile, "</dict>\n");
+       cupsFilePuts(outfile, "<dict>\n");
       }
 
       if (group)
@@ -3977,283 +4504,131 @@ print_attr(ipp_attribute_t *attr,     /* I  - Attribute to print */
     if (!attr->name)
       return;
 
-    print_xml_string("key", attr->name);
+    print_xml_string(outfile, "key", attr->name);
     if (attr->num_values > 1)
-      puts("<array>");
+      cupsFilePuts(outfile, "<array>\n");
 
     switch (attr->value_tag)
     {
       case IPP_TAG_INTEGER :
       case IPP_TAG_ENUM :
          for (i = 0; i < attr->num_values; i ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             printf("<integer>%d</integer>\n", attr->values[i].integer);
-           else
-             printf("%d ", 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 ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             puts(attr->values[i].boolean ? "<true />" : "<false />");
-           else if (attr->values[i].boolean)
-             fputs("true ", stdout);
-           else
-             fputs("false ", stdout);
+           cupsFilePuts(outfile, attr->values[i].boolean ? "<true />\n" : "<false />\n");
          break;
 
       case IPP_TAG_RANGE :
          for (i = 0; i < attr->num_values; i ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             printf("<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);
-           else
-             printf("%d-%d ", attr->values[i].range.lower,
-                    attr->values[i].range.upper);
+           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 ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             printf("<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");
-           else
-             printf("%dx%d%s ", attr->values[i].resolution.xres,
-                    attr->values[i].resolution.yres,
-                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
-                        "dpi" : "dpcm");
+           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,
+                  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 ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             printf("<date>%s</date>\n", iso_date(attr->values[i].date));
-           else
-             printf("%s ", iso_date(attr->values[i].date));
+           cupsFilePrintf(outfile, "<date>%s</date>\n", iso_date(attr->values[i].date));
          break;
 
       case IPP_TAG_STRING :
           for (i = 0; i < attr->num_values; i ++)
           {
-            if (Output == _CUPS_OUTPUT_PLIST)
-            {
-             char      buffer[IPP_MAX_LENGTH * 5 / 4 + 1];
+           char        buffer[IPP_MAX_LENGTH * 5 / 4 + 1];
                                        /* Output buffer */
 
-              printf("<data>%s</data>\n",
-                     httpEncode64_2(buffer, sizeof(buffer),
-                                    attr->values[i].unknown.data,
-                                    attr->values[i].unknown.length));
-            }
-            else
-            {
-              char     *ptr,           /* Pointer into data */
-                       *end;           /* End of data */
-
-              putchar('\"');
-              for (ptr = attr->values[i].unknown.data,
-                       end = ptr + attr->values[i].unknown.length;
-                   ptr < end;
-                   ptr ++)
-              {
-                if (*ptr == '\\' || *ptr == '\"')
-                  printf("\\%c", *ptr);
-                else if (!isprint(*ptr & 255))
-                  printf("\\%03o", *ptr & 255);
-                else
-                  putchar(*ptr);
-              }
-              putchar('\"');
-            }
+           cupsFilePrintf(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_CHARSET :
       case IPP_TAG_URI :
-      case IPP_TAG_MIMETYPE :
+      case IPP_TAG_URISCHEME :
+      case IPP_TAG_CHARSET :
       case IPP_TAG_LANGUAGE :
+      case IPP_TAG_MIMETYPE :
          for (i = 0; i < attr->num_values; i ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-             print_xml_string("string", attr->values[i].string.text);
-           else
-             printf("\"%s\" ", 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 ++)
-           if (Output == _CUPS_OUTPUT_PLIST)
-           {
-             fputs("<dict><key>language</key><string>", stdout);
-             print_xml_string(NULL, attr->values[i].string.language);
-             fputs("</string><key>string</key><string>", stdout);
-             print_xml_string(NULL, attr->values[i].string.text);
-             puts("</string></dict>");
-           }
-           else
-             printf("\"%s\"[%s] ", attr->values[i].string.text,
-                    attr->values[i].string.language);
+         {
+           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 ++)
          {
-           if (Output == _CUPS_OUTPUT_PLIST)
-           {
-             puts("<dict>");
-             for (colattr = attr->values[i].collection->attrs;
-                  colattr;
-                  colattr = colattr->next)
-               print_attr(colattr, NULL);
-             puts("</dict>");
-           }
-           else
-           {
-             if (i)
-               putchar(' ');
-
-             print_col(attr->values[i].collection);
-           }
+           cupsFilePuts(outfile, "<dict>\n");
+           for (colattr = attr->values[i].collection->attrs;
+                colattr;
+                colattr = colattr->next)
+             print_attr(outfile, format, colattr, NULL);
+           cupsFilePuts(outfile, "</dict>\n");
          }
          break;
 
       default :
-         if (Output == _CUPS_OUTPUT_PLIST)
-           printf("<string>&lt;&lt;%s&gt;&gt;</string>\n",
-                  ippTagString(attr->value_tag));
-         else
-           fputs(ippTagString(attr->value_tag), stdout);
+         cupsFilePrintf(outfile, "<string>&lt;&lt;%s&gt;&gt;</string>\n", ippTagString(attr->value_tag));
          break;
     }
 
     if (attr->num_values > 1)
-      puts("</array>");
+      cupsFilePuts(outfile, "</array>\n");
   }
   else
   {
-    char       buffer[8192];           /* Value buffer */
+    char       buffer[131072];         /* Value buffer */
 
-    if (Output == _CUPS_OUTPUT_TEST)
+    if (format == _CUPS_OUTPUT_TEST)
     {
       if (!attr->name)
       {
-        puts("        -- separator --");
+        cupsFilePuts(outfile, "        -- separator --\n");
         return;
       }
 
-      printf("        %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));
-    puts(buffer);
+    cupsFilePrintf(outfile, "%s\n", buffer);
   }
 }
 
 
-/*
- * 'print_col()' - Print a collection attribute on the screen.
- */
-
-static void
-print_col(ipp_t *col)                  /* I - Collection attribute to print */
-{
-  int                  i;              /* Looping var */
-  ipp_attribute_t      *attr;          /* Current attribute in collection */
-
-
-  fputs("{ ", stdout);
-  for (attr = col->attrs; attr; attr = attr->next)
-  {
-    printf("%s (%s%s) = ", attr->name, attr->num_values > 1 ? "1setOf " : "",
-          ippTagString(attr->value_tag));
-
-    switch (attr->value_tag)
-    {
-      case IPP_TAG_INTEGER :
-      case IPP_TAG_ENUM :
-         for (i = 0; i < attr->num_values; i ++)
-           printf("%d ", attr->values[i].integer);
-         break;
-
-      case IPP_TAG_BOOLEAN :
-         for (i = 0; i < attr->num_values; i ++)
-           if (attr->values[i].boolean)
-             printf("true ");
-           else
-             printf("false ");
-         break;
-
-      case IPP_TAG_NOVALUE :
-         printf("novalue");
-         break;
-
-      case IPP_TAG_RANGE :
-         for (i = 0; i < attr->num_values; i ++)
-           printf("%d-%d ", attr->values[i].range.lower,
-                  attr->values[i].range.upper);
-         break;
-
-      case IPP_TAG_RESOLUTION :
-         for (i = 0; i < attr->num_values; i ++)
-           printf("%dx%d%s ", 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_STRING :
-      case IPP_TAG_TEXT :
-      case IPP_TAG_NAME :
-      case IPP_TAG_KEYWORD :
-      case IPP_TAG_CHARSET :
-      case IPP_TAG_URI :
-      case IPP_TAG_MIMETYPE :
-      case IPP_TAG_LANGUAGE :
-         for (i = 0; i < attr->num_values; i ++)
-           printf("\"%s\" ", attr->values[i].string.text);
-         break;
-
-      case IPP_TAG_TEXTLANG :
-      case IPP_TAG_NAMELANG :
-         for (i = 0; i < attr->num_values; i ++)
-           printf("\"%s\"[%s] ", attr->values[i].string.text,
-                  attr->values[i].string.language);
-         break;
-
-      case IPP_TAG_BEGIN_COLLECTION :
-         for (i = 0; i < attr->num_values; i ++)
-         {
-           print_col(attr->values[i].collection);
-           putchar(' ');
-         }
-         break;
-
-      default :
-         break; /* anti-compiler-warning-code */
-    }
-  }
-
-  putchar('}');
-}
-
-
 /*
  * 'print_csv()' - Print a line of CSV text.
  */
 
 static void
 print_csv(
+    cups_file_t     *outfile,          /* I - Output file */
     ipp_attribute_t *attr,             /* I - First attribute for line */
     int             num_displayed,     /* I - Number of attributes to display */
     char            **displayed,       /* I - Attributes to display */
@@ -4288,7 +4663,7 @@ print_csv(
     for (i = 0; i < num_displayed; i ++)
     {
       if (i)
-        putchar(',');
+        cupsFilePutChar(outfile, ',');
 
       buffer[0] = '\0';
 
@@ -4306,30 +4681,30 @@ print_csv(
       if (strchr(buffer, ',') != NULL || strchr(buffer, '\"') != NULL ||
          strchr(buffer, '\\') != NULL)
       {
-        putchar('\"');
+        cupsFilePutChar(cupsFileStdout(), '\"');
         for (bufptr = buffer; *bufptr; bufptr ++)
         {
           if (*bufptr == '\\' || *bufptr == '\"')
-            putchar('\\');
-          putchar(*bufptr);
+            cupsFilePutChar(cupsFileStdout(), '\\');
+          cupsFilePutChar(cupsFileStdout(), *bufptr);
         }
-        putchar('\"');
+        cupsFilePutChar(cupsFileStdout(), '\"');
       }
       else
-        fputs(buffer, stdout);
+        cupsFilePuts(outfile, buffer);
     }
-    putchar('\n');
+    cupsFilePutChar(cupsFileStdout(), '\n');
   }
   else
   {
     for (i = 0; i < num_displayed; i ++)
     {
       if (i)
-        putchar(',');
+        cupsFilePutChar(cupsFileStdout(), ',');
 
-      fputs(displayed[i], stdout);
+      cupsFilePuts(outfile, displayed[i]);
     }
-    putchar('\n');
+    cupsFilePutChar(cupsFileStdout(), '\n');
   }
 
   free(buffer);
@@ -4341,7 +4716,8 @@ print_csv(
  */
 
 static void
-print_fatal_error(const char *s,       /* I - Printf-style format string */
+print_fatal_error(cups_file_t *outfile,        /* I - Output file */
+                 const char  *s,       /* I - Printf-style format string */
                   ...)                 /* I - Additional arguments as needed */
 {
   char         buffer[10240];          /* Format buffer */
@@ -4362,11 +4738,146 @@ print_fatal_error(const char *s,       /* I - Printf-style format string */
 
   if (Output == _CUPS_OUTPUT_PLIST)
   {
-    print_xml_header();
-    print_xml_trailer(0, buffer);
+    print_xml_header(outfile);
+    print_xml_trailer(outfile, 0, buffer);
   }
+
+  _cupsLangPrintf(stderr, "ipptool: %s", buffer);
+}
+
+
+/*
+ * 'print_ippserver_attr()' - Print a attribute suitable for use by ippserver.
+ */
+
+static void
+print_ippserver_attr(
+    cups_file_t     *outfile,          /* I - Output file */
+    ipp_attribute_t *attr,             /* I - Attribute to print */
+    int             indent)            /* I - Indentation level */
+{
+  int                  i,              /* Looping var */
+                       count = ippGetCount(attr);
+                                       /* Number of values */
+  ipp_attribute_t      *colattr;       /* Collection attribute */
+
+
+  if (indent == 0)
+    cupsFilePrintf(outfile, "ATTR %s %s", ippTagString(ippGetValueTag(attr)), ippGetName(attr));
   else
-    _cupsLangPrintf(stderr, "ipptool: %s", buffer);
+    cupsFilePrintf(outfile, "%*sMEMBER %s %s", indent, "", ippTagString(ippGetValueTag(attr)), ippGetName(attr));
+
+  switch (ippGetValueTag(attr))
+  {
+    case IPP_TAG_INTEGER :
+    case IPP_TAG_ENUM :
+       for (i = 0; i < count; i ++)
+         cupsFilePrintf(outfile, "%s%d", i ? "," : " ", ippGetInteger(attr, i));
+       break;
+
+    case IPP_TAG_BOOLEAN :
+       cupsFilePuts(outfile, ippGetBoolean(attr, 0) ? " true" : " false");
+
+       for (i = 1; i < count; i ++)
+         cupsFilePuts(outfile, ippGetBoolean(attr, 1) ? ",true" : ",false");
+       break;
+
+    case IPP_TAG_RANGE :
+       for (i = 0; i < count; i ++)
+       {
+         int upper, lower = ippGetRange(attr, i, &upper);
+
+         cupsFilePrintf(outfile, "%s%d-%d", i ? "," : " ", lower, upper);
+       }
+       break;
+
+    case IPP_TAG_RESOLUTION :
+       for (i = 0; i < count; i ++)
+       {
+         ipp_res_t units;
+         int yres, xres = ippGetResolution(attr, i, &yres, &units);
+
+         cupsFilePrintf(outfile, "%s%dx%d%s", i ? "," : " ", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+       }
+       break;
+
+    case IPP_TAG_DATE :
+       for (i = 0; i < count; i ++)
+         cupsFilePrintf(outfile, "%s%s", i ? "," : " ", iso_date(ippGetDate(attr, i)));
+       break;
+
+    case IPP_TAG_STRING :
+       for (i = 0; i < count; i ++)
+       {
+         int len;
+         const char *s = (const char *)ippGetOctetString(attr, i, &len);
+
+         cupsFilePuts(outfile, i ? "," : " ");
+         print_ippserver_string(outfile, s, (size_t)len);
+       }
+       break;
+
+    case IPP_TAG_TEXT :
+    case IPP_TAG_TEXTLANG :
+    case IPP_TAG_NAME :
+    case IPP_TAG_NAMELANG :
+    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 < count; i ++)
+       {
+         const char *s = ippGetString(attr, i, NULL);
+
+         cupsFilePuts(outfile, i ? "," : " ");
+         print_ippserver_string(outfile, s, strlen(s));
+       }
+       break;
+
+    case IPP_TAG_BEGIN_COLLECTION :
+       for (i = 0; i < attr->num_values; i ++)
+       {
+         ipp_t *col = ippGetCollection(attr, i);
+
+         cupsFilePuts(outfile, i ? ",{\n" : " {\n");
+         for (colattr = ippFirstAttribute(col); colattr; colattr = ippNextAttribute(col))
+           print_ippserver_attr(outfile, colattr, indent + 4);
+         cupsFilePrintf(outfile, "%*s}", indent, "");
+       }
+       break;
+
+    default :
+       cupsFilePuts(outfile, " \"\"");
+       break;
+  }
+
+  cupsFilePuts(outfile, "\n");
+}
+
+
+/*
+ * 'print_ippserver_string()' - Print a string suitable for use by ippserver.
+ */
+
+static void
+print_ippserver_string(
+    cups_file_t *outfile,              /* I - Output file */
+    const char  *s,                    /* I - String to print */
+    size_t      len)                   /* I - Length of string */
+{
+  cupsFilePutChar(outfile, '\"');
+  while (len > 0)
+  {
+    if (*s == '\"')
+      cupsFilePutChar(outfile, '\\');
+    cupsFilePutChar(outfile, *s);
+
+    s ++;
+    len --;
+  }
+  cupsFilePutChar(outfile, '\"');
 }
 
 
@@ -4376,6 +4887,7 @@ print_fatal_error(const char *s,  /* I - Printf-style format string */
 
 static void
 print_line(
+    cups_file_t     *outfile,          /* I - Output file */
     ipp_attribute_t *attr,             /* I - First attribute for line */
     int             num_displayed,     /* I - Number of attributes to display */
     char            **displayed,       /* I - Attributes to display */
@@ -4409,7 +4921,7 @@ print_line(
     for (i = 0; i < num_displayed; i ++)
     {
       if (i)
-        putchar(' ');
+        cupsFilePutChar(cupsFileStdout(), ' ');
 
       buffer[0] = '\0';
 
@@ -4424,31 +4936,31 @@ print_line(
         }
       }
 
-      printf("%*s", (int)-widths[i], buffer);
+      cupsFilePrintf(outfile, "%*s", (int)-widths[i], buffer);
     }
-    putchar('\n');
+    cupsFilePutChar(cupsFileStdout(), '\n');
   }
   else
   {
     for (i = 0; i < num_displayed; i ++)
     {
       if (i)
-        putchar(' ');
+        cupsFilePutChar(cupsFileStdout(), ' ');
 
-      printf("%*s", (int)-widths[i], displayed[i]);
+      cupsFilePrintf(outfile, "%*s", (int)-widths[i], displayed[i]);
     }
-    putchar('\n');
+    cupsFilePutChar(cupsFileStdout(), '\n');
 
     for (i = 0; i < num_displayed; i ++)
     {
       if (i)
-       putchar(' ');
+       cupsFilePutChar(cupsFileStdout(), ' ');
 
       memset(buffer, '-', widths[i]);
       buffer[widths[i]] = '\0';
-      fputs(buffer, stdout);
+      cupsFilePuts(outfile, buffer);
     }
-    putchar('\n');
+    cupsFilePutChar(cupsFileStdout(), '\n');
   }
 
   free(buffer);
@@ -4460,23 +4972,23 @@ print_line(
  */
 
 static void
-print_xml_header(void)
+print_xml_header(cups_file_t *outfile)         /* I - Output file */
 {
   if (!XMLHeader)
   {
-    puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-    puts("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
-         "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
-    puts("<plist version=\"1.0\">");
-    puts("<dict>");
-    puts("<key>ipptoolVersion</key>");
-    puts("<string>" CUPS_SVERSION "</string>");
-    puts("<key>Transfer</key>");
-    printf("<string>%s</string>\n",
-           Transfer == _CUPS_TRANSFER_AUTO ? "auto" :
-              Transfer == _CUPS_TRANSFER_CHUNKED ? "chunked" : "length");
-    puts("<key>Tests</key>");
-    puts("<array>");
+    cupsFilePuts(outfile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+    cupsFilePuts(outfile, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
+         "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
+    cupsFilePuts(outfile, "<plist version=\"1.0\">\n");
+    cupsFilePuts(outfile, "<dict>\n");
+    cupsFilePuts(outfile, "<key>ipptoolVersion</key>\n");
+    cupsFilePuts(outfile, "<string>" CUPS_SVERSION "</string>\n");
+    cupsFilePuts(outfile, "<key>Transfer</key>\n");
+    cupsFilePrintf(outfile, "<string>%s</string>\n",
+           Transfer == _CUPS_TRANSFER_AUTO ? "auto" :
+               Transfer == _CUPS_TRANSFER_CHUNKED ? "chunked" : "length");
+    cupsFilePuts(outfile, "<key>Tests</key>\n");
+    cupsFilePuts(outfile, "<array>\n");
 
     XMLHeader = 1;
   }
@@ -4488,20 +5000,21 @@ print_xml_header(void)
  */
 
 static void
-print_xml_string(const char *element,  /* I - Element name or NULL */
-                const char *s)         /* I - String to print */
+print_xml_string(cups_file_t *outfile, /* I - Output file */
+                 const char  *element, /* I - Element name or NULL */
+                const char  *s)        /* I - String to print */
 {
   if (element)
-    printf("<%s>", element);
+    cupsFilePrintf(outfile, "<%s>", element);
 
   while (*s)
   {
     if (*s == '&')
-      fputs("&amp;", stdout);
+      cupsFilePuts(outfile, "&amp;");
     else if (*s == '<')
-      fputs("&lt;", stdout);
+      cupsFilePuts(outfile, "&lt;");
     else if (*s == '>')
-      fputs("&gt;", stdout);
+      cupsFilePuts(outfile, "&gt;");
     else if ((*s & 0xe0) == 0xc0)
     {
      /*
@@ -4510,13 +5023,13 @@ print_xml_string(const char *element,   /* I - Element name or NULL */
 
       if ((s[1] & 0xc0) != 0x80)
       {
-        putchar('?');
+        cupsFilePutChar(outfile, '?');
         s ++;
       }
       else
       {
-        putchar(*s++);
-        putchar(*s);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s);
       }
     }
     else if ((*s & 0xf0) == 0xe0)
@@ -4527,14 +5040,14 @@ print_xml_string(const char *element,   /* I - Element name or NULL */
 
       if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80)
       {
-        putchar('?');
+        cupsFilePutChar(outfile, '?');
         s += 2;
       }
       else
       {
-        putchar(*s++);
-        putchar(*s++);
-        putchar(*s);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s);
       }
     }
     else if ((*s & 0xf8) == 0xf0)
@@ -4546,15 +5059,15 @@ print_xml_string(const char *element,   /* I - Element name or NULL */
       if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 ||
           (s[3] & 0xc0) != 0x80)
       {
-        putchar('?');
+        cupsFilePutChar(outfile, '?');
         s += 3;
       }
       else
       {
-        putchar(*s++);
-        putchar(*s++);
-        putchar(*s++);
-        putchar(*s);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s++);
+        cupsFilePutChar(outfile, *s);
       }
     }
     else if ((*s & 0x80) || (*s < ' ' && !isspace(*s & 255)))
@@ -4563,16 +5076,16 @@ print_xml_string(const char *element,   /* I - Element name or NULL */
       * Invalid control character...
       */
 
-      putchar('?');
+      cupsFilePutChar(outfile, '?');
     }
     else
-      putchar(*s);
+      cupsFilePutChar(outfile, *s);
 
     s ++;
   }
 
   if (element)
-    printf("</%s>\n", element);
+    cupsFilePrintf(outfile, "</%s>\n", element);
 }
 
 
@@ -4581,21 +5094,22 @@ print_xml_string(const char *element,   /* I - Element name or NULL */
  */
 
 static void
-print_xml_trailer(int        success,  /* I - 1 on success, 0 on failure */
-                  const char *message) /* I - Error message or NULL */
+print_xml_trailer(cups_file_t *outfile,        /* I - Output file */
+                  int         success, /* I - 1 on success, 0 on failure */
+                  const char  *message)        /* I - Error message or NULL */
 {
   if (XMLHeader)
   {
-    puts("</array>");
-    puts("<key>Successful</key>");
-    puts(success ? "<true />" : "<false />");
+    cupsFilePuts(outfile, "</array>\n");
+    cupsFilePuts(outfile, "<key>Successful</key>\n");
+    cupsFilePuts(outfile, success ? "<true />\n" : "<false />\n");
     if (message)
     {
-      puts("<key>ErrorMessage</key>");
-      print_xml_string("string", message);
+      cupsFilePuts(outfile, "<key>ErrorMessage</key>\n");
+      print_xml_string(outfile, "string", message);
     }
-    puts("</dict>");
-    puts("</plist>");
+    cupsFilePuts(outfile, "</dict>\n");
+    cupsFilePuts(outfile, "</plist>\n");
 
     XMLHeader = 0;
   }
@@ -4607,7 +5121,8 @@ print_xml_trailer(int        success,     /* I - 1 on success, 0 on failure */
  */
 
 static void
-set_variable(_cups_vars_t *vars,       /* I - Variables */
+set_variable(cups_file_t  *outfile,    /* I - Output file */
+             _cups_vars_t *vars,       /* I - Variables */
              const char   *name,       /* I - Variable name */
              const char   *value)      /* I - Value string */
 {
@@ -4632,7 +5147,7 @@ set_variable(_cups_vars_t *vars,  /* I - Variables */
   }
   else if ((var = malloc(sizeof(_cups_var_t))) == NULL)
   {
-    print_fatal_error("Unable to allocate memory for variable \"%s\".", name);
+    print_fatal_error(outfile, "Unable to allocate memory for variable \"%s\".", name);
     exit(1);
   }
   else
@@ -4682,7 +5197,7 @@ timeout_cb(http_t *http,          /* I - Connection to server */
   * buffer is empty...
   */
 
-#ifdef SO_NWRITE                       /* OS X and some versions of Linux */
+#ifdef SO_NWRITE                       /* macOS and some versions of Linux */
   socklen_t len = sizeof(buffered);    /* Size of return value */
 
   if (getsockopt(httpGetFd(http), SOL_SOCKET, SO_NWRITE, &buffered, &len))
@@ -4707,34 +5222,32 @@ timeout_cb(http_t *http,                /* I - Connection to server */
 static void
 usage(void)
 {
-  _cupsLangPuts(stderr, _("Usage: ipptool [options] URI filename [ ... "
-                         "filenameN ]"));
+  _cupsLangPuts(stderr, _("Usage: ipptool [options] URI filename [ ... filenameN ]"));
   _cupsLangPuts(stderr, _("Options:"));
+  _cupsLangPuts(stderr, _("  --help                  Show help."));
+  _cupsLangPuts(stderr, _("  --ippserver filename    Produce ippserver attribute file."));
+  _cupsLangPuts(stderr, _("  --stop-after-include-error\n"
+                          "                          Stop tests after a failed INCLUDE."));
+  _cupsLangPuts(stderr, _("  --version               Show version."));
   _cupsLangPuts(stderr, _("  -4                      Connect using IPv4."));
   _cupsLangPuts(stderr, _("  -6                      Connect using IPv6."));
   _cupsLangPuts(stderr, _("  -C                      Send requests using "
                           "chunking (default)."));
-  _cupsLangPuts(stdout, _("  -E                      Test with HTTP Upgrade to "
-                          "TLS."));
+  _cupsLangPuts(stderr, _("  -E                      Test with encryption using HTTP Upgrade to TLS."));
   _cupsLangPuts(stderr, _("  -I                      Ignore errors."));
-  _cupsLangPuts(stderr, _("  -L                      Send requests using "
-                          "content-length."));
-  _cupsLangPuts(stderr, _("  -S                      Test with SSL "
-                         "encryption."));
-  _cupsLangPuts(stderr, _("  -T seconds              Set the receive/send "
-                          "timeout in seconds."));
-  _cupsLangPuts(stderr, _("  -V version              Set default IPP "
-                          "version."));
-  _cupsLangPuts(stderr, _("  -X                      Produce XML plist instead "
-                          "of plain text."));
-  _cupsLangPuts(stderr, _("  -d name=value           Set named variable to "
-                          "value."));
-  _cupsLangPuts(stderr, _("  -f filename             Set default request "
-                          "filename."));
-  _cupsLangPuts(stderr, _("  -i seconds              Repeat the last file with "
-                          "the given time interval."));
-  _cupsLangPuts(stderr, _("  -n count                Repeat the last file the "
-                          "given number of times."));
+  _cupsLangPuts(stderr, _("  -L                      Send requests using content-length."));
+  _cupsLangPuts(stderr, _("  -P filename.plist       Produce XML plist to a file and test report to standard output."));
+  _cupsLangPuts(stderr, _("  -S                      Test with encryption using HTTPS."));
+  _cupsLangPuts(stderr, _("  -T seconds              Set the receive/send timeout in seconds."));
+  _cupsLangPuts(stderr, _("  -V version              Set default IPP version."));
+  _cupsLangPuts(stderr, _("  -X                      Produce XML plist instead of plain text."));
+  _cupsLangPuts(stderr, _("  -c                      Produce CSV output."));
+  _cupsLangPuts(stderr, _("  -d name=value           Set named variable to value."));
+  _cupsLangPuts(stderr, _("  -f filename             Set default request filename."));
+  _cupsLangPuts(stderr, _("  -h                      Validate HTTP response headers."));
+  _cupsLangPuts(stderr, _("  -i seconds              Repeat the last file with the given time interval."));
+  _cupsLangPuts(stderr, _("  -l                      Produce plain text output."));
+  _cupsLangPuts(stderr, _("  -n count                Repeat the last file the given number of times."));
   _cupsLangPuts(stderr, _("  -q                      Run silently."));
   _cupsLangPuts(stderr, _("  -t                      Produce a test report."));
   _cupsLangPuts(stderr, _("  -v                      Be verbose."));
@@ -4748,7 +5261,8 @@ usage(void)
  */
 
 static int                             /* O - 1 if valid, 0 otherwise */
-validate_attr(cups_array_t    *errors, /* I - Errors array */
+validate_attr(cups_file_t     *outfile,        /* I - Output file */
+              cups_array_t    *errors, /* I - Errors array */
               ipp_attribute_t *attr)   /* I - Attribute to validate */
 {
   int          i;                      /* Looping var */
@@ -5013,7 +5527,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
               colattr;
               colattr = colattr->next)
          {
-           if (!validate_attr(NULL, colattr))
+           if (!validate_attr(outfile, NULL, colattr))
            {
              valid = 0;
              break;
@@ -5026,7 +5540,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            while (colattr)
            {
-             validate_attr(errors, colattr);
+             validate_attr(outfile, errors, colattr);
              colattr = colattr->next;
            }
          }
@@ -5310,7 +5824,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
           char temp[256];              /* Temporary error string */
 
           regerror(i, &re, temp, sizeof(temp));
-         print_fatal_error("Unable to compile naturalLanguage regular "
+         print_fatal_error(outfile, "Unable to compile naturalLanguage regular "
                            "expression: %s.", temp);
          break;
         }
@@ -5363,7 +5877,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
           char temp[256];              /* Temporary error string */
 
           regerror(i, &re, temp, sizeof(temp));
-         print_fatal_error("Unable to compile mimeMediaType regular "
+         print_fatal_error(outfile, "Unable to compile mimeMediaType regular "
                            "expression: %s.", temp);
          break;
         }
@@ -5403,12 +5917,43 @@ validate_attr(cups_array_t    *errors,  /* I - Errors array */
 }
 
 
+/*
+ * 'with_flags_string()' - Return the "WITH-xxx" predicate that corresponds to
+                           the flags.
+ */
+
+static const char *                     /* O - WITH-xxx string */
+with_flags_string(int flags)            /* I - WITH flags */
+{
+  if (flags & _CUPS_WITH_ALL)
+  {
+    if (flags & _CUPS_WITH_HOSTNAME)
+      return ("WITH-ALL-HOSTNAMES");
+    else if (flags & _CUPS_WITH_RESOURCE)
+      return ("WITH-ALL-RESOURCES");
+    else if (flags & _CUPS_WITH_SCHEME)
+      return ("WITH-ALL-SCHEMES");
+    else
+      return ("WITH-ALL-VALUES");
+  }
+  else if (flags & _CUPS_WITH_HOSTNAME)
+    return ("WITH-HOSTNAME");
+  else if (flags & _CUPS_WITH_RESOURCE)
+    return ("WITH-RESOURCE");
+  else if (flags & _CUPS_WITH_SCHEME)
+    return ("WITH-SCHEME");
+  else
+    return ("WITH-VALUE");
+}
+
+
 /*
  * 'with_value()' - Test a WITH-VALUE predicate.
  */
 
 static int                             /* O - 1 on match, 0 on non-match */
-with_value(cups_array_t    *errors,    /* I - Errors array */
+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 */
@@ -5575,7 +6120,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
     case IPP_TAG_BOOLEAN :
        for (i = 0; i < attr->num_values; i ++)
        {
-          if (!strcmp(value, "true") == attr->values[i].boolean)
+          if ((!strcmp(value, "true")) == attr->values[i].boolean)
           {
             if (!matchbuf[0])
              strlcpy(matchbuf, value, matchlen);
@@ -5684,7 +6229,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
          {
             regerror(i, &re, temp, sizeof(temp));
 
-           print_fatal_error("Unable to compile WITH-VALUE regular expression "
+           print_fatal_error(outfile, "Unable to compile WITH-VALUE regular expression "
                              "\"%s\" - %s", value, temp);
            return (0);
          }
@@ -5718,6 +6263,34 @@ with_value(cups_array_t    *errors,      /* I - Errors array */
 
          regfree(&re);
        }
+       else if (ippGetValueTag(attr) == IPP_TAG_URI && !(flags & (_CUPS_WITH_SCHEME | _CUPS_WITH_HOSTNAME | _CUPS_WITH_RESOURCE)))
+       {
+        /*
+         * Value is a literal URI string, see if the value(s) match...
+         */
+
+         for (i = 0; i < attr->num_values; i ++)
+         {
+           if (!compare_uris(value, get_string(attr, i, flags, temp, sizeof(temp))))
+           {
+             if (!matchbuf[0])
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
+
+             if (!(flags & _CUPS_WITH_ALL))
+             {
+               match = 1;
+               break;
+             }
+           }
+           else if (flags & _CUPS_WITH_ALL)
+           {
+             match = 0;
+             break;
+           }
+         }
+       }
        else
        {
         /*
@@ -5726,7 +6299,46 @@ with_value(cups_array_t    *errors,      /* I - Errors array */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!strcmp(value, get_string(attr, i, flags, temp, sizeof(temp))))
+           int result;
+
+            switch (ippGetValueTag(attr))
+            {
+              case IPP_TAG_URI :
+                 /*
+                  * Some URI components are case-sensitive, some not...
+                  */
+
+                  if (flags & (_CUPS_WITH_SCHEME | _CUPS_WITH_HOSTNAME))
+                    result = _cups_strcasecmp(value, get_string(attr, i, flags, temp, sizeof(temp)));
+                  else
+                    result = strcmp(value, get_string(attr, i, flags, temp, sizeof(temp)));
+                  break;
+
+              case IPP_TAG_MIMETYPE :
+              case IPP_TAG_NAME :
+              case IPP_TAG_NAMELANG :
+              case IPP_TAG_TEXT :
+              case IPP_TAG_TEXTLANG :
+                 /*
+                  * mimeMediaType, nameWithoutLanguage, nameWithLanguage,
+                  * textWithoutLanguage, and textWithLanguage are defined to
+                  * be case-insensitive strings...
+                  */
+
+                  result = _cups_strcasecmp(value, get_string(attr, i, flags, temp, sizeof(temp)));
+                  break;
+
+              default :
+                 /*
+                  * Other string syntaxes are defined as lowercased so we use
+                  * case-sensitive comparisons to catch problems...
+                  */
+
+                  result = strcmp(value, get_string(attr, i, flags, temp, sizeof(temp)));
+                  break;
+            }
+
+            if (!result)
            {
              if (!matchbuf[0])
                strlcpy(matchbuf,
@@ -5764,5 +6376,184 @@ with_value(cups_array_t    *errors,     /* I - Errors array */
 
 
 /*
- * End of "$Id$".
+ * 'with_value_from()' - Test a WITH-VALUE-FROM predicate.
  */
+
+static int                             /* O - 1 on match, 0 on non-match */
+with_value_from(
+    cups_array_t    *errors,           /* I - Errors array */
+    ipp_attribute_t *fromattr,         /* I - "From" attribute */
+    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, j,                           /* Looping vars */
+       count = ippGetCount(attr),      /* Number of attribute values */
+       match = 1;                      /* Match? */
+
+
+  *matchbuf = '\0';
+
+ /*
+  * Compare the from value(s) to the attribute value(s)...
+  */
+
+  switch (ippGetValueTag(attr))
+  {
+    case IPP_TAG_INTEGER :
+        if (ippGetValueTag(fromattr) != IPP_TAG_INTEGER && ippGetValueTag(fromattr) != IPP_TAG_RANGE)
+         goto wrong_value_tag;
+
+       for (i = 0; i < count; i ++)
+       {
+         int value = ippGetInteger(attr, i);
+                                       /* Current integer value */
+
+         if (ippContainsInteger(fromattr, value))
+         {
+           if (!matchbuf[0])
+             snprintf(matchbuf, matchlen, "%d", value);
+         }
+         else
+         {
+           add_stringf(errors, "GOT: %s=%d", ippGetName(attr), value);
+           match = 0;
+         }
+       }
+       break;
+
+    case IPP_TAG_ENUM :
+        if (ippGetValueTag(fromattr) != IPP_TAG_ENUM)
+         goto wrong_value_tag;
+
+       for (i = 0; i < count; i ++)
+       {
+         int value = ippGetInteger(attr, i);
+                                       /* Current integer value */
+
+         if (ippContainsInteger(fromattr, value))
+         {
+           if (!matchbuf[0])
+             snprintf(matchbuf, matchlen, "%d", value);
+         }
+         else
+         {
+           add_stringf(errors, "GOT: %s=%d", ippGetName(attr), value);
+           match = 0;
+         }
+       }
+       break;
+
+    case IPP_TAG_RESOLUTION :
+        if (ippGetValueTag(fromattr) != IPP_TAG_RESOLUTION)
+         goto wrong_value_tag;
+
+       for (i = 0; i < count; i ++)
+       {
+         int xres, yres;
+         ipp_res_t units;
+          int fromcount = ippGetCount(fromattr);
+         int fromxres, fromyres;
+         ipp_res_t fromunits;
+
+         xres = ippGetResolution(attr, i, &yres, &units);
+
+          for (j = 0; j < fromcount; j ++)
+         {
+           fromxres = ippGetResolution(fromattr, j, &fromyres, &fromunits);
+           if (fromxres == xres && fromyres == yres && fromunits == units)
+             break;
+         }
+
+         if (j < fromcount)
+         {
+           if (!matchbuf[0])
+           {
+             if (xres == yres)
+               snprintf(matchbuf, matchlen, "%d%s", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+             else
+               snprintf(matchbuf, matchlen, "%dx%d%s", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+           }
+         }
+         else
+         {
+           if (xres == yres)
+             add_stringf(errors, "GOT: %s=%d%s", ippGetName(attr), xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+           else
+             add_stringf(errors, "GOT: %s=%dx%d%s", ippGetName(attr), xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
+
+           match = 0;
+         }
+       }
+       break;
+
+    case IPP_TAG_NOVALUE :
+    case IPP_TAG_UNKNOWN :
+       return (1);
+
+    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_URISCHEME :
+       for (i = 0; i < count; i ++)
+       {
+         const char *value = ippGetString(attr, i, NULL);
+                                       /* Current string value */
+
+         if (ippContainsString(fromattr, value))
+         {
+           if (!matchbuf[0])
+             strlcpy(matchbuf, value, matchlen);
+         }
+         else
+         {
+           add_stringf(errors, "GOT: %s='%s'", ippGetName(attr), value);
+           match = 0;
+         }
+       }
+       break;
+
+    case IPP_TAG_URI :
+       for (i = 0; i < count; i ++)
+       {
+         const char *value = ippGetString(attr, i, NULL);
+                                       /* Current string value */
+          int fromcount = ippGetCount(fromattr);
+
+          for (j = 0; j < fromcount; j ++)
+          {
+            if (!compare_uris(value, ippGetString(fromattr, j, NULL)))
+            {
+              if (!matchbuf[0])
+                strlcpy(matchbuf, value, matchlen);
+              break;
+            }
+          }
+
+         if (j >= fromcount)
+         {
+           add_stringf(errors, "GOT: %s='%s'", ippGetName(attr), value);
+           match = 0;
+         }
+       }
+       break;
+
+    default :
+        match = 0;
+        break;
+  }
+
+  return (match);
+
+  /* value tag mismatch between fromattr and attr */
+  wrong_value_tag :
+
+  add_stringf(errors, "GOT: %s OF-TYPE %s", ippGetName(attr), ippTagString(ippGetValueTag(attr)));
+
+  return (0);
+}