]> git.ipfire.org Git - thirdparty/cups.git/blame - cgi-bin/jobs.c
Update svn:keyword properties.
[thirdparty/cups.git] / cgi-bin / jobs.c
CommitLineData
ef416fc2 1/*
f2d18633 2 * "$Id$"
ef416fc2 3 *
321d8d57 4 * Job status CGI for CUPS.
ef416fc2 5 *
f3c17241 6 * Copyright 2007-2012 by Apple Inc.
ef416fc2 7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * Contents:
16 *
17 * main() - Main entry for CGI.
18 * do_job_op() - Do a job operation.
19 */
20
21/*
22 * Include necessary headers...
23 */
24
25#include "cgi-private.h"
26
27
28/*
29 * Local functions...
30 */
31
fa73b229 32static void do_job_op(http_t *http, int job_id, ipp_op_t op);
ef416fc2 33
34
35/*
36 * 'main()' - Main entry for CGI.
37 */
38
39int /* O - Exit status */
40main(int argc, /* I - Number of command-line arguments */
41 char *argv[]) /* I - Command-line arguments */
42{
ef416fc2 43 http_t *http; /* Connection to the server */
44 const char *op; /* Operation name */
fa73b229 45 const char *job_id_var; /* Job ID form variable */
46 int job_id; /* Job ID */
47
ef416fc2 48
49 /*
50 * Get any form variables...
51 */
52
53 cgiInitialize();
54
55 /*
56 * Set the web interface section...
57 */
58
59 cgiSetVariable("SECTION", "jobs");
ef55b745 60 cgiSetVariable("REFRESH_PAGE", "");
ef416fc2 61
ef416fc2 62 /*
63 * Connect to the HTTP server...
64 */
65
66 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
67
68 /*
fa73b229 69 * Get the job ID, if any...
ef416fc2 70 */
71
fa73b229 72 if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL)
73 job_id = atoi(job_id_var);
74 else
75 job_id = 0;
ef416fc2 76
77 /*
fa73b229 78 * Do the operation...
ef416fc2 79 */
80
2e4ff8af 81 if ((op = cgiGetVariable("OP")) != NULL && job_id > 0 && cgiIsPOST())
ef416fc2 82 {
83 /*
84 * Do the operation...
85 */
86
87 if (!strcmp(op, "cancel-job"))
fa73b229 88 do_job_op(http, job_id, IPP_CANCEL_JOB);
ef416fc2 89 else if (!strcmp(op, "hold-job"))
fa73b229 90 do_job_op(http, job_id, IPP_HOLD_JOB);
91 else if (!strcmp(op, "move-job"))
92 cgiMoveJobs(http, NULL, job_id);
ef416fc2 93 else if (!strcmp(op, "release-job"))
fa73b229 94 do_job_op(http, job_id, IPP_RELEASE_JOB);
ef416fc2 95 else if (!strcmp(op, "restart-job"))
fa73b229 96 do_job_op(http, job_id, IPP_RESTART_JOB);
ef416fc2 97 else
98 {
99 /*
100 * Bad operation code... Display an error...
101 */
102
fa73b229 103 cgiStartHTML(cgiText(_("Jobs")));
104 cgiCopyTemplateLang("error-op.tmpl");
105 cgiEndHTML();
ef416fc2 106 }
107 }
108 else
109 {
110 /*
111 * Show a list of jobs...
112 */
113
fa73b229 114 cgiStartHTML(cgiText(_("Jobs")));
ef416fc2 115 cgiShowJobs(http, NULL);
fa73b229 116 cgiEndHTML();
ef416fc2 117 }
118
ef416fc2 119 /*
120 * Close the HTTP server connection...
121 */
122
123 httpClose(http);
ef416fc2 124
125 /*
126 * Return with no errors...
127 */
128
129 return (0);
130}
131
132
133/*
134 * 'do_job_op()' - Do a job operation.
135 */
136
137static void
138do_job_op(http_t *http, /* I - HTTP connection */
fa73b229 139 int job_id, /* I - Job ID */
ef416fc2 140 ipp_op_t op) /* I - Operation to perform */
141{
fa73b229 142 ipp_t *request; /* IPP request */
ef416fc2 143 char uri[HTTP_MAX_URI]; /* Job URI */
fa73b229 144 const char *user; /* Username */
ef416fc2 145
ef416fc2 146
147 /*
148 * Build a job request, which requires the following
149 * attributes:
150 *
151 * attributes-charset
152 * attributes-natural-language
153 * job-uri or printer-uri (purge-jobs)
154 * requesting-user-name
155 */
156
fa73b229 157 request = ippNewRequest(op);
ef416fc2 158
bd7854cb 159 snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
160
ef416fc2 161 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
162 NULL, uri);
163
fa73b229 164 if ((user = getenv("REMOTE_USER")) == NULL)
165 user = "guest";
166
167 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
168 "requesting-user-name", NULL, user);
ef416fc2 169
170 /*
171 * Do the request and get back a response...
172 */
173
fa73b229 174 ippDelete(cupsDoRequest(http, request, "/jobs"));
ef416fc2 175
f7deaa1a 176 if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER"))
177 {
178 /*
179 * Redirect successful updates back to the parent page...
180 */
181
182 char url[1024]; /* Encoded URL */
183
184
5a9febac 185 strlcpy(url, "5;URL=", sizeof(url));
f7deaa1a 186 cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6);
187 cgiSetVariable("refresh_page", url);
188 }
5bd77a73
MS
189 else if (cupsLastError() == IPP_NOT_AUTHORIZED)
190 {
191 puts("Status: 401\n");
192 exit(0);
193 }
f7deaa1a 194
fa73b229 195 cgiStartHTML(cgiText(_("Jobs")));
ef416fc2 196
fa73b229 197 if (cupsLastError() > IPP_OK_CONFLICT)
f3c17241 198 cgiShowIPPError(_("Job operation failed"));
ef416fc2 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");
fa73b229 207
208 cgiEndHTML();
ef416fc2 209}
210
211
212/*
f2d18633 213 * End of "$Id$".
ef416fc2 214 */