1 Index: branch-1.5/backend/ipp.c
2 ===================================================================
3 --- branch-1.5/backend/ipp.c (.../branch-1.5/backend/ipp.c) (revision 10232)
4 +++ branch-1.4/backend/ipp.c (.../branch-1.4/backend/ipp.c) (revision 10232)
9 - * IPP backend for CUPS.
10 + * IPP backend for the Common UNIX Printing System (CUPS).
12 - * Copyright 2007-2011 by Apple Inc.
13 + * Copyright 2007-2010 by Apple Inc.
14 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
16 * These coded instructions, statements, and computer programs are the
19 * main() - Send a file to the printer or server.
20 * cancel_job() - Cancel a print job.
21 - * check_printer_state() - Check the printer state.
22 - * compress_files() - Compress print files.
23 - * monitor_printer() - Monitor the printer state.
24 - * new_request() - Create a new print creation or validation request.
25 + * check_printer_state() - Check the printer state...
26 + * compress_files() - Compress print files...
27 * password_cb() - Disable the password prompt for
28 * cupsDoFileRequest().
29 * report_attr() - Report an IPP attribute value.
30 * report_printer_state() - Report the printer state.
31 - * run_as_user() - Run the IPP backend as the printing user.
32 - * timeout_cb() - Handle HTTP timeouts.
33 + * run_pictwps_filter() - Convert PICT files to PostScript when printing
35 * sigterm_handler() - Handle 'terminate' signals that stop the backend.
39 * Include necessary headers.
42 +#include <cups/http-private.h>
43 #include "backend-private.h"
44 -#include <cups/array-private.h>
45 #include <sys/types.h>
48 -#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
49 -# include <xpc/xpc.h>
50 -# define kPMPrintUIToolAgent "com.apple.printuitool.agent"
51 -# define kPMStartJob 100
52 -# define kPMWaitForJob 101
53 -extern void xpc_connection_set_target_uid(xpc_connection_t connection,
55 -#endif /* HAVE_GSSAPI && HAVE_XPC */
62 -typedef struct _cups_monitor_s /**** Monitoring data ****/
64 - const char *uri, /* Printer URI */
65 - *hostname, /* Hostname */
66 - *user, /* Username */
67 - *resource; /* Resource path */
68 - int port, /* Port number */
69 - version, /* IPP version */
70 - job_id; /* Job ID for submitted job */
71 - http_encryption_t encryption; /* Use encryption? */
72 - ipp_jstate_t job_state; /* Current job state */
73 - ipp_pstate_t printer_state; /* Current printer state */
81 -static const char *auth_info_required;
82 +static char *password = NULL; /* Password for device URI */
83 +static int password_tries = 0; /* Password tries */
84 +static const char *auth_info_required = "none";
85 /* New auth-info-required value */
86 -#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
87 -static int child_pid = 0; /* Child process ID */
88 -#endif /* HAVE_GSSAPI && HAVE_XPC */
89 -static const char * const jattrs[] = /* Job attributes we want */
91 - "job-impressions-completed",
92 - "job-media-sheets-completed",
96 -static int job_canceled = 0;
97 - /* Job cancelled? */
98 -static char *password = NULL;
99 - /* Password for device URI */
100 -static int password_tries = 0;
101 - /* Password tries */
102 -static const char * const pattrs[] = /* Printer attributes we want */
104 - "copies-supported",
106 - "document-format-supported",
108 - "marker-high-levels",
110 - "marker-low-levels",
114 - "media-col-supported",
115 - "multiple-document-handling-supported",
116 - "operations-supported",
118 - "printer-alert-description",
119 - "printer-is-accepting-jobs",
121 - "printer-state-message",
122 - "printer-state-reasons"
124 -static const char * const remote_job_states[] =
125 -{ /* Remote job state keywords */
126 - "+cups-remote-pending",
127 - "+cups-remote-pending-held",
128 - "+cups-remote-processing",
129 - "+cups-remote-stopped",
130 - "+cups-remote-canceled",
131 - "+cups-remote-aborted",
132 - "+cups-remote-completed"
134 -static _cups_mutex_t report_mutex = _CUPS_MUTEX_INITIALIZER;
135 - /* Mutex to control access */
136 -static int num_attr_cache = 0;
137 - /* Number of cached attributes */
138 -static cups_option_t *attr_cache = NULL;
139 - /* Cached attributes */
140 -static cups_array_t *state_reasons; /* Array of printe-state-reasons keywords */
141 -static char tmpfilename[1024] = "";
142 - /* Temporary spool file name */
144 +static char pstmpname[1024] = ""; /* Temporary PostScript file name */
145 +#endif /* __APPLE__ */
146 +static char tmpfilename[1024] = ""; /* Temporary spool file name */
147 +static int job_cancelled = 0; /* Job cancelled? */
154 -static void cancel_job(http_t *http, const char *uri, int id,
155 - const char *resource, const char *user,
157 -static ipp_pstate_t check_printer_state(http_t *http, const char *uri,
158 - const char *resource,
159 - const char *user, int version);
160 +static void cancel_job(http_t *http, const char *uri, int id,
161 + const char *resource, const char *user, int version);
162 +static void check_printer_state(http_t *http, const char *uri,
163 + const char *resource, const char *user,
164 + int version, int job_id);
166 -static void compress_files(int num_files, char **files);
167 +static void compress_files(int num_files, char **files);
168 #endif /* HAVE_LIBZ */
169 -static void *monitor_printer(_cups_monitor_t *monitor);
170 -static ipp_t *new_request(ipp_op_t op, int version, const char *uri,
171 - const char *user, const char *title,
172 - int num_options, cups_option_t *options,
173 - const char *compression, int copies,
174 - const char *format, _ppd_cache_t *pc,
175 - ipp_attribute_t *media_col_sup,
176 - ipp_attribute_t *doc_handling_sup);
177 -static const char *password_cb(const char *);
178 -static void report_attr(ipp_attribute_t *attr);
179 -static void report_printer_state(ipp_t *ipp);
180 -#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
181 -static int run_as_user(int argc, char *argv[], uid_t uid,
182 - const char *device_uri, int fd);
183 -#endif /* HAVE_GSSAPI && HAVE_XPC */
184 -static void sigterm_handler(int sig);
185 -static int timeout_cb(http_t *http, void *user_data);
186 -static void update_reasons(ipp_attribute_t *attr, const char *s);
187 +static const char *password_cb(const char *);
188 +static void report_attr(ipp_attribute_t *attr);
189 +static int report_printer_state(ipp_t *ipp, int job_id);
192 +static int run_pictwps_filter(char **argv, const char *filename);
193 +#endif /* __APPLE__ */
194 +static void sigterm_handler(int sig);
198 * 'main()' - Send a file to the printer or server.
200 @@ -193,60 +102,65 @@
201 *name, /* Name of option */
202 *value, /* Value of option */
203 sep; /* Separator character */
204 - http_addrlist_t *addrlist; /* Address of printer */
205 int snmp_fd, /* SNMP socket */
206 start_count, /* Page count via SNMP at start */
207 page_count, /* Page count via SNMP */
208 have_supplies; /* Printer supports supply levels? */
209 int num_files; /* Number of files to print */
210 char **files, /* Files to print */
211 - *compatfile = NULL; /* Compatibility filename */
212 - off_t compatsize = 0; /* Size of compatibility file */
213 + *filename; /* Pointer to single filename */
214 int port; /* Port number (not used) */
215 - char portname[255]; /* Port name */
216 char uri[HTTP_MAX_URI]; /* Updated URI without user/pass */
217 - http_status_t http_status; /* Status of HTTP request */
218 ipp_status_t ipp_status; /* Status of IPP request */
219 http_t *http; /* HTTP connection */
220 ipp_t *request, /* IPP request */
221 *response, /* IPP response */
222 *supported; /* get-printer-attributes response */
223 time_t start_time; /* Time of first connect */
224 + int recoverable; /* Recoverable error shown? */
225 int contimeout; /* Connection timeout */
226 - int delay, /* Delay for retries */
227 - prev_delay; /* Previous delay */
228 - const char *compression; /* Compression mode */
229 - int waitjob, /* Wait for job complete? */
230 + int delay; /* Delay for retries... */
231 + int compression, /* Do compression of the job data? */
232 + waitjob, /* Wait for job complete? */
233 waitprinter; /* Wait for printer ready? */
234 - _cups_monitor_t monitor; /* Monitoring data */
235 ipp_attribute_t *job_id_attr; /* job-id attribute */
236 int job_id; /* job-id value */
237 ipp_attribute_t *job_sheets; /* job-media-sheets-completed */
238 ipp_attribute_t *job_state; /* job-state */
239 ipp_attribute_t *copies_sup; /* copies-supported */
240 - ipp_attribute_t *cups_version; /* cups-version */
241 ipp_attribute_t *format_sup; /* document-format-supported */
242 - ipp_attribute_t *media_col_sup; /* media-col-supported */
243 - ipp_attribute_t *operations_sup; /* operations-supported */
244 - ipp_attribute_t *doc_handling_sup; /* multiple-document-handling-supported */
245 ipp_attribute_t *printer_state; /* printer-state attribute */
246 ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */
247 - int validate_job; /* Does printer support Validate-Job? */
248 int copies, /* Number of copies for job */
249 copies_remaining; /* Number of copies remaining */
250 const char *content_type, /* CONTENT_TYPE environment variable */
251 - *final_content_type, /* FINAL_CONTENT_TYPE environment var */
252 - *document_format; /* document-format value */
253 - int fd; /* File descriptor */
254 - off_t bytes = 0; /* Bytes copied */
255 - char buffer[16384]; /* Copy buffer */
256 + *final_content_type; /* FINAL_CONTENT_TYPE environment var */
257 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
258 struct sigaction action; /* Actions for POSIX signals */
259 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
260 int version; /* IPP version */
261 - ppd_file_t *ppd; /* PPD file */
262 - _ppd_cache_t *pc; /* PPD cache and mapping data */
263 - fd_set input; /* Input set for select() */
264 + static const char * const pattrs[] =
265 + { /* Printer attributes we want */
266 + "com.apple.print.recoverable-message",
267 + "copies-supported",
268 + "document-format-supported",
270 + "marker-high-levels",
272 + "marker-low-levels",
276 + "printer-is-accepting-jobs",
278 + "printer-state-message",
279 + "printer-state-reasons",
281 + static const char * const jattrs[] =
282 + { /* Job attributes we want */
283 + "job-media-sheets-completed",
289 @@ -297,75 +211,12 @@
292 _cupsLangPrintf(stderr,
293 - _("Usage: %s job-id user title copies options [file]"),
294 + _("Usage: %s job-id user title copies options [file]\n"),
296 return (CUPS_BACKEND_STOP);
300 - * Get the device URI...
303 - while ((device_uri = cupsBackendDeviceURI(argv)) == NULL)
305 - _cupsLangPrintFilter(stderr, "INFO", _("Unable to locate printer."));
308 - if (getenv("CLASS") != NULL)
309 - return (CUPS_BACKEND_FAILED);
312 - if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) == NULL)
313 - auth_info_required = "none";
315 - state_reasons = _cupsArrayNewStrings(getenv("PRINTER_STATE_REASONS"));
319 - * For Kerberos, become the printing user (if we can) to get the credentials
323 - if (!getuid() && (value = getenv("AUTH_UID")) != NULL)
325 - uid_t uid = (uid_t)atoi(value);
332 - return (run_as_user(argc, argv, uid, device_uri, 0));
335 - int status = 0; /* Exit status */
337 - for (i = 6; i < argc && !status && !job_canceled; i ++)
339 - if ((fd = open(argv[i], O_RDONLY)) >= 0)
341 - status = run_as_user(argc, argv, uid, device_uri, fd);
346 - _cupsLangPrintError("ERROR", _("Unable to open print file"));
347 - status = CUPS_BACKEND_FAILED;
355 -# else /* No XPC, just try to run as the user ID */
358 -# endif /* HAVE_XPC */
360 -#endif /* HAVE_GSSAPI */
363 * Get the (final) content type...
367 * Extract the hostname and printer name from the URI...
370 + if ((device_uri = cupsBackendDeviceURI(argv)) == NULL)
371 + return (CUPS_BACKEND_FAILED);
373 httpSeparateURI(HTTP_URI_CODING_ALL, device_uri, scheme, sizeof(scheme),
374 username, sizeof(username), hostname, sizeof(hostname), &port,
375 resource, sizeof(resource));
377 * See if there are any options...
380 - compression = NULL;
386 contimeout = 7 * 24 * 60 * 60;
387 @@ -454,48 +308,48 @@
388 * Process the option...
391 - if (!_cups_strcasecmp(name, "waitjob"))
392 + if (!strcasecmp(name, "waitjob"))
395 * Wait for job completion?
398 - waitjob = !_cups_strcasecmp(value, "on") ||
399 - !_cups_strcasecmp(value, "yes") ||
400 - !_cups_strcasecmp(value, "true");
401 + waitjob = !strcasecmp(value, "on") ||
402 + !strcasecmp(value, "yes") ||
403 + !strcasecmp(value, "true");
405 - else if (!_cups_strcasecmp(name, "waitprinter"))
406 + else if (!strcasecmp(name, "waitprinter"))
409 * Wait for printer idle?
412 - waitprinter = !_cups_strcasecmp(value, "on") ||
413 - !_cups_strcasecmp(value, "yes") ||
414 - !_cups_strcasecmp(value, "true");
415 + waitprinter = !strcasecmp(value, "on") ||
416 + !strcasecmp(value, "yes") ||
417 + !strcasecmp(value, "true");
419 - else if (!_cups_strcasecmp(name, "encryption"))
420 + else if (!strcasecmp(name, "encryption"))
423 * Enable/disable encryption?
426 - if (!_cups_strcasecmp(value, "always"))
427 + if (!strcasecmp(value, "always"))
428 cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
429 - else if (!_cups_strcasecmp(value, "required"))
430 + else if (!strcasecmp(value, "required"))
431 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
432 - else if (!_cups_strcasecmp(value, "never"))
433 + else if (!strcasecmp(value, "never"))
434 cupsSetEncryption(HTTP_ENCRYPT_NEVER);
435 - else if (!_cups_strcasecmp(value, "ifrequested"))
436 + else if (!strcasecmp(value, "ifrequested"))
437 cupsSetEncryption(HTTP_ENCRYPT_IF_REQUESTED);
440 - _cupsLangPrintFilter(stderr, "ERROR",
441 - _("Unknown encryption option value: \"%s\"."),
443 + _cupsLangPrintf(stderr,
444 + _("ERROR: Unknown encryption option value \"%s\"!\n"),
448 - else if (!_cups_strcasecmp(name, "version"))
449 + else if (!strcasecmp(name, "version"))
451 if (!strcmp(value, "1.0"))
453 @@ -505,24 +359,23 @@
455 else if (!strcmp(value, "2.1"))
457 - else if (!strcmp(value, "2.2"))
461 - _cupsLangPrintFilter(stderr, "ERROR",
462 - _("Unknown version option value: \"%s\"."),
464 + _cupsLangPrintf(stderr,
465 + _("ERROR: Unknown version option value \"%s\"!\n"),
470 - else if (!_cups_strcasecmp(name, "compression"))
471 + else if (!strcasecmp(name, "compression"))
473 - if (!_cups_strcasecmp(value, "true") || !_cups_strcasecmp(value, "yes") ||
474 - !_cups_strcasecmp(value, "on") || !_cups_strcasecmp(value, "gzip"))
475 - compression = "gzip";
476 + compression = !strcasecmp(value, "true") ||
477 + !strcasecmp(value, "yes") ||
478 + !strcasecmp(value, "on") ||
479 + !strcasecmp(value, "gzip");
481 #endif /* HAVE_LIBZ */
482 - else if (!_cups_strcasecmp(name, "contimeout"))
483 + else if (!strcasecmp(name, "contimeout"))
486 * Set the connection timeout...
491 - _cupsLangPrintFilter(stderr, "ERROR",
492 - _("Unknown option \"%s\" with value \"%s\"."),
494 + _cupsLangPrintf(stderr,
495 + _("ERROR: Unknown option \"%s\" with value \"%s\"!\n"),
500 @@ -552,13 +405,64 @@
506 - send_options = !_cups_strcasecmp(final_content_type, "application/pdf") ||
507 - !_cups_strcasecmp(final_content_type, "application/vnd.cups-pdf") ||
508 - !_cups_strncasecmp(final_content_type, "image/", 6);
510 + * Copy stdin to a temporary file...
513 - fputs("DEBUG: Sending stdin for job...\n", stderr);
514 + int fd; /* File descriptor */
515 + http_addrlist_t *addrlist; /* Address list */
516 + off_t tbytes; /* Total bytes copied */
519 + fputs("STATE: +connecting-to-device\n", stderr);
520 + fprintf(stderr, "DEBUG: Looking up \"%s\"...\n", hostname);
522 + if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, "1")) == NULL)
524 + _cupsLangPrintf(stderr, _("ERROR: Unable to locate printer \'%s\'!\n"),
526 + return (CUPS_BACKEND_STOP);
529 + snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family);
531 + if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
533 + _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
534 + return (CUPS_BACKEND_FAILED);
537 + _cupsLangPuts(stderr, _("INFO: Copying print data...\n"));
539 + tbytes = backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0,
540 + backendNetworkSideCB);
543 + _cupsSNMPClose(snmp_fd);
545 + httpAddrFreeList(addrlist);
550 + * Don't try printing files less than 2 bytes...
555 + _cupsLangPuts(stderr, _("ERROR: Empty print file!\n"));
556 + unlink(tmpfilename);
557 + return (CUPS_BACKEND_FAILED);
561 + * Point to the single file from stdin...
564 + filename = tmpfilename;
571 @@ -574,10 +478,10 @@
573 compress_files(num_files, files);
574 #endif /* HAVE_LIBZ */
576 - fprintf(stderr, "DEBUG: %d files to send in job...\n", num_files);
579 + fprintf(stderr, "DEBUG: %d files to send in job...\n", num_files);
582 * Set the authentication info, if any...
586 cupsSetUser(username);
589 + else if (!getuid())
592 * Try loading authentication information from the environment.
593 @@ -610,75 +514,23 @@
597 - * Try finding the remote server...
598 + * Try connecting to the remote server...
601 - start_time = time(NULL);
604 + start_time = time(NULL);
606 - sprintf(portname, "%d", port);
607 + fputs("STATE: +connecting-to-device\n", stderr);
609 - update_reasons(NULL, "+connecting-to-device");
610 - fprintf(stderr, "DEBUG: Looking up \"%s\"...\n", hostname);
612 - while ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
614 - _cupsLangPrintFilter(stderr, "INFO",
615 - _("Unable to locate printer \"%s\"."), hostname);
618 - if (getenv("CLASS") != NULL)
620 - update_reasons(NULL, "-connecting-to-device");
621 - return (CUPS_BACKEND_STOP);
625 - http = _httpCreate(hostname, port, addrlist, cupsEncryption(), AF_UNSPEC);
626 - httpSetTimeout(http, 30.0, timeout_cb, NULL);
629 - * See if the printer supports SNMP...
632 - if ((snmp_fd = _cupsSNMPOpen(addrlist->addr.addr.sa_family)) >= 0)
634 - have_supplies = !backendSNMPSupplies(snmp_fd, &(addrlist->addr),
635 - &start_count, NULL);
638 - have_supplies = start_count = 0;
641 - * Wait for data from the filter...
644 - if (num_files == 0)
646 - if (!backendWaitLoop(snmp_fd, &(addrlist->addr), 0, backendNetworkSideCB))
647 - return (CUPS_BACKEND_OK);
648 - else if ((bytes = read(0, buffer, sizeof(buffer))) <= 0)
649 - return (CUPS_BACKEND_OK);
653 - * Try connecting to the remote server...
656 - delay = _cupsNextDelay(0, &prev_delay);
660 fprintf(stderr, "DEBUG: Connecting to %s:%d\n", hostname, port);
661 - _cupsLangPrintFilter(stderr, "INFO", _("Connecting to printer."));
662 + _cupsLangPuts(stderr, _("INFO: Connecting to printer...\n"));
664 - if (httpReconnect(http))
665 + if ((http = httpConnectEncrypt(hostname, port, cupsEncryption())) == NULL)
667 - int error = errno; /* Connection error */
669 - if (http->status == HTTP_PKI_ERROR)
670 - update_reasons(NULL, "+cups-certificate-error");
676 if (getenv("CLASS") != NULL)
677 @@ -690,85 +542,100 @@
678 * available printer in the class.
681 - _cupsLangPrintFilter(stderr, "INFO",
682 - _("Unable to contact printer, queuing on next "
683 - "printer in class."));
684 + _cupsLangPuts(stderr,
685 + _("INFO: Unable to contact printer, queuing on next "
686 + "printer in class...\n"));
688 + if (tmpfilename[0])
689 + unlink(tmpfilename);
692 * Sleep 5 seconds to keep the job from requeuing too rapidly...
697 - update_reasons(NULL, "-connecting-to-device");
699 return (CUPS_BACKEND_FAILED);
702 - fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(errno));
704 if (errno == ECONNREFUSED || errno == EHOSTDOWN ||
705 errno == EHOSTUNREACH)
707 if (contimeout && (time(NULL) - start_time) > contimeout)
709 - _cupsLangPrintFilter(stderr, "ERROR",
710 - _("The printer is not responding."));
711 - update_reasons(NULL, "-connecting-to-device");
712 + _cupsLangPuts(stderr, _("ERROR: Printer not responding!\n"));
713 return (CUPS_BACKEND_FAILED);
719 - _cupsLangPrintFilter(stderr, "WARNING",
720 - _("The printer may not exist or "
721 - "is unavailable at this time."));
725 - case EHOSTUNREACH :
726 - _cupsLangPrintFilter(stderr, "WARNING",
727 - _("The printer is unreachable at this "
730 + _cupsLangPrintf(stderr,
731 + _("WARNING: recoverable: Network host \'%s\' is busy; "
732 + "will retry in %d seconds...\n"),
735 - case ECONNREFUSED :
737 - _cupsLangPrintFilter(stderr, "WARNING",
738 - _("The printer is busy."));
744 - delay = _cupsNextDelay(delay, &prev_delay);
750 + _cupsLangPrintf(stderr, _("ERROR: Unable to locate printer \'%s\'!\n"),
752 + return (CUPS_BACKEND_STOP);
756 - _cupsLangPrintFilter(stderr, "ERROR",
757 - _("The printer is not responding."));
760 + fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(errno));
761 + _cupsLangPuts(stderr,
762 + _("ERROR: recoverable: Unable to connect to printer; will "
763 + "retry in 30 seconds...\n"));
772 - update_reasons(NULL, "-cups-certificate-error");
774 - while (http->fd < 0);
775 + while (http == NULL);
777 - if (job_canceled || !http)
778 + if (job_cancelled || !http)
780 + if (tmpfilename[0])
781 + unlink(tmpfilename);
783 return (CUPS_BACKEND_FAILED);
786 - update_reasons(NULL, "-connecting-to-device");
787 - _cupsLangPrintFilter(stderr, "INFO", _("Connected to printer."));
788 + fputs("STATE: -connecting-to-device\n", stderr);
789 + _cupsLangPuts(stderr, _("INFO: Connected to printer...\n"));
791 - fprintf(stderr, "DEBUG: Connected to %s:%d...\n",
792 - httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
793 - _httpAddrPort(http->hostaddr));
795 + if (http->hostaddr->addr.sa_family == AF_INET6)
796 + fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6)...\n",
797 + httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
798 + ntohs(http->hostaddr->ipv6.sin6_port));
800 +#endif /* AF_INET6 */
801 + if (http->hostaddr->addr.sa_family == AF_INET)
802 + fprintf(stderr, "DEBUG: Connected to %s:%d (IPv4)...\n",
803 + httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
804 + ntohs(http->hostaddr->ipv4.sin_port));
807 + * See if the printer supports SNMP...
810 + if ((snmp_fd = _cupsSNMPOpen(http->hostaddr->addr.sa_family)) >= 0)
811 + have_supplies = !backendSNMPSupplies(snmp_fd, http->hostaddr, &start_count,
814 + have_supplies = start_count = 0;
817 * Build a URI for the printer and fill the standard IPP attributes for
818 * an IPP_PRINT_FILE request. We can't use the URI in argv[0] because it
819 * might contain username:password information...
820 @@ -779,17 +646,13 @@
823 * First validate the destination and see if the device supports multiple
825 + * copies. We have to do this because some IPP servers (e.g. HP JetDirect)
826 + * don't support the copies attribute...
830 - cups_version = NULL;
832 - media_col_sup = NULL;
834 - operations_sup = NULL;
835 - doc_handling_sup = NULL;
843 @@ -821,73 +684,57 @@
844 fputs("DEBUG: Getting supported attributes...\n", stderr);
846 if (http->version < HTTP_1_1)
848 - fprintf(stderr, "DEBUG: Printer responded with HTTP version %d.%d.\n",
849 - http->version / 100, http->version % 100);
850 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
851 - "cups-ipp-wrong-http-version");
853 + httpReconnect(http);
855 - supported = cupsDoRequest(http, request, resource);
856 - ipp_status = cupsLastError();
857 + if ((supported = cupsDoRequest(http, request, resource)) == NULL)
858 + ipp_status = cupsLastError();
860 + ipp_status = supported->request.status.status_code;
862 - fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n",
863 - ippErrorString(ipp_status), cupsLastErrorString());
865 if (ipp_status > IPP_OK_CONFLICT)
867 - fprintf(stderr, "DEBUG: Get-Printer-Attributes returned %s.\n",
868 - ippErrorString(ipp_status));
870 if (ipp_status == IPP_PRINTER_BUSY ||
871 ipp_status == IPP_SERVICE_UNAVAILABLE)
873 if (contimeout && (time(NULL) - start_time) > contimeout)
875 - _cupsLangPrintFilter(stderr, "ERROR",
876 - _("The printer is not responding."));
877 + _cupsLangPuts(stderr, _("ERROR: Printer not responding!\n"));
878 return (CUPS_BACKEND_FAILED);
881 - _cupsLangPrintFilter(stderr, "INFO", _("The printer is busy."));
884 - report_printer_state(supported);
885 + _cupsLangPrintf(stderr,
886 + _("WARNING: recoverable: Network host \'%s\' is busy; "
887 + "will retry in %d seconds...\n"),
890 + report_printer_state(supported, 0);
894 - delay = _cupsNextDelay(delay, &prev_delay);
898 else if ((ipp_status == IPP_BAD_REQUEST ||
899 ipp_status == IPP_VERSION_NOT_SUPPORTED) && version > 10)
902 - * Switch to IPP/1.1 or IPP/1.0...
903 + * Switch to IPP/1.0...
908 - _cupsLangPrintFilter(stderr, "INFO",
909 - _("Printer does not support IPP/%d.%d, trying "
910 - "IPP/%s."), version / 10, version % 10, "1.1");
915 - _cupsLangPrintFilter(stderr, "INFO",
916 - _("Printer does not support IPP/%d.%d, trying "
917 - "IPP/%s."), version / 10, version % 10, "1.0");
921 + _cupsLangPrintf(stderr,
922 + _("INFO: Printer does not support IPP/%d.%d, trying "
923 + "IPP/1.0...\n"), version / 10, version % 10);
927 else if (ipp_status == IPP_NOT_FOUND)
929 - _cupsLangPrintFilter(stderr, "ERROR",
930 - _("The printer URI is incorrect or no longer "
932 + _cupsLangPuts(stderr, _("ERROR: Destination printer does not exist!\n"));
934 - ippDelete(supported);
936 + ippDelete(supported);
938 return (CUPS_BACKEND_STOP);
940 @@ -902,92 +749,33 @@
944 - _cupsLangPrintFilter(stderr, "ERROR",
945 - _("Unable to get printer status."));
946 + _cupsLangPrintf(stderr,
947 + _("ERROR: Unable to get printer status (%s)!\n"),
948 + cupsLastErrorString());
952 - ippDelete(supported);
955 + ippDelete(supported);
960 - if (!getenv("CLASS"))
961 + else if ((copies_sup = ippFindAttribute(supported, "copies-supported",
962 + IPP_TAG_RANGE)) != NULL)
965 - * Check printer-is-accepting-jobs = false and printer-state-reasons for the
966 - * "spool-area-full" keyword...
971 - if ((printer_accepting = ippFindAttribute(supported,
972 - "printer-is-accepting-jobs",
973 - IPP_TAG_BOOLEAN)) != NULL &&
974 - !printer_accepting->values[0].boolean)
976 - else if (!printer_accepting)
977 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
978 - "cups-ipp-missing-printer-is-accepting-jobs");
980 - if ((printer_state = ippFindAttribute(supported,
981 - "printer-state-reasons",
982 - IPP_TAG_KEYWORD)) != NULL && !busy)
984 - for (i = 0; i < printer_state->num_values; i ++)
985 - if (!strcmp(printer_state->values[0].string.text,
986 - "spool-area-full") ||
987 - !strncmp(printer_state->values[0].string.text, "spool-area-full-",
995 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
996 - "cups-ipp-missing-printer-state-reasons");
1000 - _cupsLangPrintFilter(stderr, "INFO", _("The printer is busy."));
1002 - report_printer_state(supported);
1006 - delay = _cupsNextDelay(delay, &prev_delay);
1008 - ippDelete(supported);
1015 - * Check for supported attributes...
1018 - if ((copies_sup = ippFindAttribute(supported, "copies-supported",
1019 - IPP_TAG_RANGE)) != NULL)
1022 * Has the "copies-supported" attribute - does it have an upper
1026 - fprintf(stderr, "DEBUG: copies-supported=%d-%d\n",
1027 - copies_sup->values[0].range.lower,
1028 - copies_sup->values[0].range.upper);
1030 if (copies_sup->values[0].range.upper <= 1)
1031 copies_sup = NULL; /* No */
1034 - cups_version = ippFindAttribute(supported, "cups-version", IPP_TAG_TEXT);
1035 + format_sup = ippFindAttribute(supported, "document-format-supported",
1036 + IPP_TAG_MIMETYPE);
1038 - if ((format_sup = ippFindAttribute(supported, "document-format-supported",
1039 - IPP_TAG_MIMETYPE)) != NULL)
1042 fprintf(stderr, "DEBUG: document-format-supported (%d values)\n",
1043 format_sup->num_values);
1044 @@ -996,71 +784,7 @@
1045 format_sup->values[i].string.text);
1048 - if ((media_col_sup = ippFindAttribute(supported, "media-col-supported",
1049 - IPP_TAG_KEYWORD)) != NULL)
1051 - fprintf(stderr, "DEBUG: media-col-supported (%d values)\n",
1052 - media_col_sup->num_values);
1053 - for (i = 0; i < media_col_sup->num_values; i ++)
1054 - fprintf(stderr, "DEBUG: [%d] = \"%s\"\n", i,
1055 - media_col_sup->values[i].string.text);
1058 - if ((operations_sup = ippFindAttribute(supported, "operations-supported",
1059 - IPP_TAG_ENUM)) != NULL)
1061 - for (i = 0; i < operations_sup->num_values; i ++)
1062 - if (operations_sup->values[i].integer == IPP_PRINT_JOB)
1065 - if (i >= operations_sup->num_values)
1066 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1067 - "cups-ipp-missing-print-job");
1069 - for (i = 0; i < operations_sup->num_values; i ++)
1070 - if (operations_sup->values[i].integer == IPP_CANCEL_JOB)
1073 - if (i >= operations_sup->num_values)
1074 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1075 - "cups-ipp-missing-cancel-job");
1077 - for (i = 0; i < operations_sup->num_values; i ++)
1078 - if (operations_sup->values[i].integer == IPP_GET_JOB_ATTRIBUTES)
1081 - if (i >= operations_sup->num_values)
1082 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1083 - "cups-ipp-missing-get-job-attributes");
1085 - for (i = 0; i < operations_sup->num_values; i ++)
1086 - if (operations_sup->values[i].integer == IPP_GET_PRINTER_ATTRIBUTES)
1089 - if (i >= operations_sup->num_values)
1090 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1091 - "cups-ipp-missing-get-printer-attributes");
1093 - for (i = 0; i < operations_sup->num_values; i ++)
1094 - if (operations_sup->values[i].integer == IPP_VALIDATE_JOB)
1100 - if (!validate_job)
1101 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1102 - "cups-ipp-missing-validate-job");
1105 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1106 - "cups-ipp-missing-operations-supported");
1108 - doc_handling_sup = ippFindAttribute(supported,
1109 - "multiple-document-handling-supported",
1112 - report_printer_state(supported);
1113 + report_printer_state(supported, 0);
1115 while (ipp_status > IPP_OK_CONFLICT);
1117 @@ -1089,13 +813,16 @@
1118 * available printer in the class.
1121 - _cupsLangPrintFilter(stderr, "INFO",
1122 - _("Unable to contact printer, queuing on next "
1123 - "printer in class."));
1124 + _cupsLangPuts(stderr,
1125 + _("INFO: Unable to contact printer, queuing on next "
1126 + "printer in class...\n"));
1128 ippDelete(supported);
1131 + if (tmpfilename[0])
1132 + unlink(tmpfilename);
1135 * Sleep 5 seconds to keep the job from requeuing too rapidly...
1137 @@ -1106,6 +833,18 @@
1144 + * If we've shown a recoverable error make sure the printer proxies
1145 + * have a chance to see the recovered message. Not pretty but
1146 + * necessary for now...
1149 + fputs("INFO: recovered: \n", stderr);
1154 * See if the printer supports multiple copies...
1156 @@ -1116,309 +855,210 @@
1158 copies_remaining = 1;
1160 - if (argc < 7 && !send_options)
1165 copies_remaining = copies;
1168 - * Prepare remaining printing options...
1169 + * Then issue the print-job request...
1177 + while (copies_remaining > 0)
1179 - num_options = cupsParseOptions(argv[5], 0, &options);
1181 + * Check for side-channel requests...
1184 - if (!cups_version && media_col_sup)
1187 - * Load the PPD file and generate PWG attribute mapping information...
1189 + backendCheckSideChannel(snmp_fd, http->hostaddr);
1191 - ppd = ppdOpenFile(getenv("PPD"));
1192 - pc = _ppdCacheCreateWithPPD(ppd);
1194 + * Build the IPP request...
1202 + if (job_cancelled)
1205 - document_format = NULL;
1206 + if (num_files > 1)
1207 + request = ippNewRequest(IPP_CREATE_JOB);
1209 + request = ippNewRequest(IPP_PRINT_JOB);
1211 - if (format_sup != NULL)
1213 - for (i = 0; i < format_sup->num_values; i ++)
1214 - if (!_cups_strcasecmp(final_content_type, format_sup->values[i].string.text))
1216 - document_format = final_content_type;
1219 + request->request.op.version[0] = version / 10;
1220 + request->request.op.version[1] = version % 10;
1222 - if (!document_format)
1224 - for (i = 0; i < format_sup->num_values; i ++)
1225 - if (!_cups_strcasecmp("application/octet-stream",
1226 - format_sup->values[i].string.text))
1228 - document_format = "application/octet-stream";
1233 + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
1237 - * If the printer does not support HTTP/1.1 (which IPP requires), copy stdin
1238 - * to a temporary file so that we can do a HTTP/1.0 submission...
1240 - * (I hate compatibility hacks!)
1242 + fprintf(stderr, "DEBUG: printer-uri = \"%s\"\n", uri);
1244 - if (http->version < HTTP_1_1 && num_files == 0)
1246 - if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
1248 - perror("DEBUG: Unable to create temporary file");
1249 - return (CUPS_BACKEND_FAILED);
1252 + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1253 + "requesting-user-name", NULL, argv[2]);
1255 - _cupsLangPrintFilter(stderr, "INFO", _("Copying print data."));
1256 + fprintf(stderr, "DEBUG: requesting-user-name = \"%s\"\n", argv[2]);
1258 - compatsize = backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0,
1259 - backendNetworkSideCB);
1261 + * Only add a "job-name" attribute if the remote server supports
1262 + * copy generation - some IPP implementations like HP's don't seem
1263 + * to like UTF-8 job names (STR #1837)...
1267 + if (argv[3][0] && copies_sup)
1268 + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
1271 - compatfile = tmpfilename;
1272 - files = &compatfile;
1275 - else if (http->version < HTTP_1_1 && num_files == 1)
1277 - struct stat fileinfo; /* File information */
1278 + fprintf(stderr, "DEBUG: job-name = \"%s\"\n", argv[3]);
1280 - if (!stat(files[0], &fileinfo))
1281 - compatsize = fileinfo.st_size;
1285 + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1286 + "compression", NULL, "gzip");
1287 +#endif /* HAVE_LIBZ */
1290 - * Start monitoring the printer in the background...
1293 + * Handle options on the command-line...
1296 - monitor.uri = uri;
1297 - monitor.hostname = hostname;
1298 - monitor.user = argv[2];
1299 - monitor.resource = resource;
1300 - monitor.port = port;
1301 - monitor.version = version;
1302 - monitor.job_id = 0;
1303 - monitor.encryption = cupsEncryption();
1304 - monitor.job_state = IPP_JOB_PENDING;
1305 - monitor.printer_state = IPP_PRINTER_IDLE;
1307 + num_options = cupsParseOptions(argv[5], 0, &options);
1309 - _cupsThreadCreate((_cups_thread_func_t)monitor_printer, &monitor);
1311 + if (!strcasecmp(final_content_type, "application/pictwps") &&
1314 + if (format_sup != NULL)
1316 + for (i = 0; i < format_sup->num_values; i ++)
1317 + if (!strcasecmp(final_content_type, format_sup->values[i].string.text))
1322 - * Validate access to the printer...
1324 + if (format_sup == NULL || i >= format_sup->num_values)
1327 + * Remote doesn't support "application/pictwps" (i.e. it's not MacOS X)
1328 + * so convert the document to PostScript...
1331 - while (!job_canceled && validate_job)
1333 - request = new_request(IPP_VALIDATE_JOB, version, uri, argv[2], argv[3],
1334 - num_options, options, compression,
1335 - copies_sup ? copies : 1, document_format, pc,
1336 - media_col_sup, doc_handling_sup);
1337 + if (run_pictwps_filter(argv, files[0]))
1340 + unlink(pstmpname);
1342 - ippDelete(cupsDoRequest(http, request, resource));
1343 + if (tmpfilename[0])
1344 + unlink(tmpfilename);
1346 - ipp_status = cupsLastError();
1347 + return (CUPS_BACKEND_FAILED);
1350 - fprintf(stderr, "DEBUG: Validate-Job: %s (%s)\n",
1351 - ippErrorString(ipp_status), cupsLastErrorString());
1352 + files[0] = pstmpname;
1357 + * Change the MIME type to application/postscript and change the
1358 + * number of copies to 1...
1361 - if (ipp_status == IPP_SERVICE_UNAVAILABLE || ipp_status == IPP_PRINTER_BUSY)
1363 - _cupsLangPrintFilter(stderr, "INFO", _("The printer is busy."));
1365 + final_content_type = "application/postscript";
1367 + copies_remaining = 1;
1371 - else if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN ||
1372 - ipp_status == IPP_AUTHENTICATION_CANCELED)
1373 +#endif /* __APPLE__ */
1375 + if (format_sup != NULL)
1378 - * Update auth-info-required as needed...
1380 + for (i = 0; i < format_sup->num_values; i ++)
1381 + if (!strcasecmp(final_content_type, format_sup->values[i].string.text))
1384 - fprintf(stderr, "DEBUG: WWW-Authenticate=\"%s\"\n",
1385 - httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE));
1386 + if (i < format_sup->num_values)
1387 + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
1388 + "document-format", NULL, final_content_type);
1391 + if (copies_sup && version > 10 && send_options)
1394 - * Normal authentication goes through the password callback, which sets
1395 - * auth_info_required to "username,password". Kerberos goes directly
1396 - * through GSSAPI, so look for Negotiate in the WWW-Authenticate header
1397 - * here and set auth_info_required as needed...
1398 + * Only send options if the destination printer supports the copies
1399 + * attribute and IPP/1.1. This is a hack for the HP and Lexmark
1400 + * implementations of IPP, which do not accept extension attributes
1401 + * and incorrectly report a client-error-bad-request error instead of
1402 + * the successful-ok-unsupported-attributes status. In short, at least
1403 + * some HP and Lexmark implementations of IPP are non-compliant.
1406 - if (!strncmp(httpGetField(http, HTTP_FIELD_WWW_AUTHENTICATE),
1408 - auth_info_required = "negotiate";
1409 + cupsEncodeOptions(request, num_options, options);
1412 + ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "copies",
1415 - else if (ipp_status == IPP_OPERATION_NOT_SUPPORTED)
1418 - * This is all too common...
1421 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1422 - "cups-ipp-missing-validate-job");
1425 - else if (ipp_status < IPP_REDIRECTION_OTHER_SITE)
1428 + cupsFreeOptions(num_options, options);
1431 - * Then issue the print-job request...
1436 - while (!job_canceled && copies_remaining > 0)
1439 - * Check for side-channel requests...
1440 + * If copies aren't supported, then we are likely dealing with an HP
1441 + * JetDirect. The HP IPP implementation seems to close the connection
1442 + * after every request - that is, it does *not* implement HTTP Keep-
1443 + * Alive, which is REQUIRED by HTTP/1.1...
1446 - backendCheckSideChannel(snmp_fd, http->hostaddr);
1448 + httpReconnect(http);
1451 - * Build the IPP job creation request...
1452 + * Do the request...
1457 + if (http->version < HTTP_1_1)
1458 + httpReconnect(http);
1460 - request = new_request(num_files > 1 ? IPP_CREATE_JOB : IPP_PRINT_JOB,
1461 - version, uri, argv[2], argv[3], num_options, options,
1462 - compression, copies_sup ? copies : 1, document_format,
1463 - pc, media_col_sup, doc_handling_sup);
1466 - * Do the request...
1470 response = cupsDoRequest(http, request, resource);
1473 - size_t length = 0; /* Length of request */
1474 + response = cupsDoFileRequest(http, request, resource, files[0]);
1476 - if (compatsize > 0)
1478 - fputs("DEBUG: Sending file using HTTP/1.0 Content-Length...\n", stderr);
1479 - length = ippLength(request) + (size_t)compatsize;
1482 - fputs("DEBUG: Sending file using HTTP/1.1 chunking...\n", stderr);
1484 - http_status = cupsSendRequest(http, request, resource, length);
1485 - if (http_status == HTTP_CONTINUE && request->state == IPP_DATA)
1487 - if (num_files == 1)
1488 - fd = open(files[0], O_RDONLY);
1492 - http_status = cupsWriteRequestData(http, buffer, bytes);
1495 - while (http_status == HTTP_CONTINUE &&
1496 - (!job_canceled || compatsize > 0))
1499 - * Check for side-channel requests and more print data...
1503 - FD_SET(fd, &input);
1504 - FD_SET(snmp_fd, &input);
1506 - while (select(fd > snmp_fd ? fd + 1 : snmp_fd + 1, &input, NULL, NULL,
1507 - NULL) <= 0 && !job_canceled);
1509 - if (FD_ISSET(snmp_fd, &input))
1510 - backendCheckSideChannel(snmp_fd, http->hostaddr);
1512 - if (FD_ISSET(fd, &input))
1514 - if ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
1516 - fprintf(stderr, "DEBUG: Read %d bytes...\n", (int)bytes);
1518 - if (cupsWriteRequestData(http, buffer, bytes) != HTTP_CONTINUE)
1521 - else if (bytes == 0 || (errno != EINTR && errno != EAGAIN))
1526 - if (num_files == 1)
1530 - response = cupsGetResponse(http, resource);
1531 - ippDelete(request);
1534 ipp_status = cupsLastError();
1536 - fprintf(stderr, "DEBUG: %s: %s (%s)\n",
1537 - num_files > 1 ? "Create-Job" : "Print-Job",
1538 - ippErrorString(ipp_status), cupsLastErrorString());
1540 if (ipp_status > IPP_OK_CONFLICT)
1545 + if (job_cancelled)
1548 if (ipp_status == IPP_SERVICE_UNAVAILABLE ||
1549 - ipp_status == IPP_NOT_POSSIBLE ||
1550 ipp_status == IPP_PRINTER_BUSY)
1552 - _cupsLangPrintFilter(stderr, "INFO", _("The printer is busy."));
1553 + _cupsLangPuts(stderr,
1554 + _("INFO: Printer busy; will retry in 10 seconds...\n"));
1557 + else if ((ipp_status == IPP_BAD_REQUEST ||
1558 + ipp_status == IPP_VERSION_NOT_SUPPORTED) && version > 10)
1561 + * Switch to IPP/1.0...
1564 - if (num_files == 0)
1567 - * We can't re-submit when we have no files to print, so exit
1568 - * immediately with the right status code...
1573 + _cupsLangPrintf(stderr,
1574 + _("INFO: Printer does not support IPP/%d.%d, trying "
1575 + "IPP/1.0...\n"), version / 10, version % 10);
1577 + httpReconnect(http);
1579 - else if (ipp_status == IPP_ERROR_JOB_CANCELED)
1584 * Update auth-info-required as needed...
1587 - _cupsLangPrintFilter(stderr, "ERROR",
1588 - _("Print file was not accepted."));
1589 + _cupsLangPrintf(stderr, _("ERROR: Print file was not accepted (%s)!\n"),
1590 + cupsLastErrorString());
1592 if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN)
1594 @@ -1436,39 +1076,25 @@
1596 auth_info_required = "negotiate";
1601 - if (num_files == 0)
1604 - * We can't re-submit when we have no files to print, so exit
1605 - * immediately with the right status code...
1612 else if ((job_id_attr = ippFindAttribute(response, "job-id",
1613 IPP_TAG_INTEGER)) == NULL)
1615 - _cupsLangPrintFilter(stderr, "INFO",
1616 - _("Print file accepted - job ID unknown."));
1617 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1618 - "cups-ipp-missing-job-id");
1619 + _cupsLangPuts(stderr,
1620 + _("NOTICE: Print file accepted - job ID unknown.\n"));
1625 - monitor.job_id = job_id = job_id_attr->values[0].integer;
1626 - _cupsLangPrintFilter(stderr, "INFO",
1627 - _("Print file accepted - job ID %d."), job_id);
1628 + job_id = job_id_attr->values[0].integer;
1629 + _cupsLangPrintf(stderr, _("NOTICE: Print file accepted - job ID %d.\n"),
1633 ippDelete(response);
1636 + if (job_cancelled)
1639 if (job_id && num_files > 1)
1640 @@ -1505,41 +1131,18 @@
1641 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
1642 "document-format", NULL, content_type);
1644 - fprintf(stderr, "DEBUG: Sending file %d using chunking...\n", i + 1);
1645 - http_status = cupsSendRequest(http, request, resource, 0);
1646 - if (http_status == HTTP_CONTINUE && request->state == IPP_DATA &&
1647 - (fd = open(files[i], O_RDONLY)) >= 0)
1649 - while (!job_canceled &&
1650 - (bytes = read(fd, buffer, sizeof(buffer))) > 0)
1652 - if (cupsWriteRequestData(http, buffer, bytes) != HTTP_CONTINUE)
1657 - * Check for side-channel requests...
1659 + if (http->version < HTTP_1_1)
1660 + httpReconnect(http);
1662 - backendCheckSideChannel(snmp_fd, http->hostaddr);
1665 + ippDelete(cupsDoFileRequest(http, request, resource, files[i]));
1670 - ippDelete(cupsGetResponse(http, resource));
1671 - ippDelete(request);
1673 - fprintf(stderr, "DEBUG: Send-Document: %s (%s)\n",
1674 - ippErrorString(cupsLastError()), cupsLastErrorString());
1676 if (cupsLastError() > IPP_OK_CONFLICT)
1678 ipp_status = cupsLastError();
1680 - _cupsLangPrintFilter(stderr, "ERROR",
1681 - _("Unable to add document to print job."));
1682 + _cupsLangPrintf(stderr,
1683 + _("ERROR: Unable to add file %d to job: %s\n"),
1684 + job_id, cupsLastErrorString());
1688 @@ -1551,7 +1154,6 @@
1689 copies_remaining --;
1691 else if (ipp_status == IPP_SERVICE_UNAVAILABLE ||
1692 - ipp_status == IPP_NOT_POSSIBLE ||
1693 ipp_status == IPP_PRINTER_BUSY)
1696 @@ -1564,9 +1166,9 @@
1697 if (!job_id || !waitjob)
1700 - _cupsLangPrintFilter(stderr, "INFO", _("Waiting for job to complete."));
1701 + _cupsLangPuts(stderr, _("INFO: Waiting for job to complete...\n"));
1703 - for (delay = _cupsNextDelay(0, &prev_delay); !job_canceled;)
1704 + for (delay = 1; !job_cancelled;)
1707 * Check for side-channel requests...
1708 @@ -1600,7 +1202,9 @@
1712 - httpReconnect(http);
1713 + if (!copies_sup || http->version < HTTP_1_1)
1714 + httpReconnect(http);
1716 response = cupsDoRequest(http, request, resource);
1717 ipp_status = cupsLastError();
1719 @@ -1610,27 +1214,22 @@
1720 * Job has gone away and/or the server has no job history...
1723 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1724 - "cups-ipp-missing-job-history");
1725 ippDelete(response);
1727 ipp_status = IPP_OK;
1731 - fprintf(stderr, "DEBUG: Get-Job-Attributes: %s (%s)\n",
1732 - ippErrorString(ipp_status), cupsLastErrorString());
1734 if (ipp_status > IPP_OK_CONFLICT)
1736 if (ipp_status != IPP_SERVICE_UNAVAILABLE &&
1737 - ipp_status != IPP_NOT_POSSIBLE &&
1738 ipp_status != IPP_PRINTER_BUSY)
1740 ippDelete(response);
1742 - _cupsLangPrintFilter(stderr, "ERROR",
1743 - _("Unable to get print job status."));
1744 + _cupsLangPrintf(stderr,
1745 + _("ERROR: Unable to get job %d attributes (%s)!\n"),
1746 + job_id, cupsLastErrorString());
1750 @@ -1640,41 +1239,23 @@
1751 if ((job_state = ippFindAttribute(response, "job-state",
1752 IPP_TAG_ENUM)) != NULL)
1755 - * Reflect the remote job state in the local queue...
1758 - if (cups_version &&
1759 - job_state->values[0].integer >= IPP_JOB_PENDING &&
1760 - job_state->values[0].integer <= IPP_JOB_COMPLETED)
1761 - update_reasons(NULL,
1762 - remote_job_states[job_state->values[0].integer -
1763 - IPP_JOB_PENDING]);
1765 - if ((job_sheets = ippFindAttribute(response,
1766 - "job-media-sheets-completed",
1767 - IPP_TAG_INTEGER)) == NULL)
1768 - job_sheets = ippFindAttribute(response,
1769 - "job-impressions-completed",
1773 - fprintf(stderr, "PAGE: total %d\n",
1774 - job_sheets->values[0].integer);
1777 * Stop polling if the job is finished or pending-held...
1780 if (job_state->values[0].integer > IPP_JOB_STOPPED)
1782 + if ((job_sheets = ippFindAttribute(response,
1783 + "job-media-sheets-completed",
1784 + IPP_TAG_INTEGER)) != NULL)
1785 + fprintf(stderr, "PAGE: total %d\n",
1786 + job_sheets->values[0].integer);
1788 ippDelete(response);
1792 - else if (ipp_status != IPP_SERVICE_UNAVAILABLE &&
1793 - ipp_status != IPP_NOT_POSSIBLE &&
1794 - ipp_status != IPP_PRINTER_BUSY)
1798 * If the printer does not return a job-state attribute, it does not
1799 @@ -1682,8 +1263,8 @@
1803 - update_reasons(NULL, "+cups-ipp-conformance-failure-report,"
1804 - "cups-ipp-missing-job-state");
1805 + fputs("DEBUG: No job-state available from printer - stopping queue.\n",
1807 ipp_status = IPP_INTERNAL_ERROR;
1810 @@ -1692,12 +1273,20 @@
1811 ippDelete(response);
1814 - * Wait before polling again...
1815 + * Check the printer state and report it if necessary...
1818 + check_printer_state(http, uri, resource, argv[2], version, job_id);
1821 + * Wait 1-10 seconds before polling again...
1826 - delay = _cupsNextDelay(delay, &prev_delay);
1833 @@ -1705,20 +1294,20 @@
1834 * Cancel the job as needed...
1837 - if (job_canceled && job_id)
1838 + if (job_cancelled && job_id)
1839 cancel_job(http, uri, job_id, resource, argv[2], version);
1842 * Check the printer state and report it if necessary...
1845 - check_printer_state(http, uri, resource, argv[2], version);
1846 + check_printer_state(http, uri, resource, argv[2], version, job_id);
1849 * Collect the final page count as needed...
1852 - if (have_supplies &&
1853 + if (have_supplies &&
1854 !backendSNMPSupplies(snmp_fd, http->hostaddr, &page_count, NULL) &&
1855 page_count > start_count)
1856 fprintf(stderr, "PAGE: total %d\n", page_count - start_count);
1857 @@ -1736,11 +1325,6 @@
1863 - cupsFreeOptions(num_options, options);
1864 - _ppdCacheDestroy(pc);
1868 ippDelete(supported);
1869 @@ -1760,28 +1344,26 @@
1871 #endif /* HAVE_LIBZ */
1875 + unlink(pstmpname);
1876 +#endif /* __APPLE__ */
1879 * Return the queue status...
1882 - if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN ||
1883 - ipp_status == IPP_AUTHENTICATION_CANCELED ||
1884 - ipp_status <= IPP_OK_CONFLICT)
1885 - fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required);
1886 + fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required);
1888 - if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN ||
1889 - ipp_status == IPP_AUTHENTICATION_CANCELED)
1890 + if (ipp_status == IPP_NOT_AUTHORIZED || ipp_status == IPP_FORBIDDEN)
1891 return (CUPS_BACKEND_AUTH_REQUIRED);
1892 else if (ipp_status == IPP_INTERNAL_ERROR)
1893 return (CUPS_BACKEND_STOP);
1894 - else if (ipp_status == IPP_DOCUMENT_FORMAT ||
1895 - ipp_status == IPP_CONFLICT)
1896 + else if (ipp_status > IPP_OK_CONFLICT)
1897 return (CUPS_BACKEND_FAILED);
1898 - else if (ipp_status > IPP_OK_CONFLICT && ipp_status != IPP_ERROR_JOB_CANCELED)
1899 - return (CUPS_BACKEND_RETRY_CURRENT);
1902 - _cupsLangPrintFilter(stderr, "INFO", _("Ready to print."));
1903 + _cupsLangPuts(stderr, _("INFO: Ready to print.\n"));
1904 return (CUPS_BACKEND_OK);
1907 @@ -1802,7 +1384,7 @@
1908 ipp_t *request; /* Cancel-Job request */
1911 - _cupsLangPrintFilter(stderr, "INFO", _("Canceling print job."));
1912 + _cupsLangPuts(stderr, _("INFO: Canceling print job...\n"));
1914 request = ippNewRequest(IPP_CANCEL_JOB);
1915 request->request.op.version[0] = version / 10;
1916 @@ -1820,34 +1402,47 @@
1920 + if (http->version < HTTP_1_1)
1921 + httpReconnect(http);
1923 ippDelete(cupsDoRequest(http, request, resource));
1925 if (cupsLastError() > IPP_OK_CONFLICT)
1926 - _cupsLangPrintFilter(stderr, "ERROR", _("Unable to cancel print job."));
1927 + _cupsLangPrintf(stderr, _("ERROR: Unable to cancel job %d: %s\n"), id,
1928 + cupsLastErrorString());
1933 - * 'check_printer_state()' - Check the printer state.
1934 + * 'check_printer_state()' - Check the printer state...
1937 -static ipp_pstate_t /* O - Current printer-state */
1939 check_printer_state(
1940 http_t *http, /* I - HTTP connection */
1941 const char *uri, /* I - Printer URI */
1942 const char *resource, /* I - Resource path */
1943 const char *user, /* I - Username, if any */
1944 - int version) /* I - IPP version */
1946 - ipp_t *request, /* IPP request */
1947 - *response; /* IPP response */
1948 - ipp_attribute_t *attr; /* Attribute in response */
1949 - ipp_pstate_t printer_state = IPP_PRINTER_STOPPED;
1950 - /* Current printer-state */
1951 + int version, /* I - IPP version */
1952 + int job_id) /* I - Current job ID */
1954 + ipp_t *request, /* IPP request */
1955 + *response; /* IPP response */
1956 + static const char * const attrs[] = /* Attributes we want */
1958 + "com.apple.print.recoverable-message",
1964 + "printer-state-message",
1965 + "printer-state-reasons"
1970 - * Send a Get-Printer-Attributes request and log the results...
1971 + * Check on the printer state...
1974 request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
1975 @@ -1855,41 +1450,34 @@
1976 request->request.op.version[1] = version % 10;
1978 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
1982 if (user && user[0])
1983 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
1984 - "requesting-user-name", NULL, user);
1985 + "requesting-user-name", NULL, user);
1987 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1988 - "requested-attributes",
1989 - (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
1990 + "requested-attributes",
1991 + (int)(sizeof(attrs) / sizeof(attrs[0])), NULL, attrs);
1994 + * Do the request...
1997 + if (http->version < HTTP_1_1)
1998 + httpReconnect(http);
2000 if ((response = cupsDoRequest(http, request, resource)) != NULL)
2002 - report_printer_state(response);
2004 - if ((attr = ippFindAttribute(response, "printer-state",
2005 - IPP_TAG_ENUM)) != NULL)
2006 - printer_state = (ipp_pstate_t)attr->values[0].integer;
2008 + report_printer_state(response, job_id);
2009 ippDelete(response);
2012 - fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n",
2013 - ippErrorString(cupsLastError()), cupsLastErrorString());
2016 - * Return the printer-state value...
2019 - return (printer_state);
2025 - * 'compress_files()' - Compress print files.
2026 + * 'compress_files()' - Compress print files...
2030 @@ -1912,19 +1500,25 @@
2032 if ((fd = cupsTempFd(filename, sizeof(filename))) < 0)
2034 - _cupsLangPrintError("ERROR", _("Unable to create compressed print file"));
2035 + _cupsLangPrintf(stderr,
2036 + _("ERROR: Unable to create temporary compressed print "
2037 + "file: %s\n"), strerror(errno));
2038 exit(CUPS_BACKEND_FAILED);
2041 if ((out = cupsFileOpenFd(fd, "w9")) == NULL)
2043 - _cupsLangPrintError("ERROR", _("Unable to open compressed print file"));
2044 + _cupsLangPrintf(stderr,
2045 + _("ERROR: Unable to open temporary compressed print "
2046 + "file: %s\n"), strerror(errno));
2047 exit(CUPS_BACKEND_FAILED);
2050 if ((in = cupsFileOpen(files[i], "r")) == NULL)
2052 - _cupsLangPrintError("ERROR", _("Unable to open print file"));
2053 + _cupsLangPrintf(stderr,
2054 + _("ERROR: Unable to open print file \"%s\": %s\n"),
2055 + files[i], strerror(errno));
2057 exit(CUPS_BACKEND_FAILED);
2059 @@ -1933,8 +1527,9 @@
2060 while ((bytes = cupsFileRead(in, buffer, sizeof(buffer))) > 0)
2061 if (cupsFileWrite(out, buffer, bytes) < bytes)
2063 - _cupsLangPrintError("ERROR",
2064 - _("Unable to generate compressed print file"));
2065 + _cupsLangPrintf(stderr,
2066 + _("ERROR: Unable to write %d bytes to \"%s\": %s\n"),
2067 + (int)bytes, filename, strerror(errno));
2070 exit(CUPS_BACKEND_FAILED);
2071 @@ -1959,365 +1554,6 @@
2075 - * 'monitor_printer()' - Monitor the printer state.
2078 -static void * /* O - Thread exit code */
2080 - _cups_monitor_t *monitor) /* I - Monitoring data */
2082 - http_t *http; /* Connection to printer */
2083 - ipp_t *request, /* IPP request */
2084 - *response; /* IPP response */
2085 - ipp_attribute_t *attr; /* Attribute in response */
2086 - int delay, /* Current delay */
2087 - prev_delay; /* Previous delay */
2091 - * Make a copy of the printer connection...
2094 - http = _httpCreate(monitor->hostname, monitor->port, NULL, monitor->encryption,
2096 - httpSetTimeout(http, 30.0, timeout_cb, NULL);
2097 - cupsSetPasswordCB(password_cb);
2100 - * Loop until the job is canceled, aborted, or completed.
2103 - delay = _cupsNextDelay(0, &prev_delay);
2105 - while (monitor->job_state < IPP_JOB_CANCELED && !job_canceled)
2108 - * Reconnect to the printer...
2111 - if (!httpReconnect(http))
2114 - * Connected, so check on the printer state...
2117 - monitor->printer_state = check_printer_state(http, monitor->uri,
2118 - monitor->resource,
2120 - monitor->version);
2122 - if (monitor->job_id > 0)
2125 - * Check the status of the job itself...
2128 - request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
2129 - request->request.op.version[0] = monitor->version / 10;
2130 - request->request.op.version[1] = monitor->version % 10;
2132 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
2133 - NULL, monitor->uri);
2134 - ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
2137 - if (monitor->user && monitor->user[0])
2138 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
2139 - "requesting-user-name", NULL, monitor->user);
2141 - ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
2142 - "requested-attributes",
2143 - (int)(sizeof(jattrs) / sizeof(jattrs[0])), NULL, jattrs);
2146 - * Do the request...
2149 - response = cupsDoRequest(http, request, monitor->resource);
2151 - fprintf(stderr, "DEBUG: Get-Job-Attributes: %s (%s)\n",
2152 - ippErrorString(cupsLastError()), cupsLastErrorString());
2154 - if ((attr = ippFindAttribute(response, "job-state",
2155 - IPP_TAG_ENUM)) != NULL)
2156 - monitor->job_state = (ipp_jstate_t)attr->values[0].integer;
2158 - monitor->job_state = IPP_JOB_COMPLETED;
2160 - ippDelete(response);
2164 - * Disconnect from the printer - we'll reconnect on the next poll...
2167 - _httpDisconnect(http);
2171 - * Sleep for N seconds...
2176 - delay = _cupsNextDelay(delay, &prev_delay);
2180 - * Cleanup and return...
2190 - * 'new_request()' - Create a new print creation or validation request.
2193 -static ipp_t * /* O - Request data */
2195 - ipp_op_t op, /* I - IPP operation code */
2196 - int version, /* I - IPP version number */
2197 - const char *uri, /* I - printer-uri value */
2198 - const char *user, /* I - requesting-user-name value */
2199 - const char *title, /* I - job-name value */
2200 - int num_options, /* I - Number of options to send */
2201 - cups_option_t *options, /* I - Options to send */
2202 - const char *compression, /* I - compression value or NULL */
2203 - int copies, /* I - copies value or 0 */
2204 - const char *format, /* I - documet-format value or NULL */
2205 - _ppd_cache_t *pc, /* I - PPD cache and mapping data */
2206 - ipp_attribute_t *media_col_sup, /* I - media-col-supported values */
2207 - ipp_attribute_t *doc_handling_sup) /* I - multiple-document-handling-supported values */
2209 - int i; /* Looping var */
2210 - ipp_t *request; /* Request data */
2211 - const char *keyword; /* PWG keyword */
2212 - _pwg_size_t *size; /* PWG media size */
2213 - ipp_t *media_col, /* media-col value */
2214 - *media_size; /* media-size value */
2215 - const char *media_source, /* media-source value */
2216 - *media_type, /* media-type value */
2217 - *collate_str; /* multiple-document-handling value */
2221 - * Create the IPP request...
2224 - request = ippNewRequest(op);
2225 - request->request.op.version[0] = version / 10;
2226 - request->request.op.version[1] = version % 10;
2228 - fprintf(stderr, "DEBUG: %s IPP/%d.%d\n",
2229 - ippOpString(request->request.op.operation_id),
2230 - request->request.op.version[0],
2231 - request->request.op.version[1]);
2234 - * Add standard attributes...
2237 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
2239 - fprintf(stderr, "DEBUG: printer-uri=\"%s\"\n", uri);
2241 - if (user && *user)
2243 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
2244 - "requesting-user-name", NULL, user);
2245 - fprintf(stderr, "DEBUG: requesting-user-name=\"%s\"\n", user);
2248 - if (title && *title)
2250 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
2252 - fprintf(stderr, "DEBUG: job-name=\"%s\"\n", title);
2257 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
2258 - "document-format", NULL, format);
2259 - fprintf(stderr, "DEBUG: document-format=\"%s\"\n", format);
2265 - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
2266 - "compression", NULL, compression);
2267 - fprintf(stderr, "DEBUG: compression=\"%s\"\n", compression);
2269 -#endif /* HAVE_LIBZ */
2272 - * Handle options on the command-line...
2275 - if (num_options > 0)
2280 - * Send standard IPP attributes...
2283 - if ((keyword = cupsGetOption("PageSize", num_options, options)) == NULL)
2284 - keyword = cupsGetOption("media", num_options, options);
2286 - if ((size = _ppdCacheGetSize(pc, keyword)) != NULL)
2289 - * Add a media-col value...
2292 - media_size = ippNew();
2293 - ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2294 - "x-dimension", size->width);
2295 - ippAddInteger(media_size, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2296 - "y-dimension", size->length);
2298 - media_col = ippNew();
2299 - ippAddCollection(media_col, IPP_TAG_ZERO, "media-size", media_size);
2301 - media_source = _ppdCacheGetSource(pc, cupsGetOption("InputSlot",
2304 - media_type = _ppdCacheGetType(pc, cupsGetOption("MediaType",
2308 - for (i = 0; i < media_col_sup->num_values; i ++)
2310 - if (!strcmp(media_col_sup->values[i].string.text,
2311 - "media-left-margin"))
2312 - ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2313 - "media-left-margin", size->left);
2314 - else if (!strcmp(media_col_sup->values[i].string.text,
2315 - "media-bottom-margin"))
2316 - ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2317 - "media-bottom-margin", size->bottom);
2318 - else if (!strcmp(media_col_sup->values[i].string.text,
2319 - "media-right-margin"))
2320 - ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2321 - "media-right-margin", size->right);
2322 - else if (!strcmp(media_col_sup->values[i].string.text,
2323 - "media-top-margin"))
2324 - ippAddInteger(media_col, IPP_TAG_ZERO, IPP_TAG_INTEGER,
2325 - "media-top-margin", size->top);
2326 - else if (!strcmp(media_col_sup->values[i].string.text,
2327 - "media-source") && media_source)
2328 - ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD,
2329 - "media-source", NULL, media_source);
2330 - else if (!strcmp(media_col_sup->values[i].string.text,
2331 - "media-type") && media_type)
2332 - ippAddString(media_col, IPP_TAG_ZERO, IPP_TAG_KEYWORD,
2333 - "media-type", NULL, media_type);
2336 - ippAddCollection(request, IPP_TAG_JOB, "media-col", media_col);
2339 - if ((keyword = cupsGetOption("output-bin", num_options,
2340 - options)) == NULL)
2341 - keyword = _ppdCacheGetBin(pc, cupsGetOption("OutputBin", num_options,
2345 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-bin",
2348 - if ((keyword = cupsGetOption("output-mode", num_options,
2349 - options)) != NULL)
2350 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-mode",
2352 - else if ((keyword = cupsGetOption("ColorModel", num_options,
2353 - options)) != NULL)
2355 - if (!_cups_strcasecmp(keyword, "Gray"))
2356 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-mode",
2357 - NULL, "monochrome");
2359 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-mode",
2363 - if ((keyword = cupsGetOption("print-quality", num_options,
2364 - options)) != NULL)
2365 - ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality",
2367 - else if ((keyword = cupsGetOption("cupsPrintQuality", num_options,
2368 - options)) != NULL)
2370 - if (!_cups_strcasecmp(keyword, "draft"))
2371 - ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality",
2372 - IPP_QUALITY_DRAFT);
2373 - else if (!_cups_strcasecmp(keyword, "normal"))
2374 - ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality",
2375 - IPP_QUALITY_NORMAL);
2376 - else if (!_cups_strcasecmp(keyword, "high"))
2377 - ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality",
2378 - IPP_QUALITY_HIGH);
2381 - if ((keyword = cupsGetOption("sides", num_options, options)) != NULL)
2382 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides",
2384 - else if (pc->sides_option &&
2385 - (keyword = cupsGetOption(pc->sides_option, num_options,
2386 - options)) != NULL)
2388 - if (!_cups_strcasecmp(keyword, pc->sides_1sided))
2389 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides",
2390 - NULL, "one-sided");
2391 - else if (!_cups_strcasecmp(keyword, pc->sides_2sided_long))
2392 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides",
2393 - NULL, "two-sided-long-edge");
2394 - if (!_cups_strcasecmp(keyword, pc->sides_2sided_short))
2395 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "sides",
2396 - NULL, "two-sided-short-edge");
2399 - if (doc_handling_sup &&
2400 - (keyword = cupsGetOption("collate", num_options, options)) != NULL)
2402 - if (!_cups_strcasecmp(keyword, "true"))
2403 - collate_str = "separate-documents-collated-copies";
2405 - collate_str = "separate-documents-uncollated-copies";
2407 - for (i = 0; i < doc_handling_sup->num_values; i ++)
2408 - if (!strcmp(doc_handling_sup->values[i].string.text, collate_str))
2410 - ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD,
2411 - "multiple-document-handling", NULL, collate_str);
2419 - * When talking to another CUPS server, send all options...
2422 - cupsEncodeOptions(request, num_options, options);
2426 - ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "copies", copies);
2434 * 'password_cb()' - Disable the password prompt for cupsDoFileRequest().
2437 @@ -2356,11 +1592,10 @@
2439 report_attr(ipp_attribute_t *attr) /* I - Attribute */
2441 - int i; /* Looping var */
2442 - char value[1024], /* Value string */
2443 - *valptr, /* Pointer into value string */
2444 - *attrptr; /* Pointer into attribute value */
2445 - const char *cached; /* Cached attribute */
2446 + int i; /* Looping var */
2447 + char value[1024], /* Value string */
2448 + *valptr, /* Pointer into value string */
2449 + *attrptr; /* Pointer into attribute value */
2453 @@ -2410,21 +1645,11 @@
2457 - _cupsMutexLock(&report_mutex);
2459 + * Tell the scheduler about the new values...
2462 - if ((cached = cupsGetOption(attr->name, num_attr_cache,
2463 - attr_cache)) == NULL || strcmp(cached, value))
2466 - * Tell the scheduler about the new values...
2469 - num_attr_cache = cupsAddOption(attr->name, value, num_attr_cache,
2471 - fprintf(stderr, "ATTR: %s=%s\n", attr->name, value);
2474 - _cupsMutexUnlock(&report_mutex);
2475 + fprintf(stderr, "ATTR: %s=%s\n", attr->name, value);
2479 @@ -2432,561 +1657,297 @@
2480 * 'report_printer_state()' - Report the printer state.
2484 -report_printer_state(ipp_t *ipp) /* I - IPP response */
2485 +static int /* O - Number of reasons shown */
2486 +report_printer_state(ipp_t *ipp, /* I - IPP response */
2487 + int job_id) /* I - Current job ID */
2489 - ipp_attribute_t *pa, /* printer-alert */
2490 - *pam, /* printer-alert-message */
2491 + int i; /* Looping var */
2492 + int count; /* Count of reasons shown... */
2493 + ipp_attribute_t *caprm, /* com.apple.print.recoverable-message */
2494 *psm, /* printer-state-message */
2495 *reasons, /* printer-state-reasons */
2496 *marker; /* marker-* attributes */
2497 - char value[1024], /* State/message string */
2498 - *valptr; /* Pointer into string */
2499 - static int ipp_supplies = -1;
2500 - /* Report supply levels? */
2501 + const char *reason; /* Current reason */
2502 + const char *prefix; /* Prefix for STATE: line */
2503 + char state[1024]; /* State string */
2504 + int saw_caprw; /* Saw com.apple.print.recoverable-warning state */
2508 - * Report alerts and messages...
2510 + if ((psm = ippFindAttribute(ipp, "printer-state-message",
2511 + IPP_TAG_TEXT)) != NULL)
2512 + fprintf(stderr, "INFO: %s\n", psm->values[0].string.text);
2514 - if ((pa = ippFindAttribute(ipp, "printer-alert", IPP_TAG_TEXT)) != NULL)
2516 + if ((reasons = ippFindAttribute(ipp, "printer-state-reasons",
2517 + IPP_TAG_KEYWORD)) == NULL)
2520 - if ((pam = ippFindAttribute(ipp, "printer-alert-message",
2521 - IPP_TAG_TEXT)) != NULL)
2525 + prefix = "STATE: ";
2527 - if ((psm = ippFindAttribute(ipp, "printer-state-message",
2528 - IPP_TAG_TEXT)) != NULL)
2529 + for (i = 0, count = 0; i < reasons->num_values; i ++)
2531 - char *ptr; /* Pointer into message */
2532 + reason = reasons->values[i].string.text;
2535 - strlcpy(value, "INFO: ", sizeof(value));
2536 - for (ptr = psm->values[0].string.text, valptr = value + 6;
2537 - *ptr && valptr < (value + sizeof(value) - 6);
2539 + if (!strcmp(reason, "com.apple.print.recoverable-warning"))
2541 + else if (strcmp(reason, "paused"))
2543 - if (*ptr < ' ' && *ptr > 0 && *ptr != '\t')
2546 - * Substitute "<XX>" for the control character; sprintf is safe because
2547 - * we always leave 6 chars free at the end...
2549 + strlcat(state, prefix, sizeof(state));
2550 + strlcat(state, reason, sizeof(state));
2552 - sprintf(valptr, "<%02X>", *ptr);
2564 + fprintf(stderr, "%s\n", state);
2566 - fputs(value, stderr);
2570 - * Now report printer-state-reasons, filtering out some of the reasons we never
2572 + * Relay com.apple.print.recoverable-message...
2575 - if ((reasons = ippFindAttribute(ipp, "printer-state-reasons",
2576 - IPP_TAG_KEYWORD)) == NULL)
2578 + if ((caprm = ippFindAttribute(ipp, "com.apple.print.recoverable-message",
2579 + IPP_TAG_TEXT)) != NULL)
2580 + fprintf(stderr, "WARNING: %s: %s\n",
2581 + saw_caprw ? "recoverable" : "recovered",
2582 + caprm->values[0].string.text);
2584 - update_reasons(reasons, NULL);
2587 * Relay the current marker-* attribute values...
2590 - if (ipp_supplies < 0)
2592 - ppd_file_t *ppd; /* PPD file */
2593 - ppd_attr_t *ppdattr; /* Attribute in PPD file */
2594 + if ((marker = ippFindAttribute(ipp, "marker-colors", IPP_TAG_NAME)) != NULL)
2595 + report_attr(marker);
2596 + if ((marker = ippFindAttribute(ipp, "marker-high-levels",
2597 + IPP_TAG_INTEGER)) != NULL)
2598 + report_attr(marker);
2599 + if ((marker = ippFindAttribute(ipp, "marker-levels",
2600 + IPP_TAG_INTEGER)) != NULL)
2601 + report_attr(marker);
2602 + if ((marker = ippFindAttribute(ipp, "marker-low-levels",
2603 + IPP_TAG_INTEGER)) != NULL)
2604 + report_attr(marker);
2605 + if ((marker = ippFindAttribute(ipp, "marker-message", IPP_TAG_TEXT)) != NULL)
2606 + report_attr(marker);
2607 + if ((marker = ippFindAttribute(ipp, "marker-names", IPP_TAG_NAME)) != NULL)
2608 + report_attr(marker);
2609 + if ((marker = ippFindAttribute(ipp, "marker-types", IPP_TAG_KEYWORD)) != NULL)
2610 + report_attr(marker);
2612 - if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL &&
2613 - (ppdattr = ppdFindAttr(ppd, "cupsIPPSupplies", NULL)) != NULL &&
2614 - ppdattr->value && _cups_strcasecmp(ppdattr->value, "true"))
2622 - if (ipp_supplies > 0)
2624 - if ((marker = ippFindAttribute(ipp, "marker-colors", IPP_TAG_NAME)) != NULL)
2625 - report_attr(marker);
2626 - if ((marker = ippFindAttribute(ipp, "marker-high-levels",
2627 - IPP_TAG_INTEGER)) != NULL)
2628 - report_attr(marker);
2629 - if ((marker = ippFindAttribute(ipp, "marker-levels",
2630 - IPP_TAG_INTEGER)) != NULL)
2631 - report_attr(marker);
2632 - if ((marker = ippFindAttribute(ipp, "marker-low-levels",
2633 - IPP_TAG_INTEGER)) != NULL)
2634 - report_attr(marker);
2635 - if ((marker = ippFindAttribute(ipp, "marker-message",
2636 - IPP_TAG_TEXT)) != NULL)
2637 - report_attr(marker);
2638 - if ((marker = ippFindAttribute(ipp, "marker-names", IPP_TAG_NAME)) != NULL)
2639 - report_attr(marker);
2640 - if ((marker = ippFindAttribute(ipp, "marker-types",
2641 - IPP_TAG_KEYWORD)) != NULL)
2642 - report_attr(marker);
2648 -#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
2651 - * 'run_as_user()' - Run the IPP backend as the printing user.
2652 + * 'run_pictwps_filter()' - Convert PICT files to PostScript when printing
2655 - * This function uses an XPC-based user agent to run the backend as the printing
2656 - * user. We need to do this in order to have access to the user's Kerberos
2658 + * This step is required because the PICT format is not documented and
2659 + * subject to change, so developing a filter for other OS's is infeasible.
2660 + * Also, fonts required by the PICT file need to be embedded on the
2661 + * client side (which has the fonts), so we run the filter to get a
2662 + * PostScript file for printing...
2665 -static int /* O - Exit status */
2666 -run_as_user(int argc, /* I - Number of command-line args */
2667 - char *argv[], /* I - Command-line arguments */
2668 - uid_t uid, /* I - User ID */
2669 - const char *device_uri, /* I - Device URI */
2670 - int fd) /* I - File to print */
2671 +static int /* O - Exit status of filter */
2672 +run_pictwps_filter(char **argv, /* I - Command-line arguments */
2673 + const char *filename)/* I - Filename */
2675 - const char *auth_negotiate;/* AUTH_NEGOTIATE env var */
2676 - xpc_connection_t conn; /* Connection to XPC service */
2677 - xpc_object_t request; /* Request message dictionary */
2678 - __block xpc_object_t response; /* Response message dictionary */
2679 - dispatch_semaphore_t sem; /* Semaphore for waiting for response */
2680 - int status = CUPS_BACKEND_FAILED;
2681 - /* Status of request */
2682 + struct stat fileinfo; /* Print file information */
2683 + const char *ppdfile; /* PPD file for destination printer */
2684 + int pid; /* Child process ID */
2685 + int fd; /* Temporary file descriptor */
2686 + int status; /* Exit status of filter */
2687 + const char *printer; /* PRINTER env var */
2688 + static char ppdenv[1024]; /* PPD environment variable */
2691 - fprintf(stderr, "DEBUG: Running IPP backend as UID %d.\n", (int)uid);
2694 - * Connect to the user agent for the specified UID...
2695 + * First get the PPD file for the printer...
2698 - conn = xpc_connection_create_mach_service(kPMPrintUIToolAgent,
2699 - dispatch_get_global_queue(0, 0), 0);
2701 + printer = getenv("PRINTER");
2704 - _cupsLangPrintFilter(stderr, "ERROR",
2705 - _("Unable to start backend process."));
2706 - fputs("DEBUG: Unable to create connection to agent.\n", stderr);
2708 + _cupsLangPuts(stderr,
2709 + _("ERROR: PRINTER environment variable not defined!\n"));
2713 - xpc_connection_set_event_handler(conn,
2714 - ^(xpc_object_t event)
2716 - xpc_type_t messageType = xpc_get_type(event);
2718 - if (messageType == XPC_TYPE_ERROR)
2720 - if (event == XPC_ERROR_CONNECTION_INTERRUPTED)
2721 - fprintf(stderr, "DEBUG: Interrupted connection to service %s.\n",
2722 - xpc_connection_get_name(conn));
2723 - else if (event == XPC_ERROR_CONNECTION_INVALID)
2724 - fprintf(stderr, "DEBUG: Connection invalid for service %s.\n",
2725 - xpc_connection_get_name(conn));
2727 - fprintf(stderr, "DEBUG: Unxpected error for service %s: %s\n",
2728 - xpc_connection_get_name(conn),
2729 - xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
2732 - xpc_connection_set_target_uid(conn, uid);
2733 - xpc_connection_resume(conn);
2736 - * Try starting the backend...
2739 - request = xpc_dictionary_create(NULL, NULL, 0);
2740 - xpc_dictionary_set_int64(request, "command", kPMStartJob);
2741 - xpc_dictionary_set_string(request, "device-uri", device_uri);
2742 - xpc_dictionary_set_string(request, "job-id", argv[1]);
2743 - xpc_dictionary_set_string(request, "user", argv[2]);
2744 - xpc_dictionary_set_string(request, "title", argv[3]);
2745 - xpc_dictionary_set_string(request, "copies", argv[4]);
2746 - xpc_dictionary_set_string(request, "options", argv[5]);
2747 - xpc_dictionary_set_string(request, "auth-info-required",
2748 - getenv("AUTH_INFO_REQUIRED"));
2749 - if ((auth_negotiate = getenv("AUTH_NEGOTIATE")) != NULL)
2750 - xpc_dictionary_set_string(request, "auth-negotiate", auth_negotiate);
2751 - xpc_dictionary_set_fd(request, "stdin", fd);
2752 - xpc_dictionary_set_fd(request, "stderr", 2);
2753 - xpc_dictionary_set_fd(request, "side-channel", CUPS_SC_FD);
2755 - sem = dispatch_semaphore_create(0);
2758 - xpc_connection_send_message_with_reply(conn, request,
2759 - dispatch_get_global_queue(0,0),
2760 - ^(xpc_object_t reply)
2762 - /* Save the response and wake up */
2763 - if (xpc_get_type(reply)
2764 - == XPC_TYPE_DICTIONARY)
2765 - response = xpc_retain(reply);
2767 - dispatch_semaphore_signal(sem);
2770 - dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
2771 - xpc_release(request);
2772 - dispatch_release(sem);
2775 + if ((ppdfile = cupsGetPPD(printer)) == NULL)
2777 - child_pid = xpc_dictionary_get_int64(response, "child-pid");
2779 - xpc_release(response);
2782 - fprintf(stderr, "DEBUG: Child PID=%d.\n", child_pid);
2785 - _cupsLangPrintFilter(stderr, "ERROR",
2786 - _("Unable to start backend process."));
2787 - fputs("DEBUG: No child PID.\n", stderr);
2790 + _cupsLangPrintf(stderr,
2791 + _("ERROR: Unable to get PPD file for printer \"%s\" - "
2792 + "%s.\n"), printer, cupsLastErrorString());
2796 - _cupsLangPrintFilter(stderr, "ERROR",
2797 - _("Unable to start backend process."));
2798 - fputs("DEBUG: No reply from agent.\n", stderr);
2800 + snprintf(ppdenv, sizeof(ppdenv), "PPD=%s", ppdfile);
2805 - * Then wait for the backend to finish...
2806 + * Then create a temporary file for printing...
2809 - request = xpc_dictionary_create(NULL, NULL, 0);
2810 - xpc_dictionary_set_int64(request, "command", kPMWaitForJob);
2811 - xpc_dictionary_set_fd(request, "stderr", 2);
2813 - sem = dispatch_semaphore_create(0);
2816 - xpc_connection_send_message_with_reply(conn, request,
2817 - dispatch_get_global_queue(0,0),
2818 - ^(xpc_object_t reply)
2820 - /* Save the response and wake up */
2821 - if (xpc_get_type(reply)
2822 - == XPC_TYPE_DICTIONARY)
2823 - response = xpc_retain(reply);
2825 - dispatch_semaphore_signal(sem);
2828 - dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
2829 - xpc_release(request);
2830 - dispatch_release(sem);
2833 + if ((fd = cupsTempFd(pstmpname, sizeof(pstmpname))) < 0)
2835 - status = xpc_dictionary_get_int64(response, "status");
2836 + _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
2842 - if (status == SIGTERM || status == SIGKILL || status == SIGPIPE)
2844 - fprintf(stderr, "DEBUG: Child terminated on signal %d.\n", status);
2845 - status = CUPS_BACKEND_FAILED;
2847 - else if (WIFSIGNALED(status))
2849 - fprintf(stderr, "DEBUG: Child crashed on signal %d.\n", status);
2850 - status = CUPS_BACKEND_STOP;
2852 - else if (WIFEXITED(status))
2854 - status = WEXITSTATUS(status);
2855 - fprintf(stderr, "DEBUG: Child exited with status %d.\n", status);
2858 + * Get the owner of the spool file - it is owned by the user we want to run
2862 - xpc_release(response);
2865 + stat(argv[6], &fileinfo);
2867 - _cupsLangPrintFilter(stderr, "ERROR",
2868 - _("Unable to get backend exit status."));
2871 + * Use the OSX defaults, as an up-stream filter created the PICT
2879 - xpc_connection_suspend(conn);
2880 - xpc_connection_cancel(conn);
2881 - xpc_release(conn);
2882 + fileinfo.st_uid = 1;
2883 + fileinfo.st_gid = 80;
2888 -#endif /* HAVE_GSSAPI && HAVE_XPC */
2890 + chown(ppdfile, fileinfo.st_uid, fileinfo.st_gid);
2892 + fchown(fd, fileinfo.st_uid, fileinfo.st_gid);
2895 - * 'sigterm_handler()' - Handle 'terminate' signals that stop the backend.
2898 + * Finally, run the filter to convert the file...
2902 -sigterm_handler(int sig) /* I - Signal */
2904 - (void)sig; /* remove compiler warnings... */
2906 -#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
2908 + if ((pid = fork()) == 0)
2910 - kill(child_pid, sig);
2913 -#endif /* HAVE_GSSAPI && HAVE_XPC */
2915 - if (!job_canceled)
2918 - * Flag that the job should be canceled...
2919 + * Child process for pictwpstops... Redirect output of pictwpstops to a
2930 - * The scheduler already tried to cancel us once, now just terminate
2931 - * after removing our temp file!
2936 + * Change to an unpriviledged user...
2939 - if (tmpfilename[0])
2940 - unlink(tmpfilename);
2941 + if (setgid(fileinfo.st_gid))
2946 + if (setuid(fileinfo.st_uid))
2950 + execlp("pictwpstops", printer, argv[1], argv[2], argv[3], argv[4], argv[5],
2952 + _cupsLangPrintf(stderr, _("ERROR: Unable to exec pictwpstops: %s\n"),
2958 - * 'timeout_cb()' - Handle HTTP timeouts.
2962 -static int /* O - 1 to continue, 0 to cancel */
2963 -timeout_cb(http_t *http, /* I - Connection to server (unused) */
2964 - void *user_data) /* I - User data (unused) */
2974 - return (!job_canceled);
2976 + _cupsLangPrintf(stderr, _("ERROR: Unable to fork pictwpstops: %s\n"),
2985 - * 'update_reasons()' - Update the printer-state-reasons values.
2989 -update_reasons(ipp_attribute_t *attr, /* I - printer-state-reasons or NULL */
2990 - const char *s) /* I - STATE: string or NULL */
2992 - char op; /* Add (+), remove (-), replace (\0) */
2993 - cups_array_t *new_reasons; /* New reasons array */
2994 - char *reason, /* Current reason */
2995 - add[2048], /* Reasons added string */
2996 - *addptr, /* Pointer into add string */
2997 - rem[2048], /* Reasons removed string */
2998 - *remptr; /* Pointer into remove string */
2999 - const char *addprefix, /* Current add string prefix */
3000 - *remprefix; /* Current remove string prefix */
3003 - fprintf(stderr, "DEBUG: update_reasons(attr=%d(%s%s), s=\"%s\")\n",
3004 - attr ? attr->num_values : 0, attr ? attr->values[0].string.text : "",
3005 - attr && attr->num_values > 1 ? ",..." : "", s ? s : "(null)");
3008 - * Create an array of new reason keyword strings...
3009 + * Now wait for the filter to complete...
3013 + if (wait(&status) < 0)
3015 - int i; /* Looping var */
3016 + _cupsLangPrintf(stderr, _("ERROR: Unable to wait for pictwpstops: %s\n"),
3024 - new_reasons = cupsArrayNew((cups_array_func_t)strcmp, NULL);
3029 - for (i = 0; i < attr->num_values; i ++)
3031 - reason = attr->values[i].string.text;
3034 - if (strcmp(reason, "none") &&
3035 - strcmp(reason, "none-report") &&
3036 - strcmp(reason, "paused") &&
3037 - strncmp(reason, "spool-area-full", 15) &&
3038 - strcmp(reason, "com.apple.print.recoverable-warning") &&
3039 - strncmp(reason, "cups-", 5))
3040 - cupsArrayAdd(new_reasons, reason);
3046 - if (*s == '+' || *s == '-')
3048 + if (status >= 256)
3049 + _cupsLangPrintf(stderr, _("ERROR: pictwpstops exited with status %d!\n"),
3053 + _cupsLangPrintf(stderr, _("ERROR: pictwpstops exited on signal %d!\n"),
3056 - new_reasons = _cupsArrayNewStrings(s);
3063 - * Compute the changes...
3064 + * Return with no errors..
3068 - addprefix = "STATE: +";
3071 - remprefix = "STATE: -";
3075 +#endif /* __APPLE__ */
3077 - fprintf(stderr, "DEBUG2: op='%c', new_reasons=%d, state_reasons=%d\n",
3078 - op ? op : ' ', cupsArrayCount(new_reasons),
3079 - cupsArrayCount(state_reasons));
3081 - _cupsMutexLock(&report_mutex);
3083 + * 'sigterm_handler()' - Handle 'terminate' signals that stop the backend.
3092 +sigterm_handler(int sig) /* I - Signal */
3094 + (void)sig; /* remove compiler warnings... */
3096 - for (reason = (char *)cupsArrayFirst(new_reasons);
3098 - reason = (char *)cupsArrayNext(new_reasons))
3100 - if (!cupsArrayFind(state_reasons, reason))
3102 - if (!strncmp(reason, "cups-remote-", 12))
3105 - * If we are setting cups-remote-xxx, remove all other cups-remote-xxx
3109 - char *temp; /* Current reason in state_reasons */
3111 - cupsArraySave(state_reasons);
3113 - for (temp = (char *)cupsArrayFirst(state_reasons);
3115 - temp = (char *)cupsArrayNext(state_reasons))
3116 - if (!strncmp(temp, "cups-remote-", 12))
3118 - snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
3120 - remptr += strlen(remptr);
3123 - cupsArrayRemove(state_reasons, temp);
3127 - cupsArrayRestore(state_reasons);
3130 - cupsArrayAdd(state_reasons, reason);
3132 - snprintf(addptr, sizeof(add) - (addptr - add), "%s%s", addprefix,
3134 - addptr += strlen(addptr);
3139 - else if (op == '-')
3140 + if (!job_cancelled)
3143 - * Remove reasons...
3144 + * Flag that the job should be cancelled...
3147 - for (reason = (char *)cupsArrayFirst(new_reasons);
3149 - reason = (char *)cupsArrayNext(new_reasons))
3151 - if (cupsArrayFind(state_reasons, reason))
3153 - snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
3155 - remptr += strlen(remptr);
3158 - cupsArrayRemove(state_reasons, reason);
3161 + job_cancelled = 1;
3167 - * Replace reasons...
3170 - for (reason = (char *)cupsArrayFirst(state_reasons);
3172 - reason = (char *)cupsArrayNext(state_reasons))
3174 - if (strncmp(reason, "cups-", 5) && !cupsArrayFind(new_reasons, reason))
3176 - snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
3178 - remptr += strlen(remptr);
3181 + * The scheduler already tried to cancel us once, now just terminate
3182 + * after removing our temp files!
3185 - cupsArrayRemove(state_reasons, reason);
3188 + if (tmpfilename[0])
3189 + unlink(tmpfilename);
3191 - for (reason = (char *)cupsArrayFirst(new_reasons);
3193 - reason = (char *)cupsArrayNext(new_reasons))
3195 - if (!cupsArrayFind(state_reasons, reason))
3197 - cupsArrayAdd(state_reasons, reason);
3200 + unlink(pstmpname);
3201 +#endif /* __APPLE__ */
3203 - snprintf(addptr, sizeof(add) - (addptr - add), "%s%s", addprefix,
3205 - addptr += strlen(addptr);
3213 - _cupsMutexUnlock(&report_mutex);
3216 - * Report changes and return...
3219 - if (add[0] && rem[0])
3220 - fprintf(stderr, "%s\n%s\n", add, rem);
3222 - fprintf(stderr, "%s\n", add);
3224 - fprintf(stderr, "%s\n", rem);