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