Blame SOURCES/0001-Printing-to-old-CUPS-servers-has-been-fixed-Issue-52.patch

ce62dc
diff --git a/cups/cups-private.h b/cups/cups-private.h
ce62dc
index 6fd66a9..1f66fd7 100644
ce62dc
--- a/cups/cups-private.h
ce62dc
+++ b/cups/cups-private.h
ce62dc
@@ -237,13 +237,9 @@ extern void		_cupsBufferRelease(char *b);
ce62dc
 
ce62dc
 extern http_t		*_cupsConnect(void);
ce62dc
 extern char		*_cupsCreateDest(const char *name, const char *info, const char *device_id, const char *device_uri, char *uri, size_t urisize);
ce62dc
-extern int		_cupsGet1284Values(const char *device_id,
ce62dc
-			                   cups_option_t **values);
ce62dc
-extern const char	*_cupsGetDestResource(cups_dest_t *dest, char *resource,
ce62dc
-			                      size_t resourcesize);
ce62dc
-extern int		_cupsGetDests(http_t *http, ipp_op_t op,
ce62dc
-			              const char *name, cups_dest_t **dests,
ce62dc
-			              cups_ptype_t type, cups_ptype_t mask);
ce62dc
+extern int		_cupsGet1284Values(const char *device_id, cups_option_t **values);
ce62dc
+extern const char	*_cupsGetDestResource(cups_dest_t *dest, unsigned flags, char *resource, size_t resourcesize);
ce62dc
+extern int		_cupsGetDests(http_t *http, ipp_op_t op, const char *name, cups_dest_t **dests, cups_ptype_t type, cups_ptype_t mask);
ce62dc
 extern const char	*_cupsGetPassword(const char *prompt);
ce62dc
 extern void		_cupsGlobalLock(void);
ce62dc
 extern _cups_globals_t	*_cupsGlobals(void);
ce62dc
@@ -253,13 +249,10 @@ extern const char	*_cupsGSSServiceName(void);
ce62dc
 #  endif /* HAVE_GSSAPI */
ce62dc
 extern int		_cupsNextDelay(int current, int *previous);
ce62dc
 extern void		_cupsSetDefaults(void);
ce62dc
-extern void		_cupsSetError(ipp_status_t status, const char *message,
ce62dc
-			              int localize);
ce62dc
+extern void		_cupsSetError(ipp_status_t status, const char *message, int localize);
ce62dc
 extern void		_cupsSetHTTPError(http_status_t status);
ce62dc
 #  ifdef HAVE_GSSAPI
ce62dc
-extern int		_cupsSetNegotiateAuthString(http_t *http,
ce62dc
-			                            const char *method,
ce62dc
-						    const char *resource);
ce62dc
+extern int		_cupsSetNegotiateAuthString(http_t *http, const char *method, const char *resource);
ce62dc
 #  endif /* HAVE_GSSAPI */
ce62dc
 extern char		*_cupsUserDefault(char *name, size_t namesize);
ce62dc
 
ce62dc
diff --git a/cups/dest-options.c b/cups/dest-options.c
ce62dc
index 51705a5..cfa28ce 100644
ce62dc
--- a/cups/dest-options.c
ce62dc
+++ b/cups/dest-options.c
ce62dc
@@ -572,6 +572,7 @@ cupsCopyDestInfo(
ce62dc
     cups_dest_t *dest)			/* I - Destination */
ce62dc
 {
ce62dc
   cups_dinfo_t	*dinfo;			/* Destination information */
ce62dc
+  unsigned	dflags;			/* Destination flags */
ce62dc
   ipp_t		*request,		/* Get-Printer-Attributes request */
ce62dc
 		*response;		/* Supported attributes */
ce62dc
   int		tries,			/* Number of tries so far */
ce62dc
@@ -581,6 +582,7 @@ cupsCopyDestInfo(
ce62dc
   char		resource[1024];		/* Resource path */
ce62dc
   int		version;		/* IPP version */
ce62dc
   ipp_status_t	status;			/* Status of request */
ce62dc
+  _cups_globals_t *cg = _cupsGlobals();	/* Pointer to library globals */
ce62dc
   static const char * const requested_attrs[] =
ce62dc
   {					/* Requested attributes */
ce62dc
     "job-template",
ce62dc
@@ -589,14 +591,25 @@ cupsCopyDestInfo(
ce62dc
   };
ce62dc
 
ce62dc
 
ce62dc
-  DEBUG_printf(("cupsCopyDestSupported(http=%p, dest=%p(%s))", (void *)http, (void *)dest, dest ? dest->name : ""));
ce62dc
+  DEBUG_printf(("cupsCopyDestInfo(http=%p, dest=%p(%s))", (void *)http, (void *)dest, dest ? dest->name : ""));
ce62dc
 
ce62dc
  /*
ce62dc
   * Get the default connection as needed...
ce62dc
   */
ce62dc
 
ce62dc
   if (!http)
ce62dc
-    http = _cupsConnect();
ce62dc
+  {
ce62dc
+    http   = _cupsConnect();
ce62dc
+    dflags = CUPS_DEST_FLAGS_NONE;
ce62dc
+  }
ce62dc
+#ifdef AF_LOCAL
ce62dc
+  else if (strcmp(http->hostname, cg->server) || (httpAddrFamily(http->hostaddr) != AF_LOCAL && cg->ipp_port != httpAddrPort(http->hostaddr)))
ce62dc
+#else
ce62dc
+  else if (strcmp(http->hostname, cg->server) || cg->ipp_port != httpAddrPort(http->hostaddr))
ce62dc
+#endif /* AF_LOCAL */
ce62dc
+    dflags = CUPS_DEST_FLAGS_DEVICE;
ce62dc
+  else
ce62dc
+    dflags = CUPS_DEST_FLAGS_NONE;
ce62dc
 
ce62dc
  /*
ce62dc
   * Range check input...
ce62dc
@@ -609,8 +622,11 @@ cupsCopyDestInfo(
ce62dc
   * Get the printer URI and resource path...
ce62dc
   */
ce62dc
 
ce62dc
-  if ((uri = _cupsGetDestResource(dest, resource, sizeof(resource))) == NULL)
ce62dc
+  if ((uri = _cupsGetDestResource(dest, dflags, resource, sizeof(resource))) == NULL)
ce62dc
+  {
ce62dc
+    DEBUG_puts("1cupsCopyDestInfo: Unable to get resource.");
ce62dc
     return (NULL);
ce62dc
+  }
ce62dc
 
ce62dc
  /*
ce62dc
   * Get the supported attributes...
ce62dc
@@ -628,28 +644,25 @@ cupsCopyDestInfo(
ce62dc
     */
ce62dc
 
ce62dc
     request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
ce62dc
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
ce62dc
-		 uri);
ce62dc
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
ce62dc
-                 "requesting-user-name", NULL, cupsUser());
ce62dc
-    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
ce62dc
-		  "requested-attributes",
ce62dc
-		  (int)(sizeof(requested_attrs) / sizeof(requested_attrs[0])),
ce62dc
-		  NULL, requested_attrs);
ce62dc
+
ce62dc
+    ippSetVersion(request, version / 10, version % 10);
ce62dc
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
ce62dc
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
ce62dc
+    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(requested_attrs) / sizeof(requested_attrs[0])), NULL, requested_attrs);
ce62dc
     response = cupsDoRequest(http, request, resource);
ce62dc
     status   = cupsLastError();
ce62dc
 
ce62dc
     if (status > IPP_STATUS_OK_IGNORED_OR_SUBSTITUTED)
ce62dc
     {
ce62dc
-      DEBUG_printf(("cupsCopyDestSupported: Get-Printer-Attributes for '%s' "
ce62dc
-		    "returned %s (%s)", dest->name, ippErrorString(status),
ce62dc
-		    cupsLastErrorString()));
ce62dc
+      DEBUG_printf(("1cupsCopyDestInfo: Get-Printer-Attributes for '%s' returned %s (%s)", dest->name, ippErrorString(status), cupsLastErrorString()));
ce62dc
 
ce62dc
       ippDelete(response);
ce62dc
       response = NULL;
ce62dc
 
ce62dc
-      if (status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED && version > 11)
ce62dc
+      if ((status == IPP_STATUS_ERROR_BAD_REQUEST || status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) && version > 11)
ce62dc
+      {
ce62dc
         version = 11;
ce62dc
+      }
ce62dc
       else if (status == IPP_STATUS_ERROR_BUSY)
ce62dc
       {
ce62dc
         sleep((unsigned)delay);
ce62dc
@@ -665,7 +678,10 @@ cupsCopyDestInfo(
ce62dc
   while (!response && tries < 10);
ce62dc
 
ce62dc
   if (!response)
ce62dc
+  {
ce62dc
+    DEBUG_puts("1cupsCopyDestInfo: Unable to get printer attributes.");
ce62dc
     return (NULL);
ce62dc
+  }
ce62dc
 
ce62dc
  /*
ce62dc
   * Allocate a cups_dinfo_t structure and return it...
ce62dc
@@ -678,6 +694,8 @@ cupsCopyDestInfo(
ce62dc
     return (NULL);
ce62dc
   }
ce62dc
 
ce62dc
+  DEBUG_printf(("1cupsCopyDestInfo: version=%d, uri=\"%s\", resource=\"%s\".", version, uri, resource));
ce62dc
+
ce62dc
   dinfo->version  = version;
ce62dc
   dinfo->uri      = uri;
ce62dc
   dinfo->resource = _cupsStrAlloc(resource);
ce62dc
diff --git a/cups/dest.c b/cups/dest.c
ce62dc
index 57a8dc9..3537572 100644
ce62dc
--- a/cups/dest.c
ce62dc
+++ b/cups/dest.c
ce62dc
@@ -1103,13 +1103,16 @@ cupsGetDest(const char  *name,		/* I - Destination name or @code NULL@ for the d
ce62dc
  * '_cupsGetDestResource()' - Get the resource path and URI for a destination.
ce62dc
  */
ce62dc
 
ce62dc
-const char *				/* O - Printer URI */
ce62dc
+const char *				/* O - URI */
ce62dc
 _cupsGetDestResource(
ce62dc
     cups_dest_t *dest,			/* I - Destination */
ce62dc
+    unsigned    flags,			/* I - Destination flags */
ce62dc
     char        *resource,		/* I - Resource buffer */
ce62dc
     size_t      resourcesize)		/* I - Size of resource buffer */
ce62dc
 {
ce62dc
-  const char	*uri;			/* Printer URI */
ce62dc
+  const char	*uri,			/* URI */
ce62dc
+		*device_uri,		/* Device URI */
ce62dc
+		*printer_uri;		/* Printer URI */
ce62dc
   char		scheme[32],		/* URI scheme */
ce62dc
 		userpass[256],		/* Username and password (unused) */
ce62dc
 		hostname[256];		/* Hostname */
ce62dc
@@ -1132,25 +1135,46 @@ _cupsGetDestResource(
ce62dc
   }
ce62dc
 
ce62dc
  /*
ce62dc
-  * Grab the printer URI...
ce62dc
+  * Grab the printer and device URIs...
ce62dc
   */
ce62dc
 
ce62dc
-  if ((uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options)) == NULL)
ce62dc
+  device_uri  = cupsGetOption("device-uri", dest->num_options, dest->options);
ce62dc
+  printer_uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);
ce62dc
+
ce62dc
+  DEBUG_printf(("1_cupsGetDestResource: device-uri=\"%s\", printer-uri-supported=\"%s\".", device_uri, printer_uri));
ce62dc
+
ce62dc
+#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
ce62dc
+  if (((flags & CUPS_DEST_FLAGS_DEVICE) || !printer_uri) && strstr(device_uri, "._tcp"))
ce62dc
   {
ce62dc
-    if ((uri = cupsGetOption("device-uri", dest->num_options, dest->options)) != NULL)
ce62dc
+    if ((device_uri = cups_dnssd_resolve(dest, device_uri, 5000, NULL, NULL, NULL)) != NULL)
ce62dc
     {
ce62dc
-#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
ce62dc
-      if (strstr(uri, "._tcp"))
ce62dc
-        uri = cups_dnssd_resolve(dest, uri, 5000, NULL, NULL, NULL);
ce62dc
-#endif /* HAVE_DNSSD || HAVE_AVAHI */
ce62dc
+      DEBUG_printf(("1_cupsGetDestResource: Resolved device-uri=\"%s\".", device_uri));
ce62dc
     }
ce62dc
-
ce62dc
-    if (uri)
ce62dc
+    else
ce62dc
     {
ce62dc
-      DEBUG_printf(("1_cupsGetDestResource: Resolved printer-uri-supported=\"%s\"", uri));
ce62dc
+      DEBUG_puts("1_cupsGetDestResource: Unable to resolve device.");
ce62dc
 
ce62dc
-      uri = _cupsCreateDest(dest->name, cupsGetOption("printer-info", dest->num_options, dest->options), NULL, uri, resource, resourcesize);
ce62dc
+      if (resource)
ce62dc
+	*resource = '\0';
ce62dc
+
ce62dc
+      _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
ce62dc
+
ce62dc
+      return (NULL);
ce62dc
     }
ce62dc
+  }
ce62dc
+#endif /* HAVE_DNSSD || HAVE_AVAHI */
ce62dc
+
ce62dc
+  if (flags & CUPS_DEST_FLAGS_DEVICE)
ce62dc
+  {
ce62dc
+    uri = device_uri;
ce62dc
+  }
ce62dc
+  else if (printer_uri)
ce62dc
+  {
ce62dc
+    uri = printer_uri;
ce62dc
+  }
ce62dc
+  else
ce62dc
+  {
ce62dc
+    uri = _cupsCreateDest(dest->name, cupsGetOption("printer-info", dest->num_options, dest->options), NULL, device_uri, resource, resourcesize);
ce62dc
 
ce62dc
     if (uri)
ce62dc
     {
ce62dc
@@ -1160,30 +1184,24 @@ _cupsGetDestResource(
ce62dc
 
ce62dc
       uri = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);
ce62dc
     }
ce62dc
-    else
ce62dc
-    {
ce62dc
-      DEBUG_puts("1_cupsGetDestResource: No printer-uri-supported found.");
ce62dc
+  }
ce62dc
 
ce62dc
-      if (resource)
ce62dc
-        *resource = '\0';
ce62dc
+  if (!uri)
ce62dc
+  {
ce62dc
+    DEBUG_puts("1_cupsGetDestResource: No printer-uri-supported or device-uri found.");
ce62dc
 
ce62dc
-      _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
ce62dc
+    if (resource)
ce62dc
+      *resource = '\0';
ce62dc
 
ce62dc
-      return (NULL);
ce62dc
-    }
ce62dc
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOENT), 0);
ce62dc
+
ce62dc
+    return (NULL);
ce62dc
   }
ce62dc
-  else
ce62dc
+  else if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, (int)resourcesize) < HTTP_URI_STATUS_OK)
ce62dc
   {
ce62dc
-    DEBUG_printf(("1_cupsGetDestResource: printer-uri-supported=\"%s\"", uri));
ce62dc
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad URI."), 1);
ce62dc
 
ce62dc
-    if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
ce62dc
-                        userpass, sizeof(userpass), hostname, sizeof(hostname),
ce62dc
-                        &port, resource, (int)resourcesize) < HTTP_URI_STATUS_OK)
ce62dc
-    {
ce62dc
-      _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad printer-uri."), 1);
ce62dc
-
ce62dc
-      return (NULL);
ce62dc
-    }
ce62dc
+    return (NULL);
ce62dc
   }
ce62dc
 
ce62dc
   DEBUG_printf(("1_cupsGetDestResource: resource=\"%s\"", resource));
ce62dc
diff --git a/cups/testdest.c b/cups/testdest.c
ce62dc
index c5c2052..27060f6 100644
ce62dc
--- a/cups/testdest.c
ce62dc
+++ b/cups/testdest.c
ce62dc
@@ -43,9 +43,12 @@ int					/* O - Exit status */
ce62dc
 main(int  argc,				/* I - Number of command-line arguments */
ce62dc
      char *argv[])			/* I - Command-line arguments */
ce62dc
 {
ce62dc
+  int		i;			/* Looping var */
ce62dc
   http_t	*http;			/* Connection to destination */
ce62dc
   cups_dest_t	*dest = NULL;		/* Destination */
ce62dc
   cups_dinfo_t	*dinfo;			/* Destination info */
ce62dc
+  unsigned	dflags = CUPS_DEST_FLAGS_NONE;
ce62dc
+					/* Destination flags */
ce62dc
 
ce62dc
 
ce62dc
   if (argc < 2)
ce62dc
@@ -103,9 +106,17 @@ main(int  argc,				/* I - Number of command-line arguments */
ce62dc
 
ce62dc
     return (0);
ce62dc
   }
ce62dc
-  else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7))
ce62dc
-    dest = cupsGetDestWithURI(NULL, argv[1]);
ce62dc
-  else if (!strcmp(argv[1], "default"))
ce62dc
+
ce62dc
+  i = 1;
ce62dc
+  if (!strcmp(argv[i], "--device"))
ce62dc
+  {
ce62dc
+    dflags = CUPS_DEST_FLAGS_DEVICE;
ce62dc
+    i ++;
ce62dc
+  }
ce62dc
+
ce62dc
+  if (!strncmp(argv[i], "ipp://", 6) || !strncmp(argv[i], "ipps://", 7))
ce62dc
+    dest = cupsGetDestWithURI(NULL, argv[i]);
ce62dc
+  else if (!strcmp(argv[i], "default"))
ce62dc
   {
ce62dc
     dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
ce62dc
     if (dest && dest->instance)
ce62dc
@@ -114,67 +125,70 @@ main(int  argc,				/* I - Number of command-line arguments */
ce62dc
       printf("default is \"%s\".\n", dest->name);
ce62dc
   }
ce62dc
   else
ce62dc
-    dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[1], NULL);
ce62dc
+    dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[i], NULL);
ce62dc
 
ce62dc
   if (!dest)
ce62dc
   {
ce62dc
-    printf("testdest: Unable to get destination \"%s\": %s\n", argv[1], cupsLastErrorString());
ce62dc
+    printf("testdest: Unable to get destination \"%s\": %s\n", argv[i], cupsLastErrorString());
ce62dc
     return (1);
ce62dc
   }
ce62dc
 
ce62dc
-  if ((http = cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE, 30000, NULL, NULL, 0, NULL, NULL)) == NULL)
ce62dc
+  i ++;
ce62dc
+
ce62dc
+  if ((http = cupsConnectDest(dest, dflags, 30000, NULL, NULL, 0, NULL, NULL)) == NULL)
ce62dc
   {
ce62dc
-    printf("testdest: Unable to connect to destination \"%s\": %s\n", argv[1], cupsLastErrorString());
ce62dc
+    printf("testdest: Unable to connect to destination \"%s\": %s\n", dest->name, cupsLastErrorString());
ce62dc
     return (1);
ce62dc
   }
ce62dc
 
ce62dc
   if ((dinfo = cupsCopyDestInfo(http, dest)) == NULL)
ce62dc
   {
ce62dc
-    printf("testdest: Unable to get information for destination \"%s\": %s\n", argv[1], cupsLastErrorString());
ce62dc
+    printf("testdest: Unable to get information for destination \"%s\": %s\n", dest->name, cupsLastErrorString());
ce62dc
     return (1);
ce62dc
   }
ce62dc
 
ce62dc
-  if (argc == 2 || (!strcmp(argv[2], "supported") && argc < 6))
ce62dc
+  if (i == argc || !strcmp(argv[i], "supported"))
ce62dc
   {
ce62dc
-    if (argc > 3)
ce62dc
-      show_supported(http, dest, dinfo, argv[3], argv[4]);
ce62dc
+    i ++;
ce62dc
+
ce62dc
+    if ((i + 1) < argc)
ce62dc
+      show_supported(http, dest, dinfo, argv[i], argv[i + 1]);
ce62dc
     else if (argc > 2)
ce62dc
-      show_supported(http, dest, dinfo, argv[3], NULL);
ce62dc
+      show_supported(http, dest, dinfo, argv[i], NULL);
ce62dc
     else
ce62dc
       show_supported(http, dest, dinfo, NULL, NULL);
ce62dc
   }
ce62dc
-  else if (!strcmp(argv[2], "conflicts") && argc > 3)
ce62dc
+  else if (!strcmp(argv[i], "conflicts") && (i + 1) < argc)
ce62dc
   {
ce62dc
-    int			i,		/* Looping var */
ce62dc
-			num_options = 0;/* Number of options */
ce62dc
+    int			num_options = 0;/* Number of options */
ce62dc
     cups_option_t	*options = NULL;/* Options */
ce62dc
 
ce62dc
-    for (i = 3; i < argc; i ++)
ce62dc
+    for (i ++; i < argc; i ++)
ce62dc
       num_options = cupsParseOptions(argv[i], num_options, &options);
ce62dc
 
ce62dc
     show_conflicts(http, dest, dinfo, num_options, options);
ce62dc
   }
ce62dc
-  else if (!strcmp(argv[2], "default") && argc == 4)
ce62dc
+  else if (!strcmp(argv[i], "default") && (i + 1) < argc)
ce62dc
   {
ce62dc
-    show_default(http, dest, dinfo, argv[3]);
ce62dc
+    show_default(http, dest, dinfo, argv[i + 1]);
ce62dc
   }
ce62dc
-  else if (!strcmp(argv[2], "localize") && argc < 6)
ce62dc
+  else if (!strcmp(argv[i], "localize"))
ce62dc
   {
ce62dc
-    if (argc > 3)
ce62dc
-      localize(http, dest, dinfo, argv[3], argv[4]);
ce62dc
+    i ++;
ce62dc
+    if ((i + 1) < argc)
ce62dc
+      localize(http, dest, dinfo, argv[i], argv[i + 1]);
ce62dc
     else if (argc > 2)
ce62dc
-      localize(http, dest, dinfo, argv[3], NULL);
ce62dc
+      localize(http, dest, dinfo, argv[i], NULL);
ce62dc
     else
ce62dc
       localize(http, dest, dinfo, NULL, NULL);
ce62dc
   }
ce62dc
-  else if (!strcmp(argv[2], "media"))
ce62dc
+  else if (!strcmp(argv[i], "media"))
ce62dc
   {
ce62dc
-    int		i;			/* Looping var */
ce62dc
     const char	*name = NULL;		/* Media name, if any */
ce62dc
     unsigned	flags = CUPS_MEDIA_FLAGS_DEFAULT;
ce62dc
 					/* Media selection flags */
ce62dc
 
ce62dc
-    for (i = 3; i < argc; i ++)
ce62dc
+    for (i ++; i < argc; i ++)
ce62dc
     {
ce62dc
       if (!strcmp(argv[i], "borderless"))
ce62dc
 	flags = CUPS_MEDIA_FLAGS_BORDERLESS;
ce62dc
@@ -192,19 +206,19 @@ main(int  argc,				/* I - Number of command-line arguments */
ce62dc
 
ce62dc
     show_media(http, dest, dinfo, flags, name);
ce62dc
   }
ce62dc
-  else if (!strcmp(argv[2], "print") && argc > 3)
ce62dc
+  else if (!strcmp(argv[i], "print") && (i + 1) < argc)
ce62dc
   {
ce62dc
-    int			i,		/* Looping var */
ce62dc
-			num_options = 0;/* Number of options */
ce62dc
+    int			num_options = 0;/* Number of options */
ce62dc
     cups_option_t	*options = NULL;/* Options */
ce62dc
+    const char		*filename = argv[i + 1];
ce62dc
 
ce62dc
-    for (i = 4; i < argc; i ++)
ce62dc
+    for (i += 2; i < argc; i ++)
ce62dc
       num_options = cupsParseOptions(argv[i], num_options, &options);
ce62dc
 
ce62dc
-    print_file(http, dest, dinfo, argv[3], num_options, options);
ce62dc
+    print_file(http, dest, dinfo, filename, num_options, options);
ce62dc
   }
ce62dc
   else
ce62dc
-    usage(argv[2]);
ce62dc
+    usage(argv[i]);
ce62dc
 
ce62dc
   return (0);
ce62dc
 }
ce62dc
@@ -740,9 +754,9 @@ usage(const char *arg)			/* I - Argument for usage message */
ce62dc
     printf("testdest: Unknown option \"%s\".\n", arg);
ce62dc
 
ce62dc
   puts("Usage:");
ce62dc
-  puts("  ./testdest name [operation ...]");
ce62dc
-  puts("  ./testdest ipp://... [operation ...]");
ce62dc
-  puts("  ./testdest ipps://... [operation ...]");
ce62dc
+  puts("  ./testdest [--device] name [operation ...]");
ce62dc
+  puts("  ./testdest [--device] ipp://... [operation ...]");
ce62dc
+  puts("  ./testdest [--device] ipps://... [operation ...]");
ce62dc
   puts("  ./testdest --enum [grayscale] [color] [duplex] [staple] [small]\n"
ce62dc
        "                    [medium] [large]");
ce62dc
   puts("");
ce62dc
diff --git a/test/ippserver.c b/test/ippserver.c
ce62dc
index 38b304f..c593d3a 100644
ce62dc
--- a/test/ippserver.c
ce62dc
+++ b/test/ippserver.c
ce62dc
@@ -461,6 +461,7 @@ static AvahiClient	*DNSSDClient = NULL;
ce62dc
 #endif /* HAVE_DNSSD */
ce62dc
 
ce62dc
 static int		KeepFiles = 0,
ce62dc
+			MaxVersion = 20,
ce62dc
 			Verbosity = 0;
ce62dc
 
ce62dc
 
ce62dc
@@ -533,6 +534,23 @@ main(int  argc,				/* I - Number of command-line args */
ce62dc
               pin = 1;
ce62dc
               break;
ce62dc
 
ce62dc
+          case 'V' : /* -V max-version */
ce62dc
+	      i ++;
ce62dc
+	      if (i >= argc)
ce62dc
+	        usage(1);
ce62dc
+
ce62dc
+              if (!strcmp(argv[i], "2.2"))
ce62dc
+                MaxVersion = 22;
ce62dc
+	      else if (!strcmp(argv[i], "2.1"))
ce62dc
+                MaxVersion = 21;
ce62dc
+	      else if (!strcmp(argv[i], "2.0"))
ce62dc
+                MaxVersion = 20;
ce62dc
+	      else if (!strcmp(argv[i], "1.1"))
ce62dc
+                MaxVersion = 11;
ce62dc
+	      else
ce62dc
+	        usage(1);
ce62dc
+              break;
ce62dc
+
ce62dc
 	  case 'a' : /* -a attributes-file */
ce62dc
 	      i ++;
ce62dc
 	      if (i >= argc)
ce62dc
@@ -1324,9 +1342,10 @@ create_printer(const char *servername,	/* I - Server hostname (NULL for default)
ce62dc
   };
ce62dc
   static const char * const versions[] =/* ipp-versions-supported values */
ce62dc
   {
ce62dc
-    "1.0",
ce62dc
     "1.1",
ce62dc
-    "2.0"
ce62dc
+    "2.0",
ce62dc
+    "2.1",
ce62dc
+    "2.2"
ce62dc
   };
ce62dc
   static const char * const features[] =/* ipp-features-supported values */
ce62dc
   {
ce62dc
@@ -1738,7 +1757,12 @@ create_printer(const char *servername,	/* I - Server hostname (NULL for default)
ce62dc
 
ce62dc
   /* ipp-versions-supported */
ce62dc
   if (!ippFindAttribute(printer->attrs, "ipp-versions-supported", IPP_TAG_ZERO))
ce62dc
-    ippAddStrings(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]), NULL, versions);
ce62dc
+  {
ce62dc
+    int num_versions = MaxVersion == 11 ? 1 : MaxVersion == 20 ? 2 : MaxVersion == 21 ? 3 : 4;
ce62dc
+					/* Number of supported versions */
ce62dc
+
ce62dc
+    ippAddStrings(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "ipp-versions-supported", num_versions, NULL, versions);
ce62dc
+  }
ce62dc
 
ce62dc
   /* job-account-id-default */
ce62dc
   if (!ippFindAttribute(printer->attrs, "job-account-id-default", IPP_TAG_ZERO))
ce62dc
@@ -5800,15 +5824,24 @@ process_ipp(_ipp_client_t *client)	/* I - Client */
ce62dc
     * Return an error, since we only support IPP 1.x and 2.x.
ce62dc
     */
ce62dc
 
ce62dc
-    respond_ipp(client, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED,
ce62dc
-                "Bad request version number %d.%d.", major, minor);
ce62dc
+    respond_ipp(client, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED, "Bad request version number %d.%d.", major, minor);
ce62dc
+  }
ce62dc
+  else if ((major * 10 + minor) > MaxVersion)
ce62dc
+  {
ce62dc
+    if (httpGetState(client->http) != HTTP_STATE_POST_SEND)
ce62dc
+      httpFlush(client->http);		/* Flush trailing (junk) data */
ce62dc
+
ce62dc
+    respond_http(client, HTTP_STATUS_BAD_REQUEST, NULL, NULL, 0);
ce62dc
+    return (0);
ce62dc
   }
ce62dc
   else if (ippGetRequestId(client->request) <= 0)
ce62dc
-    respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "Bad request-id %d.",
ce62dc
-                ippGetRequestId(client->request));
ce62dc
+  {
ce62dc
+    respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "Bad request-id %d.", ippGetRequestId(client->request));
ce62dc
+  }
ce62dc
   else if (!ippFirstAttribute(client->request))
ce62dc
-    respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST,
ce62dc
-                "No attributes in request.");
ce62dc
+  {
ce62dc
+    respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "No attributes in request.");
ce62dc
+  }
ce62dc
   else
ce62dc
   {
ce62dc
    /*
ce62dc
@@ -6877,8 +6910,7 @@ usage(int status)			/* O - Exit status */
ce62dc
 {
ce62dc
   if (!status)
ce62dc
   {
ce62dc
-    puts(CUPS_SVERSION " - Copyright 2010-2015 by Apple Inc. All rights "
ce62dc
-         "reserved.");
ce62dc
+    puts(CUPS_SVERSION " - Copyright (c) 2010-2018 by Apple Inc. All rights reserved.");
ce62dc
     puts("");
ce62dc
   }
ce62dc
 
ce62dc
@@ -6888,6 +6920,7 @@ usage(int status)			/* O - Exit status */
ce62dc
   puts("-2                      Supports 2-sided printing (default=1-sided)");
ce62dc
   puts("-M manufacturer         Manufacturer name (default=Test)");
ce62dc
   puts("-P                      PIN printing mode");
ce62dc
+  puts("-V max-version          Set maximum supported IPP version");
ce62dc
   puts("-a attributes-file      Load printer attributes from file");
ce62dc
   puts("-c command              Run command for every print job");
ce62dc
   printf("-d spool-directory      Spool directory "