]> git.ipfire.org Git - thirdparty/cups.git/blame - backend/scsi.c
Load cups into easysw/current.
[thirdparty/cups.git] / backend / scsi.c
CommitLineData
ef416fc2 1/*
323c5de1 2 * "$Id: scsi.c 6432 2007-04-02 21:50:28Z 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>
323c5de1 58#include <cups/i18n.h>
ef416fc2 59#include <stdio.h>
60#include <stdlib.h>
61#include <errno.h>
62#include <cups/string.h>
c0e1af83 63#include <cups/i18n.h>
ef416fc2 64#include <signal.h>
65
66#ifdef WIN32
67# include <io.h>
68#else
69# include <unistd.h>
70# include <fcntl.h>
71# ifdef HAVE_SYS_IOCTL_H
72# include <sys/ioctl.h>
73# endif /* HAVE_SYS_IOCTL_H */
74#endif /* WIN32 */
75
76
77/*
78 * Local functions...
79 */
80
81void list_devices(void);
82int print_device(const char *resource, int fd, int copies);
83
84
2abf387c 85#if defined(__linux__) && defined(HAVE_SCSI_SG_H)
ef416fc2 86# include "scsi-linux.c"
87#elif defined(__sgi)
88# include "scsi-irix.c"
89#else
90/*
91 * Dummy functions that do nothing on unsupported platforms...
92 */
93void list_devices(void) {}
94int print_device(const char *resource, int fd, int copies) { return (CUPS_BACKEND_FAILED); }
2abf387c 95#endif /* __linux && HAVE_SCSI_SG_H */
ef416fc2 96
97
98/*
99 * 'main()' - Send a file to the specified SCSI printer.
100 *
101 * Usage:
102 *
103 * printer-uri job-id user title copies options [file]
104 */
105
106int /* O - Exit status */
107main(int argc, /* I - Number of command-line arguments (6 or 7) */
108 char *argv[]) /* I - Command-line arguments */
109{
110 char method[255], /* Method in URI */
111 hostname[1024], /* Hostname */
112 username[255], /* Username info (not used) */
113 resource[1024], /* Resource info (device and options) */
114 *options; /* Pointer to options */
115 int port; /* Port number (not used) */
116 int fp; /* Print file */
117 int copies; /* Number of copies to print */
118 int status; /* Exit status */
119#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
120 struct sigaction action; /* Actions for POSIX signals */
121#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
122
123
124 /*
125 * Make sure status messages are not buffered...
126 */
127
128 setbuf(stderr, NULL);
129
130 /*
131 * Ignore SIGPIPE signals...
132 */
133
134#ifdef HAVE_SIGSET
135 sigset(SIGPIPE, SIG_IGN);
136#elif defined(HAVE_SIGACTION)
137 memset(&action, 0, sizeof(action));
138 action.sa_handler = SIG_IGN;
139 sigaction(SIGPIPE, &action, NULL);
140#else
141 signal(SIGPIPE, SIG_IGN);
142#endif /* HAVE_SIGSET */
143
144 /*
145 * Check command-line...
146 */
147
148 if (argc == 1)
149 {
150 list_devices();
151 return (CUPS_BACKEND_OK);
152 }
153 else if (argc < 6 || argc > 7)
154 {
c0e1af83 155 fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
156 argv[0]);
ef416fc2 157 return (CUPS_BACKEND_FAILED);
158 }
159
160 /*
161 * If we have 7 arguments, print the file named on the command-line.
162 * Otherwise, send stdin instead...
163 */
164
165 if (argc == 6)
166 {
167 fp = 0;
168 copies = 1;
169 }
170 else
171 {
172 /*
173 * Try to open the print file...
174 */
175
176 if ((fp = open(argv[6], O_RDONLY)) < 0)
177 {
178 perror("ERROR: unable to open print file");
179 return (CUPS_BACKEND_FAILED);
180 }
181
182 copies = atoi(argv[4]);
183 }
184
185 /*
186 * Extract the device name and options from the URI...
187 */
188
a4d04587 189 httpSeparateURI(HTTP_URI_CODING_ALL, cupsBackendDeviceURI(argv),
190 method, sizeof(method), username, sizeof(username),
191 hostname, sizeof(hostname), &port,
ef416fc2 192 resource, sizeof(resource));
193
194 /*
195 * See if there are any options...
196 */
197
198 if ((options = strchr(resource, '?')) != NULL)
199 {
200 /*
201 * Yup, terminate the device name string and move to the first
202 * character of the options...
203 */
204
205 *options++ = '\0';
206 }
207
208 /*
209 * Finally, send the print file...
210 */
211
212 status = print_device(resource, fp, copies);
213
214 /*
215 * Close input file and return...
216 */
217
218 if (fp != 0)
219 close(fp);
220
221 return (status);
222}
223
224
225/*
323c5de1 226 * End of "$Id: scsi.c 6432 2007-04-02 21:50:28Z mike $".
ef416fc2 227 */