]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/classes.c
Merge changes from CUPS 1.4svn-r8033.
[thirdparty/cups.git] / cgi-bin / classes.c
index 28aa7a925c854d1db8a849b923ce79023306c0f8..fa4b49edc1ef5b39bcf842f8e16d82110ba70795 100644 (file)
@@ -14,9 +14,6 @@
  *
  * Contents:
  *
- *   main()             - Main entry for CGI.
- *   show_all_classes() - Show all classes...
- *   show_class()       - Show a single class.
  */
 
 /*
  * Local functions...
  */
 
-void   show_all_classes(http_t *http, const char *username);
-void   show_class(http_t *http, const char *printer);
+static void    do_class_op(http_t *http, const char *printer, ipp_op_t op,
+                           const char *title);
+static void    show_all_classes(http_t *http, const char *username);
+static void    show_class(http_t *http, const char *printer);
 
 
 /*
@@ -80,6 +79,9 @@ main(int  argc,                               /* I - Number of command-line arguments */
 
     if (!*pclass)
       pclass = NULL;
+
+    if (pclass)
+      cgiSetVariable("PRINTER_NAME", pclass);
   }
 
  /*
@@ -138,21 +140,40 @@ main(int  argc,                           /* I - Number of command-line arguments */
     else
       show_class(http, pclass);
   }
-  else if (!strcasecmp(op, "print-test-page") && pclass)
-    cgiPrintTestPage(http, pclass);
-  else if (!strcasecmp(op, "move-jobs") && pclass)
-    cgiMoveJobs(http, pclass, 0);
+  else if (pclass)
+  {
+    if (!strcmp(op, "start-class"))
+      do_class_op(http, pclass, IPP_RESUME_PRINTER, cgiText(_("Resume Class")));
+    else if (!strcmp(op, "stop-class"))
+      do_class_op(http, pclass, IPP_PAUSE_PRINTER, cgiText(_("Pause Class")));
+    else if (!strcmp(op, "accept-jobs"))
+      do_class_op(http, pclass, CUPS_ACCEPT_JOBS, cgiText(_("Accept Jobs")));
+    else if (!strcmp(op, "reject-jobs"))
+      do_class_op(http, pclass, CUPS_REJECT_JOBS, cgiText(_("Reject Jobs")));
+    else if (!strcmp(op, "purge-jobs"))
+      do_class_op(http, pclass, IPP_PURGE_JOBS, cgiText(_("Purge Jobs")));
+    else if (!strcasecmp(op, "print-test-page"))
+      cgiPrintTestPage(http, pclass);
+    else if (!strcasecmp(op, "move-jobs"))
+      cgiMoveJobs(http, pclass, 0);
+    else
+    {
+     /*
+      * Unknown/bad operation...
+      */
+
+      cgiStartHTML(pclass);
+      cgiCopyTemplateLang("error-op.tmpl");
+      cgiEndHTML();
+    }
+  }
   else
   {
    /*
     * Unknown/bad operation...
     */
 
-    if (pclass)
-      cgiStartHTML(pclass);
-    else
-      cgiStartHTML(cgiText(_("Classes")));
-
+    cgiStartHTML(cgiText(_("Classes")));
     cgiCopyTemplateLang("error-op.tmpl");
     cgiEndHTML();
   }
@@ -171,11 +192,94 @@ main(int  argc,                           /* I - Number of command-line arguments */
 }
 
 
+/*
+ * 'do_class_op()' - Do a class operation.
+ */
+
+static void
+do_class_op(http_t      *http,         /* I - HTTP connection */
+            const char *printer,       /* I - Printer name */
+           ipp_op_t    op,             /* I - Operation to perform */
+           const char  *title)         /* I - Title of page */
+{
+  ipp_t                *request;               /* IPP request */
+  char         uri[HTTP_MAX_URI],      /* Printer URI */
+               resource[HTTP_MAX_URI]; /* Path for request */
+
+
+ /*
+  * Build a printer request, which requires the following
+  * attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
+  */
+
+  request = ippNewRequest(op);
+
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                   "localhost", 0, "/classes/%s", printer);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+               NULL, uri);
+
+ /*
+  * Do the request and get back a response...
+  */
+
+  snprintf(resource, sizeof(resource), "/classes/%s", printer);
+  ippDelete(cupsDoRequest(http, request, resource));
+
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
+  {
+    cgiStartHTML(title);
+    cgiShowIPPError(_("Unable to do maintenance command:"));
+  }
+  else
+  {
+   /*
+    * Redirect successful updates back to the printer page...
+    */
+
+    char       url[1024],              /* Printer/class URL */
+               refresh[1024];          /* Refresh URL */
+
+
+    cgiRewriteURL(uri, url, sizeof(url), NULL);
+    cgiFormEncode(uri, url, sizeof(uri));
+    snprintf(refresh, sizeof(refresh), "5;URL=%s", uri);
+    cgiSetVariable("refresh_page", refresh);
+
+    cgiStartHTML(title);
+
+    cgiSetVariable("IS_CLASS", "YES");
+
+    if (op == IPP_PAUSE_PRINTER)
+      cgiCopyTemplateLang("printer-stop.tmpl");
+    else if (op == IPP_RESUME_PRINTER)
+      cgiCopyTemplateLang("printer-start.tmpl");
+    else if (op == CUPS_ACCEPT_JOBS)
+      cgiCopyTemplateLang("printer-accept.tmpl");
+    else if (op == CUPS_REJECT_JOBS)
+      cgiCopyTemplateLang("printer-reject.tmpl");
+    else if (op == IPP_PURGE_JOBS)
+      cgiCopyTemplateLang("printer-purge.tmpl");
+  }
+
+  cgiEndHTML();
+}
+
+
 /*
  * 'show_all_classes()' - Show all classes...
  */
 
-void
+static void
 show_all_classes(http_t     *http,     /* I - Connection to server */
                  const char *user)     /* I - Username */
 {
@@ -335,7 +439,7 @@ show_all_classes(http_t     *http,  /* I - Connection to server */
  * 'show_class()' - Show a single class.
  */
 
-void
+static void
 show_class(http_t     *http,           /* I - Connection to server */
            const char *pclass)         /* I - Name of class */
 {
@@ -407,7 +511,6 @@ show_class(http_t     *http,                /* I - Connection to server */
     * Show the class status...
     */
 
-    cgiSetVariable("_SINGLE_DEST", "1");
     cgiCopyTemplateLang("class.tmpl");
 
    /*