]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/printers.c
Sandboxed applications were not able to get the default printer (Issue #5676)
[thirdparty/cups.git] / cgi-bin / printers.c
index 36e992025cb0e5efe0beb85dc8b45bc80abb0a3d..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-2012 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,8 +158,8 @@ 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 (!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")));
@@ -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 && *var)
-      ascending = !_cups_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...
     */
@@ -571,8 +547,3 @@ show_printer(http_t     *http,              /* I - Connection to server */
 
    cgiEndHTML();
 }
-
-
-/*
- * End of "$Id: printers.c 7940 2008-09-16 00:45:16Z mike $".
- */