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