]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/scsi.c
6e3f278b2ce0c86d10893536c44649848687c828
4 * SCSI printer backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2003-2006 by Easy Software Products, all rights reserved.
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the
10 * following conditions are met:
12 * 1. Redistributions of source code must retain the above
13 * copyright notice, this list of conditions and the
14 * following disclaimer.
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.
21 * 3. All advertising materials mentioning features or use
22 * of this software must display the following
25 * This product includes software developed by Easy
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.
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
49 * main() - Send a file to the specified SCSI printer.
53 * Include necessary headers.
56 #include <cups/backend.h>
57 #include <cups/cups.h>
58 #include <cups/i18n.h>
62 #include <cups/string.h>
63 #include <cups/i18n.h>
71 # ifdef HAVE_SYS_IOCTL_H
72 # include <sys/ioctl.h>
73 # endif /* HAVE_SYS_IOCTL_H */
81 void list_devices(void);
82 int print_device(const char *resource
, int fd
, int copies
);
85 #if defined(__linux__) && defined(HAVE_SCSI_SG_H)
86 # include "scsi-linux.c"
88 # include "scsi-irix.c"
91 * Dummy functions that do nothing on unsupported platforms...
93 void list_devices(void) {}
94 int print_device(const char *resource
, int fd
, int copies
) { return (CUPS_BACKEND_FAILED
); }
95 #endif /* __linux && HAVE_SCSI_SG_H */
99 * 'main()' - Send a file to the specified SCSI printer.
103 * printer-uri job-id user title copies options [file]
106 int /* O - Exit status */
107 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
108 char *argv
[]) /* I - Command-line arguments */
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 */
125 * Make sure status messages are not buffered...
128 setbuf(stderr
, NULL
);
131 * Ignore SIGPIPE signals...
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
);
141 signal(SIGPIPE
, SIG_IGN
);
142 #endif /* HAVE_SIGSET */
145 * Check command-line...
151 return (CUPS_BACKEND_OK
);
153 else if (argc
< 6 || argc
> 7)
155 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
157 return (CUPS_BACKEND_FAILED
);
161 * If we have 7 arguments, print the file named on the command-line.
162 * Otherwise, send stdin instead...
173 * Try to open the print file...
176 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
178 perror("ERROR: unable to open print file");
179 return (CUPS_BACKEND_FAILED
);
182 copies
= atoi(argv
[4]);
186 * Extract the device name and options from the URI...
189 httpSeparateURI(HTTP_URI_CODING_ALL
, cupsBackendDeviceURI(argv
),
190 method
, sizeof(method
), username
, sizeof(username
),
191 hostname
, sizeof(hostname
), &port
,
192 resource
, sizeof(resource
));
195 * See if there are any options...
198 if ((options
= strchr(resource
, '?')) != NULL
)
201 * Yup, terminate the device name string and move to the first
202 * character of the options...
209 * Finally, send the print file...
212 status
= print_device(resource
, fp
, copies
);
215 * Close input file and return...