]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/jobs.c
2 * "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $"
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
, cups_lang_t
*language
, 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 cups_lang_t
*language
; /* Language information */
53 http_t
*http
; /* Connection to the server */
54 const char *op
; /* Operation name */
58 * Get any form variables...
64 * Set the web interface section...
67 cgiSetVariable("SECTION", "jobs");
70 * Get the request language...
73 language
= cupsLangDefault();
76 * Connect to the HTTP server...
79 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
82 * Tell the client to expect UTF-8 encoded HTML...
85 puts("Content-Type: text/html;charset=utf-8\n");
88 * Send a standard header...
91 cgiSetVariable("TITLE", _cupsLangString(language
, _("Jobs")));
93 cgiSetServerVersion();
95 cgiCopyTemplateLang("header.tmpl");
97 if ((op
= cgiGetVariable("OP")) != NULL
)
100 * Do the operation...
103 if (!strcmp(op
, "cancel-job"))
104 do_job_op(http
, language
, IPP_CANCEL_JOB
);
105 else if (!strcmp(op
, "hold-job"))
106 do_job_op(http
, language
, IPP_HOLD_JOB
);
107 else if (!strcmp(op
, "release-job"))
108 do_job_op(http
, language
, IPP_RELEASE_JOB
);
109 else if (!strcmp(op
, "restart-job"))
110 do_job_op(http
, language
, IPP_RESTART_JOB
);
114 * Bad operation code... Display an error...
117 cgiCopyTemplateLang("job-op.tmpl");
123 * Show a list of jobs...
126 cgiShowJobs(http
, NULL
);
129 cgiCopyTemplateLang("trailer.tmpl");
132 * Close the HTTP server connection...
136 cupsLangFree(language
);
139 * Return with no errors...
147 * 'do_job_op()' - Do a job operation.
151 do_job_op(http_t
*http
, /* I - HTTP connection */
152 cups_lang_t
*language
, /* I - Client's language */
153 ipp_op_t op
) /* I - Operation to perform */
155 ipp_t
*request
, /* IPP request */
156 *response
; /* IPP response */
157 char uri
[HTTP_MAX_URI
]; /* Job URI */
158 const char *job
; /* Job ID */
159 ipp_status_t status
; /* Operation status... */
162 if ((job
= cgiGetVariable("JOB_ID")) != NULL
)
163 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%s", job
);
166 cgiSetVariable("ERROR", ippErrorString(IPP_NOT_FOUND
));
167 cgiCopyTemplateLang("error.tmpl");
172 * Build a job request, which requires the following
176 * attributes-natural-language
177 * job-uri or printer-uri (purge-jobs)
178 * requesting-user-name
183 request
->request
.op
.operation_id
= op
;
184 request
->request
.op
.request_id
= 1;
186 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
187 "attributes-charset", NULL
, cupsLangEncoding(language
));
189 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
190 "attributes-natural-language", NULL
, language
->language
);
192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
195 if (getenv("REMOTE_USER") != NULL
)
197 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
198 NULL
, getenv("REMOTE_USER"));
200 if (strcmp(getenv("REMOTE_USER"), "root"))
201 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
204 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
208 * Do the request and get back a response...
211 if ((response
= cupsDoRequest(http
, request
, "/jobs")) != NULL
)
213 status
= response
->request
.status
.status_code
;
218 status
= cupsLastError();
220 if (status
> IPP_OK_CONFLICT
)
222 cgiSetVariable("ERROR", ippErrorString(status
));
223 cgiCopyTemplateLang("error.tmpl");
225 else if (op
== IPP_CANCEL_JOB
)
226 cgiCopyTemplateLang("job-cancel.tmpl");
227 else if (op
== IPP_HOLD_JOB
)
228 cgiCopyTemplateLang("job-hold.tmpl");
229 else if (op
== IPP_RELEASE_JOB
)
230 cgiCopyTemplateLang("job-release.tmpl");
231 else if (op
== IPP_RESTART_JOB
)
232 cgiCopyTemplateLang("job-restart.tmpl");
237 * End of "$Id: jobs.c 4921 2006-01-12 21:26:26Z mike $".