2 * "$Id: jobs.c 9771 2011-05-12 05:21:56Z mike $"
4 * Job status CGI for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Main entry for CGI.
18 * do_job_op() - Do a job operation.
22 * Include necessary headers...
25 #include "cgi-private.h"
32 static void do_job_op(http_t *http, int job_id, ipp_op_t op);
36 * 'main()' - Main entry for CGI.
39 int /* O - Exit status */
40 main(int argc, /* I - Number of command-line arguments */
41 char *argv[]) /* I - Command-line arguments */
43 http_t *http; /* Connection to the server */
44 const char *op; /* Operation name */
45 const char *job_id_var; /* Job ID form variable */
46 int job_id; /* Job ID */
50 * Get any form variables...
56 * Set the web interface section...
59 cgiSetVariable("SECTION", "jobs");
60 cgiSetVariable("REFRESH_PAGE", "");
63 * Connect to the HTTP server...
66 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
69 * Get the job ID, if any...
72 if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL)
73 job_id = atoi(job_id_var);
81 if ((op = cgiGetVariable("OP")) != NULL && job_id > 0 && cgiIsPOST())
87 if (!strcmp(op, "cancel-job"))
88 do_job_op(http, job_id, IPP_CANCEL_JOB);
89 else if (!strcmp(op, "hold-job"))
90 do_job_op(http, job_id, IPP_HOLD_JOB);
91 else if (!strcmp(op, "move-job"))
92 cgiMoveJobs(http, NULL, job_id);
93 else if (!strcmp(op, "release-job"))
94 do_job_op(http, job_id, IPP_RELEASE_JOB);
95 else if (!strcmp(op, "restart-job"))
96 do_job_op(http, job_id, IPP_RESTART_JOB);
100 * Bad operation code... Display an error...
103 cgiStartHTML(cgiText(_("Jobs")));
104 cgiCopyTemplateLang("error-op.tmpl");
111 * Show a list of jobs...
114 cgiStartHTML(cgiText(_("Jobs")));
115 cgiShowJobs(http, NULL);
120 * Close the HTTP server connection...
126 * Return with no errors...
134 * 'do_job_op()' - Do a job operation.
138 do_job_op(http_t *http, /* I - HTTP connection */
139 int job_id, /* I - Job ID */
140 ipp_op_t op) /* I - Operation to perform */
142 ipp_t *request; /* IPP request */
143 char uri[HTTP_MAX_URI]; /* Job URI */
144 const char *user; /* Username */
148 * Build a job request, which requires the following
152 * attributes-natural-language
153 * job-uri or printer-uri (purge-jobs)
154 * requesting-user-name
157 request = ippNewRequest(op);
159 snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
161 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
164 if ((user = getenv("REMOTE_USER")) == NULL)
167 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
168 "requesting-user-name", NULL, user);
171 * Do the request and get back a response...
174 ippDelete(cupsDoRequest(http, request, "/jobs"));
176 if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER"))
179 * Redirect successful updates back to the parent page...
182 char url[1024]; /* Encoded URL */
185 strcpy(url, "5;URL=");
186 cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6);
187 cgiSetVariable("refresh_page", url);
189 else if (cupsLastError() == IPP_NOT_AUTHORIZED)
191 puts("Status: 401\n");
195 cgiStartHTML(cgiText(_("Jobs")));
197 if (cupsLastError() > IPP_OK_CONFLICT)
198 cgiShowIPPError(_("Job operation failed:"));
199 else if (op == IPP_CANCEL_JOB)
200 cgiCopyTemplateLang("job-cancel.tmpl");
201 else if (op == IPP_HOLD_JOB)
202 cgiCopyTemplateLang("job-hold.tmpl");
203 else if (op == IPP_RELEASE_JOB)
204 cgiCopyTemplateLang("job-release.tmpl");
205 else if (op == IPP_RESTART_JOB)
206 cgiCopyTemplateLang("job-restart.tmpl");
213 * End of "$Id: jobs.c 9771 2011-05-12 05:21:56Z mike $".