]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
c0e1af83 | 2 | * "$Id: scsi.c 6411 2007-03-28 23:02:51Z mike $" |
ef416fc2 | 3 | * |
4 | * SCSI printer backend for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 2003-2006 by Easy Software Products, all rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or | |
9 | * without modification, are permitted provided that the | |
10 | * following conditions are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain the above | |
13 | * copyright notice, this list of conditions and the | |
14 | * following disclaimer. | |
15 | * | |
16 | * 2. Redistributions in binary form must reproduce the | |
17 | * above copyright notice, this list of conditions and | |
18 | * the following disclaimer in the documentation and/or | |
19 | * other materials provided with the distribution. | |
20 | * | |
21 | * 3. All advertising materials mentioning features or use | |
22 | * of this software must display the following | |
23 | * acknowledgement: | |
24 | * | |
25 | * This product includes software developed by Easy | |
26 | * Software Products. | |
27 | * | |
28 | * 4. The name of Easy Software Products may not be used to | |
29 | * endorse or promote products derived from this software | |
30 | * without specific prior written permission. | |
31 | * | |
32 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS | |
33 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
34 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
35 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
36 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS | |
37 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
40 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
41 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
42 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | |
43 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
44 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | |
45 | * DAMAGE. | |
46 | * | |
47 | * Contents: | |
48 | * | |
49 | * main() - Send a file to the specified SCSI printer. | |
50 | */ | |
51 | ||
52 | /* | |
53 | * Include necessary headers. | |
54 | */ | |
55 | ||
56 | #include <cups/backend.h> | |
57 | #include <cups/cups.h> | |
58 | #include <stdio.h> | |
59 | #include <stdlib.h> | |
60 | #include <errno.h> | |
61 | #include <cups/string.h> | |
c0e1af83 | 62 | #include <cups/i18n.h> |
ef416fc2 | 63 | #include <signal.h> |
64 | ||
65 | #ifdef WIN32 | |
66 | # include <io.h> | |
67 | #else | |
68 | # include <unistd.h> | |
69 | # include <fcntl.h> | |
70 | # ifdef HAVE_SYS_IOCTL_H | |
71 | # include <sys/ioctl.h> | |
72 | # endif /* HAVE_SYS_IOCTL_H */ | |
73 | #endif /* WIN32 */ | |
74 | ||
75 | ||
76 | /* | |
77 | * Local functions... | |
78 | */ | |
79 | ||
80 | void list_devices(void); | |
81 | int print_device(const char *resource, int fd, int copies); | |
82 | ||
83 | ||
2abf387c | 84 | #if defined(__linux__) && defined(HAVE_SCSI_SG_H) |
ef416fc2 | 85 | # include "scsi-linux.c" |
86 | #elif defined(__sgi) | |
87 | # include "scsi-irix.c" | |
88 | #else | |
89 | /* | |
90 | * Dummy functions that do nothing on unsupported platforms... | |
91 | */ | |
92 | void list_devices(void) {} | |
93 | int print_device(const char *resource, int fd, int copies) { return (CUPS_BACKEND_FAILED); } | |
2abf387c | 94 | #endif /* __linux && HAVE_SCSI_SG_H */ |
ef416fc2 | 95 | |
96 | ||
97 | /* | |
98 | * 'main()' - Send a file to the specified SCSI printer. | |
99 | * | |
100 | * Usage: | |
101 | * | |
102 | * printer-uri job-id user title copies options [file] | |
103 | */ | |
104 | ||
105 | int /* O - Exit status */ | |
106 | main(int argc, /* I - Number of command-line arguments (6 or 7) */ | |
107 | char *argv[]) /* I - Command-line arguments */ | |
108 | { | |
109 | char method[255], /* Method in URI */ | |
110 | hostname[1024], /* Hostname */ | |
111 | username[255], /* Username info (not used) */ | |
112 | resource[1024], /* Resource info (device and options) */ | |
113 | *options; /* Pointer to options */ | |
114 | int port; /* Port number (not used) */ | |
115 | int fp; /* Print file */ | |
116 | int copies; /* Number of copies to print */ | |
117 | int status; /* Exit status */ | |
118 | #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) | |
119 | struct sigaction action; /* Actions for POSIX signals */ | |
120 | #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ | |
121 | ||
122 | ||
123 | /* | |
124 | * Make sure status messages are not buffered... | |
125 | */ | |
126 | ||
127 | setbuf(stderr, NULL); | |
128 | ||
129 | /* | |
130 | * Ignore SIGPIPE signals... | |
131 | */ | |
132 | ||
133 | #ifdef HAVE_SIGSET | |
134 | sigset(SIGPIPE, SIG_IGN); | |
135 | #elif defined(HAVE_SIGACTION) | |
136 | memset(&action, 0, sizeof(action)); | |
137 | action.sa_handler = SIG_IGN; | |
138 | sigaction(SIGPIPE, &action, NULL); | |
139 | #else | |
140 | signal(SIGPIPE, SIG_IGN); | |
141 | #endif /* HAVE_SIGSET */ | |
142 | ||
143 | /* | |
144 | * Check command-line... | |
145 | */ | |
146 | ||
147 | if (argc == 1) | |
148 | { | |
149 | list_devices(); | |
150 | return (CUPS_BACKEND_OK); | |
151 | } | |
152 | else if (argc < 6 || argc > 7) | |
153 | { | |
c0e1af83 | 154 | fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"), |
155 | argv[0]); | |
ef416fc2 | 156 | return (CUPS_BACKEND_FAILED); |
157 | } | |
158 | ||
159 | /* | |
160 | * If we have 7 arguments, print the file named on the command-line. | |
161 | * Otherwise, send stdin instead... | |
162 | */ | |
163 | ||
164 | if (argc == 6) | |
165 | { | |
166 | fp = 0; | |
167 | copies = 1; | |
168 | } | |
169 | else | |
170 | { | |
171 | /* | |
172 | * Try to open the print file... | |
173 | */ | |
174 | ||
175 | if ((fp = open(argv[6], O_RDONLY)) < 0) | |
176 | { | |
177 | perror("ERROR: unable to open print file"); | |
178 | return (CUPS_BACKEND_FAILED); | |
179 | } | |
180 | ||
181 | copies = atoi(argv[4]); | |
182 | } | |
183 | ||
184 | /* | |
185 | * Extract the device name and options from the URI... | |
186 | */ | |
187 | ||
a4d04587 | 188 | httpSeparateURI(HTTP_URI_CODING_ALL, cupsBackendDeviceURI(argv), |
189 | method, sizeof(method), username, sizeof(username), | |
190 | hostname, sizeof(hostname), &port, | |
ef416fc2 | 191 | resource, sizeof(resource)); |
192 | ||
193 | /* | |
194 | * See if there are any options... | |
195 | */ | |
196 | ||
197 | if ((options = strchr(resource, '?')) != NULL) | |
198 | { | |
199 | /* | |
200 | * Yup, terminate the device name string and move to the first | |
201 | * character of the options... | |
202 | */ | |
203 | ||
204 | *options++ = '\0'; | |
205 | } | |
206 | ||
207 | /* | |
208 | * Finally, send the print file... | |
209 | */ | |
210 | ||
211 | status = print_device(resource, fp, copies); | |
212 | ||
213 | /* | |
214 | * Close input file and return... | |
215 | */ | |
216 | ||
217 | if (fp != 0) | |
218 | close(fp); | |
219 | ||
220 | return (status); | |
221 | } | |
222 | ||
223 | ||
224 | /* | |
c0e1af83 | 225 | * End of "$Id: scsi.c 6411 2007-03-28 23:02:51Z mike $". |
ef416fc2 | 226 | */ |