2 * Printing utilities for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cups-private.h"
17 #if defined(WIN32) || defined(__EMX__)
21 #endif /* WIN32 || __EMX__ */
25 * Enumeration data and callback...
28 typedef struct _cups_createdata_s
30 const char *name
; /* Destination name */
31 cups_dest_t
*dest
; /* Matching destination */
34 static int cups_create_cb(_cups_createdata_t
*data
, unsigned flags
, cups_dest_t
*dest
);
38 * 'cupsCancelJob()' - Cancel a print job on the default server.
40 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
41 * to cancel the current job on the named destination.
43 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
44 * the cause of any failure.
49 int /* O - 1 on success, 0 on failure */
50 cupsCancelJob(const char *name
, /* I - Name of printer or class */
51 int job_id
) /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
53 return (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0)
54 < IPP_STATUS_REDIRECTION_OTHER_SITE
);
59 * 'cupsCancelJob2()' - Cancel or purge a print job.
61 * Canceled jobs remain in the job history while purged jobs are removed
62 * from the job history.
64 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
65 * to cancel the current job on the named destination.
67 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
68 * the cause of any failure.
70 * @since CUPS 1.4/macOS 10.6@ @exclude all@
73 ipp_status_t
/* O - IPP status */
74 cupsCancelJob2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
75 const char *name
, /* I - Name of printer or class */
76 int job_id
, /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
77 int purge
) /* I - 1 to purge, 0 to cancel */
79 char uri
[HTTP_MAX_URI
]; /* Job/printer URI */
80 ipp_t
*request
; /* IPP request */
84 * Range check input...
87 if (job_id
< -1 || (!name
&& job_id
== 0))
89 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
94 * Connect to the default server as needed...
98 if ((http
= _cupsConnect()) == NULL
)
99 return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE
);
102 * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
106 * attributes-natural-language
107 * job-uri or printer-uri + job-id
108 * requesting-user-name
109 * [purge-job] or [purge-jobs]
112 request
= ippNewRequest(job_id
< 0 ? IPP_OP_PURGE_JOBS
: IPP_OP_CANCEL_JOB
);
116 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
117 "localhost", ippPort(), "/printers/%s", name
);
119 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
121 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
126 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
128 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
, uri
);
131 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
134 if (purge
&& job_id
>= 0)
135 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-job", 1);
136 else if (!purge
&& job_id
< 0)
137 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", 0);
143 ippDelete(cupsDoRequest(http
, request
, "/jobs/"));
145 return (cupsLastError());
150 * 'cupsCreateJob()' - Create an empty job for streaming.
152 * Use this function when you want to stream print data using the
153 * @link cupsStartDocument@, @link cupsWriteRequestData@, and
154 * @link cupsFinishDocument@ functions. If you have one or more files to
155 * print, use the @link cupsPrintFile2@ or @link cupsPrintFiles2@ function
158 * @since CUPS 1.4/macOS 10.6@ @exclude all@
161 int /* O - Job ID or 0 on error */
163 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
164 const char *name
, /* I - Destination name */
165 const char *title
, /* I - Title of job */
166 int num_options
, /* I - Number of options */
167 cups_option_t
*options
) /* I - Options */
169 int job_id
= 0; /* job-id value */
170 ipp_status_t status
; /* Create-Job status */
171 _cups_createdata_t data
; /* Enumeration data */
172 cups_dinfo_t
*info
; /* Destination information */
175 DEBUG_printf(("cupsCreateJob(http=%p, name=\"%s\", title=\"%s\", num_options=%d, options=%p)", (void *)http
, name
, title
, num_options
, (void *)options
));
178 * Range check input...
183 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
188 * Lookup the destination...
194 cupsEnumDests(0, 1000, NULL
, 0, 0, (cups_dest_cb_t
)cups_create_cb
, &data
);
198 DEBUG_puts("1cupsCreateJob: Destination not found.");
199 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOENT
), 0);
204 * Query dest information and create the job...
207 DEBUG_puts("1cupsCreateJob: Querying destination info.");
208 if ((info
= cupsCopyDestInfo(http
, data
.dest
)) == NULL
)
210 DEBUG_puts("1cupsCreateJob: Query failed.");
211 cupsFreeDests(1, data
.dest
);
215 status
= cupsCreateDestJob(http
, data
.dest
, info
, &job_id
, title
, num_options
, options
);
216 DEBUG_printf(("1cupsCreateJob: cupsCreateDestJob returned %04x (%s)", status
, ippErrorString(status
)));
218 cupsFreeDestInfo(info
);
219 cupsFreeDests(1, data
.dest
);
225 if (status
>= IPP_STATUS_REDIRECTION_OTHER_SITE
)
233 * 'cupsFinishDocument()' - Finish sending a document.
235 * The document must have been started using @link cupsStartDocument@.
237 * @since CUPS 1.4/macOS 10.6@ @exclude all@
240 ipp_status_t
/* O - Status of document submission */
241 cupsFinishDocument(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
242 const char *name
) /* I - Destination name */
244 char resource
[1024]; /* Printer resource */
247 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
249 ippDelete(cupsGetResponse(http
, resource
));
251 return (cupsLastError());
256 * 'cupsFreeJobs()' - Free memory used by job data.
260 cupsFreeJobs(int num_jobs
, /* I - Number of jobs */
261 cups_job_t
*jobs
) /* I - Jobs */
263 int i
; /* Looping var */
264 cups_job_t
*job
; /* Current job */
267 if (num_jobs
<= 0 || !jobs
)
270 for (i
= num_jobs
, job
= jobs
; i
> 0; i
--, job
++)
272 _cupsStrFree(job
->dest
);
273 _cupsStrFree(job
->user
);
274 _cupsStrFree(job
->format
);
275 _cupsStrFree(job
->title
);
283 * 'cupsGetClasses()' - Get a list of printer classes from the default server.
285 * This function is deprecated and no longer returns a list of printer
286 * classes - use @link cupsGetDests@ instead.
288 * @deprecated@ @exclude all@
291 int /* O - Number of classes */
292 cupsGetClasses(char ***classes
) /* O - Classes */
302 * 'cupsGetDefault()' - Get the default printer or class for the default server.
304 * This function returns the default printer or class as defined by
305 * the LPDEST or PRINTER environment variables. If these environment
306 * variables are not set, the server default destination is returned.
307 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
308 * functions to get the user-defined default printer, as this function does
309 * not support the lpoptions-defined default printer.
314 const char * /* O - Default printer or @code NULL@ */
318 * Return the default printer...
321 return (cupsGetDefault2(CUPS_HTTP_DEFAULT
));
326 * 'cupsGetDefault2()' - Get the default printer or class for the specified server.
328 * This function returns the default printer or class as defined by
329 * the LPDEST or PRINTER environment variables. If these environment
330 * variables are not set, the server default destination is returned.
331 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
332 * functions to get the user-defined default printer, as this function does
333 * not support the lpoptions-defined default printer.
335 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
338 const char * /* O - Default printer or @code NULL@ */
339 cupsGetDefault2(http_t
*http
) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
341 ipp_t
*request
, /* IPP Request */
342 *response
; /* IPP Response */
343 ipp_attribute_t
*attr
; /* Current attribute */
344 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
348 * See if we have a user default printer set...
351 if (_cupsUserDefault(cg
->def_printer
, sizeof(cg
->def_printer
)))
352 return (cg
->def_printer
);
355 * Connect to the server as needed...
359 if ((http
= _cupsConnect()) == NULL
)
363 * Build a CUPS_GET_DEFAULT request, which requires the following
367 * attributes-natural-language
370 request
= ippNewRequest(IPP_OP_CUPS_GET_DEFAULT
);
373 * Do the request and get back a response...
376 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
378 if ((attr
= ippFindAttribute(response
, "printer-name",
379 IPP_TAG_NAME
)) != NULL
)
381 strlcpy(cg
->def_printer
, attr
->values
[0].string
.text
,
382 sizeof(cg
->def_printer
));
384 return (cg
->def_printer
);
395 * 'cupsGetJobs()' - Get the jobs from the default server.
397 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
398 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
399 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
400 * jobs that are stopped, canceled, aborted, or completed.
405 int /* O - Number of jobs */
406 cupsGetJobs(cups_job_t
**jobs
, /* O - Job data */
407 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
408 int myjobs
, /* I - 0 = all users, 1 = mine */
409 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
415 return (cupsGetJobs2(CUPS_HTTP_DEFAULT
, jobs
, name
, myjobs
, whichjobs
));
421 * 'cupsGetJobs2()' - Get the jobs from the specified server.
423 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
424 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
425 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
426 * jobs that are stopped, canceled, aborted, or completed.
428 * @since CUPS 1.1.21/macOS 10.4@
431 int /* O - Number of jobs */
432 cupsGetJobs2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
433 cups_job_t
**jobs
, /* O - Job data */
434 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
435 int myjobs
, /* I - 0 = all users, 1 = mine */
436 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
438 int n
; /* Number of jobs */
439 ipp_t
*request
, /* IPP Request */
440 *response
; /* IPP Response */
441 ipp_attribute_t
*attr
; /* Current attribute */
442 cups_job_t
*temp
; /* Temporary pointer */
444 priority
, /* job-priority */
445 size
; /* job-k-octets */
446 ipp_jstate_t state
; /* job-state */
447 time_t completed_time
, /* time-at-completed */
448 creation_time
, /* time-at-creation */
449 processing_time
; /* time-at-processing */
450 const char *dest
, /* job-printer-uri */
451 *format
, /* document-format */
452 *title
, /* job-name */
453 *user
; /* job-originating-user-name */
454 char uri
[HTTP_MAX_URI
]; /* URI for jobs */
455 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
456 static const char * const attrs
[] = /* Requested attributes */
462 "job-originating-user-name",
473 * Range check input...
478 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
484 * Get the right URI...
489 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
490 "localhost", 0, "/printers/%s",
491 name
) < HTTP_URI_STATUS_OK
)
493 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
494 _("Unable to create printer-uri"), 1);
500 strlcpy(uri
, "ipp://localhost/", sizeof(uri
));
503 if ((http
= _cupsConnect()) == NULL
)
507 * Build an IPP_GET_JOBS request, which requires the following
511 * attributes-natural-language
513 * requesting-user-name
516 * requested-attributes
519 request
= ippNewRequest(IPP_OP_GET_JOBS
);
521 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
522 "printer-uri", NULL
, uri
);
524 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
525 "requesting-user-name", NULL
, cupsUser());
528 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
530 if (whichjobs
== CUPS_WHICHJOBS_COMPLETED
)
531 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
532 "which-jobs", NULL
, "completed");
533 else if (whichjobs
== CUPS_WHICHJOBS_ALL
)
534 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
535 "which-jobs", NULL
, "all");
537 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
538 "requested-attributes", sizeof(attrs
) / sizeof(attrs
[0]),
542 * Do the request and get back a response...
548 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
550 for (attr
= response
->attrs
; attr
; attr
= attr
->next
)
553 * Skip leading attributes until we hit a job...
556 while (attr
&& attr
->group_tag
!= IPP_TAG_JOB
)
563 * Pull the needed attributes from this job...
569 state
= IPP_JSTATE_PENDING
;
572 format
= "application/octet-stream";
578 while (attr
&& attr
->group_tag
== IPP_TAG_JOB
)
580 if (!strcmp(attr
->name
, "job-id") &&
581 attr
->value_tag
== IPP_TAG_INTEGER
)
582 id
= attr
->values
[0].integer
;
583 else if (!strcmp(attr
->name
, "job-state") &&
584 attr
->value_tag
== IPP_TAG_ENUM
)
585 state
= (ipp_jstate_t
)attr
->values
[0].integer
;
586 else if (!strcmp(attr
->name
, "job-priority") &&
587 attr
->value_tag
== IPP_TAG_INTEGER
)
588 priority
= attr
->values
[0].integer
;
589 else if (!strcmp(attr
->name
, "job-k-octets") &&
590 attr
->value_tag
== IPP_TAG_INTEGER
)
591 size
= attr
->values
[0].integer
;
592 else if (!strcmp(attr
->name
, "time-at-completed") &&
593 attr
->value_tag
== IPP_TAG_INTEGER
)
594 completed_time
= attr
->values
[0].integer
;
595 else if (!strcmp(attr
->name
, "time-at-creation") &&
596 attr
->value_tag
== IPP_TAG_INTEGER
)
597 creation_time
= attr
->values
[0].integer
;
598 else if (!strcmp(attr
->name
, "time-at-processing") &&
599 attr
->value_tag
== IPP_TAG_INTEGER
)
600 processing_time
= attr
->values
[0].integer
;
601 else if (!strcmp(attr
->name
, "job-printer-uri") &&
602 attr
->value_tag
== IPP_TAG_URI
)
604 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
607 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
608 attr
->value_tag
== IPP_TAG_NAME
)
609 user
= attr
->values
[0].string
.text
;
610 else if (!strcmp(attr
->name
, "document-format") &&
611 attr
->value_tag
== IPP_TAG_MIMETYPE
)
612 format
= attr
->values
[0].string
.text
;
613 else if (!strcmp(attr
->name
, "job-name") &&
614 (attr
->value_tag
== IPP_TAG_TEXT
||
615 attr
->value_tag
== IPP_TAG_NAME
))
616 title
= attr
->values
[0].string
.text
;
622 * See if we have everything needed...
634 * Allocate memory for the job...
638 temp
= malloc(sizeof(cups_job_t
));
640 temp
= realloc(*jobs
, sizeof(cups_job_t
) * (size_t)(n
+ 1));
648 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, NULL
, 0);
650 cupsFreeJobs(n
, *jobs
);
663 * Copy the data over...
666 temp
->dest
= _cupsStrAlloc(dest
);
667 temp
->user
= _cupsStrAlloc(user
);
668 temp
->format
= _cupsStrAlloc(format
);
669 temp
->title
= _cupsStrAlloc(title
);
671 temp
->priority
= priority
;
674 temp
->completed_time
= completed_time
;
675 temp
->creation_time
= creation_time
;
676 temp
->processing_time
= processing_time
;
685 if (n
== 0 && cg
->last_error
>= IPP_STATUS_ERROR_BAD_REQUEST
)
693 * 'cupsGetPrinters()' - Get a list of printers from the default server.
695 * This function is deprecated and no longer returns a list of printers - use
696 * @link cupsGetDests@ instead.
698 * @deprecated@ @exclude all@
701 int /* O - Number of printers */
702 cupsGetPrinters(char ***printers
) /* O - Printers */
712 * 'cupsPrintFile()' - Print a file to a printer or class on the default server.
717 int /* O - Job ID or 0 on error */
718 cupsPrintFile(const char *name
, /* I - Destination name */
719 const char *filename
, /* I - File to print */
720 const char *title
, /* I - Title of job */
721 int num_options
,/* I - Number of options */
722 cups_option_t
*options
) /* I - Options */
724 DEBUG_printf(("cupsPrintFile(name=\"%s\", filename=\"%s\", title=\"%s\", num_options=%d, options=%p)", name
, filename
, title
, num_options
, (void *)options
));
726 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, 1, &filename
, title
,
727 num_options
, options
));
732 * 'cupsPrintFile2()' - Print a file to a printer or class on the specified
735 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
738 int /* O - Job ID or 0 on error */
740 http_t
*http
, /* I - Connection to server */
741 const char *name
, /* I - Destination name */
742 const char *filename
, /* I - File to print */
743 const char *title
, /* I - Title of job */
744 int num_options
, /* I - Number of options */
745 cups_option_t
*options
) /* I - Options */
747 DEBUG_printf(("cupsPrintFile2(http=%p, name=\"%s\", filename=\"%s\", title=\"%s\", num_options=%d, options=%p)", (void *)http
, name
, filename
, title
, num_options
, (void *)options
));
749 return (cupsPrintFiles2(http
, name
, 1, &filename
, title
, num_options
,
755 * 'cupsPrintFiles()' - Print one or more files to a printer or class on the
761 int /* O - Job ID or 0 on error */
763 const char *name
, /* I - Destination name */
764 int num_files
, /* I - Number of files */
765 const char **files
, /* I - File(s) to print */
766 const char *title
, /* I - Title of job */
767 int num_options
, /* I - Number of options */
768 cups_option_t
*options
) /* I - Options */
770 DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, files=%p, title=\"%s\", num_options=%d, options=%p)", name
, num_files
, (void *)files
, title
, num_options
, (void *)options
));
773 * Print the file(s)...
776 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, num_files
, files
, title
,
777 num_options
, options
));
782 * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the
785 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
788 int /* O - Job ID or 0 on error */
790 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
791 const char *name
, /* I - Destination name */
792 int num_files
, /* I - Number of files */
793 const char **files
, /* I - File(s) to print */
794 const char *title
, /* I - Title of job */
795 int num_options
, /* I - Number of options */
796 cups_option_t
*options
) /* I - Options */
798 int i
; /* Looping var */
799 int job_id
; /* New job ID */
800 const char *docname
; /* Basename of current filename */
801 const char *format
; /* Document format */
802 cups_file_t
*fp
; /* Current file */
803 char buffer
[8192]; /* Copy buffer */
804 ssize_t bytes
; /* Bytes in buffer */
805 http_status_t status
; /* Status of write */
806 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
807 ipp_status_t cancel_status
; /* Status code to preserve */
808 char *cancel_message
; /* Error message to preserve */
811 DEBUG_printf(("cupsPrintFiles2(http=%p, name=\"%s\", num_files=%d, files=%p, title=\"%s\", num_options=%d, options=%p)", (void *)http
, name
, num_files
, (void *)files
, title
, num_options
, (void *)options
));
814 * Range check input...
817 if (!name
|| num_files
< 1 || !files
)
819 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
825 * Create the print job...
828 if ((job_id
= cupsCreateJob(http
, name
, title
, num_options
, options
)) == 0)
832 * Send each of the files...
835 if (cupsGetOption("raw", num_options
, options
))
836 format
= CUPS_FORMAT_RAW
;
837 else if ((format
= cupsGetOption("document-format", num_options
,
839 format
= CUPS_FORMAT_AUTO
;
841 for (i
= 0; i
< num_files
; i
++)
844 * Start the next file...
847 if ((docname
= strrchr(files
[i
], '/')) != NULL
)
852 if ((fp
= cupsFileOpen(files
[i
], "rb")) == NULL
)
855 * Unable to open print file, cancel the job and return...
858 _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_ACCESS
, NULL
, 0);
862 status
= cupsStartDocument(http
, name
, job_id
, docname
, format
,
863 i
== (num_files
- 1));
865 while (status
== HTTP_STATUS_CONTINUE
&&
866 (bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
867 status
= cupsWriteRequestData(http
, buffer
, (size_t)bytes
);
871 if (status
!= HTTP_STATUS_CONTINUE
|| cupsFinishDocument(http
, name
) != IPP_STATUS_OK
)
874 * Unable to queue, cancel the job and return...
884 * If we get here, something happened while sending the print job so we need
885 * to cancel the job without setting the last error (since we need to preserve
886 * the current error...
891 cancel_status
= cg
->last_error
;
892 cancel_message
= cg
->last_status_message
?
893 _cupsStrRetain(cg
->last_status_message
) : NULL
;
895 cupsCancelJob2(http
, name
, job_id
, 0);
897 cg
->last_error
= cancel_status
;
898 cg
->last_status_message
= cancel_message
;
905 * 'cupsStartDocument()' - Add a document to a job created with cupsCreateJob().
907 * Use @link cupsWriteRequestData@ to write data for the document and
908 * @link cupsFinishDocument@ to finish the document and get the submission status.
910 * The MIME type constants @code CUPS_FORMAT_AUTO@, @code CUPS_FORMAT_PDF@,
911 * @code CUPS_FORMAT_POSTSCRIPT@, @code CUPS_FORMAT_RAW@, and
912 * @code CUPS_FORMAT_TEXT@ are provided for the "format" argument, although
913 * any supported MIME type string can be supplied.
915 * @since CUPS 1.4/macOS 10.6@ @exclude all@
918 http_status_t
/* O - HTTP status of request */
920 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
921 const char *name
, /* I - Destination name */
922 int job_id
, /* I - Job ID from @link cupsCreateJob@ */
923 const char *docname
, /* I - Name of document */
924 const char *format
, /* I - MIME type or @code CUPS_FORMAT_foo@ */
925 int last_document
) /* I - 1 for last document in job, 0 otherwise */
927 char resource
[1024], /* Resource for destinatio */
928 printer_uri
[1024]; /* Printer URI */
929 ipp_t
*request
; /* Send-Document request */
930 http_status_t status
; /* HTTP status */
934 * Create a Send-Document request...
937 if ((request
= ippNewRequest(IPP_OP_SEND_DOCUMENT
)) == NULL
)
939 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOMEM
), 0);
940 return (HTTP_STATUS_ERROR
);
943 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
), "ipp",
944 NULL
, "localhost", ippPort(), "/printers/%s", name
);
945 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
947 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
949 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", job_id
);
950 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
953 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
956 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
,
957 "document-format", NULL
, format
);
958 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", (char)last_document
);
961 * Send and delete the request, then return the status...
964 status
= cupsSendRequest(http
, request
, resource
, CUPS_LENGTH_VARIABLE
);
973 * 'cups_create_cb()' - Find the destination for printing.
976 static int /* O - 0 on match */
978 _cups_createdata_t
*data
, /* I - Data from cupsCreateJob call */
979 unsigned flags
, /* I - Enumeration flags */
980 cups_dest_t
*dest
) /* I - Destination */
982 DEBUG_printf(("2cups_create_cb(data=%p(%s), flags=%08x, dest=%p(%s))", (void *)data
, data
->name
, flags
, (void *)dest
, dest
->name
));
986 if (dest
->instance
|| strcasecmp(data
->name
, dest
->name
))
989 cupsCopyDest(dest
, 0, &data
->dest
);