]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/jobs.c
3a14cc0836e069de6a561fbb5cd653046c479ba6
2 * "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $"
4 * Job status CGI for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Main entry for CGI.
27 * do_job_op() - Do a job operation.
31 * Include necessary headers...
34 #include "cgi-private.h"
41 static void do_job_op(http_t
*http
, int job_id
, ipp_op_t op
);
45 * 'main()' - Main entry for CGI.
48 int /* O - Exit status */
49 main(int argc
, /* I - Number of command-line arguments */
50 char *argv
[]) /* I - Command-line arguments */
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 */
59 * Get any form variables...
65 * Set the web interface section...
68 cgiSetVariable("SECTION", "jobs");
71 * Connect to the HTTP server...
74 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
77 * Get the job ID, if any...
80 if ((job_id_var
= cgiGetVariable("JOB_ID")) != NULL
)
81 job_id
= atoi(job_id_var
);
89 if ((op
= cgiGetVariable("OP")) != NULL
&& job_id
> 0)
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
);
108 * Bad operation code... Display an error...
111 cgiStartHTML(cgiText(_("Jobs")));
112 cgiCopyTemplateLang("error-op.tmpl");
119 * Show a list of jobs...
122 cgiStartHTML(cgiText(_("Jobs")));
123 cgiShowJobs(http
, NULL
);
128 * Close the HTTP server connection...
134 * Return with no errors...
142 * 'do_job_op()' - Do a job operation.
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 */
150 ipp_t
*request
; /* IPP request */
151 char uri
[HTTP_MAX_URI
]; /* Job URI */
152 const char *user
; /* Username */
156 * Build a job request, which requires the following
160 * attributes-natural-language
161 * job-uri or printer-uri (purge-jobs)
162 * requesting-user-name
165 request
= ippNewRequest(op
);
167 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
169 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
172 if ((user
= getenv("REMOTE_USER")) == NULL
)
175 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
176 "requesting-user-name", NULL
, user
);
179 * Do the request and get back a response...
182 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
184 cgiStartHTML(cgiText(_("Jobs")));
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");
202 * End of "$Id: jobs.c 177 2006-06-21 00:20:03Z jlovell $".