]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpstat.c
Import CUPS v1.7.1
[thirdparty/cups.git] / systemv / lpstat.c
index fd36fe898da80bd459f098183a5a43114a2abf07..6c52e2dd8d99a5856ef2de0ab627d8a864aa99a7 100644 (file)
@@ -1,30 +1,16 @@
 /*
- * "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $"
+ * "$Id: lpstat.c 11395 2013-11-06 20:06:50Z msweet $"
  *
- *   "lpstat" command for CUPS.
+ * "lpstat" command for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2013 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.
- *   match_list()     - Match a name from a list of comma or space-separated
- *                      names.
- *   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.
+ * 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/".
  */
 
 /*
@@ -109,6 +95,7 @@ main(int  argc,                              /* I - Number of command-line arguments */
              _cupsLangPuts(stdout, cupsServer());
            else
              _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort());
+           op = 'H';
             break;
 
         case 'P' : /* Show paper types */
@@ -199,44 +186,22 @@ main(int  argc,                           /* I - Number of command-line arguments */
              {
                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_accepting(NULL, num_dests, dests);
            }
            break;
 
-#ifdef __sgi
-        case 'b' : /* Show both the local and remote status */
-           op = 'b';
-
-           if (argv[i][2])
-           {
-            /*
-             * 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], argv[i] + 2, &num_dests, &dests);
-
-             puts("");
-             status |= show_jobs(argv[i] + 2, NULL, 3, ranking, which);
-           }
-           else
-           {
-             _cupsLangPrintf(stderr,
-                             _("%s: Error - expected destination after "
-                               "\"-b\" option."),
-                             argv[0]);
-
-             return (1);
-           }
-           break;
-#endif /* __sgi */
-
         case 'c' : /* Show classes and members */
            op = 'c';
 
@@ -267,6 +232,16 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
              dests     = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL);
              num_dests = dests ? 1 : 0;
+
+             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);
+             }
            }
 
             show_default(dests);
@@ -299,18 +274,7 @@ main(int  argc,                            /* I - Number of command-line arguments */
            break;
 
         case 'l' : /* Long status or long job status */
-#ifdef __sgi
-           op = 'l';
-
-           if (argv[i][2])
-           {
-              check_dest(argv[0], argv[i] + 2, &num_dests, &dests);
-
-             status |= show_jobs(argv[i] + 2, NULL, 3, ranking, which);
-           }
-           else
-#endif /* __sgi */
-             long_status = 2;
+           long_status = 2;
            break;
 
         case 'o' : /* Show jobs by destination */
@@ -359,6 +323,16 @@ main(int  argc,                            /* I - Number of command-line arguments */
              {
                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);
@@ -378,6 +352,16 @@ main(int  argc,                            /* I - Number of command-line arguments */
            {
              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);
+             }
            }
 
            show_default(cupsGetDest(NULL, NULL, num_dests, dests));
@@ -392,6 +376,16 @@ main(int  argc,                            /* I - Number of command-line arguments */
            {
              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);
+             }
            }
 
            show_scheduler();
@@ -441,6 +435,16 @@ main(int  argc,                            /* I - Number of command-line arguments */
              {
                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);
@@ -500,9 +504,16 @@ check_dest(const char  *command,   /* I  - Command name */
 
       if ((*dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, pptr)) == NULL)
       {
-        _cupsLangPrintf(stderr,
-                       _("%s: Invalid destination name in list \"%s\"."),
-                       command, name);
+       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
@@ -554,8 +565,15 @@ check_dest(const char  *command,   /* I  - Command name */
 
     if (!cupsGetDest(printer, NULL, *num_dests, *dests))
     {
-      _cupsLangPrintf(stderr,
-                      _("%s: Unknown destination \"%s\"."), 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);
     }
   }
@@ -670,16 +688,27 @@ show_accepting(const char  *printers,     /* I - Destinations */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, 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", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_accepting: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -782,11 +811,6 @@ show_accepting(const char  *printers,      /* I - Destinations */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -849,7 +873,25 @@ show_classes(const char *dests)            /* I - Destinations */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, 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...");
 
@@ -987,11 +1029,6 @@ show_classes(const char *dests)           /* I - Destinations */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1097,16 +1134,27 @@ show_devices(const char  *printers,     /* I - Destinations */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, 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", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_devices: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -1246,11 +1294,6 @@ show_devices(const char  *printers,      /* I - Destinations */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1334,19 +1377,30 @@ show_jobs(const char *dests,            /* I - Destinations */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, 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", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
-
     rank = -1;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
@@ -1492,11 +1546,6 @@ show_jobs(const char *dests,             /* I - Destinations */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -1587,16 +1636,27 @@ show_printers(const char  *printers,    /* I - Destinations */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(CUPS_HTTP_DEFAULT, 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", cupsLastErrorString());
-      ippDelete(response);
-      return (1);
-    }
+  if (response)
+  {
+    DEBUG_puts("show_printers: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -2018,11 +2078,6 @@ show_printers(const char  *printers,     /* I - Destinations */
 
     ippDelete(response);
   }
-  else
-  {
-    _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
-    return (1);
-  }
 
   return (0);
 }
@@ -2050,5 +2105,5 @@ show_scheduler(void)
 
 
 /*
- * End of "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $".
+ * End of "$Id: lpstat.c 11395 2013-11-06 20:06:50Z msweet $".
  */