]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/jobs.c
2 * Job status CGI for CUPS.
4 * Copyright 2007-2014 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include "cgi-private.h"
25 static void do_job_op(http_t
*http
, int job_id
, ipp_op_t op
);
29 * 'main()' - Main entry for CGI.
32 int /* O - Exit status */
35 http_t
*http
; /* Connection to the server */
36 const char *op
; /* Operation name */
37 const char *job_id_var
; /* Job ID form variable */
38 int job_id
; /* Job ID */
42 * Get any form variables...
48 * Set the web interface section...
51 cgiSetVariable("SECTION", "jobs");
52 cgiSetVariable("REFRESH_PAGE", "");
55 * Connect to the HTTP server...
58 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
61 * Get the job ID, if any...
64 if ((job_id_var
= cgiGetVariable("JOB_ID")) != NULL
)
65 job_id
= atoi(job_id_var
);
73 if ((op
= cgiGetVariable("OP")) != NULL
&& job_id
> 0 && cgiIsPOST())
79 if (!strcmp(op
, "cancel-job"))
80 do_job_op(http
, job_id
, IPP_CANCEL_JOB
);
81 else if (!strcmp(op
, "hold-job"))
82 do_job_op(http
, job_id
, IPP_HOLD_JOB
);
83 else if (!strcmp(op
, "move-job"))
84 cgiMoveJobs(http
, NULL
, job_id
);
85 else if (!strcmp(op
, "release-job"))
86 do_job_op(http
, job_id
, IPP_RELEASE_JOB
);
87 else if (!strcmp(op
, "restart-job"))
88 do_job_op(http
, job_id
, IPP_RESTART_JOB
);
92 * Bad operation code... Display an error...
95 cgiStartHTML(cgiText(_("Jobs")));
96 cgiCopyTemplateLang("error-op.tmpl");
103 * Show a list of jobs...
106 cgiStartHTML(cgiText(_("Jobs")));
107 cgiShowJobs(http
, NULL
);
112 * Close the HTTP server connection...
118 * Return with no errors...
126 * 'do_job_op()' - Do a job operation.
130 do_job_op(http_t
*http
, /* I - HTTP connection */
131 int job_id
, /* I - Job ID */
132 ipp_op_t op
) /* I - Operation to perform */
134 ipp_t
*request
; /* IPP request */
135 char uri
[HTTP_MAX_URI
]; /* Job URI */
136 const char *user
; /* Username */
140 * Build a job request, which requires the following
144 * attributes-natural-language
145 * job-uri or printer-uri (purge-jobs)
146 * requesting-user-name
149 request
= ippNewRequest(op
);
151 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
153 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
156 if ((user
= getenv("REMOTE_USER")) == NULL
)
159 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
160 "requesting-user-name", NULL
, user
);
163 * Do the request and get back a response...
166 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
168 if (cupsLastError() <= IPP_OK_CONFLICT
&& getenv("HTTP_REFERER"))
171 * Redirect successful updates back to the parent page...
174 char url
[1024]; /* Encoded URL */
177 strlcpy(url
, "5;URL=", sizeof(url
));
178 cgiFormEncode(url
+ 6, getenv("HTTP_REFERER"), sizeof(url
) - 6);
179 cgiSetVariable("refresh_page", url
);
181 else if (cupsLastError() == IPP_NOT_AUTHORIZED
)
183 puts("Status: 401\n");
187 cgiStartHTML(cgiText(_("Jobs")));
189 if (cupsLastError() > IPP_OK_CONFLICT
)
190 cgiShowIPPError(_("Job operation failed"));
191 else if (op
== IPP_CANCEL_JOB
)
192 cgiCopyTemplateLang("job-cancel.tmpl");
193 else if (op
== IPP_HOLD_JOB
)
194 cgiCopyTemplateLang("job-hold.tmpl");
195 else if (op
== IPP_RELEASE_JOB
)
196 cgiCopyTemplateLang("job-release.tmpl");
197 else if (op
== IPP_RESTART_JOB
)
198 cgiCopyTemplateLang("job-restart.tmpl");