]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/printers.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cgi-bin / printers.c
index 8b613f3b71d1e74660814d50b481afdc86031075..bbc153e3b74a35ecc414e5f399db5ddf634af200 100644 (file)
@@ -1,23 +1,10 @@
 /*
- * "$Id: printers.c 7940 2008-09-16 00:45:16Z mike $"
+ * Printer status CGI for CUPS.
  *
- *   Printer status CGI for CUPS.
+ * Copyright 2007-2016 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2011 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()              - Main entry for CGI.
- *   do_printer_op()     - Do a printer operation.
- *   show_all_printers() - Show all printers...
- *   show_printer()      - Show a single printer.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -43,8 +30,7 @@ static void   show_printer(http_t *http, const char *printer);
  */
 
 int                                    /* O - Exit status */
-main(int  argc,                                /* I - Number of command-line arguments */
-     char *argv[])                     /* I - Command-line arguments */
+main(void)
 {
   const char   *printer;               /* Printer name */
   const char   *user;                  /* Username */
@@ -172,17 +158,17 @@ main(int  argc,                           /* I - Number of command-line arguments */
       do_printer_op(http, printer, CUPS_ACCEPT_JOBS, cgiText(_("Accept Jobs")));
     else if (!strcmp(op, "reject-jobs"))
       do_printer_op(http, printer, CUPS_REJECT_JOBS, cgiText(_("Reject Jobs")));
-    else if (!strcmp(op, "purge-jobs"))
-      do_printer_op(http, printer, IPP_PURGE_JOBS, cgiText(_("Purge Jobs")));
-    else if (!strcasecmp(op, "print-self-test-page"))
+    else if (!strcmp(op, "cancel-jobs"))
+      do_printer_op(http, printer, IPP_OP_CANCEL_JOBS, cgiText(_("Cancel Jobs")));
+    else if (!_cups_strcasecmp(op, "print-self-test-page"))
       cgiPrintCommand(http, printer, "PrintSelfTestPage",
                       cgiText(_("Print Self-Test Page")));
-    else if (!strcasecmp(op, "clean-print-heads"))
+    else if (!_cups_strcasecmp(op, "clean-print-heads"))
       cgiPrintCommand(http, printer, "Clean all",
                       cgiText(_("Clean Print Heads")));
-    else if (!strcasecmp(op, "print-test-page"))
+    else if (!_cups_strcasecmp(op, "print-test-page"))
       cgiPrintTestPage(http, printer);
-    else if (!strcasecmp(op, "move-jobs"))
+    else if (!_cups_strcasecmp(op, "move-jobs"))
       cgiMoveJobs(http, printer, 0);
     else
     {
@@ -266,7 +252,7 @@ do_printer_op(http_t      *http,    /* I - HTTP connection */
   else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     cgiStartHTML(title);
-    cgiShowIPPError(_("Unable to do maintenance command:"));
+    cgiShowIPPError(_("Unable to do maintenance command"));
   }
   else
   {
@@ -293,8 +279,8 @@ do_printer_op(http_t      *http,    /* I - HTTP connection */
       cgiCopyTemplateLang("printer-accept.tmpl");
     else if (op == CUPS_REJECT_JOBS)
       cgiCopyTemplateLang("printer-reject.tmpl");
-    else if (op == IPP_PURGE_JOBS)
-      cgiCopyTemplateLang("printer-purge.tmpl");
+    else if (op == IPP_OP_CANCEL_JOBS)
+      cgiCopyTemplateLang("printer-cancel-jobs.tmpl");
   }
 
   cgiEndHTML();
@@ -314,8 +300,7 @@ show_all_printers(http_t     *http, /* I - Connection to server */
                        *response;      /* IPP response */
   cups_array_t         *printers;      /* Array of printer objects */
   ipp_attribute_t      *printer;       /* Printer object */
-  int                  ascending,      /* Order of printers (0 = descending) */
-                       first,          /* First printer to show */
+  int                  first,          /* First printer to show */
                        count;          /* Number of printers */
   const char           *var;           /* Form variable */
   void                 *search;        /* Search data */
@@ -397,25 +382,10 @@ show_all_printers(http_t     *http,       /* I - Connection to server */
     sprintf(val, "%d", count);
     cgiSetVariable("TOTAL", val);
 
-    if ((var = cgiGetVariable("ORDER")) != NULL)
-      ascending = !strcasecmp(var, "asc");
-    else
-      ascending = 1;
-
-    if (ascending)
-    {
-      for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first);
-          i < CUPS_PAGE_MAX && printer;
-          i ++, printer = (ipp_attribute_t *)cupsArrayNext(printers))
-        cgiSetIPPObjectVars(printer, NULL, i);
-    }
-    else
-    {
-      for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, count - first - 1);
-          i < CUPS_PAGE_MAX && printer;
-          i ++, printer = (ipp_attribute_t *)cupsArrayPrev(printers))
-        cgiSetIPPObjectVars(printer, NULL, i);
-    }
+    for (i = 0, printer = (ipp_attribute_t *)cupsArrayIndex(printers, first);
+        i < CUPS_PAGE_MAX && printer;
+        i ++, printer = (ipp_attribute_t *)cupsArrayNext(printers))
+      cgiSetIPPObjectVars(printer, NULL, i);
 
    /*
     * Save navigation URLs...
@@ -435,6 +405,12 @@ show_all_printers(http_t     *http,        /* I - Connection to server */
       cgiSetVariable("NEXT", val);
     }
 
+    if (count > CUPS_PAGE_MAX)
+    {
+      snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX));
+      cgiSetVariable("LAST", val);
+    }
+
    /*
     * Then show everything...
     */
@@ -464,7 +440,7 @@ show_all_printers(http_t     *http, /* I - Connection to server */
     * Show the error...
     */
 
-    cgiShowIPPError(_("Unable to get printer list:"));
+    cgiShowIPPError(_("Unable to get printer list"));
   }
 
    cgiEndHTML();
@@ -566,13 +542,8 @@ show_printer(http_t     *http,             /* I - Connection to server */
     */
 
     cgiStartHTML(printer);
-    cgiShowIPPError(_("Unable to get printer status:"));
+    cgiShowIPPError(_("Unable to get printer status"));
   }
 
    cgiEndHTML();
 }
-
-
-/*
- * End of "$Id: printers.c 7940 2008-09-16 00:45:16Z mike $".
- */