2 * "$Id: ipp.c,v 1.38.2.19 2003/01/23 19:25:29 mike Exp $"
4 * IPP backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Send a file to the printer or server.
29 * password_cb() - Disable the password prompt for
30 * cupsDoFileRequest().
31 * report_printer_state() - Report the printer state.
35 * Include necessary headers.
41 #include <sys/types.h>
43 #include <cups/cups.h>
44 #include <cups/language.h>
45 #include <cups/string.h>
53 const char *password_cb(const char *);
54 int report_printer_state(ipp_t
*ipp
);
57 int run_pictwps_filter(char **argv
, char *filename
, int length
);
58 #endif /* __APPLE__ */
65 char *password
= NULL
;
69 * 'main()' - Send a file to the printer or server.
73 * printer-uri job-id user title copies options [file]
76 int /* O - Exit status */
77 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
78 char *argv
[]) /* I - Command-line arguments */
80 int i
; /* Looping var */
81 int num_options
; /* Number of printer options */
82 cups_option_t
*options
; /* Printer options */
83 char method
[255], /* Method in URI */
84 hostname
[1024], /* Hostname */
85 username
[255], /* Username info */
86 resource
[1024], /* Resource info (printer name) */
87 filename
[1024]; /* File to print */
88 int port
; /* Port number (not used) */
89 char uri
[HTTP_MAX_URI
];/* Updated URI without user/pass */
90 ipp_status_t ipp_status
; /* Status of IPP request */
91 http_t
*http
; /* HTTP connection */
92 ipp_t
*request
, /* IPP request */
93 *response
, /* IPP response */
94 *supported
; /* get-printer-attributes response */
95 ipp_attribute_t
*job_id_attr
; /* job-id attribute */
96 int job_id
; /* job-id value */
97 ipp_attribute_t
*job_state
; /* job-state attribute */
98 ipp_attribute_t
*copies_sup
; /* copies-supported attribute */
99 ipp_attribute_t
*charset_sup
; /* charset-supported attribute */
100 ipp_attribute_t
*format_sup
; /* document-format-supported attribute */
101 ipp_attribute_t
*printer_state
;
102 /* printer-state attribute */
103 ipp_attribute_t
*printer_accepting
;
104 /* printer-is-accepting-jobs attribute */
105 const char *charset
; /* Character set to use */
106 cups_lang_t
*language
; /* Default language */
107 int copies
; /* Number of copies remaining */
108 const char *content_type
; /* CONTENT_TYPE environment variable */
109 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
110 struct sigaction action
; /* Actions for POSIX signals */
111 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
112 int version
; /* IPP version */
113 int reasons
; /* Number of printer-state-reasons shown */
117 * Make sure status messages are not buffered...
120 setbuf(stderr
, NULL
);
123 * Ignore SIGPIPE signals...
127 sigset(SIGPIPE
, SIG_IGN
);
128 #elif defined(HAVE_SIGACTION)
129 memset(&action
, 0, sizeof(action
));
130 action
.sa_handler
= SIG_IGN
;
131 sigaction(SIGPIPE
, &action
, NULL
);
133 signal(SIGPIPE
, SIG_IGN
);
134 #endif /* HAVE_SIGSET */
137 * Check command-line...
144 if ((s
= strrchr(argv
[0], '/')) != NULL
)
149 printf("network %s \"Unknown\" \"Internet Printing Protocol (%s)\"\n", s
, s
);
152 else if (argc
< 6 || argc
> 7)
154 fprintf(stderr
, "Usage: %s job-id user title copies options [file]\n",
160 * Get the content type...
164 content_type
= getenv("CONTENT_TYPE");
166 content_type
= "application/vnd.cups-raw";
168 if (content_type
== NULL
)
169 content_type
= "application/octet-stream";
172 * If we have 7 arguments, print the file named on the command-line.
173 * Otherwise, copy stdin to a temporary file and print the temporary
180 * Copy stdin to a temporary file...
183 int fd
; /* Temporary file */
184 char buffer
[8192]; /* Buffer for copying */
185 int bytes
; /* Number of bytes read */
188 if ((fd
= cupsTempFd(filename
, sizeof(filename
))) < 0)
190 perror("ERROR: unable to create temporary file");
194 while ((bytes
= fread(buffer
, 1, sizeof(buffer
), stdin
)) > 0)
195 if (write(fd
, buffer
, bytes
) < bytes
)
197 perror("ERROR: unable to write to temporary file");
206 else if (strcasecmp(content_type
, "application/pictwps") == 0)
209 * Convert to PostScript...
212 if (run_pictwps_filter(argv
, filename
, sizeof(filename
)))
216 * Change the MIME type to application/vnd.cups-postscript...
219 content_type
= "application/vnd.cups-postscript";
221 #endif /* __APPLE__ */
223 strlcpy(filename
, argv
[6], sizeof(filename
));
226 * Extract the hostname and printer name from the URI...
229 httpSeparate(argv
[0], method
, username
, hostname
, &port
, resource
);
232 * Set the authentication info, if any...
235 cupsSetPasswordCB(password_cb
);
239 if ((password
= strchr(username
, ':')) != NULL
)
242 cupsSetUser(username
);
246 * Try connecting to the remote server...
251 fprintf(stderr
, "INFO: Connecting to %s on port %d...\n", hostname
, port
);
253 if ((http
= httpConnectEncrypt(hostname
, port
, cupsEncryption())) == NULL
)
255 if (getenv("CLASS") != NULL
)
258 * If the CLASS environment variable is set, the job was submitted
259 * to a class and not to a specific queue. In this case, we want
260 * to abort immediately so that the job can be requeued on the next
261 * available printer in the class.
264 fprintf(stderr
, "INFO: Unable to queue job on %s, queuing on next printer in class...\n",
267 if (argc
== 6 || strcmp(filename
, argv
[6]))
271 * Sleep 5 seconds to keep the job from requeuing too rapidly...
279 if (errno
== ECONNREFUSED
|| errno
== EHOSTDOWN
||
280 errno
== EHOSTUNREACH
)
282 fprintf(stderr
, "INFO: Network host \'%s\' is busy; will retry in 30 seconds...",
288 fprintf(stderr
, "INFO: Unable to lookup host \'%s\' - %s\n",
289 hostname
, hstrerror(h_errno
));
294 perror("ERROR: Unable to connect to IPP host");
299 while (http
== NULL
);
301 fprintf(stderr
, "INFO: Connected to %s...\n", hostname
);
304 * Build a URI for the printer and fill the standard IPP attributes for
305 * an IPP_PRINT_FILE request. We can't use the URI in argv[0] because it
306 * might contain username:password information...
309 snprintf(uri
, sizeof(uri
), "%s://%s:%d%s", method
, hostname
, port
, resource
);
312 * First validate the destination and see if the device supports multiple
313 * copies. We have to do this because some IPP servers (e.g. HP JetDirect)
314 * don't support the copies attribute...
317 language
= cupsLangDefault();
327 * Build the IPP request...
331 request
->request
.op
.version
[1] = version
;
332 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
333 request
->request
.op
.request_id
= 1;
335 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
336 "attributes-charset", NULL
, "utf-8");
338 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
339 "attributes-natural-language", NULL
,
340 language
!= NULL
? language
->language
: "en");
342 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
349 fputs("DEBUG: Getting supported attributes...\n", stderr
);
351 if ((supported
= cupsDoRequest(http
, request
, resource
)) == NULL
)
352 ipp_status
= cupsLastError();
354 ipp_status
= supported
->request
.status
.status_code
;
356 if (ipp_status
> IPP_OK_CONFLICT
)
358 if (ipp_status
== IPP_PRINTER_BUSY
||
359 ipp_status
== IPP_SERVICE_UNAVAILABLE
)
361 fputs("INFO: Printer busy; will retry in 10 seconds...\n", stderr
);
362 report_printer_state(supported
);
365 else if ((ipp_status
== IPP_BAD_REQUEST
||
366 ipp_status
== IPP_VERSION_NOT_SUPPORTED
) && version
== 1)
369 * Switch to IPP/1.0...
372 fputs("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n", stderr
);
377 fprintf(stderr
, "ERROR: Unable to get printer status (%s)!\n",
378 ippErrorString(ipp_status
));
381 ippDelete(supported
);
385 else if ((copies_sup
= ippFindAttribute(supported
, "copies-supported",
386 IPP_TAG_RANGE
)) != NULL
)
389 * Has the "copies-supported" attribute - does it have an upper
393 if (copies_sup
->values
[0].range
.upper
<= 1)
394 copies_sup
= NULL
; /* No */
397 charset_sup
= ippFindAttribute(supported
, "charset-supported",
399 format_sup
= ippFindAttribute(supported
, "document-format-supported",
404 fprintf(stderr
, "DEBUG: document-format-supported (%d values)\n",
405 format_sup
->num_values
);
406 for (i
= 0; i
< format_sup
->num_values
; i
++)
407 fprintf(stderr
, "DEBUG: [%d] = \"%s\"\n", i
,
408 format_sup
->values
[i
].string
.text
);
411 report_printer_state(supported
);
413 while (ipp_status
> IPP_OK_CONFLICT
);
416 * See if the printer is accepting jobs and is not stopped; if either
417 * condition is true and we are printing to a class, requeue the job...
420 if (getenv("CLASS") != NULL
)
422 printer_state
= ippFindAttribute(supported
, "printer-state",
424 printer_accepting
= ippFindAttribute(supported
, "printer-is-accepting-jobs",
427 if (printer_state
== NULL
||
428 printer_state
->values
[0].integer
> IPP_PRINTER_PROCESSING
||
429 printer_accepting
== NULL
||
430 !printer_accepting
->values
[0].boolean
)
433 * If the CLASS environment variable is set, the job was submitted
434 * to a class and not to a specific queue. In this case, we want
435 * to abort immediately so that the job can be requeued on the next
436 * available printer in the class.
439 fprintf(stderr
, "INFO: Unable to queue job on %s, queuing on next printer in class...\n",
442 ippDelete(supported
);
445 if (argc
== 6 || strcmp(filename
, argv
[6]))
449 * Sleep 5 seconds to keep the job from requeuing too rapidly...
459 * Now that we are "connected" to the port, ignore SIGTERM so that we
460 * can finish out any page data the driver sends (e.g. to eject the
461 * current page... Only ignore SIGTERM if we are printing data from
462 * stdin (otherwise you can't cancel raw jobs...)
467 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
468 sigset(SIGTERM
, SIG_IGN
);
469 #elif defined(HAVE_SIGACTION)
470 memset(&action
, 0, sizeof(action
));
472 sigemptyset(&action
.sa_mask
);
473 action
.sa_handler
= SIG_IGN
;
474 sigaction(SIGTERM
, &action
, NULL
);
476 signal(SIGTERM
, SIG_IGN
);
477 #endif /* HAVE_SIGSET */
481 * See if the printer supports multiple copies...
484 if (copies_sup
|| argc
< 7)
487 copies
= atoi(argv
[4]);
490 * Figure out the character set to use...
493 charset
= language
? cupsLangEncoding(language
) : "us-ascii";
498 * See if IPP server supports the requested character set...
501 for (i
= 0; i
< charset_sup
->num_values
; i
++)
502 if (strcasecmp(charset
, charset_sup
->values
[i
].string
.text
) == 0)
506 * If not, choose us-ascii or utf-8...
509 if (i
>= charset_sup
->num_values
)
512 * See if us-ascii is supported...
515 for (i
= 0; i
< charset_sup
->num_values
; i
++)
516 if (strcasecmp("us-ascii", charset_sup
->values
[i
].string
.text
) == 0)
519 if (i
< charset_sup
->num_values
)
520 charset
= "us-ascii";
527 * Then issue the print-job request...
535 * Build the IPP request...
539 request
->request
.op
.version
[1] = version
;
540 request
->request
.op
.operation_id
= IPP_PRINT_JOB
;
541 request
->request
.op
.request_id
= 1;
543 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
544 "attributes-charset", NULL
, charset
);
546 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
547 "attributes-natural-language", NULL
,
548 language
!= NULL
? language
->language
: "en");
550 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
553 fprintf(stderr
, "DEBUG: printer-uri = \"%s\"\n", uri
);
556 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
559 fprintf(stderr
, "DEBUG: requesting-user-name = \"%s\"\n", argv
[2]);
562 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "job-name", NULL
,
565 fprintf(stderr
, "DEBUG: job-name = \"%s\"\n", argv
[3]);
568 * Handle options on the command-line...
572 num_options
= cupsParseOptions(argv
[5], 0, &options
);
574 if (content_type
!= NULL
&& format_sup
!= NULL
)
576 for (i
= 0; i
< format_sup
->num_values
; i
++)
577 if (strcasecmp(content_type
, format_sup
->values
[i
].string
.text
) == 0)
580 if (i
< format_sup
->num_values
)
581 num_options
= cupsAddOption("document-format", content_type
,
582 num_options
, &options
);
588 * Only send options if the destination printer supports the copies
589 * attribute. This is a hack for the HP JetDirect implementation of
590 * IPP, which does not accept extension attributes and incorrectly
591 * reports a client-error-bad-request error instead of the
592 * successful-ok-unsupported-attributes status. In short, at least
593 * some HP implementations of IPP are non-compliant.
596 cupsEncodeOptions(request
, num_options
, options
);
597 ippAddInteger(request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "copies",
601 cupsFreeOptions(num_options
, options
);
604 * If copies aren't supported, then we are likely dealing with an HP
605 * JetDirect. The HP IPP implementation seems to close the connection
606 * after every request (that is, it does *not* implement HTTP Keep-
607 * Alive, which is REQUIRED by HTTP/1.1...
617 if ((response
= cupsDoFileRequest(http
, request
, resource
, filename
)) == NULL
)
618 ipp_status
= cupsLastError();
620 ipp_status
= response
->request
.status
.status_code
;
622 if (ipp_status
> IPP_OK_CONFLICT
)
626 if (ipp_status
== IPP_SERVICE_UNAVAILABLE
||
627 ipp_status
== IPP_PRINTER_BUSY
)
629 fputs("INFO: Printer is busy; retrying print job...\n", stderr
);
633 fprintf(stderr
, "ERROR: Print file was not accepted (%s)!\n",
634 ippErrorString(ipp_status
));
636 else if ((job_id_attr
= ippFindAttribute(response
, "job-id",
637 IPP_TAG_INTEGER
)) == NULL
)
639 fputs("INFO: Print file accepted - job ID unknown.\n", stderr
);
644 job_id
= job_id_attr
->values
[0].integer
;
645 fprintf(stderr
, "INFO: Print file accepted - job ID %d.\n", job_id
);
651 if (ipp_status
<= IPP_OK_CONFLICT
&& argc
> 6)
653 fprintf(stderr
, "PAGE: 1 %d\n", copies_sup
? atoi(argv
[4]) : 1);
656 else if (ipp_status
!= IPP_SERVICE_UNAVAILABLE
&&
657 ipp_status
!= IPP_PRINTER_BUSY
)
661 * Wait for the job to complete...
667 fputs("INFO: Waiting for job to complete...\n", stderr
);
672 * Build an IPP_GET_JOB_ATTRIBUTES request...
676 request
->request
.op
.version
[1] = version
;
677 request
->request
.op
.operation_id
= IPP_GET_JOB_ATTRIBUTES
;
678 request
->request
.op
.request_id
= 1;
680 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
681 "attributes-charset", NULL
, charset
);
683 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
684 "attributes-natural-language", NULL
,
685 language
!= NULL
? language
->language
: "en");
687 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
690 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id",
694 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
697 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
698 "requested-attributes", NULL
, "job-state");
707 if ((response
= cupsDoRequest(http
, request
, resource
)) == NULL
)
708 ipp_status
= cupsLastError();
710 ipp_status
= response
->request
.status
.status_code
;
712 if (ipp_status
== IPP_NOT_FOUND
)
715 * Job has gone away and/or the server has no job history...
724 if (ipp_status
> IPP_OK_CONFLICT
)
726 if (ipp_status
!= IPP_SERVICE_UNAVAILABLE
&&
727 ipp_status
!= IPP_PRINTER_BUSY
)
732 fprintf(stderr
, "ERROR: Unable to get job %d attributes (%s)!\n",
733 job_id
, ippErrorString(ipp_status
));
737 else if ((job_state
= ippFindAttribute(response
, "job-state", IPP_TAG_ENUM
)) != NULL
)
740 * Stop polling if the job is finished or pending-held...
743 if (job_state
->values
[0].integer
> IPP_JOB_PROCESSING
||
744 job_state
->values
[0].integer
== IPP_JOB_HELD
)
755 * Now check on the printer state...
759 request
->request
.op
.version
[1] = version
;
760 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
761 request
->request
.op
.request_id
= 1;
763 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
764 "attributes-charset", NULL
, charset
);
766 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
767 "attributes-natural-language", NULL
,
768 language
!= NULL
? language
->language
: "en");
770 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
774 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
777 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
778 "requested-attributes", NULL
, "printer-state-reasons");
787 if ((response
= cupsDoRequest(http
, request
, resource
)) != NULL
)
789 reasons
= report_printer_state(response
);
794 * Wait 10 seconds before polling again...
808 ippDelete(supported
);
811 * Close and remove the temporary file if necessary...
814 if (argc
== 6 || strcmp(filename
, argv
[6]))
818 * Return the queue status...
821 if (ipp_status
<= IPP_OK_CONFLICT
&& reasons
== 0)
822 fputs("INFO: Ready to print.\n", stderr
);
824 return (ipp_status
> IPP_OK_CONFLICT
);
829 * 'password_cb()' - Disable the password prompt for cupsDoFileRequest().
832 const char * /* O - Password */
833 password_cb(const char *prompt
) /* I - Prompt (not used) */
842 * 'report_printer_state()' - Report the printer state.
845 int /* O - Number of reasons shown */
846 report_printer_state(ipp_t
*ipp
) /* I - IPP response */
848 int i
; /* Looping var */
849 int count
; /* Count of reasons shown... */
850 ipp_attribute_t
*reasons
; /* printer-state-reasons */
851 const char *message
; /* Message to show */
852 char unknown
[1024]; /* Unknown message string */
855 if ((reasons
= ippFindAttribute(ipp
, "printer-state-reasons",
856 IPP_TAG_KEYWORD
)) == NULL
)
859 for (i
= 0, count
= 0; i
< reasons
->num_values
; i
++)
863 if (strncmp(reasons
->values
[i
].string
.text
, "media-needed", 12) == 0)
864 message
= "Media tray needs to be filled.";
865 else if (strncmp(reasons
->values
[i
].string
.text
, "media-jam", 9) == 0)
866 message
= "Media jam!";
867 else if (strncmp(reasons
->values
[i
].string
.text
, "moving-to-paused", 16) == 0 ||
868 strncmp(reasons
->values
[i
].string
.text
, "paused", 6) == 0 ||
869 strncmp(reasons
->values
[i
].string
.text
, "shutdown", 8) == 0)
870 message
= "Printer off-line.";
871 else if (strncmp(reasons
->values
[i
].string
.text
, "toner-low", 9) == 0)
872 message
= "Toner low.";
873 else if (strncmp(reasons
->values
[i
].string
.text
, "toner-empty", 11) == 0)
874 message
= "Out of toner!";
875 else if (strncmp(reasons
->values
[i
].string
.text
, "cover-open", 10) == 0)
876 message
= "Cover open.";
877 else if (strncmp(reasons
->values
[i
].string
.text
, "interlock-open", 14) == 0)
878 message
= "Interlock open.";
879 else if (strncmp(reasons
->values
[i
].string
.text
, "door-open", 9) == 0)
880 message
= "Door open.";
881 else if (strncmp(reasons
->values
[i
].string
.text
, "input-tray-missing", 18) == 0)
882 message
= "Media tray missing!";
883 else if (strncmp(reasons
->values
[i
].string
.text
, "media-low", 9) == 0)
884 message
= "Media tray almost empty.";
885 else if (strncmp(reasons
->values
[i
].string
.text
, "media-empty", 11) == 0)
886 message
= "Media tray empty!";
887 else if (strncmp(reasons
->values
[i
].string
.text
, "output-tray-missing", 19) == 0)
888 message
= "Output tray missing!";
889 else if (strncmp(reasons
->values
[i
].string
.text
, "output-area-almost-full", 23) == 0)
890 message
= "Output bin almost full.";
891 else if (strncmp(reasons
->values
[i
].string
.text
, "output-area-full", 16) == 0)
892 message
= "Output bin full!";
893 else if (strncmp(reasons
->values
[i
].string
.text
, "marker-supply-low", 17) == 0)
894 message
= "Ink/toner almost empty.";
895 else if (strncmp(reasons
->values
[i
].string
.text
, "marker-supply-empty", 19) == 0)
896 message
= "Ink/toner empty!";
897 else if (strncmp(reasons
->values
[i
].string
.text
, "marker-waste-almost-full", 24) == 0)
898 message
= "Ink/toner waste bin almost full.";
899 else if (strncmp(reasons
->values
[i
].string
.text
, "marker-waste-full", 17) == 0)
900 message
= "Ink/toner waste bin full!";
901 else if (strncmp(reasons
->values
[i
].string
.text
, "fuser-over-temp", 15) == 0)
902 message
= "Fuser temperature high!";
903 else if (strncmp(reasons
->values
[i
].string
.text
, "fuser-under-temp", 16) == 0)
904 message
= "Fuser temperature low!";
905 else if (strncmp(reasons
->values
[i
].string
.text
, "opc-near-eol", 12) == 0)
906 message
= "OPC almost at end-of-life.";
907 else if (strncmp(reasons
->values
[i
].string
.text
, "opc-life-over", 13) == 0)
908 message
= "OPC at end-of-life!";
909 else if (strncmp(reasons
->values
[i
].string
.text
, "developer-low", 13) == 0)
910 message
= "Developer almost empty.";
911 else if (strncmp(reasons
->values
[i
].string
.text
, "developer-empty", 15) == 0)
912 message
= "Developer empty!";
913 else if (strstr(reasons
->values
[i
].string
.text
, "error") != NULL
)
917 snprintf(unknown
, sizeof(unknown
), "Unknown printer error (%s)!",
918 reasons
->values
[i
].string
.text
);
924 if (strstr(reasons
->values
[i
].string
.text
, "error"))
925 fprintf(stderr
, "ERROR: %s\n", message
);
926 else if (strstr(reasons
->values
[i
].string
.text
, "warning"))
927 fprintf(stderr
, "WARNING: %s\n", message
);
929 fprintf(stderr
, "INFO: %s\n", message
);
939 * 'run_pictwps_filter()' - Convert PICT files to PostScript when printing
942 * This step is required because the PICT format is not documented and
943 * subject to change, so developing a filter for other OS's is infeasible.
944 * Also, fonts required by the PICT file need to be embedded on the
945 * client side (which has the fonts), so we run the filter to get a
946 * PostScript file for printing...
949 int /* O - Exit status of filter */
950 run_pictwps_filter(char **argv
, /* I - Command-line arguments */
951 char *filename
, /* I - Filename buffer */
952 int length
) /* I - Size of filename buffer */
954 struct stat fileinfo
; /* Print file information */
955 const char *ppdfile
; /* PPD file for destination printer */
956 int pid
; /* Child process ID */
957 int fd
; /* Temporary file descriptor */
958 int status
; /* Exit status of filter */
959 const char *printer
; /* PRINTER env var */
960 static char ppdenv
[1024]; /* PPD environment variable */
964 * First get the PPD file for the printer...
967 printer
= getenv("PRINTER");
970 fputs("ERROR: PRINTER environment variable not defined!\n", stderr
);
974 if ((ppdfile
= cupsGetPPD(printer
)) == NULL
)
976 fprintf(stderr
, "ERROR: Unable to get PPD file for printer \"%s\" - %s.\n",
977 printer
, ippErrorString(cupsLastError()));
981 snprintf(ppdenv
, sizeof(ppdenv
), "PPD=%s", ppdfile
);
985 * Then create a temporary file for printing...
988 if ((fd
= cupsTempFd(filename
, length
)) < 0)
990 fprintf(stderr
, "ERROR: Unable to create temporary file - %s.\n",
991 printer
, strerror(errno
));
996 * Get the owner of the spool file - it is owned by the user we want to run
1000 stat(argv
[6], &fileinfo
);
1003 * Finally, run the filter to convert the file...
1006 if ((pid
= fork()) == 0)
1009 * Child process for pictwpstops... Redirect output of pictwpstops to a
1020 * Change to an unpriviledged user...
1023 setgid(fileinfo
.st_gid
);
1024 setuid(fileinfo
.st_uid
);
1027 execlp("pictwpstops", printer
, argv
[1], argv
[2], argv
[3], argv
[4], argv
[5],
1029 perror("ERROR: Unable to exec pictwpstops");
1038 perror("ERROR: Unable to fork pictwpstops");
1045 * Now wait for the filter to complete...
1048 if (wait(&status
) < 0)
1050 perror("ERROR: Unable to wait for pictwpstops");
1061 fprintf(stderr
, "ERROR: pictwpstops exited with status %d!\n",
1064 fprintf(stderr
, "ERROR: pictwpstops exited on signal %d!\n",
1072 * Return with no errors..
1077 #endif /* __APPLE__ */
1081 * End of "$Id: ipp.c,v 1.38.2.19 2003/01/23 19:25:29 mike Exp $".