]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/jobs.c
3a14cc0836e069de6a561fbb5cd653046c479ba6
[thirdparty/cups.git] / cgi-bin / jobs.c
1 /*
2 * "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $"
3 *
4 * Job status CGI for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * main() - Main entry for CGI.
27 * do_job_op() - Do a job operation.
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 #include "cgi-private.h"
35
36
37 /*
38 * Local functions...
39 */
40
41 static void do_job_op(http_t *http, int job_id, ipp_op_t op);
42
43
44 /*
45 * 'main()' - Main entry for CGI.
46 */
47
48 int /* O - Exit status */
49 main(int argc, /* I - Number of command-line arguments */
50 char *argv[]) /* I - Command-line arguments */
51 {
52 http_t *http; /* Connection to the server */
53 const char *op; /* Operation name */
54 const char *job_id_var; /* Job ID form variable */
55 int job_id; /* Job ID */
56
57
58 /*
59 * Get any form variables...
60 */
61
62 cgiInitialize();
63
64 /*
65 * Set the web interface section...
66 */
67
68 cgiSetVariable("SECTION", "jobs");
69
70 /*
71 * Connect to the HTTP server...
72 */
73
74 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
75
76 /*
77 * Get the job ID, if any...
78 */
79
80 if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL)
81 job_id = atoi(job_id_var);
82 else
83 job_id = 0;
84
85 /*
86 * Do the operation...
87 */
88
89 if ((op = cgiGetVariable("OP")) != NULL && job_id > 0)
90 {
91 /*
92 * Do the operation...
93 */
94
95 if (!strcmp(op, "cancel-job"))
96 do_job_op(http, job_id, IPP_CANCEL_JOB);
97 else if (!strcmp(op, "hold-job"))
98 do_job_op(http, job_id, IPP_HOLD_JOB);
99 else if (!strcmp(op, "move-job"))
100 cgiMoveJobs(http, NULL, job_id);
101 else if (!strcmp(op, "release-job"))
102 do_job_op(http, job_id, IPP_RELEASE_JOB);
103 else if (!strcmp(op, "restart-job"))
104 do_job_op(http, job_id, IPP_RESTART_JOB);
105 else
106 {
107 /*
108 * Bad operation code... Display an error...
109 */
110
111 cgiStartHTML(cgiText(_("Jobs")));
112 cgiCopyTemplateLang("error-op.tmpl");
113 cgiEndHTML();
114 }
115 }
116 else
117 {
118 /*
119 * Show a list of jobs...
120 */
121
122 cgiStartHTML(cgiText(_("Jobs")));
123 cgiShowJobs(http, NULL);
124 cgiEndHTML();
125 }
126
127 /*
128 * Close the HTTP server connection...
129 */
130
131 httpClose(http);
132
133 /*
134 * Return with no errors...
135 */
136
137 return (0);
138 }
139
140
141 /*
142 * 'do_job_op()' - Do a job operation.
143 */
144
145 static void
146 do_job_op(http_t *http, /* I - HTTP connection */
147 int job_id, /* I - Job ID */
148 ipp_op_t op) /* I - Operation to perform */
149 {
150 ipp_t *request; /* IPP request */
151 char uri[HTTP_MAX_URI]; /* Job URI */
152 const char *user; /* Username */
153
154
155 /*
156 * Build a job request, which requires the following
157 * attributes:
158 *
159 * attributes-charset
160 * attributes-natural-language
161 * job-uri or printer-uri (purge-jobs)
162 * requesting-user-name
163 */
164
165 request = ippNewRequest(op);
166
167 snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
168
169 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
170 NULL, uri);
171
172 if ((user = getenv("REMOTE_USER")) == NULL)
173 user = "guest";
174
175 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
176 "requesting-user-name", NULL, user);
177
178 /*
179 * Do the request and get back a response...
180 */
181
182 ippDelete(cupsDoRequest(http, request, "/jobs"));
183
184 cgiStartHTML(cgiText(_("Jobs")));
185
186 if (cupsLastError() > IPP_OK_CONFLICT)
187 cgiShowIPPError(_("Job operation failed:"));
188 else if (op == IPP_CANCEL_JOB)
189 cgiCopyTemplateLang("job-cancel.tmpl");
190 else if (op == IPP_HOLD_JOB)
191 cgiCopyTemplateLang("job-hold.tmpl");
192 else if (op == IPP_RELEASE_JOB)
193 cgiCopyTemplateLang("job-release.tmpl");
194 else if (op == IPP_RESTART_JOB)
195 cgiCopyTemplateLang("job-restart.tmpl");
196
197 cgiEndHTML();
198 }
199
200
201 /*
202 * End of "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $".
203 */