2 * "$Id: dest-job.c 11558 2014-02-06 18:33:34Z msweet $"
4 * Destination job support for CUPS.
6 * Copyright 2012-2014 by Apple Inc.
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/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * Include necessary headers...
21 #include "cups-private.h"
25 * 'cupsCancelDestJob()' - Cancel a job on a destination.
27 * The "job_id" is the number returned by cupsCreateDestJob.
29 * Returns IPP_STATUS_OK on success and IPP_NOT_AUTHORIZED or IPP_FORBIDDEN on
32 * @since CUPS 1.6/OS X 10.8@
36 cupsCancelDestJob(http_t
*http
, /* I - Connection to destination */
37 cups_dest_t
*dest
, /* I - Destination */
38 int job_id
) /* I - Job ID */
40 /* TODO: Needs to be implemented! */
41 /* Probably also needs to be revved to accept cups_dinfo_t... */
46 return (IPP_STATUS_ERROR_NOT_FOUND
);
51 * 'cupsCloseDestJob()' - Close a job and start printing.
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@
57 * @since CUPS 1.6/OS X 10.8@
60 ipp_status_t
/* O - IPP status code */
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 */
67 int i
; /* Looping var */
68 ipp_t
*request
= NULL
;/* Close-Job/Send-Document request */
69 ipp_attribute_t
*attr
; /* operations-supported attribute */
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
));
77 * Range check input...
80 if (!http
|| !dest
|| !info
|| job_id
<= 0)
82 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
83 DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
84 return (IPP_STATUS_ERROR_INTERNAL
);
88 * Build a Close-Job or empty Send-Document request...
91 if ((attr
= ippFindAttribute(info
->attrs
, "operations-supported",
92 IPP_TAG_ENUM
)) != NULL
)
94 for (i
= 0; i
< attr
->num_values
; i
++)
95 if (attr
->values
[i
].integer
== IPP_OP_CLOSE_JOB
)
97 request
= ippNewRequest(IPP_OP_CLOSE_JOB
);
103 request
= ippNewRequest(IPP_OP_SEND_DOCUMENT
);
107 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOMEM
), 0);
108 DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
110 return (IPP_STATUS_ERROR_INTERNAL
);
113 ippSetVersion(request
, info
->version
/ 10, info
->version
% 10);
115 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
117 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
119 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
121 if (ippGetOperation(request
) == IPP_OP_SEND_DOCUMENT
)
122 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", 1);
125 * Send the request and return the status...
128 ippDelete(cupsDoRequest(http
, request
, info
->resource
));
130 DEBUG_printf(("1cupsCloseDestJob: %s (%s)", ippErrorString(cupsLastError()),
131 cupsLastErrorString()));
133 return (cupsLastError());
138 * 'cupsCreateDestJob()' - Create a job on a destination.
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".
143 * @since CUPS 1.6/OS X 10.8@
146 ipp_status_t
/* O - IPP status code */
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 */
156 ipp_t
*request
, /* Create-Job request */
157 *response
; /* Create-Job response */
158 ipp_attribute_t
*attr
; /* job-id attribute */
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
,
168 * Range check input...
174 if (!http
|| !dest
|| !info
|| !job_id
)
176 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
177 DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
178 return (IPP_STATUS_ERROR_INTERNAL
);
182 * Build a Create-Job request...
185 if ((request
= ippNewRequest(IPP_OP_CREATE_JOB
)) == NULL
)
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
);
192 ippSetVersion(request
, info
->version
/ 10, info
->version
% 10);
194 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
196 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
199 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "job-name", NULL
,
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
);
207 * Send the request and get the job-id...
210 response
= cupsDoRequest(http
, request
, info
->resource
);
212 if ((attr
= ippFindAttribute(response
, "job-id", IPP_TAG_INTEGER
)) != NULL
)
214 *job_id
= attr
->values
[0].integer
;
215 DEBUG_printf(("1cupsCreateDestJob: job-id=%d", *job_id
));
221 * Return the status code from the Create-Job request...
224 DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()),
225 cupsLastErrorString()));
227 return (cupsLastError());
232 * 'cupsFinishDestDocument()' - Finish the current document.
234 * Returns @code IPP_STATUS_OK@ or @code IPP_STATUS_OK_SUBST@ on success.
236 * @since CUPS 1.6/OS X 10.8@
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 */
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
));
250 * Range check input...
253 if (!http
|| !dest
|| !info
)
255 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
256 DEBUG_puts("1cupsFinishDestDocument: Bad arguments.");
257 return (IPP_STATUS_ERROR_INTERNAL
);
261 * Get the response at the end of the document and return it...
264 ippDelete(cupsGetResponse(http
, info
->resource
));
266 DEBUG_printf(("1cupsFinishDestDocument: %s (%s)",
267 ippErrorString(cupsLastError()), cupsLastErrorString()));
269 return (cupsLastError());
274 * 'cupsStartDestDocument()' - Start a new document.
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.
283 * @since CUPS 1.6/OS X 10.8@
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 */
298 ipp_t
*request
; /* Send-Document request */
299 http_status_t status
; /* HTTP status */
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
));
310 * Range check input...
313 if (!http
|| !dest
|| !info
|| job_id
<= 0)
315 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
316 DEBUG_puts("1cupsStartDestDocument: Bad arguments.");
317 return (HTTP_STATUS_ERROR
);
321 * Create a Send-Document request...
324 if ((request
= ippNewRequest(IPP_OP_SEND_DOCUMENT
)) == NULL
)
326 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOMEM
), 0);
327 DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document "
329 return (HTTP_STATUS_ERROR
);
332 ippSetVersion(request
, info
->version
/ 10, info
->version
% 10);
334 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-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",
340 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
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
);
347 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_OPERATION
);
348 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_DOCUMENT
);
351 * Send and delete the request, then return the status...
354 status
= cupsSendRequest(http
, request
, info
->resource
, CUPS_LENGTH_VARIABLE
);
363 * End of "$Id: dest-job.c 11558 2014-02-06 18:33:34Z msweet $".