]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpq.c
Fix lpadmin error reporting for IPP Everywhere printers (Issue #5370)
[thirdparty/cups.git] / berkeley / lpq.c
index a5e009171c2d106bfce880390cdc9f80cae7391d..47220f5d77c2792694b597e52edf8334f4d427ba 100644 (file)
@@ -1,58 +1,28 @@
 /*
- * "$Id: lpq.c 4906 2006-01-10 20:53:28Z mike $"
+ * "lpq" command for CUPS.
  *
- *   "lpq" command for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2016 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- * Contents:
- *
- *   main()         - Parse options and commands.
- *   show_jobs()    - Show jobs.
- *   show_printer() - Show printer status.
- *   usage()        - Show program usage.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-/*
- * Include necessary headers...
- */
-
-#include <stdio.h>
-#include <stdlib.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 int     show_jobs(http_t *, const char *, const char *, const int,
-                         const int);
-static void    show_printer(http_t *, const char *);
-static void    usage(void);
+static http_t  *connect_server(const char *, http_t *);
+static int     show_jobs(const char *, http_t *, const char *,
+                         const char *, const int, const int);
+static void    show_printer(const char *, http_t *, const char *);
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
@@ -60,137 +30,186 @@ static void       usage(void);
  */
 
 int
-main(int  argc,                /* I - Number of command-line arguments */
-     char *argv[])     /* I - Command-line arguments */
+main(int  argc,                                /* I - Number of command-line arguments */
+     char *argv[])                     /* I - Command-line arguments */
 {
-  int          i;              /* Looping var */
-  http_t       *http;          /* Connection to server */
-  const char   *dest,          /* Desired printer */
-               *user,          /* Desired user */
-               *val;           /* Environment variable name */
-  char         *instance;      /* Printer instance */
-  int          id,             /* Desired job ID */
-               all,            /* All printers */
-               interval,       /* Reporting interval */
-               longstatus;     /* Show file details */
-  int          num_dests;      /* Number of destinations */
-  cups_dest_t  *dests;         /* Destinations */
-  cups_lang_t  *language;      /* Language */
-#ifdef HAVE_SSL
-  http_encryption_t encryption;        /* Encryption? */
-#endif /* HAVE_SSL */
-
-
-  language = cupsLangDefault();
-
- /*
-  * Connect to the scheduler...
-  */
-
-  if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                 cupsEncryption())) == NULL)
-  {
-    _cupsLangPuts(stderr, language,
-                  _("lpq: Unable to contact server!\n"));
-    return (1);
-  }
+  int          i;                      /* Looping var */
+  http_t       *http;                  /* Connection to server */
+  const char   *opt,                   /* Option pointer */
+               *dest,                  /* Desired printer */
+               *user,                  /* Desired user */
+               *val;                   /* Environment variable name */
+  char         *instance;              /* Printer instance */
+  int          id,                     /* Desired job ID */
+               all,                    /* All printers */
+               interval,               /* Reporting interval */
+               longstatus;             /* Show file details */
+  cups_dest_t  *named_dest;            /* Named destination */
+
+
+  _cupsSetLocale(argv);
 
  /*
   * Check for command-line options...
   */
 
+  http       = NULL;
   dest       = NULL;
   user       = NULL;
   id         = 0;
   interval   = 0;
   longstatus = 0;
   all        = 0;
-  num_dests  = cupsGetDests(&dests);
 
   for (i = 1; i < argc; i ++)
+  {
     if (argv[i][0] == '+')
+    {
       interval = atoi(argv[i] + 1);
+    }
     else if (argv[i][0] == '-')
     {
-      switch (argv[i][1])
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'E' : /* Encrypt */
+       switch (*opt)
+       {
+         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           encryption = HTTP_ENCRYPT_REQUIRED;
+             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 
-           if (http)
-             httpEncryption(http, encryption);
+             if (http)
+               httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr, language,
-                           _("%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 'U' : /* Username */
+             if (opt[1] != '\0')
+             {
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
+                 return (1);
+               }
 
-        case 'P' : /* Printer */
-           if (argv[i][2])
-             dest = argv[i] + 2;
-           else
-           {
-             i ++;
+               cupsSetUser(argv[i]);
+             }
+             break;
 
-             if (i >= argc)
+         case 'P' : /* Printer */
+             if (opt[1] != '\0')
              {
-               httpClose(http);
-               cupsFreeDests(num_dests, dests);
-               
-               usage();
+               dest = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             dest = argv[i];
-           }
+               if (i >= argc)
+               {
+                 httpClose(http);
 
-           if ((instance = strchr(dest, '/')) != NULL)
-             *instance++ = '\0';
+                 usage();
+               }
 
-            if (cupsGetDest(dest, instance, num_dests, dests) == NULL)
-           {
-             if (instance)
-               _cupsLangPrintf(stderr, language,
-                               _("lpq: Unknown destination \"%s/%s\"!\n"),
-                               dest, instance);
-              else
-               _cupsLangPrintf(stderr, language,
-                               _("lpq: Unknown destination \"%s\"!\n"), dest);
+               dest = argv[i];
+             }
+
+             if ((instance = strchr(dest, '/')) != NULL)
+               *instance++ = '\0';
 
-             return (1);
-           }
-           break;
+             http = connect_server(argv[0], http);
 
-       case 'a' : /* All printers */
-           all = 1;
-           break;
+             if ((named_dest = cupsGetNamedDest(http, dest, instance)) == 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."), argv[0]);
+               else if (instance)
+                 _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s/%s\"."), argv[0], dest, instance);
+               else
+                 _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."), argv[0], dest);
+
+               return (1);
+             }
 
-       case 'l' : /* Long status */
-           longstatus = 1;
-           break;
+             cupsFreeDests(1, named_dest);
+             break;
 
-       default :
-           httpClose(http);
-           cupsFreeDests(num_dests, dests);
+         case 'a' : /* All printers */
+             all = 1;
+             break;
 
-           usage();
-           break;
+         case 'h' : /* Connect to host */
+             if (http)
+             {
+               httpClose(http);
+               http = NULL;
+             }
+
+             if (opt[1] != '\0')
+             {
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]);
+                 return (1);
+               }
+               else
+                 cupsSetServer(argv[i]);
+             }
+             break;
+
+         case 'l' : /* Long status */
+             longstatus = 1;
+             break;
+
+         default :
+             httpClose(http);
+
+             usage();
+       }
       }
     }
     else if (isdigit(argv[i][0] & 255))
+    {
       id = atoi(argv[i]);
+    }
     else
+    {
       user = argv[i];
+    }
+  }
+
+  http = connect_server(argv[0], http);
 
   if (dest == NULL && !all)
   {
-    for (i = 0; i < num_dests; i ++)
-      if (dests[i].is_default)
-       dest = dests[i].name;
-
-    if (dest == NULL)
+    if ((named_dest = cupsGetNamedDest(http, NULL, NULL)) == 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."),
+                       argv[0]);
+        return (1);
+      }
+
       val = NULL;
 
       if ((dest = getenv("LPDEST")) == NULL)
@@ -206,18 +225,20 @@ main(int  argc,           /* I - Number of command-line arguments */
       else
        val = "LPDEST";
 
-      if (dest && !cupsGetDest(dest, NULL, num_dests, dests))
-       _cupsLangPrintf(stderr, language,
-                       _("lp: error - %s environment variable names "
-                         "non-existent destination \"%s\"!\n"),
-                       val, dest);
+      if (dest && val)
+       _cupsLangPrintf(stderr,
+                       _("%s: Error - %s environment variable names "
+                         "non-existent destination \"%s\"."), argv[0], val,
+                       dest);
       else
-       _cupsLangPuts(stderr, language,
-                     _("lpq: error - no default destination available.\n"));
+       _cupsLangPrintf(stderr,
+                       _("%s: Error - no default destination available."),
+                       argv[0]);
       httpClose(http);
-      cupsFreeDests(num_dests, dests);
       return (1);
     }
+
+    dest = named_dest->name;
   }
 
  /*
@@ -227,14 +248,14 @@ main(int  argc,           /* I - Number of command-line arguments */
   for (;;)
   {
     if (dest)
-      show_printer(http, dest);
+      show_printer(argv[0], http, dest);
 
-    i = show_jobs(http, dest, user, id, longstatus);
+    i = show_jobs(argv[0], http, dest, user, id, longstatus);
 
     if (i && interval)
     {
       fflush(stdout);
-      sleep(interval);
+      sleep((unsigned)interval);
     }
     else
       break;
@@ -244,44 +265,75 @@ main(int  argc,           /* I - Number of command-line arguments */
   * Close the connection to the server and return...
   */
 
-  cupsFreeDests(num_dests, dests);
   httpClose(http);
 
   return (0);
 }
 
 
+/*
+ * 'connect_server()' - Connect to the server as necessary...
+ */
+
+static http_t *                                /* O - New HTTP connection */
+connect_server(const char *command,    /* I - Command name */
+               http_t     *http)       /* I - Current HTTP connection */
+{
+  if (!http)
+  {
+    http = httpConnectEncrypt(cupsServer(), ippPort(),
+                             cupsEncryption());
+
+    if (http == NULL)
+    {
+      _cupsLangPrintf(stderr, _("%s: Unable to connect to server."), command);
+      exit(1);
+    }
+  }
+
+  return (http);
+}
+
+
 /*
  * 'show_jobs()' - Show jobs.
  */
 
-static int                     /* O - Number of jobs in queue */
-show_jobs(http_t     *http,    /* I - HTTP connection to server */
-          const char *dest,    /* I - Destination */
-         const char *user,     /* I - User */
-         const int  id,        /* I - Job ID */
-         const int  longstatus)/* I - 1 if long report desired */
+static int                             /* O - Number of jobs in queue */
+show_jobs(const char *command,         /* I - Command name */
+          http_t     *http,            /* I - HTTP connection to server */
+          const char *dest,            /* I - Destination */
+         const char *user,             /* I - User */
+         const int  id,                /* I - Job ID */
+         const int  longstatus)        /* I - 1 if long report desired */
 {
-  ipp_t                *request,       /* IPP Request */
-               *response;      /* IPP Response */
-  ipp_attribute_t *attr;       /* Current attribute */
-  cups_lang_t  *language;      /* Default language */
-  const char   *jobdest,       /* Pointer into job-printer-uri */
-               *jobuser,       /* Pointer to job-originating-user-name */
-               *jobname;       /* Pointer to job-name */
-  ipp_jstate_t jobstate;       /* job-state */
-  int          jobid,          /* job-id */
-               jobsize,        /* job-k-octets */
-#ifdef __osf__
-               jobpriority,    /* job-priority */
-#endif /* __osf__ */
-               jobcount,       /* Number of jobs */
-               jobcopies,      /* Number of copies */
-               rank;           /* Rank of job */
-  char         resource[1024]; /* Resource string */
-  char         rankstr[255];   /* Rank string */
-  char         namestr[1024];  /* Job name string */
-  static const char *ranks[10] =/* Ranking strings */
+  ipp_t                *request,               /* IPP Request */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
+  const char   *jobdest,               /* Pointer into job-printer-uri */
+               *jobuser,               /* Pointer to job-originating-user-name */
+               *jobname;               /* Pointer to job-name */
+  ipp_jstate_t jobstate;               /* job-state */
+  int          jobid,                  /* job-id */
+               jobsize,                /* job-k-octets */
+               jobcount,               /* Number of jobs */
+               jobcopies,              /* Number of copies */
+               rank;                   /* Rank of job */
+  char         resource[1024];         /* Resource string */
+  char         rankstr[255];           /* Rank string */
+  char         namestr[1024];          /* Job name string */
+  static const char * const jobattrs[] =/* Job attributes we want to see */
+               {
+                 "copies",
+                 "job-id",
+                 "job-k-octets",
+                 "job-name",
+                 "job-originating-user-name",
+                 "job-printer-uri",
+                 "job-priority",
+                 "job-state"
+               };
+  static const char * const ranks[10] =        /* Ranking strings */
                {
                  "th",
                  "st",
@@ -296,8 +348,8 @@ show_jobs(http_t     *http, /* I - HTTP connection to server */
                };
 
 
-  DEBUG_printf(("show_jobs(%08x, %08x, %08x, %d, %d)\n", http, dest, user, id,
-                longstatus));
+  DEBUG_printf(("show_jobs(http=%p, dest=%p, user=%p, id=%d, longstatus%d)\n",
+                http, dest, user, id, longstatus));
 
   if (http == NULL)
     return (0);
@@ -309,39 +361,29 @@ show_jobs(http_t     *http,       /* I - HTTP connection to server */
   *    attributes-charset
   *    attributes-natural-language
   *    job-uri or printer-uri
+  *    requested-attributes
+  *    requesting-user-name
   */
 
-  request = ippNew();
-
-  request->request.op.operation_id = id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS;
-  request->request.op.request_id   = 1;
-
-  language = cupsLangDefault();
-
-  attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                      "attributes-charset", NULL, cupsLangEncoding(language));
+  request = ippNewRequest(id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS);
 
-  attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                      "attributes-natural-language", NULL, language->language);
-
-  if (dest == NULL)
+  if (id)
   {
-    if (id)
-      sprintf(resource, "ipp://localhost/jobs/%d", id);
-    else
-      strcpy(resource, "ipp://localhost/jobs");
-
+    snprintf(resource, sizeof(resource), "ipp://localhost/jobs/%d", id);
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
                  NULL, resource);
   }
-  else
+  else if (dest)
   {
-    httpAssembleURIf(resource, sizeof(resource), "ipp", NULL, "localhost", 0,
-                    "/printers/%s", dest);
+    httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
+                     NULL, "localhost", 0, "/printers/%s", dest);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, resource);
   }
+  else
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+                 NULL, "ipp://localhost/");
 
   if (user)
   {
@@ -349,6 +391,13 @@ show_jobs(http_t     *http,        /* I - HTTP connection to server */
                  "requesting-user-name", NULL, user);
     ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
   }
+  else
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+                 "requesting-user-name", NULL, cupsUser());
+
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+                "requested-attributes",
+                (int)(sizeof(jobattrs) / sizeof(jobattrs[0])), NULL, jobattrs);
 
  /*
   * Do the request and get back a response...
@@ -360,8 +409,7 @@ show_jobs(http_t     *http, /* I - HTTP connection to server */
   {
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, language, _("lpq: get-jobs failed: %s\n"),
-                     ippErrorString(response->request.status.status_code));
+      _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
       ippDelete(response);
       return (0);
     }
@@ -390,49 +438,40 @@ show_jobs(http_t     *http,       /* I - HTTP connection to server */
 
       jobid       = 0;
       jobsize     = 0;
-#ifdef __osf__
-      jobpriority = 50;
-#endif /* __osf__ */
       jobstate    = IPP_JOB_PENDING;
-      jobname     = "untitled";
-      jobuser     = NULL;
+      jobname     = "unknown";
+      jobuser     = "unknown";
       jobdest     = NULL;
       jobcopies   = 1;
 
       while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
       {
-        if (strcmp(attr->name, "job-id") == 0 &&
+        if (!strcmp(attr->name, "job-id") &&
            attr->value_tag == IPP_TAG_INTEGER)
          jobid = attr->values[0].integer;
 
-        if (strcmp(attr->name, "job-k-octets") == 0 &&
+        if (!strcmp(attr->name, "job-k-octets") &&
            attr->value_tag == IPP_TAG_INTEGER)
          jobsize = attr->values[0].integer;
 
-#ifdef __osf__
-        if (strcmp(attr->name, "job-priority") == 0 &&
-           attr->value_tag == IPP_TAG_INTEGER)
-         jobpriority = attr->values[0].integer;
-#endif /* __osf__ */
-
-        if (strcmp(attr->name, "job-state") == 0 &&
+        if (!strcmp(attr->name, "job-state") &&
            attr->value_tag == IPP_TAG_ENUM)
          jobstate = (ipp_jstate_t)attr->values[0].integer;
 
-        if (strcmp(attr->name, "job-printer-uri") == 0 &&
+        if (!strcmp(attr->name, "job-printer-uri") &&
            attr->value_tag == IPP_TAG_URI)
          if ((jobdest = strrchr(attr->values[0].string.text, '/')) != NULL)
            jobdest ++;
 
-        if (strcmp(attr->name, "job-originating-user-name") == 0 &&
+        if (!strcmp(attr->name, "job-originating-user-name") &&
            attr->value_tag == IPP_TAG_NAME)
          jobuser = attr->values[0].string.text;
 
-        if (strcmp(attr->name, "job-name") == 0 &&
+        if (!strcmp(attr->name, "job-name") &&
            attr->value_tag == IPP_TAG_NAME)
          jobname = attr->values[0].string.text;
 
-        if (strcmp(attr->name, "copies") == 0 &&
+        if (!strcmp(attr->name, "copies") &&
            attr->value_tag == IPP_TAG_INTEGER)
          jobcopies = attr->values[0].integer;
 
@@ -452,15 +491,9 @@ show_jobs(http_t     *http,        /* I - HTTP connection to server */
       }
 
       if (!longstatus && jobcount == 0)
-#ifdef __osf__
-       _cupsLangPuts(stdout, language,
-                     _("Rank   Owner      Pri  Job        Files"
-                       "                       Total Size\n"));
-#else
-       _cupsLangPuts(stdout, language,
+       _cupsLangPuts(stdout,
                      _("Rank    Owner   Job     File(s)"
-                       "                         Total Size\n"));
-#endif /* __osf__ */
+                       "                         Total Size"));
 
       jobcount ++;
 
@@ -469,7 +502,7 @@ show_jobs(http_t     *http, /* I - HTTP connection to server */
       */
 
       if (jobstate == IPP_JOB_PROCESSING)
-       strcpy(rankstr, "active");
+       strlcpy(rankstr, "active", sizeof(rankstr));
       else
       {
        /*
@@ -487,7 +520,7 @@ show_jobs(http_t     *http, /* I - HTTP connection to server */
 
       if (longstatus)
       {
-        _cupsLangPuts(stdout, language, "");
+        _cupsLangPuts(stdout, "\n");
 
         if (jobcopies > 1)
          snprintf(namestr, sizeof(namestr), "%d copies of %s", jobcopies,
@@ -495,22 +528,15 @@ show_jobs(http_t     *http,       /* I - HTTP connection to server */
        else
          strlcpy(namestr, jobname, sizeof(namestr));
 
-        _cupsLangPrintf(stdout, language, _("%s: %-33.33s [job %d localhost]\n"),
+        _cupsLangPrintf(stdout, _("%s: %-33.33s [job %d localhost]"),
                        jobuser, rankstr, jobid);
-        _cupsLangPrintf(stdout, language, _("        %-39.39s %.0f bytes\n"),
+        _cupsLangPrintf(stdout, _("        %-39.39s %.0f bytes"),
                        namestr, 1024.0 * jobsize);
       }
       else
-#ifdef __osf__
-        _cupsLangPrintf(stdout, language,
-                       _("%-6s %-10.10s %-4d %-10d %-27.27s %.0f bytes\n"),
-                       rankstr, jobuser, jobpriority, jobid, jobname,
-                       1024.0 * jobsize);
-#else
-        _cupsLangPrintf(stdout, language,
-                       _("%-7s %-7.7s %-7d %-31.31s %.0f bytes\n"),
+        _cupsLangPrintf(stdout,
+                       _("%-7s %-7.7s %-7d %-31.31s %.0f bytes"),
                        rankstr, jobuser, jobid, jobname, 1024.0 * jobsize);
-#endif /* __osf */
 
       if (attr == NULL)
         break;
@@ -520,13 +546,12 @@ show_jobs(http_t     *http,       /* I - HTTP connection to server */
   }
   else
   {
-    _cupsLangPrintf(stderr, language, _("lpq: get-jobs failed: %s\n"),
-                    ippErrorString(cupsLastError()));
+    _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
     return (0);
   }
 
   if (jobcount == 0)
-    _cupsLangPuts(stdout, language, _("no entries\n"));
+    _cupsLangPuts(stdout, _("no entries"));
 
   return (jobcount);
 }
@@ -537,16 +562,15 @@ show_jobs(http_t     *http,       /* I - HTTP connection to server */
  */
 
 static void
-show_printer(http_t     *http, /* I - HTTP connection to server */
-             const char *dest) /* I - Destination */
+show_printer(const char *command,      /* I - Command name */
+             http_t     *http,         /* I - HTTP connection to server */
+             const char *dest)         /* I - Destination */
 {
-  ipp_t                *request,       /* IPP Request */
-               *response;      /* IPP Response */
-  ipp_attribute_t *attr;       /* Current attribute */
-  cups_lang_t  *language;      /* Default language */
-  ipp_pstate_t state;          /* Printer state */
-  char         uri[HTTP_MAX_URI];
-                               /* Printer URI */
+  ipp_t                *request,               /* IPP Request */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
+  ipp_pstate_t state;                  /* Printer state */
+  char         uri[HTTP_MAX_URI];      /* Printer URI */
 
 
   if (http == NULL)
@@ -561,21 +585,10 @@ show_printer(http_t     *http,    /* I - HTTP connection to server */
   *    printer-uri
   */
 
-  request = ippNew();
-
-  request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
-  request->request.op.request_id   = 1;
-
-  language = cupsLangDefault();
+  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-               "attributes-charset", NULL, cupsLangEncoding(language));
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-               "attributes-natural-language", NULL, language->language);
-
-  httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0,
-                  "/printers/%s", dest);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                   "localhost", 0, "/printers/%s", dest);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
 
@@ -587,9 +600,7 @@ show_printer(http_t     *http,      /* I - HTTP connection to server */
   {
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, language,
-                      _("lpq: get-printer-attributes failed: %s\n"),
-                     ippErrorString(response->request.status.status_code));
+      _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
       ippDelete(response);
       return;
     }
@@ -602,23 +613,21 @@ show_printer(http_t     *http,    /* I - HTTP connection to server */
     switch (state)
     {
       case IPP_PRINTER_IDLE :
-          _cupsLangPrintf(stdout, language, _("%s is ready\n"), dest);
+          _cupsLangPrintf(stdout, _("%s is ready"), dest);
          break;
       case IPP_PRINTER_PROCESSING :
-          _cupsLangPrintf(stdout, language, _("%s is ready and printing\n"),
+          _cupsLangPrintf(stdout, _("%s is ready and printing"),
                          dest);
          break;
       case IPP_PRINTER_STOPPED :
-          _cupsLangPrintf(stdout, language, _("%s is not ready\n"), dest);
+          _cupsLangPrintf(stdout, _("%s is not ready"), dest);
          break;
     }
 
     ippDelete(response);
   }
   else
-    _cupsLangPrintf(stderr, language,
-                    _("lpq: get-printer-attributes failed: %s\n"),
-                   ippErrorString(cupsLastError()));
+    _cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
 }
 
 
@@ -629,12 +638,8 @@ show_printer(http_t     *http,     /* I - HTTP connection to server */
 static void
 usage(void)
 {
-  _cupsLangPuts(stderr, cupsLangDefault(),
-                _("Usage: lpq [-P dest] [-l] [+interval]\n"));
+  _cupsLangPuts(stderr,
+                _("Usage: lpq [-P dest] [-U username] [-h hostname[:port]] "
+                 "[-l] [+interval]"));
   exit(1);
 }
-
-
-/*
- * End of "$Id: lpq.c 4906 2006-01-10 20:53:28Z mike $".
- */