]>
Commit | Line | Data |
---|---|---|
dcb445bc | 1 | /* |
1a18c85c | 2 | * "$Id: dest-job.c 11558 2014-02-06 18:33:34Z msweet $" |
dcb445bc | 3 | * |
1a18c85c | 4 | * Destination job support for CUPS. |
dcb445bc | 5 | * |
1a18c85c | 6 | * Copyright 2012-2014 by Apple Inc. |
dcb445bc | 7 | * |
1a18c85c MS |
8 | * These coded instructions, statements, and computer programs are the |
9 | * property of Apple Inc. and are protected by Federal copyright | |
10 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
11 | * which should have been included with this file. If this file is | |
12 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
dcb445bc | 13 | * |
1a18c85c | 14 | * This file is subject to the Apple OS-Developed Software exception. |
dcb445bc MS |
15 | */ |
16 | ||
17 | /* | |
18 | * Include necessary headers... | |
19 | */ | |
20 | ||
21 | #include "cups-private.h" | |
22 | ||
23 | ||
24 | /* | |
25 | * 'cupsCancelDestJob()' - Cancel a job on a destination. | |
26 | * | |
27 | * The "job_id" is the number returned by cupsCreateDestJob. | |
28 | * | |
cb7f98ee | 29 | * Returns IPP_STATUS_OK on success and IPP_NOT_AUTHORIZED or IPP_FORBIDDEN on |
dcb445bc MS |
30 | * failure. |
31 | * | |
f3c17241 | 32 | * @since CUPS 1.6/OS X 10.8@ |
dcb445bc MS |
33 | */ |
34 | ||
35 | ipp_status_t | |
36 | cupsCancelDestJob(http_t *http, /* I - Connection to destination */ | |
37 | cups_dest_t *dest, /* I - Destination */ | |
38 | int job_id) /* I - Job ID */ | |
39 | { | |
1a18c85c MS |
40 | /* TODO: Needs to be implemented! */ |
41 | /* Probably also needs to be revved to accept cups_dinfo_t... */ | |
42 | (void)http; | |
43 | (void)dest; | |
44 | (void)job_id; | |
45 | ||
cb7f98ee | 46 | return (IPP_STATUS_ERROR_NOT_FOUND); |
dcb445bc MS |
47 | } |
48 | ||
49 | ||
50 | /* | |
51 | * 'cupsCloseDestJob()' - Close a job and start printing. | |
52 | * | |
53 | * Use when the last call to cupsStartDocument passed 0 for "last_document". | |
cb7f98ee | 54 | * "job_id" is the job ID returned by cupsCreateDestJob. Returns @code IPP_STATUS_OK@ |
82cc1f9a | 55 | * on success. |
dcb445bc | 56 | * |
f3c17241 | 57 | * @since CUPS 1.6/OS X 10.8@ |
dcb445bc MS |
58 | */ |
59 | ||
82cc1f9a | 60 | ipp_status_t /* O - IPP status code */ |
dcb445bc | 61 | cupsCloseDestJob( |
82cc1f9a MS |
62 | http_t *http, /* I - Connection to destination */ |
63 | cups_dest_t *dest, /* I - Destination */ | |
64 | cups_dinfo_t *info, /* I - Destination information */ | |
65 | int job_id) /* I - Job ID */ | |
dcb445bc | 66 | { |
82cc1f9a MS |
67 | int i; /* Looping var */ |
68 | ipp_t *request = NULL;/* Close-Job/Send-Document request */ | |
69 | ipp_attribute_t *attr; /* operations-supported attribute */ | |
70 | ||
71 | ||
72 | DEBUG_printf(("cupsCloseDestJob(http=%p, dest=%p(%s/%s), info=%p, job_id=%d)", | |
73 | http, dest, dest ? dest->name : NULL, | |
74 | dest ? dest->instance : NULL, info, job_id)); | |
75 | ||
76 | /* | |
77 | * Range check input... | |
78 | */ | |
79 | ||
80 | if (!http || !dest || !info || job_id <= 0) | |
81 | { | |
cb7f98ee | 82 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
82cc1f9a | 83 | DEBUG_puts("1cupsCloseDestJob: Bad arguments."); |
cb7f98ee | 84 | return (IPP_STATUS_ERROR_INTERNAL); |
82cc1f9a MS |
85 | } |
86 | ||
87 | /* | |
88 | * Build a Close-Job or empty Send-Document request... | |
89 | */ | |
90 | ||
91 | if ((attr = ippFindAttribute(info->attrs, "operations-supported", | |
92 | IPP_TAG_ENUM)) != NULL) | |
93 | { | |
94 | for (i = 0; i < attr->num_values; i ++) | |
cb7f98ee | 95 | if (attr->values[i].integer == IPP_OP_CLOSE_JOB) |
82cc1f9a | 96 | { |
cb7f98ee | 97 | request = ippNewRequest(IPP_OP_CLOSE_JOB); |
82cc1f9a MS |
98 | break; |
99 | } | |
100 | } | |
101 | ||
102 | if (!request) | |
cb7f98ee | 103 | request = ippNewRequest(IPP_OP_SEND_DOCUMENT); |
82cc1f9a MS |
104 | |
105 | if (!request) | |
106 | { | |
cb7f98ee | 107 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0); |
82cc1f9a MS |
108 | DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document " |
109 | "request."); | |
cb7f98ee | 110 | return (IPP_STATUS_ERROR_INTERNAL); |
82cc1f9a MS |
111 | } |
112 | ||
6961465f MS |
113 | ippSetVersion(request, info->version / 10, info->version % 10); |
114 | ||
82cc1f9a MS |
115 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
116 | NULL, info->uri); | |
117 | ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", | |
118 | job_id); | |
119 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", | |
120 | NULL, cupsUser()); | |
cb7f98ee | 121 | if (ippGetOperation(request) == IPP_OP_SEND_DOCUMENT) |
82cc1f9a MS |
122 | ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1); |
123 | ||
124 | /* | |
125 | * Send the request and return the status... | |
126 | */ | |
127 | ||
128 | ippDelete(cupsDoRequest(http, request, info->resource)); | |
129 | ||
130 | DEBUG_printf(("1cupsCloseDestJob: %s (%s)", ippErrorString(cupsLastError()), | |
131 | cupsLastErrorString())); | |
132 | ||
133 | return (cupsLastError()); | |
dcb445bc MS |
134 | } |
135 | ||
136 | ||
137 | /* | |
138 | * 'cupsCreateDestJob()' - Create a job on a destination. | |
139 | * | |
cb7f98ee | 140 | * Returns @code IPP_STATUS_OK@ or @code IPP_STATUS_OK_SUBST@ on success, saving the job ID |
82cc1f9a | 141 | * in the variable pointed to by "job_id". |
dcb445bc | 142 | * |
f3c17241 | 143 | * @since CUPS 1.6/OS X 10.8@ |
dcb445bc MS |
144 | */ |
145 | ||
146 | ipp_status_t /* O - IPP status code */ | |
147 | cupsCreateDestJob( | |
148 | http_t *http, /* I - Connection to destination */ | |
149 | cups_dest_t *dest, /* I - Destination */ | |
150 | cups_dinfo_t *info, /* I - Destination information */ | |
151 | int *job_id, /* O - Job ID or 0 on error */ | |
152 | const char *title, /* I - Job name */ | |
153 | int num_options, /* I - Number of job options */ | |
154 | cups_option_t *options) /* I - Job options */ | |
155 | { | |
82cc1f9a MS |
156 | ipp_t *request, /* Create-Job request */ |
157 | *response; /* Create-Job response */ | |
158 | ipp_attribute_t *attr; /* job-id attribute */ | |
159 | ||
160 | ||
161 | DEBUG_printf(("cupsCreateDestJob(http=%p, dest=%p(%s/%s), info=%p, " | |
162 | "job_id=%p, title=\"%s\", num_options=%d, options=%p)", | |
163 | http, dest, dest ? dest->name : NULL, | |
164 | dest ? dest->instance : NULL, info, job_id, title, num_options, | |
165 | options)); | |
166 | ||
167 | /* | |
168 | * Range check input... | |
169 | */ | |
170 | ||
171 | if (job_id) | |
172 | *job_id = 0; | |
173 | ||
174 | if (!http || !dest || !info || !job_id) | |
175 | { | |
cb7f98ee | 176 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
82cc1f9a | 177 | DEBUG_puts("1cupsCreateDestJob: Bad arguments."); |
cb7f98ee | 178 | return (IPP_STATUS_ERROR_INTERNAL); |
82cc1f9a MS |
179 | } |
180 | ||
181 | /* | |
182 | * Build a Create-Job request... | |
183 | */ | |
184 | ||
cb7f98ee | 185 | if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL) |
82cc1f9a | 186 | { |
cb7f98ee | 187 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0); |
82cc1f9a | 188 | DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request."); |
cb7f98ee | 189 | return (IPP_STATUS_ERROR_INTERNAL); |
82cc1f9a MS |
190 | } |
191 | ||
6961465f MS |
192 | ippSetVersion(request, info->version / 10, info->version % 10); |
193 | ||
82cc1f9a MS |
194 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
195 | NULL, info->uri); | |
196 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", | |
197 | NULL, cupsUser()); | |
198 | if (title) | |
199 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL, | |
200 | title); | |
a29fd7dd | 201 | |
a469f8a5 | 202 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION); |
a29fd7dd MS |
203 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); |
204 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION); | |
82cc1f9a MS |
205 | |
206 | /* | |
207 | * Send the request and get the job-id... | |
208 | */ | |
dcb445bc | 209 | |
82cc1f9a MS |
210 | response = cupsDoRequest(http, request, info->resource); |
211 | ||
212 | if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) != NULL) | |
213 | { | |
214 | *job_id = attr->values[0].integer; | |
215 | DEBUG_printf(("1cupsCreateDestJob: job-id=%d", *job_id)); | |
216 | } | |
217 | ||
218 | ippDelete(response); | |
219 | ||
220 | /* | |
221 | * Return the status code from the Create-Job request... | |
222 | */ | |
223 | ||
224 | DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()), | |
225 | cupsLastErrorString())); | |
226 | ||
227 | return (cupsLastError()); | |
dcb445bc MS |
228 | } |
229 | ||
230 | ||
231 | /* | |
232 | * 'cupsFinishDestDocument()' - Finish the current document. | |
233 | * | |
cb7f98ee | 234 | * Returns @code IPP_STATUS_OK@ or @code IPP_STATUS_OK_SUBST@ on success. |
dcb445bc | 235 | * |
f3c17241 | 236 | * @since CUPS 1.6/OS X 10.8@ |
dcb445bc MS |
237 | */ |
238 | ||
82cc1f9a | 239 | ipp_status_t /* O - Status of document submission */ |
dcb445bc | 240 | cupsFinishDestDocument( |
82cc1f9a MS |
241 | http_t *http, /* I - Connection to destination */ |
242 | cups_dest_t *dest, /* I - Destination */ | |
243 | cups_dinfo_t *info) /* I - Destination information */ | |
dcb445bc | 244 | { |
82cc1f9a MS |
245 | DEBUG_printf(("cupsFinishDestDocument(http=%p, dest=%p(%s/%s), info=%p)", |
246 | http, dest, dest ? dest->name : NULL, | |
247 | dest ? dest->instance : NULL, info)); | |
248 | ||
249 | /* | |
250 | * Range check input... | |
251 | */ | |
252 | ||
253 | if (!http || !dest || !info) | |
254 | { | |
cb7f98ee | 255 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
82cc1f9a | 256 | DEBUG_puts("1cupsFinishDestDocument: Bad arguments."); |
cb7f98ee | 257 | return (IPP_STATUS_ERROR_INTERNAL); |
82cc1f9a MS |
258 | } |
259 | ||
260 | /* | |
261 | * Get the response at the end of the document and return it... | |
262 | */ | |
263 | ||
264 | ippDelete(cupsGetResponse(http, info->resource)); | |
265 | ||
266 | DEBUG_printf(("1cupsFinishDestDocument: %s (%s)", | |
267 | ippErrorString(cupsLastError()), cupsLastErrorString())); | |
268 | ||
269 | return (cupsLastError()); | |
dcb445bc MS |
270 | } |
271 | ||
272 | ||
273 | /* | |
274 | * 'cupsStartDestDocument()' - Start a new document. | |
275 | * | |
276 | * "job_id" is the job ID returned by cupsCreateDestJob. "docname" is the name | |
277 | * of the document/file being printed, "format" is the MIME media type for the | |
278 | * document (see CUPS_FORMAT_xxx constants), and "num_options" and "options" | |
279 | * are the options do be applied to the document. "last_document" should be 1 | |
280 | * if this is the last document to be submitted in the job. Returns | |
82cc1f9a | 281 | * @code HTTP_CONTINUE@ on success. |
dcb445bc | 282 | * |
f3c17241 | 283 | * @since CUPS 1.6/OS X 10.8@ |
dcb445bc MS |
284 | */ |
285 | ||
82cc1f9a | 286 | http_status_t /* O - Status of document creation */ |
dcb445bc MS |
287 | cupsStartDestDocument( |
288 | http_t *http, /* I - Connection to destination */ | |
289 | cups_dest_t *dest, /* I - Destination */ | |
290 | cups_dinfo_t *info, /* I - Destination information */ | |
291 | int job_id, /* I - Job ID */ | |
292 | const char *docname, /* I - Document name */ | |
293 | const char *format, /* I - Document format */ | |
294 | int num_options, /* I - Number of document options */ | |
295 | cups_option_t *options, /* I - Document options */ | |
296 | int last_document) /* I - 1 if this is the last document */ | |
297 | { | |
82cc1f9a MS |
298 | ipp_t *request; /* Send-Document request */ |
299 | http_status_t status; /* HTTP status */ | |
300 | ||
301 | ||
302 | DEBUG_printf(("cupsStartDestDocument(http=%p, dest=%p(%s/%s), info=%p, " | |
303 | "job_id=%d, docname=\"%s\", format=\"%s\", num_options=%d, " | |
304 | "options=%p, last_document=%d)", | |
305 | http, dest, dest ? dest->name : NULL, | |
306 | dest ? dest->instance : NULL, info, job_id, docname, format, | |
307 | num_options, options, last_document)); | |
308 | ||
309 | /* | |
310 | * Range check input... | |
311 | */ | |
312 | ||
313 | if (!http || !dest || !info || job_id <= 0) | |
314 | { | |
cb7f98ee | 315 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
82cc1f9a | 316 | DEBUG_puts("1cupsStartDestDocument: Bad arguments."); |
cb7f98ee | 317 | return (HTTP_STATUS_ERROR); |
82cc1f9a MS |
318 | } |
319 | ||
320 | /* | |
321 | * Create a Send-Document request... | |
322 | */ | |
323 | ||
cb7f98ee | 324 | if ((request = ippNewRequest(IPP_OP_SEND_DOCUMENT)) == NULL) |
82cc1f9a | 325 | { |
cb7f98ee | 326 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0); |
82cc1f9a MS |
327 | DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document " |
328 | "request."); | |
cb7f98ee | 329 | return (HTTP_STATUS_ERROR); |
82cc1f9a MS |
330 | } |
331 | ||
6961465f MS |
332 | ippSetVersion(request, info->version / 10, info->version % 10); |
333 | ||
82cc1f9a MS |
334 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
335 | NULL, info->uri); | |
336 | ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", job_id); | |
337 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", | |
338 | NULL, cupsUser()); | |
339 | if (docname) | |
340 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "document-name", | |
341 | NULL, docname); | |
342 | if (format) | |
343 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, | |
344 | "document-format", NULL, format); | |
1a18c85c | 345 | ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", (char)last_document); |
82cc1f9a | 346 | |
a469f8a5 | 347 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION); |
82cc1f9a MS |
348 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_DOCUMENT); |
349 | ||
350 | /* | |
351 | * Send and delete the request, then return the status... | |
352 | */ | |
353 | ||
354 | status = cupsSendRequest(http, request, info->resource, CUPS_LENGTH_VARIABLE); | |
355 | ||
356 | ippDelete(request); | |
357 | ||
358 | return (status); | |
dcb445bc MS |
359 | } |
360 | ||
361 | ||
362 | /* | |
1a18c85c | 363 | * End of "$Id: dest-job.c 11558 2014-02-06 18:33:34Z msweet $". |
dcb445bc | 364 | */ |