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

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