]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/dest-job.c
Full sweep of all Clang warnings, plus some bug fixes for incorrect memcpy usage.
[thirdparty/cups.git] / cups / dest-job.c
1 /*
2 * "$Id$"
3 *
4 * Destination job support for CUPS.
5 *
6 * Copyright 2012-2014 by Apple Inc.
7 *
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/".
13 *
14 * This file is subject to the Apple OS-Developed Software exception.
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 *
29 * Returns IPP_STATUS_OK on success and IPP_NOT_AUTHORIZED or IPP_FORBIDDEN on
30 * failure.
31 *
32 * @since CUPS 1.6/OS X 10.8@
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 {
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
46 return (IPP_STATUS_ERROR_NOT_FOUND);
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".
54 * "job_id" is the job ID returned by cupsCreateDestJob. Returns @code IPP_STATUS_OK@
55 * on success.
56 *
57 * @since CUPS 1.6/OS X 10.8@
58 */
59
60 ipp_status_t /* O - IPP status code */
61 cupsCloseDestJob(
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 */
66 {
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 {
82 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
83 DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
84 return (IPP_STATUS_ERROR_INTERNAL);
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 ++)
95 if (attr->values[i].integer == IPP_OP_CLOSE_JOB)
96 {
97 request = ippNewRequest(IPP_OP_CLOSE_JOB);
98 break;
99 }
100 }
101
102 if (!request)
103 request = ippNewRequest(IPP_OP_SEND_DOCUMENT);
104
105 if (!request)
106 {
107 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
108 DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
109 "request.");
110 return (IPP_STATUS_ERROR_INTERNAL);
111 }
112
113 ippSetVersion(request, info->version / 10, info->version % 10);
114
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());
121 if (ippGetOperation(request) == IPP_OP_SEND_DOCUMENT)
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());
134 }
135
136
137 /*
138 * 'cupsCreateDestJob()' - Create a job on a destination.
139 *
140 * Returns @code IPP_STATUS_OK@ or @code IPP_STATUS_OK_SUBST@ on success, saving the job ID
141 * in the variable pointed to by "job_id".
142 *
143 * @since CUPS 1.6/OS X 10.8@
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 {
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 {
176 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
177 DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
178 return (IPP_STATUS_ERROR_INTERNAL);
179 }
180
181 /*
182 * Build a Create-Job request...
183 */
184
185 if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
186 {
187 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
188 DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request.");
189 return (IPP_STATUS_ERROR_INTERNAL);
190 }
191
192 ippSetVersion(request, info->version / 10, info->version % 10);
193
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);
201
202 cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
203 cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
204 cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION);
205
206 /*
207 * Send the request and get the job-id...
208 */
209
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());
228 }
229
230
231 /*
232 * 'cupsFinishDestDocument()' - Finish the current document.
233 *
234 * Returns @code IPP_STATUS_OK@ or @code IPP_STATUS_OK_SUBST@ on success.
235 *
236 * @since CUPS 1.6/OS X 10.8@
237 */
238
239 ipp_status_t /* O - Status of document submission */
240 cupsFinishDestDocument(
241 http_t *http, /* I - Connection to destination */
242 cups_dest_t *dest, /* I - Destination */
243 cups_dinfo_t *info) /* I - Destination information */
244 {
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 {
255 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
256 DEBUG_puts("1cupsFinishDestDocument: Bad arguments.");
257 return (IPP_STATUS_ERROR_INTERNAL);
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());
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
281 * @code HTTP_CONTINUE@ on success.
282 *
283 * @since CUPS 1.6/OS X 10.8@
284 */
285
286 http_status_t /* O - Status of document creation */
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 {
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 {
315 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
316 DEBUG_puts("1cupsStartDestDocument: Bad arguments.");
317 return (HTTP_STATUS_ERROR);
318 }
319
320 /*
321 * Create a Send-Document request...
322 */
323
324 if ((request = ippNewRequest(IPP_OP_SEND_DOCUMENT)) == NULL)
325 {
326 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
327 DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document "
328 "request.");
329 return (HTTP_STATUS_ERROR);
330 }
331
332 ippSetVersion(request, info->version / 10, info->version % 10);
333
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);
345 ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", (char)last_document);
346
347 cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
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);
359 }
360
361
362 /*
363 * End of "$Id$".
364 */