]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpstat.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / systemv / lpstat.c
index ba63ae2c6815a0af78521f8f9e033d4e40d12605..96d4acc85756a0bb129888c5e0d874ef3285587c 100644 (file)
@@ -1,60 +1,37 @@
 /*
- * "$Id: lpstat.c 7620 2008-06-06 17:24:22Z mike $"
+ * "lpstat" command for CUPS.
  *
- *   "lpstat" command for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007 by Apple Inc.
- *   Copyright 1997-2006 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/".
- *
- * Contents:
- *
- *   main()           - Parse options and show status information.
- *   check_dest()     - Verify that the named destination(s) exists.
- *   connect_server() - Connect to the server as necessary...
- *   show_accepting() - Show acceptance status.
- *   show_classes()   - Show printer classes.
- *   show_default()   - Show default destination.
- *   show_devices()   - Show printer devices.
- *   show_jobs()      - Show active print jobs.
- *   show_printers()  - Show printers.
- *   show_scheduler() - Show scheduler status.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <cups/http-private.h>
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/debug.h>
+#include <cups/cups-private.h>
 
 
 /*
  * Local functions...
  */
 
-static void    check_dest(const char *, http_t *, const char *, int *,
-                          cups_dest_t **);
-static http_t  *connect_server(const char *, http_t *);
-static int     show_accepting(http_t *, const char *, int, cups_dest_t *);
-static int     show_classes(http_t *, const char *);
-static void    show_default(int, cups_dest_t *);
-static int     show_devices(http_t *, const char *, int, cups_dest_t *);
-static int     show_jobs(http_t *, const char *, const char *, int, int,
-                         const char *);
-static int     show_printers(http_t *, const char *, int, cups_dest_t *, int);
-static void    show_scheduler(http_t *);
+static void    check_dest(const char *command, const char *name,
+                          int *num_dests, cups_dest_t **dests);
+static int     match_list(const char *list, const char *name);
+static int     show_accepting(const char *printers, int num_dests,
+                              cups_dest_t *dests);
+static int     show_classes(const char *dests);
+static void    show_default(cups_dest_t *dest);
+static int     show_devices(const char *printers, int num_dests,
+                            cups_dest_t *dests);
+static int     show_jobs(const char *dests, const char *users, int long_status,
+                         int ranking, const char *which);
+static int     show_printers(const char *printers, int num_dests,
+                             cups_dest_t *dests, int long_status);
+static void    show_scheduler(void);
 
 
 /*
@@ -67,7 +44,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
 {
   int          i,                      /* Looping var */
                status;                 /* Exit status */
-  http_t       *http;                  /* Connection to server */
+  char         *opt;                   /* Option pointer */
   int          num_dests;              /* Number of user destinations */
   cups_dest_t  *dests;                 /* User destinations */
   int          long_status;            /* Long status report? */
@@ -82,7 +59,6 @@ main(int  argc,                               /* I - Number of command-line arguments */
   * Parse command-line options...
   */
 
-  http        = NULL;
   num_dests   = 0;
   dests       = NULL;
   long_status = 0;
@@ -92,384 +68,432 @@ main(int  argc,                           /* I - Number of command-line arguments */
   op          = 0;
 
   for (i = 1; i < argc; i ++)
+  {
     if (argv[i][0] == '-')
-      switch (argv[i][1])
+    {
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'D' : /* Show description */
-           long_status = 1;
-           break;
+       switch (*opt)
+       {
+         case 'D' : /* Show description */
+             long_status = 1;
+             break;
 
-        case 'E' : /* Encrypt */
+         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
-
-           if (http)
-             httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr,
-                           _("%s: Sorry, no encryption support compiled in!\n"),
-                           argv[0]);
+             _cupsLangPrintf(stderr,
+                             _("%s: Sorry, no encryption support."),
+                             argv[0]);
 #endif /* HAVE_SSL */
-           break;
+             break;
 
-        case 'P' : /* Show paper types */
-           op = 'P';
-           break;
+         case 'H' : /* Show server and port */
+             if (cupsServer()[0] == '/')
+               _cupsLangPuts(stdout, cupsServer());
+             else
+               _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort());
+             op = 'H';
+             break;
+
+         case 'P' : /* Show paper types */
+             op = 'P';
+             break;
 
-        case 'R' : /* Show ranking */
-           ranking = 1;
-           break;
+         case 'R' : /* Show ranking */
+             ranking = 1;
+             break;
 
-        case 'S' : /* Show charsets */
-           op = 'S';
-           if (!argv[i][2])
-             i ++;
-           break;
+         case 'S' : /* Show charsets */
+             op = 'S';
+             if (!argv[i][2])
+               i ++;
+             break;
 
-        case 'U' : /* Username */
-           if (argv[i][2] != '\0')
-             cupsSetUser(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+         case 'U' : /* Username */
+             if (opt[1] != '\0')
+             {
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected username after "
-                                 "\'-U\' option!\n"),
-                               argv[0]);
-               return (1);
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
+                 return (1);
+               }
+
+               cupsSetUser(argv[i]);
              }
+             break;
 
-              cupsSetUser(argv[i]);
-           }
-           break;
-           
-        case 'W' : /* Show which jobs? */
-           if (argv[i][2])
-             which = argv[i] + 2;
-           else
-           {
-             i ++;
+         case 'W' : /* Show which jobs? */
+             if (opt[1] != '\0')
+             {
+               which = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
+                 return (1);
+               }
+
+               which = argv[i];
+             }
 
-             if (i >= argc)
+             if (strcmp(which, "completed") && strcmp(which, "not-completed") && strcmp(which, "all"))
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - need \"completed\", "
-                                 "\"not-completed\", or \"all\" after "
-                                 "\'-W\' option!\n"),
-                               argv[0]);
+               _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
                return (1);
-              }
+             }
+             break;
 
-             which = argv[i];
-           }
+         case 'a' : /* Show acceptance status */
+             op = 'a';
 
-            if (strcmp(which, "completed") && strcmp(which, "not-completed") &&
-               strcmp(which, "all"))
-           {
-             _cupsLangPrintf(stderr,
-                             _("%s: Error - need \"completed\", "
-                               "\"not-completed\", or \"all\" after "
-                               "\'-W\' option!\n"),
-                             argv[0]);
-             return (1);
-           }
-           break;
+             if (opt[1] != '\0')
+             {
+               check_dest(argv[0], opt + 1, &num_dests, &dests);
 
-        case 'a' : /* Show acceptance status */
-           op   = 'a';
-           http = connect_server(argv[0], http);
+               status |= show_accepting(opt + 1, num_dests, dests);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+               check_dest(argv[0], argv[i], &num_dests, &dests);
 
-             status |= show_accepting(http, argv[i] + 2, num_dests, dests);
-           }
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
+               status |= show_accepting(argv[i], num_dests, dests);
+             }
+             else
+             {
+               if (num_dests <= 1)
+               {
+                 cupsFreeDests(num_dests, dests);
+                 num_dests = cupsGetDests(&dests);
 
-              check_dest(argv[0], http, argv[i], &num_dests, &dests);
+                 if (num_dests == 0 && (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+                 {
+                   _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                   return (1);
+                 }
+               }
 
-             status |= show_accepting(http, argv[i], num_dests, dests);
-           }
-           else
-           {
-              if (num_dests == 0)
-               num_dests = cupsGetDests2(http, &dests);
+               status |= show_accepting(NULL, num_dests, dests);
+             }
+             break;
 
-             status |= show_accepting(http, NULL, num_dests, dests);
-           }
-           break;
+         case 'c' : /* Show classes and members */
+             op = 'c';
 
-#ifdef __sgi
-        case 'b' : /* Show both the local and remote status */
-           op   = 'b';
-           http = connect_server(argv[0], http);
+             if (opt[1] != '\0')
+             {
+               check_dest(argv[0], opt + 1, &num_dests, &dests);
 
-           if (argv[i][2] != '\0')
-           {
-            /*
-             * The local and remote status are separated by a blank line;
-             * since all CUPS jobs are networked, we only output the
-             * second list for now...  In the future, we might further
-             * emulate this by listing the remote server's queue, but
-             * for now this is enough to make the SGI printstatus program
-             * happy...
-             */
-
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
-
-             puts("");
-             status |= show_jobs(http, argv[i] + 2, NULL, 3, ranking, which);
-           }
-           else
-           {
-             _cupsLangPrintf(stderr,
-                             _("%s: Error - expected destination after "
-                               "\'-b\' option!\n"),
-                             argv[0]);
+               status |= show_classes(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
 
-             return (1);
-           }
-           break;
-#endif /* __sgi */
+               check_dest(argv[0], argv[i], &num_dests, &dests);
 
-        case 'c' : /* Show classes and members */
-           op   = 'c';
-           http = connect_server(argv[0], http);
+               status |= show_classes(argv[i]);
+             }
+             else
+               status |= show_classes(NULL);
+             break;
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+         case 'd' : /* Show default destination */
+             op = 'd';
 
-             status |= show_classes(http, argv[i] + 2);
-           }
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
+             if (num_dests != 1 || !dests[0].is_default)
+             {
+               cupsFreeDests(num_dests, dests);
 
-              check_dest(argv[0], http, argv[i], &num_dests, &dests);
+               dests     = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
+               num_dests = dests ? 1 : 0;
 
-             status |= show_classes(http, argv[i]);
-           }
-           else
-             status |= show_classes(http, NULL);
-           break;
+               if (num_dests == 0 &&
+                   (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                    cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                 return (1);
+               }
+             }
 
-        case 'd' : /* Show default destination */
-           op   = 'd';
-           http = connect_server(argv[0], http);
+             show_default(dests);
+             break;
 
-            if (num_dests == 0)
-             num_dests = cupsGetDests2(http, &dests);
+         case 'e' : /* List destinations */
+             {
+                cups_dest_t *temp = NULL, *dest;
+                int j, num_temp = cupsGetDests(&temp);
+
+                op = 'e';
+
+                for (j = num_temp, dest = temp; j > 0; j --, dest ++)
+                {
+                  if (dest->instance)
+                    printf("%s/%s", dest->name, dest->instance);
+                  else
+                    fputs(dest->name, stdout);
+
+                  if (long_status)
+                  {
+                    const char *printer_uri_supported = cupsGetOption("printer-uri-supported", dest->num_options, dest->options);
+                    const char *printer_is_temporary = cupsGetOption("printer-is-temporary", dest->num_options, dest->options);
+                    const char *type = "network";
+
+                    if (printer_is_temporary && !strcmp(printer_is_temporary, "true"))
+                      type = "temporary";
+                    else if (printer_uri_supported)
+                      type = "permanent";
+
+                    printf(" %s %s %s\n", type, printer_uri_supported ? printer_uri_supported : "none", cupsGetOption("device-uri", dest->num_options, dest->options));
+                  }
+                  else
+                    putchar('\n');
+                }
+
+                cupsFreeDests(num_temp, temp);
+              }
+              break;
 
-            show_default(num_dests, dests);
-           break;
+         case 'f' : /* Show forms */
+             op   = 'f';
+             if (opt[1] != '\0')
+             {
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+               if (i >= argc)
+                 return (1);
+             }
+             break;
 
-        case 'f' : /* Show forms */
-           op   = 'f';
-           if (!argv[i][2])
-             i ++;
-           break;
+         case 'h' : /* Connect to host */
+             if (opt[1] != '\0')
+             {
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-        case 'h' : /* Connect to host */
-           if (http)
-           {
-             httpClose(http);
-             http = NULL;
-           }
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]);
+                 return (1);
+               }
 
-           if (argv[i][2] != '\0')
-             cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
+               cupsSetServer(argv[i]);
+             }
+             break;
+
+         case 'l' : /* Long status or long job status */
+             long_status = 2;
+             break;
+
+         case 'o' : /* Show jobs by destination */
+             op = 'o';
 
-             if (i >= argc)
+             if (opt[1])
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected hostname after "
-                                 "\'-h\' option!\n"),
-                               argv[0]);
-               return (1);
-              }
+               check_dest(argv[0], opt + 1, &num_dests, &dests);
 
-             cupsSetServer(argv[i]);
-           }
-           break;
+               status |= show_jobs(opt + 1, NULL, long_status, ranking, which);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
 
-        case 'l' : /* Long status or long job status */
-#ifdef __sgi
-           op   = 'l';
-           http = connect_server(argv[0], http);
+               check_dest(argv[0], argv[i], &num_dests, &dests);
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+               status |= show_jobs(argv[i], NULL, long_status, ranking, which);
+             }
+             else
+               status |= show_jobs(NULL, NULL, long_status, ranking, which);
+             break;
 
-             status |= show_jobs(http, argv[i] + 2, NULL, 3, ranking, which);
-           }
-           else
-#endif /* __sgi */
-             long_status = 2;
-           break;
+         case 'p' : /* Show printers */
+             op = 'p';
 
-        case 'o' : /* Show jobs by destination */
-           op   = 'o';
-           http = connect_server(argv[0], http);
+             if (opt[1] != '\0')
+             {
+               check_dest(argv[0], opt + 1, &num_dests, &dests);
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+               status |= show_printers(opt + 1, num_dests, dests,
+                                       long_status);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
 
-             status |= show_jobs(http, argv[i] + 2, NULL, long_status,
-                                 ranking, which);
-           }
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
+               check_dest(argv[0], argv[i], &num_dests, &dests);
 
-              check_dest(argv[0], http, argv[i], &num_dests, &dests);
+               status |= show_printers(argv[i], num_dests, dests, long_status);
+             }
+             else
+             {
+               if (num_dests <= 1)
+               {
+                 cupsFreeDests(num_dests, dests);
+                 num_dests = cupsGetDests(&dests);
+
+                 if (num_dests == 0 &&
+                     (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+                 {
+                   _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                   return (1);
+                 }
+               }
+
+               status |= show_printers(NULL, num_dests, dests, long_status);
+             }
+             break;
 
-             status |= show_jobs(http, argv[i], NULL, long_status,
-                                 ranking, which);
-           }
-           else
-             status |= show_jobs(http, NULL, NULL, long_status,
-                                 ranking, which);
-           break;
+         case 'r' : /* Show scheduler status */
+             op = 'r';
 
-        case 'p' : /* Show printers */
-           op   = 'p';
-           http = connect_server(argv[0], http);
+             show_scheduler();
+             break;
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+         case 's' : /* Show summary */
+             op = 's';
 
-             status |= show_printers(http, argv[i] + 2, num_dests, dests, long_status);
-           }
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
+             if (num_dests <= 1)
+             {
+               cupsFreeDests(num_dests, dests);
+               num_dests = cupsGetDests(&dests);
 
-              check_dest(argv[0], http, argv[i], &num_dests, &dests);
+               if (num_dests == 0 &&
+                   (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                    cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                 return (1);
+               }
+             }
 
-             status |= show_printers(http, argv[i], num_dests, dests, long_status);
-           }
-           else
-           {
-              if (num_dests == 0)
-               num_dests = cupsGetDests2(http, &dests);
+             show_default(cupsGetDest(NULL, NULL, num_dests, dests));
+             status |= show_classes(NULL);
+             status |= show_devices(NULL, num_dests, dests);
+             break;
 
-             status |= show_printers(http, NULL, num_dests, dests, long_status);
-           }
-           break;
-
-        case 'r' : /* Show scheduler status */
-           op   = 'r';
-           http = connect_server(argv[0], http);
-
-           show_scheduler(http);
-           break;
-
-        case 's' : /* Show summary */
-           op   = 's';
-           http = connect_server(argv[0], http);
-
-            if (num_dests == 0)
-             num_dests = cupsGetDests2(http, &dests);
-
-           show_default(num_dests, dests);
-           status |= show_classes(http, NULL);
-           status |= show_devices(http, NULL, num_dests, dests);
-           break;
-
-        case 't' : /* Show all info */
-           op   = 't';
-           http = connect_server(argv[0], http);
-
-            if (num_dests == 0)
-             num_dests = cupsGetDests2(http, &dests);
-
-           show_scheduler(http);
-           show_default(num_dests, dests);
-           status |= show_classes(http, NULL);
-           status |= show_devices(http, NULL, num_dests, dests);
-           status |= show_accepting(http, NULL, num_dests, dests);
-           status |= show_printers(http, NULL, num_dests, dests, long_status);
-           status |= show_jobs(http, NULL, NULL, long_status, ranking, which);
-           break;
-
-        case 'u' : /* Show jobs by user */
-           op   = 'u';
-           http = connect_server(argv[0], http);
-
-           if (argv[i][2] != '\0')
-             status |= show_jobs(http, NULL, argv[i] + 2, long_status,
-                                 ranking, which);
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
-             status |= show_jobs(http, NULL, argv[i], long_status,
-                                 ranking, which);
-           }
-           else
-             status |= show_jobs(http, NULL, NULL, long_status,
-                                 ranking, which);
-           break;
+         case 't' : /* Show all info */
+             op = 't';
 
-        case 'v' : /* Show printer devices */
-           op   = 'v';
-           http = connect_server(argv[0], http);
+             if (num_dests <= 1)
+             {
+               cupsFreeDests(num_dests, dests);
+               num_dests = cupsGetDests(&dests);
 
-           if (argv[i][2] != '\0')
-           {
-              check_dest(argv[0], http, argv[i] + 2, &num_dests, &dests);
+               if (num_dests == 0 &&
+                   (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                    cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                 return (1);
+               }
+             }
 
-             status |= show_devices(http, argv[i] + 2, num_dests, dests);
-           }
-           else if ((i + 1) < argc && argv[i + 1][0] != '-')
-           {
-             i ++;
+             show_scheduler();
+             show_default(cupsGetDest(NULL, NULL, num_dests, dests));
+             status |= show_classes(NULL);
+             status |= show_devices(NULL, num_dests, dests);
+             status |= show_accepting(NULL, num_dests, dests);
+             status |= show_printers(NULL, num_dests, dests, long_status);
+             status |= show_jobs(NULL, NULL, long_status, ranking, which);
+             break;
 
-              check_dest(argv[0], http, argv[i], &num_dests, &dests);
+         case 'u' : /* Show jobs by user */
+             op = 'u';
 
-             status |= show_devices(http, argv[i], num_dests, dests);
-           }
-           else
-           {
-              if (num_dests == 0)
-               num_dests = cupsGetDests2(http, &dests);
+             if (opt[1] != '\0')
+             {
+               status |= show_jobs(NULL, opt + 1, long_status, ranking, which);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
+               status |= show_jobs(NULL, argv[i], long_status, ranking, which);
+             }
+             else
+               status |= show_jobs(NULL, NULL, long_status, ranking, which);
+             break;
 
-             status |= show_devices(http, NULL, num_dests, dests);
-           }
-           break;
+         case 'v' : /* Show printer devices */
+             op = 'v';
+
+             if (opt[1] != '\0')
+             {
+               check_dest(argv[0], opt + 1, &num_dests, &dests);
 
+               status |= show_devices(opt + 1, num_dests, dests);
+               opt += strlen(opt) - 1;
+             }
+             else if ((i + 1) < argc && argv[i + 1][0] != '-')
+             {
+               i ++;
+
+               check_dest(argv[0], argv[i], &num_dests, &dests);
 
-       default :
-           _cupsLangPrintf(stderr,
-                           _("%s: Error - unknown option \'%c\'!\n"),
-                           argv[0], argv[i][1]);
-           return (1);
+               status |= show_devices(argv[i], num_dests, dests);
+             }
+             else
+             {
+               if (num_dests <= 1)
+               {
+                 cupsFreeDests(num_dests, dests);
+                 num_dests = cupsGetDests(&dests);
+
+                 if (num_dests == 0 &&
+                     (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+                      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED))
+                 {
+                   _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]);
+                   return (1);
+                 }
+               }
+
+               status |= show_devices(NULL, num_dests, dests);
+             }
+             break;
+
+         default :
+             _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], argv[i][1]);
+             return (1);
+       }
       }
+    }
     else
     {
-      http = connect_server(argv[0], http);
-
-      status |= show_jobs(http, argv[i], NULL, long_status, ranking, which);
+      status |= show_jobs(argv[i], NULL, long_status, ranking, which);
       op = 'o';
     }
+  }
 
   if (!op)
-  {
-    http = connect_server(argv[0], http);
-
-    status |= show_jobs(http, NULL, cupsUser(), long_status, ranking, which);
-  }
+    status |= show_jobs(NULL, cupsUser(), long_status, ranking, which);
 
   return (status);
 }
@@ -481,28 +505,59 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
 static void
 check_dest(const char  *command,       /* I  - Command name */
-           http_t      *http,          /* I  - HTTP connection */
-           const char  *name,          /* I  - Name of printer/class(es) */
+           const char  *name,          /* I  - List of printer/class names */
            int         *num_dests,     /* IO - Number of destinations */
           cups_dest_t **dests)         /* IO - Destinations */
 {
-  const char   *dptr;
-  char         *pptr,
-               printer[128];
+  const char   *dptr;                  /* Pointer into name */
+  char         *pptr,                  /* Pointer into printer */
+               printer[1024];          /* Current printer/class name */
 
 
  /*
   * Load the destination list as necessary...
   */
 
-  if (*num_dests == 0)
-    *num_dests = cupsGetDests2(http, dests);
+  if (*num_dests <= 1)
+  {
+    if (*num_dests)
+      cupsFreeDests(*num_dests, *dests);
+
+    if (strchr(name, ','))
+      *num_dests = cupsGetDests(dests);
+    else
+    {
+      strlcpy(printer, name, sizeof(printer));
+      if ((pptr = strchr(printer, '/')) != NULL)
+        *pptr++ = '\0';
+
+      if ((*dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, pptr)) == NULL)
+      {
+       if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+           cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+         _cupsLangPrintf(stderr,
+                         _("%s: Error - add '/version=1.1' to server name."),
+                         command);
+       else
+         _cupsLangPrintf(stderr,
+                         _("%s: Invalid destination name in list \"%s\"."),
+                         command, name);
+
+        exit(1);
+      }
+      else
+      {
+        *num_dests = 1;
+        return;
+      }
+    }
+  }
 
  /*
   * Scan the name string for printer/class name(s)...
   */
 
-  for (dptr = name; *dptr != '\0';) 
+  for (dptr = name; *dptr;)
   {
    /*
     * Skip leading whitespace and commas...
@@ -511,21 +566,21 @@ check_dest(const char  *command,  /* I  - Command name */
     while (isspace(*dptr & 255) || *dptr == ',')
       dptr ++;
 
-    if (*dptr == '\0')
+    if (!*dptr)
       break;
 
    /*
     * Extract a single destination name from the name string...
     */
 
-    for (pptr = printer; !isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0';)
+    for (pptr = printer; !isspace(*dptr & 255) && *dptr != ',' && *dptr;)
     {
-      if ((pptr - printer) < (sizeof(printer) - 1))
+      if ((size_t)(pptr - printer) < (sizeof(printer) - 1))
         *pptr++ = *dptr++;
       else
       {
         _cupsLangPrintf(stderr,
-                       _("%s: Invalid destination name in list \"%s\"!\n"),
+                       _("%s: Invalid destination name in list \"%s\"."),
                        command, name);
         exit(1);
       }
@@ -537,10 +592,17 @@ check_dest(const char  *command,  /* I  - Command name */
     * Check the destination...
     */
 
-    if (cupsGetDest(printer, NULL, *num_dests, *dests) == NULL)
+    if (!cupsGetDest(printer, NULL, *num_dests, *dests))
     {
-      _cupsLangPrintf(stderr,
-                      _("%s: Unknown destination \"%s\"!\n"), command, printer);
+      if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+          cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+       _cupsLangPrintf(stderr,
+                       _("%s: Error - add '/version=1.1' to server name."),
+                       command);
+      else
+       _cupsLangPrintf(stderr,
+                       _("%s: Unknown destination \"%s\"."), command, printer);
+
       exit(1);
     }
   }
@@ -548,26 +610,54 @@ check_dest(const char  *command,  /* I  - Command name */
 
 
 /*
- * 'connect_server()' - Connect to the server as necessary...
+ * 'match_list()' - Match a name from a list of comma or space-separated names.
  */
 
-static http_t *                                /* O - New HTTP connection */
-connect_server(const char *command,    /* I - Command name */
-               http_t     *http)       /* I - Current HTTP connection */
+static int                             /* O - 1 on match, 0 on no match */
+match_list(const char *list,           /* I - List of names */
+           const char *name)           /* I - Name to find */
 {
-  if (!http)
+  const char   *nameptr;               /* Pointer into name */
+
+
+ /*
+  * An empty list always matches...
+  */
+
+  if (!list || !*list)
+    return (1);
+
+  if (!name)
+    return (0);
+
+  while (*list)
   {
-    http = httpConnectEncrypt(cupsServer(), ippPort(),
-                             cupsEncryption());
+   /*
+    * Skip leading whitespace and commas...
+    */
 
-    if (http == NULL)
-    {
-      _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"), command);
-      exit(1);
-    }
+    while (isspace(*list & 255) || *list == ',')
+      list ++;
+
+    if (!*list)
+      break;
+
+   /*
+    * Compare names...
+    */
+
+    for (nameptr = name;
+        *nameptr && *list && tolower(*nameptr & 255) == tolower(*list & 255);
+        nameptr ++, list ++);
+
+    if (!*nameptr && (!*list || *list == ',' || isspace(*list & 255)))
+      return (1);
+
+    while (*list && !isspace(*list & 255) && *list != ',')
+      list ++;
   }
 
-  return (http);
+  return (0);
 }
 
 
@@ -576,8 +666,7 @@ connect_server(const char *command, /* I - Command name */
  */
 
 static int                             /* O - 0 on success, 1 on fail */
-show_accepting(http_t      *http,      /* I - HTTP connection to server */
-               const char  *printers,  /* I - Destinations */
+show_accepting(const char  *printers,  /* I - Destinations */
                int         num_dests,  /* I - Number of user-defined dests */
               cups_dest_t *dests)      /* I - User-defined destinations */
 {
@@ -589,11 +678,7 @@ show_accepting(http_t      *http,  /* I - HTTP connection to server */
                *message;               /* Printer device URI */
   int          accepting;              /* Accepting requests? */
   time_t       ptime;                  /* Printer state time */
-  struct tm    *pdate;                 /* Printer state date & time */
   char         printer_state_time[255];/* Printer state time */
-  const char   *dptr,                  /* Pointer into destination list */
-               *ptr;                   /* Pointer into printer name */
-  int          match;                  /* Non-zero if this job matches */
   static const char *pattrs[] =                /* Attributes we need for printers... */
                {
                  "printer-name",
@@ -603,10 +688,7 @@ show_accepting(http_t      *http,  /* I - HTTP connection to server */
                };
 
 
-  DEBUG_printf(("show_accepting(%p, %p)\n", http, printers));
-
-  if (http == NULL)
-    return (1);
+  DEBUG_printf(("show_accepting(printers=\"%s\")\n", printers));
 
   if (printers != NULL && !strcmp(printers, "all"))
     printers = NULL;
@@ -634,16 +716,27 @@ show_accepting(http_t      *http, /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
+
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
   {
-    DEBUG_puts("show_accepting: request succeeded...");
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server name."),
+                   "lpstat");
+    ippDelete(response);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
+    ippDelete(response);
+    return (1);
+  }
 
-    if (response->request.status.status_code > IPP_OK_CONFLICT)
-    {
-      _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_accepting: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -701,83 +794,41 @@ show_accepting(http_t      *http, /* I - HTTP connection to server */
           continue;
       }
 
-     /*
-      * See if this is a printer we're interested in...
-      */
-
-      match = printers == NULL;
-
-      if (printers != NULL)
-      {
-        for (dptr = printers; *dptr != '\0';)
-       {
-        /*
-         * Skip leading whitespace and commas...
-         */
-
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = printer;
-              *ptr != '\0' && *dptr != '\0' && tolower(*ptr & 255) == tolower(*dptr & 255);
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
-         {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
-
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-        }
-      }
-
      /*
       * Display the printer entry if needed...
       */
 
-      if (match)
+      if (match_list(printers, printer))
       {
-        pdate = localtime(&ptime);
-        strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate);
+        _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
 
         if (accepting)
-         _cupsLangPrintf(stdout, _("%s accepting requests since %s\n"),
+         _cupsLangPrintf(stdout, _("%s accepting requests since %s"),
                          printer, printer_state_time);
        else
-         _cupsLangPrintf(stdout, _("%s not accepting requests since %s -\n"
-                                   "\t%s\n"),
-                         printer, printer_state_time,
-                         message == NULL ? "reason unknown" : message);
+       {
+         _cupsLangPrintf(stdout, _("%s not accepting requests since %s -"),
+                         printer, printer_state_time);
+         _cupsLangPrintf(stdout, _("\t%s"),
+                         (message == NULL || !*message) ?
+                             "reason unknown" : message);
+        }
 
         for (i = 0; i < num_dests; i ++)
-         if (!strcasecmp(dests[i].name, printer) && dests[i].instance)
+         if (!_cups_strcasecmp(dests[i].name, printer) && dests[i].instance)
          {
             if (accepting)
-             _cupsLangPrintf(stdout, _("%s/%s accepting requests since %s\n"),
+             _cupsLangPrintf(stdout, _("%s/%s accepting requests since %s"),
                              printer, dests[i].instance, printer_state_time);
            else
-             _cupsLangPrintf(stdout, _("%s/%s not accepting requests since "
-                                       "%s -\n\t%s\n"),
-                             printer, dests[i].instance, printer_state_time,
-                             message == NULL ? "reason unknown" : message);
+           {
+             _cupsLangPrintf(stdout,
+                             _("%s/%s not accepting requests since %s -"),
+                             printer, dests[i].instance, printer_state_time);
+             _cupsLangPrintf(stdout, _("\t%s"),
+                             (message == NULL || !*message) ?
+                                 "reason unknown" : message);
+            }
          }
       }
 
@@ -787,11 +838,6 @@ show_accepting(http_t      *http,  /* I - HTTP connection to server */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -802,8 +848,7 @@ show_accepting(http_t      *http,   /* I - HTTP connection to server */
  */
 
 static int                             /* O - 0 on success, 1 on fail */
-show_classes(http_t     *http,         /* I - HTTP connection to server */
-             const char *dests)                /* I - Destinations */
+show_classes(const char *dests)                /* I - Destinations */
 {
   int          i;                      /* Looping var */
   ipp_t                *request,               /* IPP Request */
@@ -819,9 +864,6 @@ show_classes(http_t     *http,              /* I - HTTP connection to server */
                server[HTTP_MAX_URI],   /* Server name */
                resource[HTTP_MAX_URI]; /* Resource name */
   int          port;                   /* Port number */
-  const char   *dptr,                  /* Pointer into destination list */
-               *ptr;                   /* Pointer into printer name */
-  int          match;                  /* Non-zero if this job matches */
   static const char *cattrs[] =                /* Attributes we need for classes... */
                {
                  "printer-name",
@@ -830,10 +872,7 @@ show_classes(http_t     *http,             /* I - HTTP connection to server */
                };
 
 
-  DEBUG_printf(("show_classes(%p, %p)\n", http, dests));
-
-  if (http == NULL)
-    return (1);
+  DEBUG_printf(("show_classes(dests=\"%s\")\n", dests));
 
   if (dests != NULL && !strcmp(dests, "all"))
     dests = NULL;
@@ -861,13 +900,31 @@ show_classes(http_t     *http,            /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
+
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+  {
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server name."),
+                   "lpstat");
+    ippDelete(response);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
+    ippDelete(response);
+    return (1);
+  }
+
+  if (response)
   {
     DEBUG_puts("show_classes: request succeeded...");
 
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
+      _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
       ippDelete(response);
       return (1);
     }
@@ -926,120 +983,68 @@ show_classes(http_t     *http,           /* I - HTTP connection to server */
                        username, sizeof(username), server, sizeof(server),
                        &port, resource, sizeof(resource));
 
-        if (!strcasecmp(server, http->hostname))
-         http2 = http;
+        if (!_cups_strcasecmp(server, cupsServer()))
+         http2 = CUPS_HTTP_DEFAULT;
        else
          http2 = httpConnectEncrypt(server, port, cupsEncryption());
 
-       if (http2 != NULL)
-       {
-        /*
-         * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
-         * following attributes:
-         *
-         *    attributes-charset
-         *    attributes-natural-language
-         *    printer-uri
-         *    requested-attributes
-         */
-
-         request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
-
-         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
-                      "printer-uri", NULL, printer_uri);
-
-         ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-                       "requested-attributes",
-                       sizeof(cattrs) / sizeof(cattrs[0]),
-                       NULL, cattrs);
+       /*
+       * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
+       * following attributes:
+       *
+       *    attributes-charset
+       *    attributes-natural-language
+       *    printer-uri
+       *    requested-attributes
+       */
 
-          if ((response2 = cupsDoRequest(http2, request, "/")) != NULL)
-           members = ippFindAttribute(response2, "member-names", IPP_TAG_NAME);
+       request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
 
-          if (http2 != http)
-            httpClose(http2);
-        }
-      }
+       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
+                    "printer-uri", NULL, printer_uri);
 
-     /*
-      * See if we have everything needed...
-      */
+       ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+                     "requested-attributes",
+                     sizeof(cattrs) / sizeof(cattrs[0]),
+                     NULL, cattrs);
 
-      if (printer == NULL)
-      {
-        if (response2)
-         ippDelete(response2);
+       if ((response2 = cupsDoRequest(http2, request, "/")) != NULL)
+         members = ippFindAttribute(response2, "member-names", IPP_TAG_NAME);
 
-        if (attr == NULL)
-         break;
-       else
-          continue;
+       if (http2)
+         httpClose(http2);
       }
 
      /*
-      * See if this is a printer we're interested in...
-      */
-
-      match = dests == NULL;
-
-      if (dests != NULL)
-      {
-        for (dptr = dests; *dptr != '\0';)
-       {
-        /*
-         * Skip leading whitespace and commas...
-         */
-
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = printer;
-              *ptr != '\0' && *dptr != '\0' && tolower(*ptr & 255) == tolower(*dptr & 255);
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
-         {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
+      * See if we have everything needed...
+      */
 
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
+      if (printer == NULL)
+      {
+        if (response2)
+         ippDelete(response2);
 
-         if (*dptr == '\0')
-           break;
-        }
+        if (attr == NULL)
+         break;
+       else
+          continue;
       }
 
      /*
       * Display the printer entry if needed...
       */
 
-      if (match)
+      if (match_list(dests, printer))
       {
-        _cupsLangPrintf(stdout, _("members of class %s:\n"), printer);
+        _cupsLangPrintf(stdout, _("members of class %s:"), printer);
 
        if (members)
        {
          for (i = 0; i < members->num_values; i ++)
-           _cupsLangPrintf(stdout, "\t%s\n",
-                           members->values[i].string.text);
+           _cupsLangPrintf(stdout, "\t%s", members->values[i].string.text);
         }
        else
-         _cupsLangPuts(stdout, "\tunknown\n");
+         _cupsLangPuts(stdout, "\tunknown");
       }
 
       if (response2)
@@ -1051,11 +1056,6 @@ show_classes(http_t     *http,           /* I - HTTP connection to server */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1066,20 +1066,19 @@ show_classes(http_t     *http,          /* I - HTTP connection to server */
  */
 
 static void
-show_default(int         num_dests,    /* I - Number of user-defined dests */
-            cups_dest_t *dests)        /* I - User-defined destinations */
+show_default(cups_dest_t *dest)                /* I - Default destination */
 {
-  cups_dest_t  *dest;                  /* Destination */
   const char   *printer,               /* Printer name */
                *val;                   /* Environment variable name */
 
-  if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) != NULL)
+
+  if (dest)
   {
     if (dest->instance)
-      _cupsLangPrintf(stdout, _("system default destination: %s/%s\n"),
+      _cupsLangPrintf(stdout, _("system default destination: %s/%s"),
                       dest->name, dest->instance);
     else
-      _cupsLangPrintf(stdout, _("system default destination: %s\n"),
+      _cupsLangPrintf(stdout, _("system default destination: %s"),
                       dest->name);
   }
   else
@@ -1099,13 +1098,13 @@ show_default(int         num_dests,     /* I - Number of user-defined dests */
     else
       val = "LPDEST";
 
-    if (printer && !cupsGetDest(printer, NULL, num_dests, dests))
+    if (printer)
       _cupsLangPrintf(stdout,
                       _("lpstat: error - %s environment variable names "
-                       "non-existent destination \"%s\"!\n"),
+                       "non-existent destination \"%s\"."),
                      val, printer);
     else
-      _cupsLangPuts(stdout, _("no system default destination\n"));
+      _cupsLangPuts(stdout, _("no system default destination"));
   }
 }
 
@@ -1115,8 +1114,7 @@ show_default(int         num_dests,       /* I - Number of user-defined dests */
  */
 
 static int                             /* O - 0 on success, 1 on fail */
-show_devices(http_t      *http,                /* I - HTTP connection to server */
-             const char  *printers,    /* I - Destinations */
+show_devices(const char  *printers,    /* I - Destinations */
              int         num_dests,    /* I - Number of user-defined dests */
             cups_dest_t *dests)        /* I - User-defined destinations */
 {
@@ -1126,10 +1124,7 @@ show_devices(http_t      *http,          /* I - HTTP connection to server */
   ipp_attribute_t *attr;               /* Current attribute */
   const char   *printer,               /* Printer name */
                *uri,                   /* Printer URI */
-               *device,                /* Printer device URI */
-               *dptr,                  /* Pointer into destination list */
-               *ptr;                   /* Pointer into printer name */
-  int          match;                  /* Non-zero if this job matches */
+               *device;                /* Printer device URI */
   static const char *pattrs[] =                /* Attributes we need for printers... */
                {
                  "printer-name",
@@ -1138,10 +1133,7 @@ show_devices(http_t      *http,          /* I - HTTP connection to server */
                };
 
 
-  DEBUG_printf(("show_devices(%p, %p)\n", http, dests));
-
-  if (http == NULL)
-    return (1);
+  DEBUG_printf(("show_devices(printers=\"%s\")\n", printers));
 
   if (printers != NULL && !strcmp(printers, "all"))
     printers = NULL;
@@ -1169,16 +1161,27 @@ show_devices(http_t      *http,         /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
+
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
   {
-    DEBUG_puts("show_devices: request succeeded...");
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server name."),
+                   "lpstat");
+    ippDelete(response);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
+    ippDelete(response);
+    return (1);
+  }
 
-    if (response->request.status.status_code > IPP_OK_CONFLICT)
-    {
-      _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_devices: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -1234,130 +1237,37 @@ show_devices(http_t      *http,                /* I - HTTP connection to server */
           continue;
       }
 
-     /*
-      * See if this is a printer we're interested in...
-      */
-
-      match = printers == NULL;
-
-      if (printers != NULL)
-      {
-        for (dptr = printers; *dptr != '\0';)
-       {
-        /*
-         * Skip leading whitespace and commas...
-         */
-
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = printer;
-              *ptr != '\0' && *dptr != '\0' && tolower(*ptr & 255) == tolower(*dptr & 255);
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
-         {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
-
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-        }
-      }
-
      /*
       * Display the printer entry if needed...
       */
 
-      if (match)
+      if (match_list(printers, printer))
       {
-#ifdef __osf__ /* Compaq/Digital like to do it their own way... */
-        char   method[HTTP_MAX_URI],   /* Components of printer URI */
-               username[HTTP_MAX_URI],
-               hostname[HTTP_MAX_URI],
-               resource[HTTP_MAX_URI];
-       int     port;
-
-
-        if (device == NULL)
-       {
-         httpSeparateURI(HTTP_URI_CODING_ALL, uri, method, sizeof(method),
-                         username, sizeof(username), hostname,
-                         sizeof(hostname), &port, resource, sizeof(resource));
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to remote "
-                           "printer %s on %s\n"),
-                         printer, strrchr(resource, '/') + 1, hostname);
-        }
-        else if (!strncmp(device, "file:", 5))
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to %s\n"),
-                         printer, device + 5);
-        else
-          _cupsLangPrintf(stdout,
-                         _("Output for printer %s is sent to %s\n"),
-                         printer, device);
-
-        for (i = 0; i < num_dests; i ++)
-         if (!strcasecmp(printer, dests[i].name) && dests[i].instance)
-         {
-            if (device == NULL)
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to "
-                               "remote printer %s on %s\n"),
-                             printer, dests[i].instance,
-                             strrchr(resource, '/') + 1, hostname);
-            else if (!strncmp(device, "file:", 5))
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to %s\n"),
-                             printer, dests[i].instance, device + 5);
-            else
-              _cupsLangPrintf(stdout,
-                             _("Output for printer %s/%s is sent to %s\n"),
-                             printer, dests[i].instance, device);
-         }
-#else
         if (device == NULL)
-          _cupsLangPrintf(stdout, _("device for %s: %s\n"),
+          _cupsLangPrintf(stdout, _("device for %s: %s"),
                          printer, uri);
         else if (!strncmp(device, "file:", 5))
-          _cupsLangPrintf(stdout, _("device for %s: %s\n"),
+          _cupsLangPrintf(stdout, _("device for %s: %s"),
                          printer, device + 5);
         else
-          _cupsLangPrintf(stdout, _("device for %s: %s\n"),
+          _cupsLangPrintf(stdout, _("device for %s: %s"),
                          printer, device);
 
         for (i = 0; i < num_dests; i ++)
-         if (!strcasecmp(printer, dests[i].name) && dests[i].instance)
+        {
+         if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
          {
             if (device == NULL)
-              _cupsLangPrintf(stdout, _("device for %s/%s: %s\n"),
+              _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
                              printer, dests[i].instance, uri);
             else if (!strncmp(device, "file:", 5))
-              _cupsLangPrintf(stdout, _("device for %s/%s: %s\n"),
+              _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
                              printer, dests[i].instance, device + 5);
             else
-              _cupsLangPrintf(stdout, _("device for %s/%s: %s\n"),
+              _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
                              printer, dests[i].instance, device);
          }
-#endif /* __osf__ */
+       }
       }
 
       if (attr == NULL)
@@ -1366,11 +1276,6 @@ show_devices(http_t      *http,          /* I - HTTP connection to server */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1381,8 +1286,7 @@ show_devices(http_t      *http,           /* I - HTTP connection to server */
  */
 
 static int                             /* O - 0 on success, 1 on fail */
-show_jobs(http_t     *http,            /* I - HTTP connection to server */
-          const char *dests,           /* I - Destinations */
+show_jobs(const char *dests,           /* I - Destinations */
           const char *users,           /* I - Users */
           int        long_status,      /* I - Show long status? */
           int        ranking,          /* I - Show job ranking? */
@@ -1395,15 +1299,12 @@ show_jobs(http_t     *http,             /* I - HTTP connection to server */
                *reasons;               /* Job state reasons attribute */
   const char   *dest,                  /* Pointer into job-printer-uri */
                *username,              /* Pointer to job-originating-user-name */
-               *title;                 /* Pointer to job-name */
+               *message,               /* Pointer to job-printer-state-message */
+               *time_at;               /* time-at-xxx attribute name to use */
   int          rank,                   /* Rank in queue */
                jobid,                  /* job-id */
                size;                   /* job-k-octets */
   time_t       jobtime;                /* time-at-creation */
-  struct tm    *jobdate;               /* Date & time */
-  const char   *dptr,                  /* Pointer into destination list */
-               *ptr;                   /* Pointer into printer name */
-  int          match;                  /* Non-zero if this job matches */
   char         temp[255],              /* Temporary buffer */
                date[255];              /* Date buffer */
   static const char *jattrs[] =                /* Attributes we need for jobs... */
@@ -1411,17 +1312,18 @@ show_jobs(http_t     *http,             /* I - HTTP connection to server */
                  "job-id",
                  "job-k-octets",
                  "job-name",
-                 "time-at-creation",
-                 "job-printer-uri",
                  "job-originating-user-name",
-                 "job-state-reasons"
+                 "job-printer-state-message",
+                 "job-printer-uri",
+                 "job-state-reasons",
+                 "time-at-creation",
+                 "time-at-completed"
                };
 
 
-  DEBUG_printf(("show_jobs(%p, %p, %p)\n", http, dests, users));
-
-  if (http == NULL)
-    return (1);
+  DEBUG_printf(("show_jobs(dests=\"%s\", users=\"%s\", long_status=%d, "
+                "ranking=%d, which=\"%s\")\n", dests, users, long_status,
+               ranking, which));
 
   if (dests != NULL && !strcmp(dests, "all"))
     dests = NULL;
@@ -1432,18 +1334,23 @@ show_jobs(http_t     *http,             /* I - HTTP connection to server */
   *
   *    attributes-charset
   *    attributes-natural-language
-  *    job-uri
+  *    printer-uri
   *    requested-attributes
+  *    requesting-user-name
+  *    which-jobs
   */
 
   request = ippNewRequest(IPP_GET_JOBS);
 
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+               NULL, "ipp://localhost/");
+
   ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
                 "requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]),
                NULL, jattrs);
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
-               NULL, "ipp://localhost/jobs/");
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
                NULL, which);
@@ -1452,18 +1359,36 @@ show_jobs(http_t     *http,             /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
+
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+  {
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server name."),
+                   "lpstat");
+    ippDelete(response);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
+    ippDelete(response);
+    return (1);
+  }
+
+  if (response)
   {
    /*
     * Loop through the job list and display them...
     */
 
-    if (response->request.status.status_code > IPP_OK_CONFLICT)
-    {
-      _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+    if (!strcmp(which, "aborted") ||
+        !strcmp(which, "canceled") ||
+        !strcmp(which, "completed"))
+      time_at = "time-at-completed";
+    else
+      time_at = "time-at-creation";
 
     rank = -1;
 
@@ -1488,7 +1413,7 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
       username = NULL;
       dest     = NULL;
       jobtime  = 0;
-      title    = "no title";
+      message  = NULL;
       reasons  = NULL;
 
       while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
@@ -1496,30 +1421,25 @@ show_jobs(http_t     *http,             /* I - HTTP connection to server */
         if (!strcmp(attr->name, "job-id") &&
            attr->value_tag == IPP_TAG_INTEGER)
          jobid = attr->values[0].integer;
-
-        if (!strcmp(attr->name, "job-k-octets") &&
-           attr->value_tag == IPP_TAG_INTEGER)
+        else if (!strcmp(attr->name, "job-k-octets") &&
+                attr->value_tag == IPP_TAG_INTEGER)
          size = attr->values[0].integer;
-
-        if (!strcmp(attr->name, "time-at-creation") &&
-           attr->value_tag == IPP_TAG_INTEGER)
+        else if (!strcmp(attr->name, time_at) && attr->value_tag == IPP_TAG_INTEGER)
          jobtime = attr->values[0].integer;
-
-        if (!strcmp(attr->name, "job-printer-uri") &&
-           attr->value_tag == IPP_TAG_URI)
+        else if (!strcmp(attr->name, "job-printer-state-message") &&
+                attr->value_tag == IPP_TAG_TEXT)
+         message = attr->values[0].string.text;
+        else if (!strcmp(attr->name, "job-printer-uri") &&
+                attr->value_tag == IPP_TAG_URI)
+       {
          if ((dest = strrchr(attr->values[0].string.text, '/')) != NULL)
            dest ++;
-
-        if (!strcmp(attr->name, "job-originating-user-name") &&
-           attr->value_tag == IPP_TAG_NAME)
+        }
+        else if (!strcmp(attr->name, "job-originating-user-name") &&
+                attr->value_tag == IPP_TAG_NAME)
          username = attr->values[0].string.text;
-
-        if (!strcmp(attr->name, "job-name") &&
-           attr->value_tag == IPP_TAG_NAME)
-         title = attr->values[0].string.text;
-
-        if (!strcmp(attr->name, "job-state-reasons") &&
-           attr->value_tag == IPP_TAG_KEYWORD)
+        else if (!strcmp(attr->name, "job-state-reasons") &&
+                attr->value_tag == IPP_TAG_KEYWORD)
          reasons = attr;
 
         attr = attr->next;
@@ -1538,143 +1458,49 @@ show_jobs(http_t     *http,            /* I - HTTP connection to server */
       }
 
      /*
-      * See if this is a job we're interested in...
+      * Display the job...
       */
 
-      match = (dests == NULL && users == NULL);
       rank ++;
 
-      if (dests != NULL)
+      if (match_list(dests, dest) && match_list(users, username))
       {
-        for (dptr = dests; *dptr != '\0';)
-       {
-        /*
-         * Skip leading whitespace and commas...
-         */
-
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = dest;
-              *ptr != '\0' && *dptr != '\0' && tolower(*ptr & 255) == tolower(*dptr & 255);
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
-         {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
-
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
+        snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);
 
-         if (*dptr == '\0')
-           break;
-        }
-      }
+       _cupsStrDate(date, sizeof(date), jobtime);
 
-      if (users != NULL && username != NULL)
-      {
-        for (dptr = users; *dptr != '\0';)
+       if (ranking)
+         _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s",
+                         rank, temp, username ? username : "unknown",
+                         1024.0 * size, date);
+       else
+         _cupsLangPrintf(stdout, "%-23s %-13s %8.0f   %s",
+                         temp, username ? username : "unknown",
+                         1024.0 * size, date);
+       if (long_status)
        {
-        /*
-         * Skip leading whitespace and commas...
-         */
+         if (message)
+           _cupsLangPrintf(stdout, _("\tStatus: %s"), message);
 
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = username;
-              *ptr != '\0' && *dptr != '\0' && *ptr == *dptr;
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
+         if (reasons)
          {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
-
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-        }
-      }
-
-     /*
-      * Display the job...
-      */
-
-      if (match)
-      {
-        jobdate = localtime(&jobtime);
-        snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);
-
-        if (long_status == 3)
-       {
-        /*
-         * Show the consolidated output format for the SGI tools...
-         */
+           char        alerts[1024],   /* Alerts string */
+                     *aptr;            /* Pointer into alerts string */
 
-         if (!strftime(date, sizeof(date), "%b %d %H:%M", jobdate))
-           strcpy(date, "Unknown");
-
-         _cupsLangPrintf(stdout, "%s;%s;%d;%s;%s\n",
-                         temp, username ? username : "unknown",
-                         size, title ? title : "unknown", date);
-       }
-       else
-       {
-         if (!strftime(date, sizeof(date), "%c", jobdate))
-           strcpy(date, "Unknown");
-
-          if (ranking)
-           _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s\n",
-                           rank, temp, username ? username : "unknown",
-                           1024.0 * size, date);
-          else
-           _cupsLangPrintf(stdout, "%-23s %-13s %8.0f   %s\n",
-                           temp, username ? username : "unknown",
-                           1024.0 * size, date);
-          if (long_status)
-          {
-           if (reasons)
+           for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
            {
-             _cupsLangPuts(stdout, _("\tAlerts:"));
-             for (i = 0; i < reasons->num_values; i ++)
-               _cupsLangPrintf(stdout, " %s",
-                               reasons->values[i].string.text);
-             _cupsLangPuts(stdout, "\n");
+             if (i)
+               snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
+             else
+               strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
+
+             aptr += strlen(aptr);
            }
-           _cupsLangPrintf(stdout, _("\tqueued for %s\n"), dest);
+
+           _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
          }
+
+         _cupsLangPrintf(stdout, _("\tqueued for %s"), dest);
        }
       }
 
@@ -1684,11 +1510,6 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1699,8 +1520,7 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
  */
 
 static int                             /* O - 0 on success, 1 on fail */
-show_printers(http_t      *http,       /* I - HTTP connection to server */
-              const char  *printers,   /* I - Destinations */
+show_printers(const char  *printers,   /* I - Destinations */
               int         num_dests,   /* I - Number of user-defined dests */
              cups_dest_t *dests,       /* I - User-defined destinations */
               int         long_status) /* I - Show long status? */
@@ -1723,15 +1543,11 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
   ipp_pstate_t pstate;                 /* Printer state */
   cups_ptype_t ptype;                  /* Printer type */
   time_t       ptime;                  /* Printer state time */
-  struct tm    *pdate;                 /* Printer state date & time */
   int          jobid;                  /* Job ID of current job */
-  const char   *dptr,                  /* Pointer into destination list */
-               *ptr;                   /* Pointer into printer name */
-  int          match;                  /* Non-zero if this job matches */
   char         printer_uri[HTTP_MAX_URI],
                                        /* Printer URI */
                printer_state_time[255];/* Printer state time */
-  const char   *root;                  /* Server root directory... */
+  _cups_globals_t *cg = _cupsGlobals();        /* Global data */
   static const char *pattrs[] =                /* Attributes we need for printers... */
                {
                  "printer-name",
@@ -1749,17 +1565,13 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
                };
   static const char *jattrs[] =                /* Attributes we need for jobs... */
                {
-                 "job-id"
+                 "job-id",
+                 "job-state"
                };
 
 
-  DEBUG_printf(("show_printers(%p, %p)\n", http, dests));
-
-  if (http == NULL)
-    return (1);
-
-  if ((root = getenv("CUPS_SERVERROOT")) == NULL)
-    root = CUPS_SERVERROOT;
+  DEBUG_printf(("show_printers(printers=\"%s\", num_dests=%d, dests=%p, "
+                "long_status=%d)\n", printers, num_dests, dests, long_status));
 
   if (printers != NULL && !strcmp(printers, "all"))
     printers = NULL;
@@ -1787,16 +1599,27 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
+
+  if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
+      cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
   {
-    DEBUG_puts("show_printers: request succeeded...");
+    _cupsLangPrintf(stderr,
+                   _("%s: Error - add '/version=1.1' to server name."),
+                   "lpstat");
+    ippDelete(response);
+    return (1);
+  }
+  else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
+    ippDelete(response);
+    return (1);
+  }
 
-    if (response->request.status.status_code > IPP_OK_CONFLICT)
-    {
-      _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_printers: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -1887,59 +1710,11 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
           continue;
       }
 
-     /*
-      * See if this is a printer we're interested in...
-      */
-
-      match = printers == NULL;
-
-      if (printers != NULL)
-      {
-        for (dptr = printers; *dptr != '\0';)
-       {
-        /*
-         * Skip leading whitespace and commas...
-         */
-
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-
-         /*
-         * Compare names...
-         */
-
-         for (ptr = printer;
-              *ptr != '\0' && *dptr != '\0' && tolower(*ptr & 255) == tolower(*dptr & 255);
-              ptr ++, dptr ++);
-
-          if (*ptr == '\0' && (*dptr == '\0' || *dptr == ',' || isspace(*dptr & 255)))
-         {
-           match = 1;
-           break;
-         }
-
-         /*
-         * Skip trailing junk...
-         */
-
-          while (!isspace(*dptr & 255) && *dptr != ',' && *dptr != '\0')
-           dptr ++;
-         while (isspace(*dptr & 255) || *dptr == ',')
-           dptr ++;
-
-         if (*dptr == '\0')
-           break;
-        }
-      }
-
      /*
       * Display the printer entry if needed...
       */
 
-      if (match)
+      if (match_list(printers, printer))
       {
        /*
         * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
@@ -1973,7 +1748,7 @@ show_printers(http_t      *http,  /* I - HTTP connection to server */
          ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                       "printer-uri", NULL, printer_uri);
 
-          if ((jobs = cupsDoRequest(http, request, "/")) != NULL)
+          if ((jobs = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL)
          {
           /*
            * Get the current active job on this queue...
@@ -1997,7 +1772,7 @@ show_printers(http_t      *http,  /* I - HTTP connection to server */
                jobid = jobattr->values[0].integer;
               else if (!strcmp(jobattr->name, "job-state") &&
                       jobattr->value_tag == IPP_TAG_ENUM)
-               jobstate = jobattr->values[0].integer;
+               jobstate = (ipp_jstate_t)jobattr->values[0].integer;
            }
 
             if (jobstate != IPP_JOB_PROCESSING)
@@ -2011,137 +1786,139 @@ show_printers(http_t      *http,      /* I - HTTP connection to server */
         * Display it...
        */
 
-        pdate = localtime(&ptime);
-        strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate);
+        _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
 
         switch (pstate)
        {
          case IPP_PRINTER_IDLE :
-             _cupsLangPrintf(stdout,
-                             _("printer %s is idle.  enabled since %s\n"),
-                             printer, printer_state_time);
+             if (ippContainsString(reasons, "hold-new-jobs"))
+               _cupsLangPrintf(stdout, _("printer %s is holding new jobs.  enabled since %s"), printer, printer_state_time);
+             else
+               _cupsLangPrintf(stdout, _("printer %s is idle.  enabled since %s"), printer, printer_state_time);
              break;
          case IPP_PRINTER_PROCESSING :
-             _cupsLangPrintf(stdout,
-                             _("printer %s now printing %s-%d.  "
-                               "enabled since %s\n"),
-                             printer, printer, jobid, printer_state_time);
+             _cupsLangPrintf(stdout, _("printer %s now printing %s-%d.  enabled since %s"), printer, printer, jobid, printer_state_time);
              break;
          case IPP_PRINTER_STOPPED :
-             _cupsLangPrintf(stdout,
-                             _("printer %s disabled since %s -\n"),
-                             printer, printer_state_time);
+             _cupsLangPrintf(stdout, _("printer %s disabled since %s -"), printer, printer_state_time);
              break;
        }
 
         if ((message && *message) || pstate == IPP_PRINTER_STOPPED)
        {
          if (!message || !*message)
-           _cupsLangPuts(stdout, _("\treason unknown\n"));
+           _cupsLangPuts(stdout, _("\treason unknown"));
          else
-           _cupsLangPrintf(stdout, "\t%s\n", message);
+           _cupsLangPrintf(stdout, "\t%s", message);
        }
 
         if (long_status > 1)
-         _cupsLangPuts(stdout,
-                       _("\tForm mounted:\n"
-                         "\tContent types: any\n"
-                         "\tPrinter types: unknown\n"));
+       {
+         _cupsLangPuts(stdout, _("\tForm mounted:"));
+         _cupsLangPuts(stdout, _("\tContent types: any"));
+         _cupsLangPuts(stdout, _("\tPrinter types: unknown"));
+       }
 
         if (long_status)
        {
-         _cupsLangPrintf(stdout, _("\tDescription: %s\n"),
+         _cupsLangPrintf(stdout, _("\tDescription: %s"),
                          description ? description : "");
 
          if (reasons)
          {
-           _cupsLangPuts(stdout, _("\tAlerts:"));
-           for (j = 0; j < reasons->num_values; j ++)
-             _cupsLangPrintf(stdout, " %s",
-                             reasons->values[j].string.text);
-           _cupsLangPuts(stdout, "\n");
+           char        alerts[1024],   /* Alerts string */
+                       *aptr;          /* Pointer into alerts string */
+
+           for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
+           {
+             if (i)
+               snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
+             else
+               strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
+
+             aptr += strlen(aptr);
+           }
+
+           _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
          }
        }
         if (long_status > 1)
        {
-         _cupsLangPrintf(stdout, _("\tLocation: %s\n"),
+         _cupsLangPrintf(stdout, _("\tLocation: %s"),
                          location ? location : "");
 
          if (ptype & CUPS_PRINTER_REMOTE)
          {
-           _cupsLangPuts(stdout, _("\tConnection: remote\n"));
+           _cupsLangPuts(stdout, _("\tConnection: remote"));
 
            if (make_model && !strstr(make_model, "System V Printer") &&
                     !strstr(make_model, "Raw Printer") && uri)
-             _cupsLangPrintf(stdout, _("\tInterface: %s.ppd\n"),
+             _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"),
                              uri);
          }
          else
          {
-           _cupsLangPuts(stdout, _("\tConnection: direct\n"));
+           _cupsLangPuts(stdout, _("\tConnection: direct"));
 
-           if (make_model && strstr(make_model, "System V Printer"))
-             _cupsLangPrintf(stdout,
-                             _("\tInterface: %s/interfaces/%s\n"),
-                             root, printer);
-           else if (make_model && !strstr(make_model, "Raw Printer"))
+           if (make_model && !strstr(make_model, "Raw Printer"))
              _cupsLangPrintf(stdout,
-                             _("\tInterface: %s/ppd/%s.ppd\n"), root, printer);
+                             _("\tInterface: %s/ppd/%s.ppd"),
+                             cg->cups_serverroot, printer);
           }
-         _cupsLangPuts(stdout, _("\tOn fault: no alert\n"));
-         _cupsLangPuts(stdout, _("\tAfter fault: continue\n"));
+         _cupsLangPuts(stdout, _("\tOn fault: no alert"));
+         _cupsLangPuts(stdout, _("\tAfter fault: continue"));
              /* TODO update to use printer-error-policy */
           if (allowed)
          {
-           _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
+           _cupsLangPuts(stdout, _("\tUsers allowed:"));
            for (j = 0; j < allowed->num_values; j ++)
-             _cupsLangPrintf(stdout, "\t\t%s\n",
+             _cupsLangPrintf(stdout, "\t\t%s",
                              allowed->values[j].string.text);
          }
          else if (denied)
          {
-           _cupsLangPuts(stdout, _("\tUsers denied:\n"));
+           _cupsLangPuts(stdout, _("\tUsers denied:"));
            for (j = 0; j < denied->num_values; j ++)
-             _cupsLangPrintf(stdout, "\t\t%s\n",
+             _cupsLangPrintf(stdout, "\t\t%s",
                              denied->values[j].string.text);
          }
          else
          {
-           _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
-           _cupsLangPuts(stdout, _("\t\t(all)\n"));
+           _cupsLangPuts(stdout, _("\tUsers allowed:"));
+           _cupsLangPuts(stdout, _("\t\t(all)"));
          }
-         _cupsLangPuts(stdout, _("\tForms allowed:\n"));
-         _cupsLangPuts(stdout, _("\t\t(none)\n"));
-         _cupsLangPuts(stdout, _("\tBanner required\n"));
-         _cupsLangPuts(stdout, _("\tCharset sets:\n"));
-         _cupsLangPuts(stdout, _("\t\t(none)\n"));
-         _cupsLangPuts(stdout, _("\tDefault pitch:\n"));
-         _cupsLangPuts(stdout, _("\tDefault page size:\n"));
-         _cupsLangPuts(stdout, _("\tDefault port settings:\n"));
+         _cupsLangPuts(stdout, _("\tForms allowed:"));
+         _cupsLangPuts(stdout, _("\t\t(none)"));
+         _cupsLangPuts(stdout, _("\tBanner required"));
+         _cupsLangPuts(stdout, _("\tCharset sets:"));
+         _cupsLangPuts(stdout, _("\t\t(none)"));
+         _cupsLangPuts(stdout, _("\tDefault pitch:"));
+         _cupsLangPuts(stdout, _("\tDefault page size:"));
+         _cupsLangPuts(stdout, _("\tDefault port settings:"));
        }
 
         for (i = 0; i < num_dests; i ++)
-         if (!strcasecmp(printer, dests[i].name) && dests[i].instance)
+         if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
          {
             switch (pstate)
            {
              case IPP_PRINTER_IDLE :
                  _cupsLangPrintf(stdout,
                                  _("printer %s/%s is idle.  "
-                                   "enabled since %s\n"),
+                                   "enabled since %s"),
                                  printer, dests[i].instance,
                                  printer_state_time);
                  break;
              case IPP_PRINTER_PROCESSING :
                  _cupsLangPrintf(stdout,
                                  _("printer %s/%s now printing %s-%d.  "
-                                   "enabled since %s\n"),
+                                   "enabled since %s"),
                                  printer, dests[i].instance, printer, jobid,
                                  printer_state_time);
                  break;
              case IPP_PRINTER_STOPPED :
                  _cupsLangPrintf(stdout,
-                                 _("printer %s/%s disabled since %s -\n"),
+                                 _("printer %s/%s disabled since %s -"),
                                  printer, dests[i].instance,
                                  printer_state_time);
                  break;
@@ -2150,87 +1927,93 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
             if ((message && *message) || pstate == IPP_PRINTER_STOPPED)
            {
              if (!message || !*message)
-               _cupsLangPuts(stdout, _("\treason unknown\n"));
+               _cupsLangPuts(stdout, _("\treason unknown"));
              else
-               _cupsLangPrintf(stdout, "\t%s\n", message);
+               _cupsLangPrintf(stdout, "\t%s", message);
             }
 
             if (long_status > 1)
-             _cupsLangPuts(stdout,
-                           _("\tForm mounted:\n"
-                             "\tContent types: any\n"
-                             "\tPrinter types: unknown\n"));
+           {
+             _cupsLangPuts(stdout, _("\tForm mounted:"));
+             _cupsLangPuts(stdout, _("\tContent types: any"));
+             _cupsLangPuts(stdout, _("\tPrinter types: unknown"));
+           }
 
             if (long_status)
            {
-             _cupsLangPrintf(stdout, _("\tDescription: %s\n"),
+             _cupsLangPrintf(stdout, _("\tDescription: %s"),
                              description ? description : "");
 
              if (reasons)
              {
-               _cupsLangPuts(stdout, _("\tAlerts:"));
-               for (j = 0; j < reasons->num_values; j ++)
-                 _cupsLangPrintf(stdout, " %s",
-                                 reasons->values[j].string.text);
-               _cupsLangPuts(stdout, "\n");
+               char    alerts[1024],   /* Alerts string */
+                       *aptr;          /* Pointer into alerts string */
+
+               for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
+               {
+                 if (i)
+                   snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
+                 else
+                   strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
+
+                 aptr += strlen(aptr);
+               }
+
+               _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
              }
            }
             if (long_status > 1)
            {
-             _cupsLangPrintf(stdout, _("\tLocation: %s\n"),
+             _cupsLangPrintf(stdout, _("\tLocation: %s"),
                              location ? location : "");
 
              if (ptype & CUPS_PRINTER_REMOTE)
              {
-               _cupsLangPuts(stdout, _("\tConnection: remote\n"));
+               _cupsLangPuts(stdout, _("\tConnection: remote"));
 
                if (make_model && !strstr(make_model, "System V Printer") &&
                         !strstr(make_model, "Raw Printer") && uri)
-                 _cupsLangPrintf(stdout, _("\tInterface: %s.ppd\n"),
-                                 uri);
+                 _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"), uri);
              }
              else
              {
-               _cupsLangPuts(stdout, _("\tConnection: direct\n"));
+               _cupsLangPuts(stdout, _("\tConnection: direct"));
 
-               if (make_model && strstr(make_model, "System V Printer"))
+               if (make_model && !strstr(make_model, "Raw Printer"))
                  _cupsLangPrintf(stdout,
-                                 _("\tInterface: %s/interfaces/%s\n"),
-                                 root, printer);
-               else if (make_model && !strstr(make_model, "Raw Printer"))
-                 _cupsLangPrintf(stdout,
-                                 _("\tInterface: %s/ppd/%s.ppd\n"), root, printer);
+                                 _("\tInterface: %s/ppd/%s.ppd"),
+                                 cg->cups_serverroot, printer);
               }
-             _cupsLangPuts(stdout, _("\tOn fault: no alert\n"));
-             _cupsLangPuts(stdout, _("\tAfter fault: continue\n"));
+             _cupsLangPuts(stdout, _("\tOn fault: no alert"));
+             _cupsLangPuts(stdout, _("\tAfter fault: continue"));
                  /* TODO update to use printer-error-policy */
               if (allowed)
              {
-               _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
+               _cupsLangPuts(stdout, _("\tUsers allowed:"));
                for (j = 0; j < allowed->num_values; j ++)
-                 _cupsLangPrintf(stdout, "\t\t%s\n",
+                 _cupsLangPrintf(stdout, "\t\t%s",
                                  allowed->values[j].string.text);
              }
              else if (denied)
              {
-               _cupsLangPuts(stdout, _("\tUsers denied:\n"));
+               _cupsLangPuts(stdout, _("\tUsers denied:"));
                for (j = 0; j < denied->num_values; j ++)
-                 _cupsLangPrintf(stdout, "\t\t%s\n",
+                 _cupsLangPrintf(stdout, "\t\t%s",
                                  denied->values[j].string.text);
              }
              else
              {
-               _cupsLangPuts(stdout, _("\tUsers allowed:\n"));
-               _cupsLangPuts(stdout, _("\t\t(all)\n"));
+               _cupsLangPuts(stdout, _("\tUsers allowed:"));
+               _cupsLangPuts(stdout, _("\t\t(all)"));
              }
-             _cupsLangPuts(stdout, _("\tForms allowed:\n"));
-             _cupsLangPuts(stdout, _("\t\t(none)\n"));
-             _cupsLangPuts(stdout, _("\tBanner required\n"));
-             _cupsLangPuts(stdout, _("\tCharset sets:\n"));
-             _cupsLangPuts(stdout, _("\t\t(none)\n"));
-             _cupsLangPuts(stdout, _("\tDefault pitch:\n"));
-             _cupsLangPuts(stdout, _("\tDefault page size:\n"));
-             _cupsLangPuts(stdout, _("\tDefault port settings:\n"));
+             _cupsLangPuts(stdout, _("\tForms allowed:"));
+             _cupsLangPuts(stdout, _("\t\t(none)"));
+             _cupsLangPuts(stdout, _("\tBanner required"));
+             _cupsLangPuts(stdout, _("\tCharset sets:"));
+             _cupsLangPuts(stdout, _("\t\t(none)"));
+             _cupsLangPuts(stdout, _("\tDefault pitch:"));
+             _cupsLangPuts(stdout, _("\tDefault page size:"));
+             _cupsLangPuts(stdout, _("\tDefault port settings:"));
            }
          }
       }
@@ -2241,11 +2024,6 @@ show_printers(http_t      *http, /* I - HTTP connection to server */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s\n", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -2256,15 +2034,17 @@ show_printers(http_t      *http,        /* I - HTTP connection to server */
  */
 
 static void
-show_scheduler(http_t *http)   /* I - HTTP connection to server */
+show_scheduler(void)
 {
-  if (http)
-    _cupsLangPuts(stdout, _("scheduler is running\n"));
-  else
-    _cupsLangPuts(stdout, _("scheduler is not running\n"));
-}
+  http_t       *http;                  /* Connection to server */
 
 
-/*
- * End of "$Id: lpstat.c 7620 2008-06-06 17:24:22Z mike $".
- */
+  if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
+                                 cupsEncryption())) != NULL)
+  {
+    _cupsLangPuts(stdout, _("scheduler is running"));
+    httpClose(http);
+  }
+  else
+    _cupsLangPuts(stdout, _("scheduler is not running"));
+}