]> git.ipfire.org Git - thirdparty/cups.git/blame - cgi-bin/jobs.c
Remove svn:keywords since they cause svn_load_dirs.pl to complain about every file.
[thirdparty/cups.git] / cgi-bin / jobs.c
CommitLineData
ef416fc2 1/*
c07d5b2d 2 * "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $"
ef416fc2 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
fa73b229 41static void do_job_op(http_t *http, int job_id, ipp_op_t op);
ef416fc2 42
43
44/*
45 * 'main()' - Main entry for CGI.
46 */
47
48int /* O - Exit status */
49main(int argc, /* I - Number of command-line arguments */
50 char *argv[]) /* I - Command-line arguments */
51{
ef416fc2 52 http_t *http; /* Connection to the server */
53 const char *op; /* Operation name */
fa73b229 54 const char *job_id_var; /* Job ID form variable */
55 int job_id; /* Job ID */
56
ef416fc2 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
ef416fc2 70 /*
71 * Connect to the HTTP server...
72 */
73
74 http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
75
76 /*
fa73b229 77 * Get the job ID, if any...
ef416fc2 78 */
79
fa73b229 80 if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL)
81 job_id = atoi(job_id_var);
82 else
83 job_id = 0;
ef416fc2 84
85 /*
fa73b229 86 * Do the operation...
ef416fc2 87 */
88
fa73b229 89 if ((op = cgiGetVariable("OP")) != NULL && job_id > 0)
ef416fc2 90 {
91 /*
92 * Do the operation...
93 */
94
95 if (!strcmp(op, "cancel-job"))
fa73b229 96 do_job_op(http, job_id, IPP_CANCEL_JOB);
ef416fc2 97 else if (!strcmp(op, "hold-job"))
fa73b229 98 do_job_op(http, job_id, IPP_HOLD_JOB);
99 else if (!strcmp(op, "move-job"))
100 cgiMoveJobs(http, NULL, job_id);
ef416fc2 101 else if (!strcmp(op, "release-job"))
fa73b229 102 do_job_op(http, job_id, IPP_RELEASE_JOB);
ef416fc2 103 else if (!strcmp(op, "restart-job"))
fa73b229 104 do_job_op(http, job_id, IPP_RESTART_JOB);
ef416fc2 105 else
106 {
107 /*
108 * Bad operation code... Display an error...
109 */
110
fa73b229 111 cgiStartHTML(cgiText(_("Jobs")));
112 cgiCopyTemplateLang("error-op.tmpl");
113 cgiEndHTML();
ef416fc2 114 }
115 }
116 else
117 {
118 /*
119 * Show a list of jobs...
120 */
121
fa73b229 122 cgiStartHTML(cgiText(_("Jobs")));
ef416fc2 123 cgiShowJobs(http, NULL);
fa73b229 124 cgiEndHTML();
ef416fc2 125 }
126
ef416fc2 127 /*
128 * Close the HTTP server connection...
129 */
130
131 httpClose(http);
ef416fc2 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
145static void
146do_job_op(http_t *http, /* I - HTTP connection */
fa73b229 147 int job_id, /* I - Job ID */
ef416fc2 148 ipp_op_t op) /* I - Operation to perform */
149{
fa73b229 150 ipp_t *request; /* IPP request */
ef416fc2 151 char uri[HTTP_MAX_URI]; /* Job URI */
fa73b229 152 const char *user; /* Username */
ef416fc2 153
ef416fc2 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
fa73b229 165 request = ippNewRequest(op);
ef416fc2 166
bd7854cb 167 snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
168
ef416fc2 169 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
170 NULL, uri);
171
fa73b229 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);
ef416fc2 177
178 /*
179 * Do the request and get back a response...
180 */
181
fa73b229 182 ippDelete(cupsDoRequest(http, request, "/jobs"));
ef416fc2 183
fa73b229 184 cgiStartHTML(cgiText(_("Jobs")));
ef416fc2 185
fa73b229 186 if (cupsLastError() > IPP_OK_CONFLICT)
187 cgiShowIPPError(_("Job operation failed:"));
ef416fc2 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");
fa73b229 196
197 cgiEndHTML();
ef416fc2 198}
199
200
201/*
c07d5b2d 202 * End of "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $".
ef416fc2 203 */