]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpstat.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / systemv / lpstat.c
index 6feb00e599f0a5cc3ad7afa2a75689e4a0f9c6cf..86e7a7ca33361566623cbb9481d37ebece973de3 100644 (file)
@@ -1,14 +1,11 @@
 /*
  * "lpstat" command for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright © 2007-2018 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
- * missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -36,6 +33,7 @@ static int    show_jobs(const char *dests, const char *users, int long_status,
 static int     show_printers(const char *printers, int num_dests,
                              cups_dest_t *dests, int long_status);
 static void    show_scheduler(void);
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
@@ -73,11 +71,13 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   for (i = 1; i < argc; i ++)
   {
-    if (argv[i][0] == '-')
+    if (!strcmp(argv[i], "--help"))
+      usage();
+    else if (argv[i][0] == '-')
     {
       for (opt = argv[i] + 1; *opt; opt ++)
       {
-       switch (argv[i][1])
+       switch (*opt)
        {
          case 'D' : /* Show description */
              long_status = 1;
@@ -127,7 +127,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                cupsSetUser(argv[i]);
@@ -147,7 +147,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                which = argv[i];
@@ -156,7 +156,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              if (strcmp(which, "completed") && strcmp(which, "not-completed") && strcmp(which, "all"))
              {
                _cupsLangPrintf(stderr, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv[0]);
-               return (1);
+               usage();
              }
              break;
 
@@ -240,6 +240,41 @@ main(int  argc,                            /* I - Number of command-line arguments */
              show_default(dests);
              break;
 
+         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;
+
          case 'f' : /* Show forms */
              op   = 'f';
              if (opt[1] != '\0')
@@ -450,7 +485,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
          default :
              _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], argv[i][1]);
-             return (1);
+             usage();
        }
       }
     }
@@ -599,7 +634,7 @@ match_list(const char *list,                /* I - List of names */
   if (!name)
     return (0);
 
-  while (*list)
+  do
   {
    /*
     * Skip leading whitespace and commas...
@@ -625,6 +660,7 @@ match_list(const char *list,                /* I - List of names */
     while (*list && !isspace(*list & 255) && *list != ',')
       list ++;
   }
+  while (*list);
 
   return (0);
 }
@@ -657,8 +693,6 @@ show_accepting(const char  *printers,       /* I - Destinations */
                };
 
 
-  DEBUG_printf(("show_accepting(printers=\"%s\")\n", printers));
-
   if (printers != NULL && !strcmp(printers, "all"))
     printers = NULL;
 
@@ -705,8 +739,6 @@ show_accepting(const char  *printers,       /* I - Destinations */
 
   if (response)
   {
-    DEBUG_puts("show_accepting: request succeeded...");
-
    /*
     * Loop through the printers returned in the list and display
     * their devices...
@@ -779,8 +811,8 @@ show_accepting(const char  *printers,       /* I - Destinations */
          _cupsLangPrintf(stdout, _("%s not accepting requests since %s -"),
                          printer, printer_state_time);
          _cupsLangPrintf(stdout, _("\t%s"),
-                         (message == NULL || !*message) ?
-                             "reason unknown" : message);
+                         (message && *message) ?
+                             message : "reason unknown");
         }
 
         for (i = 0; i < num_dests; i ++)
@@ -795,8 +827,8 @@ show_accepting(const char  *printers,       /* I - Destinations */
                              _("%s/%s not accepting requests since %s -"),
                              printer, dests[i].instance, printer_state_time);
              _cupsLangPrintf(stdout, _("\t%s"),
-                             (message == NULL || !*message) ?
-                                 "reason unknown" : message);
+                             (message && *message) ?
+                                 message : "reason unknown");
             }
          }
       }
@@ -841,8 +873,6 @@ show_classes(const char *dests)             /* I - Destinations */
                };
 
 
-  DEBUG_printf(("show_classes(dests=\"%s\")\n", dests));
-
   if (dests != NULL && !strcmp(dests, "all"))
     dests = NULL;
 
@@ -889,8 +919,6 @@ show_classes(const char *dests)             /* I - Destinations */
 
   if (response)
   {
-    DEBUG_puts("show_classes: request succeeded...");
-
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
       _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
@@ -923,7 +951,7 @@ show_classes(const char *dests)             /* I - Destinations */
       printer_uri = NULL;
       members     = NULL;
 
-      while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
+      do
       {
         if (!strcmp(attr->name, "printer-name") &&
            attr->value_tag == IPP_TAG_NAME)
@@ -939,6 +967,7 @@ show_classes(const char *dests)             /* I - Destinations */
 
         attr = attr->next;
       }
+         while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER);
 
      /*
       * If this is a remote class, grab the class info from the
@@ -1102,8 +1131,6 @@ show_devices(const char  *printers,       /* I - Destinations */
                };
 
 
-  DEBUG_printf(("show_devices(printers=\"%s\")\n", printers));
-
   if (printers != NULL && !strcmp(printers, "all"))
     printers = NULL;
 
@@ -1150,8 +1177,6 @@ show_devices(const char  *printers,       /* I - Destinations */
 
   if (response)
   {
-    DEBUG_puts("show_devices: request succeeded...");
-
    /*
     * Loop through the printers returned in the list and display
     * their devices...
@@ -1290,10 +1315,6 @@ show_jobs(const char *dests,             /* I - Destinations */
                };
 
 
-  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;
 
@@ -1539,9 +1560,6 @@ show_printers(const char  *printers,      /* I - Destinations */
                };
 
 
-  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;
 
@@ -1588,8 +1606,6 @@ show_printers(const char  *printers,      /* I - Destinations */
 
   if (response)
   {
-    DEBUG_puts("show_printers: request succeeded...");
-
    /*
     * Loop through the printers returned in the list and display
     * their status...
@@ -1760,29 +1776,25 @@ show_printers(const char  *printers,    /* I - Destinations */
         switch (pstate)
        {
          case IPP_PRINTER_IDLE :
-             _cupsLangPrintf(stdout,
-                             _("printer %s is idle.  enabled since %s"),
-                             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"),
-                             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 -"),
-                             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"));
+         if (message && *message)
+               _cupsLangPrintf(stdout, "\t%s", message);
          else
-           _cupsLangPrintf(stdout, "\t%s", message);
+           _cupsLangPuts(stdout, _("\treason unknown"));
        }
 
         if (long_status > 1)
@@ -1899,10 +1911,10 @@ show_printers(const char  *printers,    /* I - Destinations */
 
             if ((message && *message) || pstate == IPP_PRINTER_STOPPED)
            {
-             if (!message || !*message)
-               _cupsLangPuts(stdout, _("\treason unknown"));
-             else
+             if (message && *message)
                _cupsLangPrintf(stdout, "\t%s", message);
+             else
+               _cupsLangPuts(stdout, _("\treason unknown"));
             }
 
             if (long_status > 1)
@@ -2021,3 +2033,37 @@ show_scheduler(void)
   else
     _cupsLangPuts(stdout, _("scheduler is not running"));
 }
+
+
+/*
+ * 'usage()' - Show program usage and exit.
+ */
+
+static void
+usage(void)
+{
+  _cupsLangPuts(stdout, _("Usage: lpstat [options]"));
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("-E                      Encrypt the connection to the server"));
+  _cupsLangPuts(stdout, _("-h server[:port]        Connect to the named server and port"));
+  _cupsLangPuts(stdout, _("-l                      Show verbose (long) output"));
+  _cupsLangPuts(stdout, _("-U username             Specify the username to use for authentication"));
+
+  _cupsLangPuts(stdout, _("-H                      Show the default server and port"));
+  _cupsLangPuts(stdout, _("-W completed            Show completed jobs"));
+  _cupsLangPuts(stdout, _("-W not-completed        Show pending jobs"));
+  _cupsLangPuts(stdout, _("-a [destination(s)]     Show the accepting state of destinations"));
+  _cupsLangPuts(stdout, _("-c [class(es)]          Show classes and their member printers"));
+  _cupsLangPuts(stdout, _("-d                      Show the default destination"));
+  _cupsLangPuts(stdout, _("-e                      Show available destinations on the network"));
+  _cupsLangPuts(stdout, _("-o [destination(s)]     Show jobs"));
+  _cupsLangPuts(stdout, _("-p [printer(s)]         Show the processing state of destinations"));
+  _cupsLangPuts(stdout, _("-r                      Show whether the CUPS server is running"));
+  _cupsLangPuts(stdout, _("-R                      Show the ranking of jobs"));
+  _cupsLangPuts(stdout, _("-s                      Show a status summary"));
+  _cupsLangPuts(stdout, _("-t                      Show all status information"));
+  _cupsLangPuts(stdout, _("-u [user(s)]            Show jobs queued by the current or specified users"));
+  _cupsLangPuts(stdout, _("-v [printer(s)]         Show the devices for each destination"));
+
+  exit(1);
+}