]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/jobs.c
Load cups into easysw/current.
[thirdparty/cups.git] / cgi-bin / jobs.c
index 648d3815020871e26bbbdbe1ff34d3ddd3dd4b38..ed379b001341167109b72c51d2a1569038939619 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $"
+ * "$Id: jobs.c 5104 2006-02-15 03:21:04Z mike $"
  *
  *   Job status CGI for the Common UNIX Printing System (CUPS).
  *
@@ -38,7 +38,7 @@
  * Local functions...
  */
 
-static void    do_job_op(http_t *http, cups_lang_t *language, ipp_op_t op);
+static void    do_job_op(http_t *http, int job_id, ipp_op_t op);
 
 
 /*
@@ -49,10 +49,11 @@ int                                 /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line arguments */
      char *argv[])                     /* I - Command-line arguments */
 {
-  cups_lang_t  *language;              /* Language information */
   http_t       *http;                  /* Connection to the server */
   const char   *op;                    /* Operation name */
-  
+  const char   *job_id_var;            /* Job ID form variable */
+  int          job_id;                 /* Job ID */
+
 
  /*
   * Get any form variables...
@@ -66,12 +67,6 @@ main(int  argc,                              /* I - Number of command-line arguments */
 
   cgiSetVariable("SECTION", "jobs");
 
- /*
-  * Get the request language...
-  */
-
-  language = cupsLangDefault();
-
  /*
   * Connect to the HTTP server...
   */
@@ -79,42 +74,43 @@ main(int  argc,                             /* I - Number of command-line arguments */
   http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
 
  /*
-  * Tell the client to expect UTF-8 encoded HTML...
+  * Get the job ID, if any...
   */
 
-  puts("Content-Type: text/html;charset=utf-8\n");
+  if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL)
+    job_id = atoi(job_id_var);
+  else
+    job_id = 0;
 
  /*
-  * Send a standard header...
+  * Do the operation...
   */
 
-  cgiSetVariable("TITLE", _cupsLangString(language, _("Jobs")));
-
-  cgiSetServerVersion();
-
-  cgiCopyTemplateLang("header.tmpl");
-
-  if ((op = cgiGetVariable("OP")) != NULL)
+  if ((op = cgiGetVariable("OP")) != NULL && job_id > 0)
   {
    /*
     * Do the operation...
     */
 
     if (!strcmp(op, "cancel-job"))
-      do_job_op(http, language, IPP_CANCEL_JOB);
+      do_job_op(http, job_id, IPP_CANCEL_JOB);
     else if (!strcmp(op, "hold-job"))
-      do_job_op(http, language, IPP_HOLD_JOB);
+      do_job_op(http, job_id, IPP_HOLD_JOB);
+    else if (!strcmp(op, "move-job"))
+      cgiMoveJobs(http, NULL, job_id);
     else if (!strcmp(op, "release-job"))
-      do_job_op(http, language, IPP_RELEASE_JOB);
+      do_job_op(http, job_id, IPP_RELEASE_JOB);
     else if (!strcmp(op, "restart-job"))
-      do_job_op(http, language, IPP_RESTART_JOB);
+      do_job_op(http, job_id, IPP_RESTART_JOB);
     else
     {
      /*
       * Bad operation code...  Display an error...
       */
 
-      cgiCopyTemplateLang("job-op.tmpl");
+      cgiStartHTML(cgiText(_("Jobs")));
+      cgiCopyTemplateLang("error-op.tmpl");
+      cgiEndHTML();
     }
   }
   else
@@ -123,17 +119,16 @@ main(int  argc,                           /* I - Number of command-line arguments */
     * Show a list of jobs...
     */
 
+    cgiStartHTML(cgiText(_("Jobs")));
     cgiShowJobs(http, NULL);
+    cgiEndHTML();
   }
 
-  cgiCopyTemplateLang("trailer.tmpl");
-
  /*
   * Close the HTTP server connection...
   */
 
   httpClose(http);
-  cupsLangFree(language);
 
  /*
   * Return with no errors...
@@ -149,25 +144,14 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
 static void
 do_job_op(http_t      *http,           /* I - HTTP connection */
-          cups_lang_t *language,       /* I - Client's language */
+          int         job_id,          /* I - Job ID */
          ipp_op_t    op)               /* I - Operation to perform */
 {
-  ipp_t                *request,               /* IPP request */
-               *response;              /* IPP response */
+  ipp_t                *request;               /* IPP request */
   char         uri[HTTP_MAX_URI];      /* Job URI */
-  const char   *job;                   /* Job ID */
-  ipp_status_t status;                 /* Operation status... */
+  const char   *user;                  /* Username */
 
 
-  if ((job = cgiGetVariable("JOB_ID")) != NULL)
-    snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%s", job);
-  else
-  {
-    cgiSetVariable("ERROR", ippErrorString(IPP_NOT_FOUND));
-    cgiCopyTemplateLang("error.tmpl");
-    return;
-  }
-
  /*
   * Build a job request, which requires the following
   * attributes:
@@ -178,50 +162,29 @@ do_job_op(http_t      *http,              /* I - HTTP connection */
   *    requesting-user-name
   */
 
-  request = ippNew();
-
-  request->request.op.operation_id = op;
-  request->request.op.request_id   = 1;
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-               "attributes-charset", NULL, cupsLangEncoding(language));
+  request = ippNewRequest(op);
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-               "attributes-natural-language", NULL, language->language);
+  snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
                NULL, uri);
 
-  if (getenv("REMOTE_USER") != NULL)
-  {
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
-                 NULL, getenv("REMOTE_USER"));
+  if ((user = getenv("REMOTE_USER")) == NULL)
+    user = "guest";
 
-    if (strcmp(getenv("REMOTE_USER"), "root"))
-      ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
-  }
-  else
-    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
-                 NULL, "unknown");
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+               "requesting-user-name", NULL, user);
 
  /*
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
-  {
-    status = response->request.status.status_code;
+  ippDelete(cupsDoRequest(http, request, "/jobs"));
 
-    ippDelete(response);
-  }
-  else
-    status = cupsLastError();
+  cgiStartHTML(cgiText(_("Jobs")));
 
-  if (status > IPP_OK_CONFLICT)
-  {
-    cgiSetVariable("ERROR", ippErrorString(status));
-    cgiCopyTemplateLang("error.tmpl");
-  }
+  if (cupsLastError() > IPP_OK_CONFLICT)
+    cgiShowIPPError(_("Job operation failed:"));
   else if (op == IPP_CANCEL_JOB)
     cgiCopyTemplateLang("job-cancel.tmpl");
   else if (op == IPP_HOLD_JOB)
@@ -230,9 +193,11 @@ do_job_op(http_t      *http,               /* I - HTTP connection */
     cgiCopyTemplateLang("job-release.tmpl");
   else if (op == IPP_RESTART_JOB)
     cgiCopyTemplateLang("job-restart.tmpl");
+
+  cgiEndHTML();
 }
 
 
 /*
- * End of "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $".
+ * End of "$Id: jobs.c 5104 2006-02-15 03:21:04Z mike $".
  */