2 * Printing utilities for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include "cups-private.h"
18 #if defined(WIN32) || defined(__EMX__)
22 #endif /* WIN32 || __EMX__ */
26 * 'cupsCancelJob()' - Cancel a print job on the default server.
28 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
29 * to cancel the current job on the named destination.
31 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
32 * the cause of any failure.
37 int /* O - 1 on success, 0 on failure */
38 cupsCancelJob(const char *name
, /* I - Name of printer or class */
39 int job_id
) /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
41 return (cupsCancelJob2(CUPS_HTTP_DEFAULT
, name
, job_id
, 0)
42 < IPP_STATUS_REDIRECTION_OTHER_SITE
);
47 * 'cupsCancelJob2()' - Cancel or purge a print job.
49 * Canceled jobs remain in the job history while purged jobs are removed
50 * from the job history.
52 * Pass @code CUPS_JOBID_ALL@ to cancel all jobs or @code CUPS_JOBID_CURRENT@
53 * to cancel the current job on the named destination.
55 * Use the @link cupsLastError@ and @link cupsLastErrorString@ functions to get
56 * the cause of any failure.
58 * @since CUPS 1.4/macOS 10.6@ @exclude all@
61 ipp_status_t
/* O - IPP status */
62 cupsCancelJob2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
63 const char *name
, /* I - Name of printer or class */
64 int job_id
, /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
65 int purge
) /* I - 1 to purge, 0 to cancel */
67 char uri
[HTTP_MAX_URI
]; /* Job/printer URI */
68 ipp_t
*request
; /* IPP request */
72 * Range check input...
75 if (job_id
< -1 || (!name
&& job_id
== 0))
77 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
82 * Connect to the default server as needed...
86 if ((http
= _cupsConnect()) == NULL
)
87 return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE
);
90 * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
94 * attributes-natural-language
95 * job-uri or printer-uri + job-id
96 * requesting-user-name
97 * [purge-job] or [purge-jobs]
100 request
= ippNewRequest(job_id
< 0 ? IPP_OP_PURGE_JOBS
: IPP_OP_CANCEL_JOB
);
104 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
105 "localhost", ippPort(), "/printers/%s", name
);
107 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
,
109 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
114 snprintf(uri
, sizeof(uri
), "ipp://localhost/jobs/%d", job_id
);
116 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri", NULL
, uri
);
119 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
122 if (purge
&& job_id
>= 0)
123 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-job", 1);
124 else if (!purge
&& job_id
< 0)
125 ippAddBoolean(request
, IPP_TAG_OPERATION
, "purge-jobs", 0);
131 ippDelete(cupsDoRequest(http
, request
, "/jobs/"));
133 return (cupsLastError());
138 * 'cupsCreateJob()' - Create an empty job for streaming.
140 * Use this function when you want to stream print data using the
141 * @link cupsStartDocument@, @link cupsWriteRequestData@, and
142 * @link cupsFinishDocument@ functions. If you have one or more files to
143 * print, use the @link cupsPrintFile2@ or @link cupsPrintFiles2@ function
146 * @since CUPS 1.4/macOS 10.6@ @exclude all@
149 int /* O - Job ID or 0 on error */
151 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
152 const char *name
, /* I - Destination name */
153 const char *title
, /* I - Title of job */
154 int num_options
, /* I - Number of options */
155 cups_option_t
*options
) /* I - Options */
157 int job_id
= 0; /* job-id value */
158 ipp_status_t status
; /* Create-Job status */
159 cups_dest_t
*dest
; /* Destination */
160 cups_dinfo_t
*info
; /* Destination information */
163 DEBUG_printf(("cupsCreateJob(http=%p, name=\"%s\", title=\"%s\", num_options=%d, options=%p)", (void *)http
, name
, title
, num_options
, (void *)options
));
166 * Range check input...
171 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
176 * Lookup the destination...
179 if ((dest
= cupsGetNamedDest(http
, name
, NULL
)) == NULL
)
181 DEBUG_puts("1cupsCreateJob: Destination not found.");
182 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOENT
), 0);
187 * Query dest information and create the job...
190 DEBUG_puts("1cupsCreateJob: Querying destination info.");
191 if ((info
= cupsCopyDestInfo(http
, dest
)) == NULL
)
193 DEBUG_puts("1cupsCreateJob: Query failed.");
194 cupsFreeDests(1, dest
);
198 status
= cupsCreateDestJob(http
, dest
, info
, &job_id
, title
, num_options
, options
);
199 DEBUG_printf(("1cupsCreateJob: cupsCreateDestJob returned %04x (%s)", status
, ippErrorString(status
)));
201 cupsFreeDestInfo(info
);
202 cupsFreeDests(1, dest
);
208 if (status
>= IPP_STATUS_REDIRECTION_OTHER_SITE
)
216 * 'cupsFinishDocument()' - Finish sending a document.
218 * The document must have been started using @link cupsStartDocument@.
220 * @since CUPS 1.4/macOS 10.6@ @exclude all@
223 ipp_status_t
/* O - Status of document submission */
224 cupsFinishDocument(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
225 const char *name
) /* I - Destination name */
227 char resource
[1024]; /* Printer resource */
230 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
232 ippDelete(cupsGetResponse(http
, resource
));
234 return (cupsLastError());
239 * 'cupsFreeJobs()' - Free memory used by job data.
243 cupsFreeJobs(int num_jobs
, /* I - Number of jobs */
244 cups_job_t
*jobs
) /* I - Jobs */
246 int i
; /* Looping var */
247 cups_job_t
*job
; /* Current job */
250 if (num_jobs
<= 0 || !jobs
)
253 for (i
= num_jobs
, job
= jobs
; i
> 0; i
--, job
++)
255 _cupsStrFree(job
->dest
);
256 _cupsStrFree(job
->user
);
257 _cupsStrFree(job
->format
);
258 _cupsStrFree(job
->title
);
266 * 'cupsGetClasses()' - Get a list of printer classes from the default server.
268 * This function is deprecated and no longer returns a list of printer
269 * classes - use @link cupsGetDests@ instead.
271 * @deprecated@ @exclude all@
274 int /* O - Number of classes */
275 cupsGetClasses(char ***classes
) /* O - Classes */
285 * 'cupsGetDefault()' - Get the default printer or class for the default server.
287 * This function returns the default printer or class as defined by
288 * the LPDEST or PRINTER environment variables. If these environment
289 * variables are not set, the server default destination is returned.
290 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
291 * functions to get the user-defined default printer, as this function does
292 * not support the lpoptions-defined default printer.
297 const char * /* O - Default printer or @code NULL@ */
301 * Return the default printer...
304 return (cupsGetDefault2(CUPS_HTTP_DEFAULT
));
309 * 'cupsGetDefault2()' - Get the default printer or class for the specified server.
311 * This function returns the default printer or class as defined by
312 * the LPDEST or PRINTER environment variables. If these environment
313 * variables are not set, the server default destination is returned.
314 * Applications should use the @link cupsGetDests@ and @link cupsGetDest@
315 * functions to get the user-defined default printer, as this function does
316 * not support the lpoptions-defined default printer.
318 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
321 const char * /* O - Default printer or @code NULL@ */
322 cupsGetDefault2(http_t
*http
) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
324 ipp_t
*request
, /* IPP Request */
325 *response
; /* IPP Response */
326 ipp_attribute_t
*attr
; /* Current attribute */
327 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
331 * See if we have a user default printer set...
334 if (_cupsUserDefault(cg
->def_printer
, sizeof(cg
->def_printer
)))
335 return (cg
->def_printer
);
338 * Connect to the server as needed...
342 if ((http
= _cupsConnect()) == NULL
)
346 * Build a CUPS_GET_DEFAULT request, which requires the following
350 * attributes-natural-language
353 request
= ippNewRequest(IPP_OP_CUPS_GET_DEFAULT
);
356 * Do the request and get back a response...
359 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
361 if ((attr
= ippFindAttribute(response
, "printer-name",
362 IPP_TAG_NAME
)) != NULL
)
364 strlcpy(cg
->def_printer
, attr
->values
[0].string
.text
,
365 sizeof(cg
->def_printer
));
367 return (cg
->def_printer
);
378 * 'cupsGetJobs()' - Get the jobs from the default server.
380 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
381 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
382 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
383 * jobs that are stopped, canceled, aborted, or completed.
388 int /* O - Number of jobs */
389 cupsGetJobs(cups_job_t
**jobs
, /* O - Job data */
390 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
391 int myjobs
, /* I - 0 = all users, 1 = mine */
392 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
398 return (cupsGetJobs2(CUPS_HTTP_DEFAULT
, jobs
, name
, myjobs
, whichjobs
));
404 * 'cupsGetJobs2()' - Get the jobs from the specified server.
406 * A "whichjobs" value of @code CUPS_WHICHJOBS_ALL@ returns all jobs regardless
407 * of state, while @code CUPS_WHICHJOBS_ACTIVE@ returns jobs that are
408 * pending, processing, or held and @code CUPS_WHICHJOBS_COMPLETED@ returns
409 * jobs that are stopped, canceled, aborted, or completed.
411 * @since CUPS 1.1.21/macOS 10.4@
414 int /* O - Number of jobs */
415 cupsGetJobs2(http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
416 cups_job_t
**jobs
, /* O - Job data */
417 const char *name
, /* I - @code NULL@ = all destinations, otherwise show jobs for named destination */
418 int myjobs
, /* I - 0 = all users, 1 = mine */
419 int whichjobs
) /* I - @code CUPS_WHICHJOBS_ALL@, @code CUPS_WHICHJOBS_ACTIVE@, or @code CUPS_WHICHJOBS_COMPLETED@ */
421 int n
; /* Number of jobs */
422 ipp_t
*request
, /* IPP Request */
423 *response
; /* IPP Response */
424 ipp_attribute_t
*attr
; /* Current attribute */
425 cups_job_t
*temp
; /* Temporary pointer */
427 priority
, /* job-priority */
428 size
; /* job-k-octets */
429 ipp_jstate_t state
; /* job-state */
430 time_t completed_time
, /* time-at-completed */
431 creation_time
, /* time-at-creation */
432 processing_time
; /* time-at-processing */
433 const char *dest
, /* job-printer-uri */
434 *format
, /* document-format */
435 *title
, /* job-name */
436 *user
; /* job-originating-user-name */
437 char uri
[HTTP_MAX_URI
]; /* URI for jobs */
438 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
439 static const char * const attrs
[] = /* Requested attributes */
445 "job-originating-user-name",
456 * Range check input...
461 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
467 * Get the right URI...
472 if (httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
473 "localhost", 0, "/printers/%s",
474 name
) < HTTP_URI_STATUS_OK
)
476 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
477 _("Unable to create printer-uri"), 1);
483 strlcpy(uri
, "ipp://localhost/", sizeof(uri
));
486 if ((http
= _cupsConnect()) == NULL
)
490 * Build an IPP_GET_JOBS request, which requires the following
494 * attributes-natural-language
496 * requesting-user-name
499 * requested-attributes
502 request
= ippNewRequest(IPP_OP_GET_JOBS
);
504 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
505 "printer-uri", NULL
, uri
);
507 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
508 "requesting-user-name", NULL
, cupsUser());
511 ippAddBoolean(request
, IPP_TAG_OPERATION
, "my-jobs", 1);
513 if (whichjobs
== CUPS_WHICHJOBS_COMPLETED
)
514 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
515 "which-jobs", NULL
, "completed");
516 else if (whichjobs
== CUPS_WHICHJOBS_ALL
)
517 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
518 "which-jobs", NULL
, "all");
520 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
521 "requested-attributes", sizeof(attrs
) / sizeof(attrs
[0]),
525 * Do the request and get back a response...
531 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
533 for (attr
= response
->attrs
; attr
; attr
= attr
->next
)
536 * Skip leading attributes until we hit a job...
539 while (attr
&& attr
->group_tag
!= IPP_TAG_JOB
)
546 * Pull the needed attributes from this job...
552 state
= IPP_JSTATE_PENDING
;
555 format
= "application/octet-stream";
561 while (attr
&& attr
->group_tag
== IPP_TAG_JOB
)
563 if (!strcmp(attr
->name
, "job-id") &&
564 attr
->value_tag
== IPP_TAG_INTEGER
)
565 id
= attr
->values
[0].integer
;
566 else if (!strcmp(attr
->name
, "job-state") &&
567 attr
->value_tag
== IPP_TAG_ENUM
)
568 state
= (ipp_jstate_t
)attr
->values
[0].integer
;
569 else if (!strcmp(attr
->name
, "job-priority") &&
570 attr
->value_tag
== IPP_TAG_INTEGER
)
571 priority
= attr
->values
[0].integer
;
572 else if (!strcmp(attr
->name
, "job-k-octets") &&
573 attr
->value_tag
== IPP_TAG_INTEGER
)
574 size
= attr
->values
[0].integer
;
575 else if (!strcmp(attr
->name
, "time-at-completed") &&
576 attr
->value_tag
== IPP_TAG_INTEGER
)
577 completed_time
= attr
->values
[0].integer
;
578 else if (!strcmp(attr
->name
, "time-at-creation") &&
579 attr
->value_tag
== IPP_TAG_INTEGER
)
580 creation_time
= attr
->values
[0].integer
;
581 else if (!strcmp(attr
->name
, "time-at-processing") &&
582 attr
->value_tag
== IPP_TAG_INTEGER
)
583 processing_time
= attr
->values
[0].integer
;
584 else if (!strcmp(attr
->name
, "job-printer-uri") &&
585 attr
->value_tag
== IPP_TAG_URI
)
587 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
590 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
591 attr
->value_tag
== IPP_TAG_NAME
)
592 user
= attr
->values
[0].string
.text
;
593 else if (!strcmp(attr
->name
, "document-format") &&
594 attr
->value_tag
== IPP_TAG_MIMETYPE
)
595 format
= attr
->values
[0].string
.text
;
596 else if (!strcmp(attr
->name
, "job-name") &&
597 (attr
->value_tag
== IPP_TAG_TEXT
||
598 attr
->value_tag
== IPP_TAG_NAME
))
599 title
= attr
->values
[0].string
.text
;
605 * See if we have everything needed...
617 * Allocate memory for the job...
621 temp
= malloc(sizeof(cups_job_t
));
623 temp
= realloc(*jobs
, sizeof(cups_job_t
) * (size_t)(n
+ 1));
631 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, NULL
, 0);
633 cupsFreeJobs(n
, *jobs
);
646 * Copy the data over...
649 temp
->dest
= _cupsStrAlloc(dest
);
650 temp
->user
= _cupsStrAlloc(user
);
651 temp
->format
= _cupsStrAlloc(format
);
652 temp
->title
= _cupsStrAlloc(title
);
654 temp
->priority
= priority
;
657 temp
->completed_time
= completed_time
;
658 temp
->creation_time
= creation_time
;
659 temp
->processing_time
= processing_time
;
668 if (n
== 0 && cg
->last_error
>= IPP_STATUS_ERROR_BAD_REQUEST
)
676 * 'cupsGetPrinters()' - Get a list of printers from the default server.
678 * This function is deprecated and no longer returns a list of printers - use
679 * @link cupsGetDests@ instead.
681 * @deprecated@ @exclude all@
684 int /* O - Number of printers */
685 cupsGetPrinters(char ***printers
) /* O - Printers */
695 * 'cupsPrintFile()' - Print a file to a printer or class on the default server.
700 int /* O - Job ID or 0 on error */
701 cupsPrintFile(const char *name
, /* I - Destination name */
702 const char *filename
, /* I - File to print */
703 const char *title
, /* I - Title of job */
704 int num_options
,/* I - Number of options */
705 cups_option_t
*options
) /* I - Options */
707 DEBUG_printf(("cupsPrintFile(name=\"%s\", filename=\"%s\", title=\"%s\", num_options=%d, options=%p)", name
, filename
, title
, num_options
, (void *)options
));
709 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, 1, &filename
, title
,
710 num_options
, options
));
715 * 'cupsPrintFile2()' - Print a file to a printer or class on the specified
718 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
721 int /* O - Job ID or 0 on error */
723 http_t
*http
, /* I - Connection to server */
724 const char *name
, /* I - Destination name */
725 const char *filename
, /* I - File to print */
726 const char *title
, /* I - Title of job */
727 int num_options
, /* I - Number of options */
728 cups_option_t
*options
) /* I - Options */
730 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
));
732 return (cupsPrintFiles2(http
, name
, 1, &filename
, title
, num_options
,
738 * 'cupsPrintFiles()' - Print one or more files to a printer or class on the
744 int /* O - Job ID or 0 on error */
746 const char *name
, /* I - Destination name */
747 int num_files
, /* I - Number of files */
748 const char **files
, /* I - File(s) to print */
749 const char *title
, /* I - Title of job */
750 int num_options
, /* I - Number of options */
751 cups_option_t
*options
) /* I - Options */
753 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
));
756 * Print the file(s)...
759 return (cupsPrintFiles2(CUPS_HTTP_DEFAULT
, name
, num_files
, files
, title
,
760 num_options
, options
));
765 * 'cupsPrintFiles2()' - Print one or more files to a printer or class on the
768 * @since CUPS 1.1.21/macOS 10.4@ @exclude all@
771 int /* O - Job ID or 0 on error */
773 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
774 const char *name
, /* I - Destination name */
775 int num_files
, /* I - Number of files */
776 const char **files
, /* I - File(s) to print */
777 const char *title
, /* I - Title of job */
778 int num_options
, /* I - Number of options */
779 cups_option_t
*options
) /* I - Options */
781 int i
; /* Looping var */
782 int job_id
; /* New job ID */
783 const char *docname
; /* Basename of current filename */
784 const char *format
; /* Document format */
785 cups_file_t
*fp
; /* Current file */
786 char buffer
[8192]; /* Copy buffer */
787 ssize_t bytes
; /* Bytes in buffer */
788 http_status_t status
; /* Status of write */
789 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
790 ipp_status_t cancel_status
; /* Status code to preserve */
791 char *cancel_message
; /* Error message to preserve */
794 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
));
797 * Range check input...
800 if (!name
|| num_files
< 1 || !files
)
802 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(EINVAL
), 0);
808 * Create the print job...
811 if ((job_id
= cupsCreateJob(http
, name
, title
, num_options
, options
)) == 0)
815 * Send each of the files...
818 if (cupsGetOption("raw", num_options
, options
))
819 format
= CUPS_FORMAT_RAW
;
820 else if ((format
= cupsGetOption("document-format", num_options
,
822 format
= CUPS_FORMAT_AUTO
;
824 for (i
= 0; i
< num_files
; i
++)
827 * Start the next file...
830 if ((docname
= strrchr(files
[i
], '/')) != NULL
)
835 if ((fp
= cupsFileOpen(files
[i
], "rb")) == NULL
)
838 * Unable to open print file, cancel the job and return...
841 _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_ACCESS
, NULL
, 0);
845 status
= cupsStartDocument(http
, name
, job_id
, docname
, format
,
846 i
== (num_files
- 1));
848 while (status
== HTTP_STATUS_CONTINUE
&&
849 (bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
850 status
= cupsWriteRequestData(http
, buffer
, (size_t)bytes
);
854 if (status
!= HTTP_STATUS_CONTINUE
|| cupsFinishDocument(http
, name
) != IPP_STATUS_OK
)
857 * Unable to queue, cancel the job and return...
867 * If we get here, something happened while sending the print job so we need
868 * to cancel the job without setting the last error (since we need to preserve
869 * the current error...
874 cancel_status
= cg
->last_error
;
875 cancel_message
= cg
->last_status_message
?
876 _cupsStrRetain(cg
->last_status_message
) : NULL
;
878 cupsCancelJob2(http
, name
, job_id
, 0);
880 cg
->last_error
= cancel_status
;
881 cg
->last_status_message
= cancel_message
;
888 * 'cupsStartDocument()' - Add a document to a job created with cupsCreateJob().
890 * Use @link cupsWriteRequestData@ to write data for the document and
891 * @link cupsFinishDocument@ to finish the document and get the submission status.
893 * The MIME type constants @code CUPS_FORMAT_AUTO@, @code CUPS_FORMAT_PDF@,
894 * @code CUPS_FORMAT_POSTSCRIPT@, @code CUPS_FORMAT_RAW@, and
895 * @code CUPS_FORMAT_TEXT@ are provided for the "format" argument, although
896 * any supported MIME type string can be supplied.
898 * @since CUPS 1.4/macOS 10.6@ @exclude all@
901 http_status_t
/* O - HTTP status of request */
903 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
904 const char *name
, /* I - Destination name */
905 int job_id
, /* I - Job ID from @link cupsCreateJob@ */
906 const char *docname
, /* I - Name of document */
907 const char *format
, /* I - MIME type or @code CUPS_FORMAT_foo@ */
908 int last_document
) /* I - 1 for last document in job, 0 otherwise */
910 char resource
[1024], /* Resource for destinatio */
911 printer_uri
[1024]; /* Printer URI */
912 ipp_t
*request
; /* Send-Document request */
913 http_status_t status
; /* HTTP status */
917 * Create a Send-Document request...
920 if ((request
= ippNewRequest(IPP_OP_SEND_DOCUMENT
)) == NULL
)
922 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, strerror(ENOMEM
), 0);
923 return (HTTP_STATUS_ERROR
);
926 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
), "ipp",
927 NULL
, "localhost", ippPort(), "/printers/%s", name
);
928 snprintf(resource
, sizeof(resource
), "/printers/%s", name
);
930 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
932 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", job_id
);
933 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
936 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "document-name",
939 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_MIMETYPE
,
940 "document-format", NULL
, format
);
941 ippAddBoolean(request
, IPP_TAG_OPERATION
, "last-document", (char)last_document
);
944 * Send and delete the request, then return the status...
947 status
= cupsSendRequest(http
, request
, resource
, CUPS_LENGTH_VARIABLE
);