]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
354aadbe | 2 | * "$Id: jobs.c 11984 2014-07-02 13:16:59Z msweet $" |
ef416fc2 | 3 | * |
7e86f2f6 | 4 | * Job status CGI for CUPS. |
ef416fc2 | 5 | * |
7e86f2f6 MS |
6 | * Copyright 2007-2014 by Apple Inc. |
7 | * Copyright 1997-2006 by Easy Software Products. | |
ef416fc2 | 8 | * |
7e86f2f6 MS |
9 | * These coded instructions, statements, and computer programs are the |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | */ |
15 | ||
16 | /* | |
17 | * Include necessary headers... | |
18 | */ | |
19 | ||
20 | #include "cgi-private.h" | |
21 | ||
22 | ||
23 | /* | |
24 | * Local functions... | |
25 | */ | |
26 | ||
fa73b229 | 27 | static void do_job_op(http_t *http, int job_id, ipp_op_t op); |
ef416fc2 | 28 | |
29 | ||
30 | /* | |
31 | * 'main()' - Main entry for CGI. | |
32 | */ | |
33 | ||
34 | int /* O - Exit status */ | |
7e86f2f6 | 35 | main(void) |
ef416fc2 | 36 | { |
ef416fc2 | 37 | http_t *http; /* Connection to the server */ |
38 | const char *op; /* Operation name */ | |
fa73b229 | 39 | const char *job_id_var; /* Job ID form variable */ |
40 | int job_id; /* Job ID */ | |
41 | ||
ef416fc2 | 42 | |
43 | /* | |
44 | * Get any form variables... | |
45 | */ | |
46 | ||
47 | cgiInitialize(); | |
48 | ||
49 | /* | |
50 | * Set the web interface section... | |
51 | */ | |
52 | ||
53 | cgiSetVariable("SECTION", "jobs"); | |
ef55b745 | 54 | cgiSetVariable("REFRESH_PAGE", ""); |
ef416fc2 | 55 | |
ef416fc2 | 56 | /* |
57 | * Connect to the HTTP server... | |
58 | */ | |
59 | ||
60 | http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); | |
61 | ||
62 | /* | |
fa73b229 | 63 | * Get the job ID, if any... |
ef416fc2 | 64 | */ |
65 | ||
fa73b229 | 66 | if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL) |
67 | job_id = atoi(job_id_var); | |
68 | else | |
69 | job_id = 0; | |
ef416fc2 | 70 | |
71 | /* | |
fa73b229 | 72 | * Do the operation... |
ef416fc2 | 73 | */ |
74 | ||
2e4ff8af | 75 | if ((op = cgiGetVariable("OP")) != NULL && job_id > 0 && cgiIsPOST()) |
ef416fc2 | 76 | { |
77 | /* | |
78 | * Do the operation... | |
79 | */ | |
80 | ||
81 | if (!strcmp(op, "cancel-job")) | |
fa73b229 | 82 | do_job_op(http, job_id, IPP_CANCEL_JOB); |
ef416fc2 | 83 | else if (!strcmp(op, "hold-job")) |
fa73b229 | 84 | do_job_op(http, job_id, IPP_HOLD_JOB); |
85 | else if (!strcmp(op, "move-job")) | |
86 | cgiMoveJobs(http, NULL, job_id); | |
ef416fc2 | 87 | else if (!strcmp(op, "release-job")) |
fa73b229 | 88 | do_job_op(http, job_id, IPP_RELEASE_JOB); |
ef416fc2 | 89 | else if (!strcmp(op, "restart-job")) |
fa73b229 | 90 | do_job_op(http, job_id, IPP_RESTART_JOB); |
ef416fc2 | 91 | else |
92 | { | |
93 | /* | |
94 | * Bad operation code... Display an error... | |
95 | */ | |
96 | ||
fa73b229 | 97 | cgiStartHTML(cgiText(_("Jobs"))); |
98 | cgiCopyTemplateLang("error-op.tmpl"); | |
99 | cgiEndHTML(); | |
ef416fc2 | 100 | } |
101 | } | |
102 | else | |
103 | { | |
104 | /* | |
105 | * Show a list of jobs... | |
106 | */ | |
107 | ||
fa73b229 | 108 | cgiStartHTML(cgiText(_("Jobs"))); |
ef416fc2 | 109 | cgiShowJobs(http, NULL); |
fa73b229 | 110 | cgiEndHTML(); |
ef416fc2 | 111 | } |
112 | ||
ef416fc2 | 113 | /* |
114 | * Close the HTTP server connection... | |
115 | */ | |
116 | ||
117 | httpClose(http); | |
ef416fc2 | 118 | |
119 | /* | |
120 | * Return with no errors... | |
121 | */ | |
122 | ||
123 | return (0); | |
124 | } | |
125 | ||
126 | ||
127 | /* | |
128 | * 'do_job_op()' - Do a job operation. | |
129 | */ | |
130 | ||
131 | static void | |
132 | do_job_op(http_t *http, /* I - HTTP connection */ | |
fa73b229 | 133 | int job_id, /* I - Job ID */ |
ef416fc2 | 134 | ipp_op_t op) /* I - Operation to perform */ |
135 | { | |
fa73b229 | 136 | ipp_t *request; /* IPP request */ |
ef416fc2 | 137 | char uri[HTTP_MAX_URI]; /* Job URI */ |
fa73b229 | 138 | const char *user; /* Username */ |
ef416fc2 | 139 | |
ef416fc2 | 140 | |
141 | /* | |
142 | * Build a job request, which requires the following | |
143 | * attributes: | |
144 | * | |
145 | * attributes-charset | |
146 | * attributes-natural-language | |
147 | * job-uri or printer-uri (purge-jobs) | |
148 | * requesting-user-name | |
149 | */ | |
150 | ||
fa73b229 | 151 | request = ippNewRequest(op); |
ef416fc2 | 152 | |
bd7854cb | 153 | snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); |
154 | ||
ef416fc2 | 155 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", |
156 | NULL, uri); | |
157 | ||
fa73b229 | 158 | if ((user = getenv("REMOTE_USER")) == NULL) |
159 | user = "guest"; | |
160 | ||
161 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | |
162 | "requesting-user-name", NULL, user); | |
ef416fc2 | 163 | |
164 | /* | |
165 | * Do the request and get back a response... | |
166 | */ | |
167 | ||
fa73b229 | 168 | ippDelete(cupsDoRequest(http, request, "/jobs")); |
ef416fc2 | 169 | |
f7deaa1a | 170 | if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER")) |
171 | { | |
172 | /* | |
173 | * Redirect successful updates back to the parent page... | |
174 | */ | |
175 | ||
176 | char url[1024]; /* Encoded URL */ | |
177 | ||
178 | ||
5a9febac | 179 | strlcpy(url, "5;URL=", sizeof(url)); |
f7deaa1a | 180 | cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6); |
181 | cgiSetVariable("refresh_page", url); | |
182 | } | |
5bd77a73 MS |
183 | else if (cupsLastError() == IPP_NOT_AUTHORIZED) |
184 | { | |
185 | puts("Status: 401\n"); | |
186 | exit(0); | |
187 | } | |
f7deaa1a | 188 | |
fa73b229 | 189 | cgiStartHTML(cgiText(_("Jobs"))); |
ef416fc2 | 190 | |
fa73b229 | 191 | if (cupsLastError() > IPP_OK_CONFLICT) |
f3c17241 | 192 | cgiShowIPPError(_("Job operation failed")); |
ef416fc2 | 193 | else if (op == IPP_CANCEL_JOB) |
194 | cgiCopyTemplateLang("job-cancel.tmpl"); | |
195 | else if (op == IPP_HOLD_JOB) | |
196 | cgiCopyTemplateLang("job-hold.tmpl"); | |
197 | else if (op == IPP_RELEASE_JOB) | |
198 | cgiCopyTemplateLang("job-release.tmpl"); | |
199 | else if (op == IPP_RESTART_JOB) | |
200 | cgiCopyTemplateLang("job-restart.tmpl"); | |
fa73b229 | 201 | |
202 | cgiEndHTML(); | |
ef416fc2 | 203 | } |
204 | ||
205 | ||
206 | /* | |
354aadbe | 207 | * End of "$Id: jobs.c 11984 2014-07-02 13:16:59Z msweet $". |
ef416fc2 | 208 | */ |