]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cgi-private.h"
21 static void do_job_op(http_t
*http
, int job_id
, ipp_op_t op
);
25 * 'main()' - Main entry for CGI.
28 int /* O - Exit status */
31 http_t
*http
; /* Connection to the server */
32 const char *op
; /* Operation name */
33 const char *job_id_var
; /* Job ID form variable */
34 int job_id
; /* Job ID */
38 * Get any form variables...
44 * Set the web interface section...
47 cgiSetVariable("SECTION", "jobs");
48 cgiSetVariable("REFRESH_PAGE", "");
51 * Connect to the HTTP server...
54 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
57 * Get the job ID, if any...
60 if ((job_id_var
= cgiGetVariable("JOB_ID")) != NULL
)
61 job_id
= atoi(job_id_var
);
69 if ((op
= cgiGetVariable("OP")) != NULL
&& job_id
> 0 && cgiIsPOST())
75 if (!strcmp(op
, "cancel-job"))
76 do_job_op(http
, job_id
, IPP_CANCEL_JOB
);
77 else if (!strcmp(op
, "hold-job"))
78 do_job_op(http
, job_id
, IPP_HOLD_JOB
);
79 else if (!strcmp(op
, "move-job"))
80 cgiMoveJobs(http
, NULL
, job_id
);
81 else if (!strcmp(op
, "release-job"))
82 do_job_op(http
, job_id
, IPP_RELEASE_JOB
);
83 else if (!strcmp(op
, "restart-job"))
84 do_job_op(http
, job_id
, IPP_RESTART_JOB
);
88 * Bad operation code... Display an error...
91 cgiStartHTML(cgiText(_("Jobs")));
92 cgiCopyTemplateLang("error-op.tmpl");
99 * Show a list of jobs...
102 cgiStartHTML(cgiText(_("Jobs")));
103 cgiShowJobs(http
, NULL
);
108 * Close the HTTP server connection...
114 * Return with no errors...
122 * 'do_job_op()' - Do a job operation.
126 do_job_op(http_t
*http
, /* I - HTTP connection */
127 int job_id
, /* I - Job ID */
128 ipp_op_t op
) /* I - Operation to perform */
130 ipp_t
*request
; /* IPP request */
131 char uri
[HTTP_MAX_URI
]; /* Job URI */
132 const char *user
; /* Username */
136 * Build a job request, which requires the following
140 * attributes-natural-language
141 * job-uri or printer-uri (purge-jobs)
142 * requesting-user-name
145 request
= ippNewRequest(op
);
147 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
149 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
152 if ((user
= getenv("REMOTE_USER")) == NULL
)
155 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
156 "requesting-user-name", NULL
, user
);
159 * Do the request and get back a response...
162 ippDelete(cupsDoRequest(http
, request
, "/jobs"));
164 if (cupsLastError() <= IPP_OK_CONFLICT
&& getenv("HTTP_REFERER"))
167 * Redirect successful updates back to the parent page...
170 char url
[1024]; /* Encoded URL */
173 strlcpy(url
, "5;URL=", sizeof(url
));
174 cgiFormEncode(url
+ 6, getenv("HTTP_REFERER"), sizeof(url
) - 6);
175 cgiSetVariable("refresh_page", url
);
177 else if (cupsLastError() == IPP_NOT_AUTHORIZED
)
179 puts("Status: 401\n");
183 cgiStartHTML(cgiText(_("Jobs")));
185 if (cupsLastError() > IPP_OK_CONFLICT
)
186 cgiShowIPPError(_("Job operation failed"));
187 else if (op
== IPP_CANCEL_JOB
)
188 cgiCopyTemplateLang("job-cancel.tmpl");
189 else if (op
== IPP_HOLD_JOB
)
190 cgiCopyTemplateLang("job-hold.tmpl");
191 else if (op
== IPP_RELEASE_JOB
)
192 cgiCopyTemplateLang("job-release.tmpl");
193 else if (op
== IPP_RESTART_JOB
)
194 cgiCopyTemplateLang("job-restart.tmpl");