]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/scsi.c
2 * "$Id: scsi.c 7193 2008-01-07 23:01:40Z mike $"
4 * SCSI printer backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 2003-2006 by Easy Software Products, all rights reserved.
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the
11 * following conditions are met:
13 * 1. Redistributions of source code must retain the above
14 * copyright notice, this list of conditions and the
15 * following disclaimer.
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.
22 * 3. All advertising materials mentioning features or use
23 * of this software must display the following
26 * This product includes software developed by Easy
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.
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
50 * main() - Send a file to the specified SCSI printer.
54 * Include necessary headers.
57 #include <cups/backend.h>
58 #include <cups/cups.h>
59 #include <cups/i18n.h>
63 #include <cups/string.h>
64 #include <cups/i18n.h>
72 # ifdef HAVE_SYS_IOCTL_H
73 # include <sys/ioctl.h>
74 # endif /* HAVE_SYS_IOCTL_H */
82 void list_devices(void);
83 int print_device(const char *resource
, int fd
, int copies
);
86 #if defined(__linux__) && defined(HAVE_SCSI_SG_H)
87 # include "scsi-linux.c"
89 # include "scsi-irix.c"
92 * Dummy functions that do nothing on unsupported platforms...
94 void list_devices(void) {}
95 int print_device(const char *resource
, int fd
, int copies
) { return (CUPS_BACKEND_FAILED
); }
96 #endif /* __linux && HAVE_SCSI_SG_H */
100 * 'main()' - Send a file to the specified SCSI printer.
104 * printer-uri job-id user title copies options [file]
107 int /* O - Exit status */
108 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
109 char *argv
[]) /* I - Command-line arguments */
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 */
126 * Make sure status messages are not buffered...
129 setbuf(stderr
, NULL
);
132 * Ignore SIGPIPE signals...
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
);
142 signal(SIGPIPE
, SIG_IGN
);
143 #endif /* HAVE_SIGSET */
146 * Check command-line...
152 return (CUPS_BACKEND_OK
);
154 else if (argc
< 6 || argc
> 7)
156 _cupsLangPrintf(stderr
,
157 _("Usage: %s job-id user title copies options [file]\n"),
159 return (CUPS_BACKEND_FAILED
);
163 * If we have 7 arguments, print the file named on the command-line.
164 * Otherwise, send stdin instead...
175 * Try to open the print file...
178 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
180 _cupsLangPrintf(stderr
,
181 _("ERROR: Unable to open print file \"%s\": %s\n"),
182 argv
[6], strerror(errno
));
183 return (CUPS_BACKEND_FAILED
);
186 copies
= atoi(argv
[4]);
190 * Extract the device name and options from the URI...
193 httpSeparateURI(HTTP_URI_CODING_ALL
, cupsBackendDeviceURI(argv
),
194 method
, sizeof(method
), username
, sizeof(username
),
195 hostname
, sizeof(hostname
), &port
,
196 resource
, sizeof(resource
));
199 * See if there are any options...
202 if ((options
= strchr(resource
, '?')) != NULL
)
205 * Yup, terminate the device name string and move to the first
206 * character of the options...
213 * Finally, send the print file...
216 status
= print_device(resource
, fp
, copies
);
219 * Close input file and return...
230 * End of "$Id: scsi.c 7193 2008-01-07 23:01:40Z mike $".