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