]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptool.c
Fix build errors on Fedora.
[thirdparty/cups.git] / test / ipptool.c
index a364a93f7f81699ce4953f656f786b4104e8f58c..00124c1f0d48b953921f046e3ba62c779c5ecbdb 100644 (file)
@@ -1,48 +1,18 @@
 /*
  * "$Id$"
  *
- *   ipptool command for CUPS.
+ * ipptool command for CUPS.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 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/".
+ * 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.
- *
- * Contents:
- *
- *   main()              - Parse options and do tests.
- *   add_stringf()       - Add a formatted string to an array.
- *   compare_vars()      - Compare two variables.
- *   do_tests()          - Do tests as specified in the test file.
- *   expand_variables()  - Expand variables in a string.
- *   expect_matches()    - Return true if the tag matches the specification.
- *   get_collection()    - Get a collection value from the current test file.
- *   get_filename()      - Get a filename based on the current test file.
- *   get_token()         - Get a token from a file.
- *   get_variable()      - Get the value of a variable.
- *   iso_date()          - Return an ISO 8601 date/time string for the given IPP
- *                         dateTime value.
- *   password_cb()       - Password callback for authenticated tests.
- *   print_attr()        - Print an attribute on the screen.
- *   print_col()         - Print a collection attribute on the screen.
- *   print_csv()         - Print a line of CSV text.
- *   print_fatal_error() - Print a fatal error message.
- *   print_line()        - Print a line of formatted or CSV text.
- *   print_xml_header()  - Print a standard XML plist header.
- *   print_xml_string()  - Print an XML string with escaping.
- *   print_xml_trailer() - Print the XML trailer with success/fail value.
- *   set_variable()      - Set a variable value.
- *   sigterm_handler()   - Handle SIGINT and SIGTERM.
- *   timeout_cb()        - Handle HTTP timeouts.
- *   usage()             - Show program usage.
- *   validate_attr()     - Determine whether an attribute is valid.
- *   with_value()        - Test a WITH-VALUE predicate.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -53,7 +23,9 @@
 #include <cups/file-private.h>
 #include <regex.h>
 #include <sys/stat.h>
-#ifndef WIN32
+#ifdef WIN32
+#  define R_OK 0
+#else
 #  include <signal.h>
 #endif /* WIN32 */
 #ifndef O_BINARY
@@ -85,7 +57,10 @@ typedef enum _cups_with_e            /**** WITH flags ****/
 {
   _CUPS_WITH_LITERAL = 0,              /* Match string is a literal value */
   _CUPS_WITH_ALL = 1,                  /* Must match all values */
-  _CUPS_WITH_REGEX = 2                 /* Match string is a regular expression */
+  _CUPS_WITH_REGEX = 2,                        /* Match string is a regular expression */
+  _CUPS_WITH_HOSTNAME = 4,             /* Match string is a URI hostname */
+  _CUPS_WITH_RESOURCE = 8,             /* Match string is a URI resource */
+  _CUPS_WITH_SCHEME = 16               /* Match string is a URI scheme */
 } _cups_with_t;
 
 typedef struct _cups_expect_s          /**** Expected attribute info ****/
@@ -113,7 +88,10 @@ typedef struct _cups_status_s               /**** Status info ****/
 {
   ipp_status_t status;                 /* Expected status code */
   char         *if_defined,            /* Only if variable is defined */
-               *if_not_defined;        /* Only if variable is not defined */
+               *if_not_defined,        /* Only if variable is not defined */
+               *define_match,          /* Variable to define on match */
+               *define_no_match,       /* Variable to define on no-match */
+               *define_value;          /* Variable to define with value */
   int          repeat_limit,           /* Maximum number of times to repeat */
                repeat_match,           /* Repeat the test when it does not match */
                repeat_no_match;        /* Repeat the test when it matches */
@@ -145,12 +123,14 @@ typedef struct _cups_vars_s               /**** Set of variables ****/
  * Globals...
  */
 
-_cups_transfer_t Transfer = _CUPS_TRANSFER_AUTO;
+static _cups_transfer_t Transfer = _CUPS_TRANSFER_AUTO;
                                        /* How to transfer requests */
-_cups_output_t Output = _CUPS_OUTPUT_LIST;
+static _cups_output_t  Output = _CUPS_OUTPUT_LIST;
                                        /* Output mode */
-int            Cancel = 0,             /* Cancel test? */
+static int     Cancel = 0,             /* Cancel test? */
                IgnoreErrors = 0,       /* Ignore errors? */
+               StopAfterIncludeError = 0,
+                                       /* Stop after include errors? */
                Verbosity = 0,          /* Show all attributes? */
                Version = 11,           /* Default IPP version */
                XMLHeader = 0,          /* 1 if header is written */
@@ -158,22 +138,7 @@ int                Cancel = 0,             /* Cancel test? */
                PassCount = 0,          /* Number of passing tests */
                FailCount = 0,          /* Number of failing tests */
                SkipCount = 0;          /* Number of skipped tests */
-char           *Password = NULL;       /* Password from URI */
-const char * const URIStatusStrings[] =        /* URI status strings */
-{
-  "URI too large",
-  "Bad arguments to function",
-  "Bad resource in URI",
-  "Bad port number in URI",
-  "Bad hostname/address in URI",
-  "Bad username in URI",
-  "Bad scheme in URI",
-  "Bad/empty URI",
-  "OK",
-  "Missing scheme in URI",
-  "Unknown scheme in URI",
-  "Missing resource in URI"
-};
+static char    *Password = NULL;       /* Password from URI */
 
 
 /*
@@ -190,6 +155,8 @@ 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 char    *get_variable(_cups_vars_t *vars, const char *name);
@@ -277,7 +244,20 @@ main(int  argc,                            /* I - Number of command-line args */
 
   for (i = 1; i < argc; i ++)
   {
-    if (argv[i][0] == '-')
+    if (!strcmp(argv[i], "--help"))
+    {
+      usage();
+    }
+    else if (!strcmp(argv[i], "--stop-after-include-error"))
+    {
+      StopAfterIncludeError = 1;
+    }
+    else if (!strcmp(argv[i], "--version"))
+    {
+      puts(CUPS_SVERSION);
+      return (0);
+    }
+    else if (argv[i][0] == '-')
     {
       for (opt = argv[i] + 1; *opt; opt ++)
       {
@@ -328,8 +308,9 @@ main(int  argc,                             /* I - Number of command-line args */
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr,
-                             _("ipptool: Missing timeout for \"-T\"."));
+               _cupsLangPrintf(stderr,
+                               _("%s: Missing timeout for \"-T\"."),
+                               "ipptool");
                usage();
               }
 
@@ -341,8 +322,9 @@ main(int  argc,                             /* I - Number of command-line args */
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr,
-                             _("ipptool: Missing version for \"-V\"."));
+               _cupsLangPrintf(stderr,
+                               _("%s: Missing version for \"-V\"."),
+                               "ipptool");
                usage();
               }
 
@@ -359,8 +341,8 @@ main(int  argc,                             /* I - Number of command-line args */
              else
              {
                _cupsLangPrintf(stderr,
-                               _("ipptool: Bad version %s for \"-V\"."),
-                               argv[i]);
+                               _("%s: Bad version %s for \"-V\"."),
+                               "ipptool", argv[i]);
                usage();
              }
              break;
@@ -410,7 +392,10 @@ main(int  argc,                            /* I - Number of command-line args */
               }
 
               if (vars.filename)
+              {
                free(vars.filename);
+               vars.filename = NULL;
+             }
 
               if (access(argv[i], 0))
               {
@@ -433,6 +418,8 @@ main(int  argc,                             /* I - Number of command-line args */
                             cg->cups_datadir, argv[i]);
                    if (access(filename, 0))
                      vars.filename = strdup(argv[i]);
+                   else
+                     vars.filename = strdup(filename);
                  }
                  else
                    vars.filename = strdup(filename);
@@ -468,7 +455,9 @@ main(int  argc,                             /* I - Number of command-line args */
                 else if (!_cups_strcasecmp(ext, ".ps") ||
                          !_cups_strcasecmp(ext, ".ps.gz"))
                   set_variable(&vars, "filetype", "application/postscript");
-                else if (!_cups_strcasecmp(ext, ".ras") ||
+                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");
                 else if (!_cups_strcasecmp(ext, ".txt") ||
@@ -558,7 +547,6 @@ main(int  argc,                             /* I - Number of command-line args */
              _cupsLangPrintf(stderr, _("ipptool: Unknown option \"-%c\"."),
                              *opt);
              usage();
-             break;
        }
       }
     }
@@ -594,8 +582,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
       if (uri_status != HTTP_URI_OK)
       {
-        _cupsLangPrintf(stderr, _("ipptool: Bad URI - %s."),
-                       URIStatusStrings[uri_status - HTTP_URI_OVERFLOW]);
+        _cupsLangPrintf(stderr, _("ipptool: Bad URI - %s."), httpURIStatusString(uri_status));
         return (1);
       }
 
@@ -659,7 +646,7 @@ main(int  argc,                             /* I - Number of command-line args */
   {
     while (repeat > 1)
     {
-      usleep(interval);
+      usleep((useconds_t)interval);
       do_tests(&vars, testfile);
       repeat --;
     }
@@ -668,7 +655,7 @@ main(int  argc,                             /* I - Number of command-line args */
   {
     for (;;)
     {
-      usleep(interval);
+      usleep((useconds_t)interval);
       do_tests(&vars, testfile);
     }
   }
@@ -765,7 +752,8 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
                token[1024],            /* Token from file */
                *tokenptr,              /* Pointer into token */
                temp[1024],             /* Temporary string */
-               buffer[8192];           /* Copy buffer */
+               buffer[8192],           /* Copy buffer */
+               compression[16];        /* COMPRESSION value */
   ipp_t                *request = NULL,        /* IPP request */
                *response = NULL;       /* IPP response */
   size_t       length;                 /* Length of IPP request */
@@ -779,7 +767,9 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   ipp_attribute_t *attrptr,            /* Attribute pointer */
                *found,                 /* Found attribute */
                *lastcol = NULL;        /* Last collection attribute */
-  char         name[1024];             /* Name of test */
+  char         name[1024],             /* Name of test */
+               file_id[1024],          /* File identifier */
+               test_id[1024];          /* Test identifier */
   char         filename[1024];         /* Filename */
   _cups_transfer_t transfer;           /* To chunk or not to chunk */
   int          version,                /* IPP version number to use */
@@ -815,8 +805,8 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   * Connect to the server...
   */
 
-  if ((http = _httpCreate(vars->hostname, vars->port, NULL, vars->encryption,
-                         vars->family)) == NULL)
+  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,
                       vars->port, cupsLastErrorString());
@@ -824,13 +814,12 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
     goto test_exit;
   }
 
-  if (httpReconnect(http))
-  {
-    print_fatal_error("Unable to connect to %s on port %d - %s", vars->hostname,
-                      vars->port, cupsLastErrorString());
-    pass = 0;
-    goto test_exit;
-  }
+#ifdef HAVE_LIBZ
+  httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING,
+                      "deflate, gzip, identity");
+#else
+  httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING, "identity");
+#endif /* HAVE_LIBZ */
 
   if (vars->timeout > 0.0)
     httpSetTimeout(http, vars->timeout, timeout_cb, NULL);
@@ -843,6 +832,7 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
 
   errors     = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup,
                              (cups_afree_func_t)free);
+  file_id[0] = '\0';
   pass       = 1;
   linenum    = 1;
   request_id = (CUPS_RAND() % 1000) * 137 + 1;
@@ -898,6 +888,25 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
 
       continue;
     }
+    else if (!strcmp(token, "FILE-ID"))
+    {
+     /*
+      * FILE-ID "string"
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum))
+      {
+        expand_variables(vars, file_id, temp, sizeof(file_id));
+      }
+      else
+      {
+        print_fatal_error("Missing FILE-ID value on line %d.", linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      continue;
+    }
     else if (!strcmp(token, "IGNORE-ERRORS"))
     {
      /*
@@ -937,7 +946,7 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
        {
          pass = 0;
 
-         if (!IgnoreErrors)
+         if (StopAfterIncludeError)
            goto test_exit;
        }
       }
@@ -971,7 +980,7 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
        {
          pass = 0;
 
-         if (!IgnoreErrors)
+         if (StopAfterIncludeError)
            goto test_exit;
        }
       }
@@ -1006,7 +1015,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        {
          pass = 0;
 
-         if (!IgnoreErrors)
+         if (StopAfterIncludeError)
            goto test_exit;
        }
       }
@@ -1059,6 +1068,28 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        goto test_exit;
       }
     }
+    else if (!strcmp(token, "STOP-AFTER-INCLUDE-ERROR"))
+    {
+     /*
+      * STOP-AFTER-INCLUDE-ERROR yes
+      * STOP-AFTER-INCLUDE-ERROR no
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum) &&
+          (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+      {
+        StopAfterIncludeError = !_cups_strcasecmp(temp, "yes");
+      }
+      else
+      {
+        print_fatal_error("Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
+                          linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      continue;
+    }
     else if (!strcmp(token, "TRANSFER"))
     {
      /*
@@ -1146,17 +1177,19 @@ 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;
-    version       = Version;
-    transfer      = Transfer;
+    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';
 
     strlcpy(name, testfile, sizeof(name));
     if (strrchr(name, '.') != NULL)
@@ -1181,10 +1214,18 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
           _cups_strcasecmp(token, "REPEAT-NO-MATCH") &&
           _cups_strcasecmp(token, "SAME-COUNT-AS") &&
           _cups_strcasecmp(token, "WITH-ALL-VALUES") &&
+          _cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") &&
+          _cups_strcasecmp(token, "WITH-ALL-RESOURCES") &&
+          _cups_strcasecmp(token, "WITH-ALL-SCHEMES") &&
+          _cups_strcasecmp(token, "WITH-HOSTNAME") &&
+          _cups_strcasecmp(token, "WITH-RESOURCE") &&
+          _cups_strcasecmp(token, "WITH-SCHEME") &&
           _cups_strcasecmp(token, "WITH-VALUE"))
         last_expect = NULL;
 
-      if (_cups_strcasecmp(token, "IF-DEFINED") &&
+      if (_cups_strcasecmp(token, "DEFINE-MATCH") &&
+          _cups_strcasecmp(token, "DEFINE-NO-MATCH") &&
+         _cups_strcasecmp(token, "IF-DEFINED") &&
           _cups_strcasecmp(token, "IF-NOT-DEFINED") &&
           _cups_strcasecmp(token, "REPEAT-LIMIT") &&
           _cups_strcasecmp(token, "REPEAT-MATCH") &&
@@ -1204,41 +1245,44 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (col)
        {
-         ipp_attribute_t *tempcol;     /* Pointer to new buffer */
-
-
-        /*
-         * Reallocate memory...
-         */
+          ippSetCollection(request, &lastcol, ippGetCount(lastcol), col);
+        }
+       else
+       {
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "COMPRESSION"))
+      {
+       /*
+       * COMPRESSION none
+       * COMPRESSION deflate
+       * COMPRESSION gzip
+       */
 
-         if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) +
-                                         (lastcol->num_values + 1) *
-                                         sizeof(_ipp_value_t))) == NULL)
-         {
-           print_fatal_error("Unable to allocate memory on line %d.", linenum);
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, compression, temp, sizeof(compression));
+#ifdef HAVE_LIBZ
+         if (strcmp(compression, "none") && strcmp(compression, "deflate") &&
+             strcmp(compression, "gzip"))
+#else
+         if (strcmp(compression, "none"))
+#endif /* HAVE_LIBZ */
+          {
+           print_fatal_error("Unsupported COMPRESSION value '%s' on line %d.",
+                             compression, linenum);
            pass = 0;
            goto test_exit;
-         }
-
-         if (tempcol != lastcol)
-         {
-          /*
-           * Reset pointers in the list...
-           */
-
-           if (request->prev)
-             request->prev->next = tempcol;
-           else
-             request->attrs = tempcol;
-
-           lastcol = request->current = request->last = tempcol;
-         }
+          }
 
-         lastcol->values[lastcol->num_values].collection = col;
-         lastcol->num_values ++;
+          if (!strcmp(compression, "none"))
+            compression[0] = '\0';
        }
        else
        {
+         print_fatal_error("Missing COMPRESSION value on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1339,6 +1383,28 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
          goto test_exit;
        }
       }
+      else if (!strcmp(token, "SKIP-IF-MISSING"))
+      {
+       /*
+       * SKIP-IF-MISSING filename
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, token, temp, sizeof(token));
+         get_filename(testfile, filename, token, sizeof(filename));
+
+         if (access(filename, R_OK))
+           skip_test = 1;
+       }
+       else
+       {
+         print_fatal_error("Missing SKIP-IF-MISSING filename on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
       else if (!strcmp(token, "SKIP-IF-NOT-DEFINED"))
       {
        /*
@@ -1379,6 +1445,25 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
        continue;
       }
+      else if (!strcmp(token, "TEST-ID"))
+      {
+       /*
+       * TEST-ID "string"
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, test_id, temp, sizeof(test_id));
+       }
+       else
+       {
+         print_fatal_error("Missing TEST-ID value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       continue;
+      }
       else if (!strcmp(token, "TRANSFER"))
       {
        /*
@@ -1459,15 +1544,17 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         * Operation...
        */
 
-       if (!get_token(fp, token, sizeof(token), &linenum))
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("Missing OPERATION code on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
 
+       expand_variables(vars, token, temp, sizeof(token));
+
        if ((op = ippOpValue(token)) == (ipp_op_t)-1 &&
-           (op = strtol(token, NULL, 0)) == 0)
+           (op = (ipp_op_t)strtol(token, NULL, 0)) == 0)
        {
          print_fatal_error("Bad OPERATION code \"%s\" on line %d.", token,
                            linenum);
@@ -1508,13 +1595,15 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
         double delay;
 
-       if (!get_token(fp, token, sizeof(token), &linenum))
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("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)
        {
          print_fatal_error("Bad DELAY value \"%s\" on line %d.", token,
@@ -1527,7 +1616,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          if (Output == _CUPS_OUTPUT_TEST)
            printf("    [%g second delay]\n", delay);
 
-         usleep((int)(1000000.0 * delay));
+         usleep((useconds_t)(1000000.0 * delay));
        }
       }
       else if (!_cups_strcasecmp(token, "ATTR"))
@@ -1574,20 +1663,19 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
              if (!_cups_strcasecmp(token, "true"))
                attrptr = ippAddBoolean(request, group, attr, 1);
               else
-               attrptr = ippAddBoolean(request, group, attr, atoi(token));
+               attrptr = ippAddBoolean(request, group, attr, (char)atoi(token));
              break;
 
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
              if (!strchr(token, ','))
-               attrptr = ippAddInteger(request, group, value, attr,
-                                       strtol(token, &tokenptr, 0));
+               attrptr = ippAddInteger(request, group, value, attr, (int)strtol(token, &tokenptr, 0));
              else
              {
                int     values[100],    /* Values */
                        num_values = 1; /* Number of values */
 
-               values[0] = strtol(token, &tokenptr, 10);
+               values[0] = (int)strtol(token, &tokenptr, 10);
                while (tokenptr && *tokenptr &&
                       num_values < (int)(sizeof(values) / sizeof(values[0])))
                {
@@ -1596,7 +1684,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
                  else if (!isdigit(*tokenptr & 255) && *tokenptr != '-')
                    break;
 
-                 values[num_values] = strtol(tokenptr, &tokenptr, 0);
+                 values[num_values] = (int)strtol(tokenptr, &tokenptr, 0);
                  num_values ++;
                }
 
@@ -1618,11 +1706,11 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                        yres;           /* Y resolution */
                char    *ptr;           /* Pointer into value */
 
-               xres = yres = strtol(token, (char **)&ptr, 10);
+               xres = yres = (int)strtol(token, (char **)&ptr, 10);
                if (ptr > token && xres > 0)
                {
                  if (*ptr == 'x')
-                 yres = strtol(ptr + 1, (char **)&ptr, 10);
+                   yres = (int)strtol(ptr + 1, (char **)&ptr, 10);
                }
 
                if (ptr <= token || xres <= 0 || yres <= 0 || !ptr ||
@@ -1638,15 +1726,12 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                }
 
                if (!_cups_strcasecmp(ptr, "dpi"))
-                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_INCH,
-                                            xres, yres);
+                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_INCH, xres, yres);
                else if (!_cups_strcasecmp(ptr, "dpc") ||
                         !_cups_strcasecmp(ptr, "dpcm"))
-                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_CM,
-                                            xres, yres);
+                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_CM, xres, yres);
                else
-                 attrptr = ippAddResolution(request, group, attr, (ipp_res_t)0,
-                                            xres, yres);
+                 attrptr = ippAddResolution(request, group, attr, (ipp_res_t)0, xres, yres);
              }
              break;
 
@@ -1703,8 +1788,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
              break;
 
           case IPP_TAG_STRING :
-              attrptr = ippAddOctetString(request, group, attr, token,
-                                          strlen(token));
+              attrptr = ippAddOctetString(request, group, attr, token, (int)strlen(token));
              break;
 
          default :
@@ -1741,9 +1825,14 @@ do_tests(_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 ++;
+                 }
                }
 
                attrptr = ippAddStrings(request, group, value, attr, num_values,
@@ -1775,6 +1864,15 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
         expand_variables(vars, token, temp, sizeof(token));
        get_filename(testfile, filename, token, sizeof(filename));
+
+        if (access(filename, R_OK))
+        {
+         print_fatal_error("Filename \"%s\" on line %d cannot be read.",
+                           temp, linenum);
+         print_fatal_error("Filename mapped to \"%s\".", filename);
+         pass = 0;
+         goto test_exit;
+        }
       }
       else if (!_cups_strcasecmp(token, "STATUS"))
       {
@@ -1798,7 +1896,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        if ((statuses[num_statuses].status = ippErrorValue(token))
                == (ipp_status_t)-1 &&
-           (statuses[num_statuses].status = strtol(token, NULL, 0)) == 0)
+           (statuses[num_statuses].status = (ipp_status_t)strtol(token, NULL, 0)) == 0)
        {
          print_fatal_error("Bad STATUS code \"%s\" on line %d.", token,
                            linenum);
@@ -1809,6 +1907,8 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
         last_status = statuses + num_statuses;
        num_statuses ++;
 
+        last_status->define_match    = NULL;
+        last_status->define_no_match = NULL;
        last_status->if_defined      = NULL;
        last_status->if_not_defined  = NULL;
        last_status->repeat_limit    = 1000;
@@ -1892,10 +1992,12 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (last_expect)
          last_expect->define_match = strdup(token);
+       else if (last_status)
+         last_status->define_match = strdup(token);
        else
        {
-         print_fatal_error("DEFINE-MATCH without a preceding EXPECT on line "
-                           "%d.", linenum);
+         print_fatal_error("DEFINE-MATCH without a preceding EXPECT or STATUS "
+                           "on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1912,10 +2014,12 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
        if (last_expect)
          last_expect->define_no_match = strdup(token);
+       else if (last_status)
+         last_status->define_no_match = strdup(token);
        else
        {
-         print_fatal_error("DEFINE-NO-MATCH without a preceding EXPECT on "
-                           "line %d.", linenum);
+         print_fatal_error("DEFINE-NO-MATCH without a preceding EXPECT or "
+                           "STATUS on line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -1934,8 +2038,8 @@ 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 line "
-                           "%d.", linenum);
+         print_fatal_error("DEFINE-VALUE without a preceding EXPECT on "
+                           "line %d.", linenum);
          pass = 0;
          goto test_exit;
        }
@@ -2102,10 +2206,29 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        }
       }
       else if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+               !_cups_strcasecmp(token, "WITH-HOSTNAME") ||
+               !_cups_strcasecmp(token, "WITH-RESOURCE") ||
+               !_cups_strcasecmp(token, "WITH-SCHEME") ||
                !_cups_strcasecmp(token, "WITH-VALUE"))
       {
-       if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") && last_expect)
-         last_expect->with_flags = _CUPS_WITH_ALL;
+       if (last_expect)
+       {
+         if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+             !_cups_strcasecmp(token, "WITH-HOSTNAME"))
+           last_expect->with_flags = _CUPS_WITH_HOSTNAME;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+             !_cups_strcasecmp(token, "WITH-RESOURCE"))
+           last_expect->with_flags = _CUPS_WITH_RESOURCE;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+             !_cups_strcasecmp(token, "WITH-SCHEME"))
+           last_expect->with_flags = _CUPS_WITH_SCHEME;
+
+         if (!_cups_strncasecmp(token, "WITH-ALL-", 9))
+           last_expect->with_flags |= _CUPS_WITH_ALL;
+        }
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
@@ -2130,11 +2253,11 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
            * WITH-VALUE is a POSIX extended regular expression.
            */
 
-           last_expect->with_value = calloc(1, tokenptr - token);
+           last_expect->with_value = calloc(1, (size_t)(tokenptr - token));
            last_expect->with_flags |= _CUPS_WITH_REGEX;
 
            if (last_expect->with_value)
-             memcpy(last_expect->with_value, token + 1, tokenptr - token - 1);
+             memcpy(last_expect->with_value, token + 1, (size_t)(tokenptr - token - 1));
          }
          else
          {
@@ -2142,6 +2265,20 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
            * WITH-VALUE is a literal value...
            */
 
+           char *ptr;                  /* Pointer into value */
+
+            for (ptr = token; *ptr; ptr ++)
+            {
+             if (*ptr == '\\' && ptr[1])
+             {
+              /*
+               * Remove \ from \foo...
+               */
+
+               _cups_strcpy(ptr, ptr + 1);
+             }
+           }
+
            last_expect->with_value = strdup(token);
            last_expect->with_flags |= _CUPS_WITH_LITERAL;
          }
@@ -2192,24 +2329,38 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
     TestCount ++;
 
-    request->request.op.version[0]   = version / 10;
-    request->request.op.version[1]   = version % 10;
-    request->request.op.operation_id = op;
-    request->request.op.request_id   = request_id;
+    ippSetVersion(request, version / 10, version % 10);
+    ippSetOperation(request, op);
+    ippSetRequestId(request, request_id);
 
     if (Output == _CUPS_OUTPUT_PLIST)
     {
       puts("<dict>");
       puts("<key>Name</key>");
       print_xml_string("string", name);
+      if (file_id[0])
+      {
+       puts("<key>FileId</key>");
+       print_xml_string("string", file_id);
+      }
+      if (test_id[0])
+      {
+        puts("<key>TestId</key>");
+        print_xml_string("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>");
       if (request->attrs)
       {
        puts("<dict>");
-       for (attrptr = request->attrs, group = attrptr->group_tag;
+       for (attrptr = request->attrs,
+                group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
             attrptr;
             attrptr = attrptr->next)
          print_attr(attrptr, &group);
@@ -2245,8 +2396,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        puts("<key>StatusCode</key>");
        print_xml_string("string", "skip");
        puts("<key>ResponseAttributes</key>");
-       puts("<dict>");
-       puts("</dict>");
+       puts("<dict />");
       }
       else if (Output == _CUPS_OUTPUT_TEST)
        puts("SKIP]");
@@ -2288,7 +2438,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          */
 
          while ((bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
-           length += bytes;
+           length += (size_t)bytes;
 
          cupsFileClose(reqfile);
        }
@@ -2308,16 +2458,19 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          status = cupsSendRequest(http, request, resource, length);
 
+#ifdef HAVE_LIBZ
+         if (compression[0])
+           httpSetField(http, HTTP_FIELD_CONTENT_ENCODING, compression);
+#endif /* HAVE_LIBZ */
+
          if (!Cancel && status == HTTP_CONTINUE &&
              request->state == IPP_DATA && filename[0])
          {
            if ((reqfile = cupsFileOpen(filename, "r")) != NULL)
            {
              while (!Cancel &&
-                    (bytes = cupsFileRead(reqfile, buffer,
-                                          sizeof(buffer))) > 0)
-               if ((status = cupsWriteRequestData(http, buffer,
-                                                  bytes)) != HTTP_CONTINUE)
+                    (bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
+               if ((status = cupsWriteRequestData(http, buffer, (size_t)bytes)) != HTTP_CONTINUE)
                  break;
 
              cupsFileClose(reqfile);
@@ -2360,6 +2513,10 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
          else if (status != HTTP_OK)
          {
            httpFlush(http);
+
+           if (status == HTTP_STATUS_UNAUTHORIZED)
+             continue;
+
            break;
          }
        }
@@ -2559,7 +2716,8 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
 
        a = cupsArrayNew((cups_array_func_t)strcmp, NULL);
 
-       for (attrptr = response->attrs, group = attrptr->group_tag;
+       for (attrptr = response->attrs,
+                group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
             attrptr;
             attrptr = attrptr->next)
        {
@@ -2568,7 +2726,6 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
            int out_of_order = 0;       /* Are attribute groups out-of-order? */
            cupsArrayClear(a);
 
-
             switch (attrptr->group_tag)
             {
               case IPP_TAG_ZERO :
@@ -2646,11 +2803,23 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                repeat_count < statuses[i].repeat_limit)
              repeat_test = 1;
 
-           break;
+            if (statuses[i].define_match)
+              set_variable(vars, statuses[i].define_match, "1");
+
+            break;
          }
-         else if (statuses[i].repeat_no_match &&
-                  repeat_count < statuses[i].repeat_limit)
-           repeat_test = 1;
+         else
+         {
+           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;
+            }
+          }
        }
 
        if (i == num_statuses && num_statuses > 0)
@@ -2833,7 +3002,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
           fflush(stdout);
         }
 
-        sleep(repeat_interval);
+        sleep((unsigned)repeat_interval);
         repeat_interval = _cupsNextDelay(repeat_interval, &repeat_prev);
 
        if (Output == _CUPS_OUTPUT_TEST)
@@ -2965,7 +3134,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
     }
 
     if (num_displayed > 0 && !Verbosity && response &&
-        (Output == _CUPS_OUTPUT_TEST || Output == _CUPS_OUTPUT_PLIST))
+        Output == _CUPS_OUTPUT_TEST)
     {
       for (attrptr = response->attrs;
           attrptr != NULL;
@@ -3001,6 +3170,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);
     }
     num_statuses = 0;
 
@@ -3051,6 +3224,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);
   }
 
   for (i = num_expects, expect = expects; i > 0; i --, expect ++)
@@ -3171,7 +3348,7 @@ expand_variables(_cups_vars_t *vars,      /* I - Variables */
 
       if (value)
       {
-        strlcpy(dstptr, value, dstend - dstptr + 1);
+        strlcpy(dstptr, value, (size_t)(dstend - dstptr + 1));
        dstptr += strlen(dstptr);
       }
     }
@@ -3277,39 +3454,7 @@ get_collection(_cups_vars_t *vars,       /* I  - Variables */
                                        /* Collection value */
 
       if (subcol)
-      {
-       ipp_attribute_t *tempcol;       /* Pointer to new buffer */
-
-
-       /*
-       * Reallocate memory...
-       */
-
-       if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) +
-                                       (lastcol->num_values + 1) *
-                                       sizeof(_ipp_value_t))) == NULL)
-       {
-         print_fatal_error("Unable to allocate memory on line %d.", *linenum);
-         goto col_error;
-       }
-
-       if (tempcol != lastcol)
-       {
-        /*
-         * Reset pointers in the list...
-         */
-
-         if (col->prev)
-           col->prev->next = tempcol;
-         else
-           col->attrs = tempcol;
-
-         lastcol = col->current = col->last = tempcol;
-       }
-
-       lastcol->values[lastcol->num_values].collection = subcol;
-       lastcol->num_values ++;
-      }
+        ippSetCollection(col, &lastcol, ippGetCount(lastcol), subcol);
       else
        goto col_error;
     }
@@ -3354,7 +3499,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
            if (!_cups_strcasecmp(token, "true"))
              ippAddBoolean(col, IPP_TAG_ZERO, attr, 1);
            else
-             ippAddBoolean(col, IPP_TAG_ZERO, attr, atoi(token));
+             ippAddBoolean(col, IPP_TAG_ZERO, attr, (char)atoi(token));
            break;
 
        case IPP_TAG_INTEGER :
@@ -3380,15 +3525,12 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
              }
 
              if (!_cups_strcasecmp(units, "dpi"))
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                IPP_RES_PER_INCH);
+               ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_INCH, xres, yres);
              else if (!_cups_strcasecmp(units, "dpc") ||
                       !_cups_strcasecmp(units, "dpcm"))
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                IPP_RES_PER_CM);
+               ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_CM, xres, yres);
              else
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                (ipp_res_t)0);
+               ippAddResolution(col, IPP_TAG_ZERO, attr, (ipp_res_t)0, xres, yres);
            }
            break;
 
@@ -3437,6 +3579,9 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
              goto col_error;
            }
            break;
+       case IPP_TAG_STRING :
+           ippAddOctetString(col, IPP_TAG_ZERO, attr, token, (int)strlen(token));
+           break;
 
        default :
            if (!strchr(token, ','))
@@ -3534,13 +3679,60 @@ get_filename(const char *testfile,      /* I - Current test file */
     else
       dstptr = dst; /* Should never happen */
 
-    strlcpy(dstptr, src, dstsize - (dstptr - dst));
+    strlcpy(dstptr, src, dstsize - (size_t)(dstptr - dst));
   }
 
   return (dst);
 }
 
 
+/*
+ * 'get_string()' - Get a pointer to a string value or the portion of interest.
+ */
+
+static 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 */
+
+
+  ptr = attr->values[element].string.text;
+
+  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)
+      buffer[0] = '\0';
+
+    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)
+      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)
+      buffer[0] = '\0';
+
+    return (buffer);
+  }
+  else
+    return (ptr);
+}
+
+
 /*
  * 'get_token()' - Get a token from a file.
  */
@@ -3594,15 +3786,15 @@ get_token(FILE *fp,                     /* I  - File to read from */
          */
 
          if (bufptr < bufend)
-           *bufptr++ = ch;
+           *bufptr++ = (char)ch;
 
          if ((ch = getc(fp)) != EOF && bufptr < bufend)
-           *bufptr++ = ch;
+           *bufptr++ = (char)ch;
        }
        else if (ch == quote)
           break;
        else if (bufptr < bufend)
-          *bufptr++ = ch;
+          *bufptr++ = (char)ch;
       }
 
       *bufptr = '\0';
@@ -3636,7 +3828,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
        if (isspace(ch) || ch == '#')
           break;
        else if (bufptr < bufend)
-          *bufptr++ = ch;
+          *bufptr++ = (char)ch;
 
       if (ch == '#')
         ungetc(ch, fp);
@@ -3723,8 +3915,11 @@ print_attr(ipp_attribute_t *attr,        /* I  - Attribute to print */
   {
     if (!attr->name || (group && *group != attr->group_tag))
     {
-      puts("</dict>");
-      puts("<dict>");
+      if (attr->group_tag != IPP_TAG_ZERO)
+      {
+       puts("</dict>");
+       puts("<dict>");
+      }
 
       if (group)
         *group = attr->group_tag;
@@ -4225,6 +4420,8 @@ print_xml_header(void)
          "\"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" :
@@ -4422,14 +4619,35 @@ sigterm_handler(int sig)                /* I - Signal number (unused) */
  */
 
 static int                             /* O - 1 to continue, 0 to cancel */
-timeout_cb(http_t *http,               /* I - Connection to server (unused) */
+timeout_cb(http_t *http,               /* I - Connection to server */
            void   *user_data)          /* I - User data (unused) */
 {
-  (void)http;
+  int          buffered = 0;           /* Bytes buffered but not yet sent */
+
+
   (void)user_data;
 
- /* Always cancel on timeout */
-  return (0);
+  /*
+  * If the socket still have data waiting to be sent to the printer (as can
+  * happen if the printer runs out of paper), continue to wait until the output
+  * buffer is empty...
+  */
+
+#ifdef SO_NWRITE                       /* OS X and some versions of Linux */
+  socklen_t len = sizeof(buffered);    /* Size of return value */
+
+  if (getsockopt(httpGetFd(http), SOL_SOCKET, SO_NWRITE, &buffered, &len))
+    buffered = 0;
+
+#elif defined(SIOCOUTQ)                        /* Others except Windows */
+  if (ioctl(httpGetFd(http), SIOCOUTQ, &buffered))
+    buffered = 0;
+
+#else                                  /* Windows (not possible) */
+  (void)http;
+#endif /* SO_NWRITE */
+
+  return (buffered > 0);
 }
 
 
@@ -4546,7 +4764,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad boolen value %d "
-                       "(RFC 2911 section 4.1.10).", attr->name,
+                       "(RFC 2911 section 4.1.11).", attr->name,
                        attr->values[i].boolean);
          }
        }
@@ -4570,7 +4788,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
     case IPP_TAG_STRING :
         for (i = 0; i < attr->num_values; i ++)
        {
-         if (attr->values[i].unknown.length > 1023)
+         if (attr->values[i].unknown.length > IPP_MAX_OCTETSTRING)
          {
            valid = 0;
 
@@ -4593,7 +4811,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime month %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[2]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[2]);
          }
 
           if (date[3] < 1 || date[3] > 31)
@@ -4602,7 +4820,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime day %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[3]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[3]);
          }
 
           if (date[4] > 23)
@@ -4611,7 +4829,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime hours %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[4]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[4]);
          }
 
           if (date[5] > 59)
@@ -4620,7 +4838,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime minutes %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[5]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[5]);
          }
 
           if (date[6] > 60)
@@ -4629,7 +4847,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime seconds %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[6]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[6]);
          }
 
           if (date[7] > 9)
@@ -4638,7 +4856,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime deciseconds %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[7]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[7]);
          }
 
           if (date[8] != '-' && date[8] != '+')
@@ -4647,7 +4865,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime UTC sign '%c' "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[8]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[8]);
          }
 
           if (date[9] > 11)
@@ -4656,7 +4874,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime UTC hours %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[9]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[9]);
          }
 
           if (date[10] > 59)
@@ -4665,7 +4883,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad dateTime UTC minutes %u "
-                       "(RFC 2911 section 4.1.13).", attr->name, date[10]);
+                       "(RFC 2911 section 4.1.14).", attr->name, date[10]);
          }
        }
         break;
@@ -4680,7 +4898,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
            add_stringf(errors,
                        "\"%s\": Bad resolution value %dx%d%s - cross "
                        "feed resolution must be positive "
-                       "(RFC 2911 section 4.1.13).", attr->name,
+                       "(RFC 2911 section 4.1.15).", attr->name,
                        attr->values[i].resolution.xres,
                        attr->values[i].resolution.yres,
                        attr->values[i].resolution.units ==
@@ -4696,7 +4914,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
            add_stringf(errors,
                        "\"%s\": Bad resolution value %dx%d%s - feed "
                        "resolution must be positive "
-                       "(RFC 2911 section 4.1.13).", attr->name,
+                       "(RFC 2911 section 4.1.15).", attr->name,
                        attr->values[i].resolution.xres,
                        attr->values[i].resolution.yres,
                        attr->values[i].resolution.units ==
@@ -4712,7 +4930,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
 
            add_stringf(errors,
                        "\"%s\": Bad resolution value %dx%d%s - bad "
-                       "units value (RFC 2911 section 4.1.13).",
+                       "units value (RFC 2911 section 4.1.15).",
                        attr->name, attr->values[i].resolution.xres,
                        attr->values[i].resolution.yres,
                        attr->values[i].resolution.units ==
@@ -4813,7 +5031,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 1023)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_TEXT - 1))
          {
            valid = 0;
 
@@ -4873,7 +5091,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 1023)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_NAME - 1))
          {
            valid = 0;
 
@@ -4904,7 +5122,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 255)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_KEYWORD - 1))
          {
            valid = 0;
 
@@ -4935,11 +5153,10 @@ validate_attr(cups_array_t    *errors,  /* I - Errors array */
                        "\"%s\": Bad URI value \"%s\" - %s "
                        "(RFC 2911 section 4.1.5).", attr->name,
                        attr->values[i].string.text,
-                       URIStatusStrings[uri_status -
-                                        HTTP_URI_OVERFLOW]);
+                       httpURIStatusString(uri_status));
          }
 
-         if (strlen(attr->values[i].string.text) > 1023)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_URI - 1))
          {
            valid = 0;
 
@@ -4974,7 +5191,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 63)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_URISCHEME - 1))
          {
            valid = 0;
 
@@ -5005,7 +5222,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 40)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_CHARSET - 1))
          {
            valid = 0;
 
@@ -5061,7 +5278,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->name, attr->values[i].string.text);
          }
 
-         if (strlen(attr->values[i].string.text) > 63)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_LANGUAGE - 1))
          {
            valid = 0;
 
@@ -5114,7 +5331,7 @@ validate_attr(cups_array_t    *errors,    /* I - Errors array */
                        attr->name, attr->values[i].string.text);
          }
 
-         if (strlen(attr->values[i].string.text) > 255)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_MIMETYPE - 1))
          {
            valid = 0;
 
@@ -5151,7 +5368,8 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
 {
   int  i,                              /* Looping var */
        match;                          /* Match? */
-  char *valptr;                        /* Pointer into value */
+  char temp[1024],                     /* Temporary value string */
+       *valptr;                        /* Pointer into value */
 
 
   *matchbuf = '\0';
@@ -5196,7 +5414,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
             if (!*valptr)
              break;
 
-           intvalue = strtol(valptr, &nextptr, 0);
+           intvalue = (int)strtol(valptr, &nextptr, 0);
            if (nextptr == valptr)
              break;
            valptr = nextptr;
@@ -5206,8 +5424,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
                 (op == '>' && attr->values[i].integer > intvalue))
            {
              if (!matchbuf[0])
-               snprintf(matchbuf, matchlen, "%d",
-                        attr->values[i].integer);
+               snprintf(matchbuf, matchlen, "%d", attr->values[i].integer);
 
              valmatch = 1;
              break;
@@ -5262,7 +5479,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
             if (!*valptr)
              break;
 
-           intvalue = strtol(valptr, &nextptr, 0);
+           intvalue = (int)strtol(valptr, &nextptr, 0);
            if (nextptr == valptr)
              break;
            valptr = nextptr;
@@ -5335,6 +5552,63 @@ with_value(cups_array_t    *errors,      /* I - Errors array */
        }
        break;
 
+    case IPP_TAG_RESOLUTION :
+       for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].resolution.xres ==
+                 attr->values[i].resolution.yres)
+           snprintf(temp, sizeof(temp), "%d%s",
+                    attr->values[i].resolution.xres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+         else
+           snprintf(temp, sizeof(temp), "%dx%d%s",
+                    attr->values[i].resolution.xres,
+                    attr->values[i].resolution.yres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+
+          if (!strcmp(value, temp))
+          {
+            if (!matchbuf[0])
+             strlcpy(matchbuf, value, matchlen);
+
+           if (!(flags & _CUPS_WITH_ALL))
+           {
+             match = 1;
+             break;
+           }
+         }
+         else if (flags & _CUPS_WITH_ALL)
+         {
+           match = 0;
+           break;
+         }
+       }
+
+       if (!match && errors)
+       {
+         for (i = 0; i < attr->num_values; i ++)
+         {
+           if (attr->values[i].resolution.xres ==
+                   attr->values[i].resolution.yres)
+             snprintf(temp, sizeof(temp), "%d%s",
+                      attr->values[i].resolution.xres,
+                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                          "dpi" : "dpcm");
+           else
+             snprintf(temp, sizeof(temp), "%dx%d%s",
+                      attr->values[i].resolution.xres,
+                      attr->values[i].resolution.yres,
+                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                          "dpi" : "dpcm");
+
+            if (strcmp(value, temp))
+             add_stringf(errors, "GOT: %s=%s", attr->name, temp);
+         }
+       }
+       break;
+
     case IPP_TAG_NOVALUE :
     case IPP_TAG_UNKNOWN :
        return (1);
@@ -5359,8 +5633,6 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
 
           if ((i = regcomp(&re, value, REG_EXTENDED | REG_NOSUB)) != 0)
          {
-           char temp[256];             /* Temporary string */
-
             regerror(i, &re, temp, sizeof(temp));
 
            print_fatal_error("Unable to compile WITH-VALUE regular expression "
@@ -5374,10 +5646,13 @@ with_value(cups_array_t    *errors,     /* I - Errors array */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!regexec(&re, attr->values[i].string.text, 0, NULL, 0))
+           if (!regexec(&re, get_string(attr, i, flags, temp, sizeof(temp)),
+                        0, NULL, 0))
            {
              if (!matchbuf[0])
-               strlcpy(matchbuf, attr->values[i].string.text, matchlen);
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
 
              if (!(flags & _CUPS_WITH_ALL))
              {
@@ -5402,10 +5677,12 @@ with_value(cups_array_t    *errors,     /* I - Errors array */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!strcmp(value, attr->values[i].string.text))
+           if (!strcmp(value, get_string(attr, i, flags, temp, sizeof(temp))))
            {
              if (!matchbuf[0])
-               strlcpy(matchbuf, attr->values[i].string.text, matchlen);
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
 
              if (!(flags & _CUPS_WITH_ALL))
              {
@@ -5425,7 +5702,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
         {
          for (i = 0; i < attr->num_values; i ++)
            add_stringf(errors, "GOT: %s=\"%s\"", attr->name,
-                            attr->values[i].string.text);
+                       attr->values[i].string.text);
         }
        break;