]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/dest-job.c
4 * Destination job support for CUPS.
6 * Copyright 2012 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 * cupsCancelDestJob() - Cancel a job on a destination.
19 * cupsCloseDestJob() - Close a job and start printing.
20 * cupsCreateDestJob() - Create a job on a destination.
21 * cupsFinishDestDocument() - Finish the current document.
22 * cupsStartDestDocument() - Start a new document.
26 * Include necessary headers...
29 #include "cups-private.h"
33 * 'cupsCancelDestJob()' - Cancel a job on a destination.
35 * The "job_id" is the number returned by cupsCreateDestJob.
37 * Returns IPP_OK on success and IPP_NOT_AUTHORIZED or IPP_FORBIDDEN on
44 cupsCancelDestJob(http_t
*http
, /* I - Connection to destination */
45 cups_dest_t
*dest
, /* I - Destination */
46 int job_id
) /* I - Job ID */
48 return (IPP_NOT_FOUND
);
53 * 'cupsCloseDestJob()' - Close a job and start printing.
55 * Use when the last call to cupsStartDocument passed 0 for "last_document".
56 * "job_id" is the job ID returned by cupsCreateDestJob. Returns @code IPP_OK@
62 ipp_status_t
/* O - IPP status code */
64 http_t
*http
, /* I - Connection to destination */
65 cups_dest_t
*dest
, /* I - Destination */
66 cups_dinfo_t
*info
, /* I - Destination information */
67 int job_id
) /* I - Job ID */
69 int i
; /* Looping var */
70 ipp_t
*request
= NULL
;/* Close-Job/Send-Document request */
71 ipp_attribute_t
*attr
; /* operations-supported attribute */
74 DEBUG_printf(("cupsCloseDestJob(http=%p, dest=%p(%s/%s), info=%p, job_id=%d)",
75 http
, dest
, dest
? dest
->name
: NULL
,
76 dest
? dest
->instance
: NULL
, info
, job_id
));
79 * Range check input...
82 if (!http
|| !dest
|| !info
|| job_id
<= 0)
84 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
85 DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
86 return (IPP_INTERNAL_ERROR
);
90 * Build a Close-Job or empty Send-Document request...
93 if ((attr
= ippFindAttribute(info
->attrs
, "operations-supported",
94 IPP_TAG_ENUM
)) != NULL
)
96 for (i
= 0; i
< attr
->num_values
; i
++)
97 if (attr
->values
[i
].integer
== IPP_CLOSE_JOB
)
99 request
= ippNewRequest(IPP_CLOSE_JOB
);
105 request
= ippNewRequest(IPP_SEND_DOCUMENT
);
109 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
110 DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
112 return (IPP_INTERNAL_ERROR
);
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_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_OK@ or @code IPP_OK_SUBST@ on success, saving the job ID
141 * in the variable pointed to by "job_id".
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_INTERNAL_ERROR
, strerror(EINVAL
), 0);
177 DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
178 return (IPP_INTERNAL_ERROR
);
182 * Build a Create-Job request...
185 if ((request
= ippNewRequest(IPP_CREATE_JOB
)) == NULL
)
187 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
188 DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request.");
189 return (IPP_INTERNAL_ERROR
);
192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
194 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
197 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "job-name", NULL
,
199 cupsEncodeOptions(request
, num_options
, options
);
202 * Send the request and get the job-id...
205 response
= cupsDoRequest(http
, request
, info
->resource
);
207 if ((attr
= ippFindAttribute(response
, "job-id", IPP_TAG_INTEGER
)) != NULL
)
209 *job_id
= attr
->values
[0].integer
;
210 DEBUG_printf(("1cupsCreateDestJob: job-id=%d", *job_id
));
216 * Return the status code from the Create-Job request...
219 DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()),
220 cupsLastErrorString()));
222 return (cupsLastError());
227 * 'cupsFinishDestDocument()' - Finish the current document.
229 * Returns @code IPP_OK@ or @code IPP_OK_SUBST@ on success.
234 ipp_status_t
/* O - Status of document submission */
235 cupsFinishDestDocument(
236 http_t
*http
, /* I - Connection to destination */
237 cups_dest_t
*dest
, /* I - Destination */
238 cups_dinfo_t
*info
) /* I - Destination information */
240 DEBUG_printf(("cupsFinishDestDocument(http=%p, dest=%p(%s/%s), info=%p)",
241 http
, dest
, dest
? dest
->name
: NULL
,
242 dest
? dest
->instance
: NULL
, info
));
245 * Range check input...
248 if (!http
|| !dest
|| !info
)
250 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
251 DEBUG_puts("1cupsFinishDestDocument: Bad arguments.");
252 return (IPP_INTERNAL_ERROR
);
256 * Get the response at the end of the document and return it...
259 ippDelete(cupsGetResponse(http
, info
->resource
));
261 DEBUG_printf(("1cupsFinishDestDocument: %s (%s)",
262 ippErrorString(cupsLastError()), cupsLastErrorString()));
264 return (cupsLastError());
269 * 'cupsStartDestDocument()' - Start a new document.
271 * "job_id" is the job ID returned by cupsCreateDestJob. "docname" is the name
272 * of the document/file being printed, "format" is the MIME media type for the
273 * document (see CUPS_FORMAT_xxx constants), and "num_options" and "options"
274 * are the options do be applied to the document. "last_document" should be 1
275 * if this is the last document to be submitted in the job. Returns
276 * @code HTTP_CONTINUE@ on success.
281 http_status_t
/* O - Status of document creation */
282 cupsStartDestDocument(
283 http_t
*http
, /* I - Connection to destination */
284 cups_dest_t
*dest
, /* I - Destination */
285 cups_dinfo_t
*info
, /* I - Destination information */
286 int job_id
, /* I - Job ID */
287 const char *docname
, /* I - Document name */
288 const char *format
, /* I - Document format */
289 int num_options
, /* I - Number of document options */
290 cups_option_t
*options
, /* I - Document options */
291 int last_document
) /* I - 1 if this is the last document */
293 ipp_t
*request
; /* Send-Document request */
294 http_status_t status
; /* HTTP status */
297 DEBUG_printf(("cupsStartDestDocument(http=%p, dest=%p(%s/%s), info=%p, "
298 "job_id=%d, docname=\"%s\", format=\"%s\", num_options=%d, "
299 "options=%p, last_document=%d)",
300 http
, dest
, dest
? dest
->name
: NULL
,
301 dest
? dest
->instance
: NULL
, info
, job_id
, docname
, format
,
302 num_options
, options
, last_document
));
305 * Range check input...
308 if (!http
|| !dest
|| !info
|| job_id
<= 0)
310 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(EINVAL
), 0);
311 DEBUG_puts("1cupsStartDestDocument: Bad arguments.");
316 * Create a Send-Document request...
319 if ((request
= ippNewRequest(IPP_SEND_DOCUMENT
)) == NULL
)
321 _cupsSetError(IPP_INTERNAL_ERROR
, strerror(ENOMEM
), 0);
322 DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document "
327 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
329 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", job_id
);
330 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
333 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
336 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
,
337 "document-format", NULL
, format
);
338 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", last_document
);
340 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_DOCUMENT
);
343 * Send and delete the request, then return the status...
346 status
= cupsSendRequest(http
, request
, info
->resource
, CUPS_LENGTH_VARIABLE
);