/*
- * "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $"
+ * Job status CGI for CUPS.
*
- * Job status CGI for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
*
- * Copyright 1997-2006 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
- *
- * Contents:
- *
- * main() - Main entry for CGI.
- * do_job_op() - Do a job operation.
+ * 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/".
*/
/*
* 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);
/*
*/
int /* O - Exit status */
-main(int argc, /* I - Number of command-line arguments */
- char *argv[]) /* I - Command-line arguments */
+main(void)
{
- 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...
*/
cgiSetVariable("SECTION", "jobs");
-
- /*
- * Get the request language...
- */
-
- language = cupsLangDefault();
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* Connect to the HTTP server...
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 && cgiIsPOST())
{
/*
* 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
* 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...
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:
* requesting-user-name
*/
- request = ippNew();
+ request = ippNewRequest(op);
- 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));
-
- 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)
+ ippDelete(cupsDoRequest(http, request, "/jobs"));
+
+ if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER"))
{
- status = response->request.status.status_code;
+ /*
+ * Redirect successful updates back to the parent page...
+ */
- ippDelete(response);
- }
- else
- status = cupsLastError();
+ char url[1024]; /* Encoded URL */
- if (status > IPP_OK_CONFLICT)
+
+ strlcpy(url, "5;URL=", sizeof(url));
+ cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6);
+ cgiSetVariable("refresh_page", url);
+ }
+ else if (cupsLastError() == IPP_NOT_AUTHORIZED)
{
- cgiSetVariable("ERROR", ippErrorString(status));
- cgiCopyTemplateLang("error.tmpl");
+ puts("Status: 401\n");
+ exit(0);
}
+
+ cgiStartHTML(cgiText(_("Jobs")));
+
+ 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)
cgiCopyTemplateLang("job-release.tmpl");
else if (op == IPP_RESTART_JOB)
cgiCopyTemplateLang("job-restart.tmpl");
-}
-
-/*
- * End of "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $".
- */
+ cgiEndHTML();
+}