]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/scsi.c
2 * "$Id: scsi.c 177 2006-06-21 00:20:03Z jlovell $"
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>
61 #include <cups/string.h>
69 # ifdef HAVE_SYS_IOCTL_H
70 # include <sys/ioctl.h>
71 # endif /* HAVE_SYS_IOCTL_H */
79 void list_devices(void);
80 int print_device(const char *resource
, int fd
, int copies
);
84 # include "scsi-linux.c"
86 # include "scsi-irix.c"
89 * Dummy functions that do nothing on unsupported platforms...
91 void list_devices(void) {}
92 int print_device(const char *resource
, int fd
, int copies
) { return (CUPS_BACKEND_FAILED
); }
97 * 'main()' - Send a file to the specified SCSI printer.
101 * printer-uri job-id user title copies options [file]
104 int /* O - Exit status */
105 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
106 char *argv
[]) /* I - Command-line arguments */
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 */
123 * Make sure status messages are not buffered...
126 setbuf(stderr
, NULL
);
129 * Ignore SIGPIPE signals...
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
);
139 signal(SIGPIPE
, SIG_IGN
);
140 #endif /* HAVE_SIGSET */
143 * Check command-line...
149 return (CUPS_BACKEND_OK
);
151 else if (argc
< 6 || argc
> 7)
153 fputs("Usage: scsi:/dev/file job-id user title copies options [file]\n", stderr
);
154 return (CUPS_BACKEND_FAILED
);
158 * If we have 7 arguments, print the file named on the command-line.
159 * Otherwise, send stdin instead...
170 * Try to open the print file...
173 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
175 perror("ERROR: unable to open print file");
176 return (CUPS_BACKEND_FAILED
);
179 copies
= atoi(argv
[4]);
183 * Extract the device name and options from the URI...
186 httpSeparateURI(HTTP_URI_CODING_ALL
, cupsBackendDeviceURI(argv
),
187 method
, sizeof(method
), username
, sizeof(username
),
188 hostname
, sizeof(hostname
), &port
,
189 resource
, sizeof(resource
));
192 * See if there are any options...
195 if ((options
= strchr(resource
, '?')) != NULL
)
198 * Yup, terminate the device name string and move to the first
199 * character of the options...
206 * Finally, send the print file...
209 status
= print_device(resource
, fp
, copies
);
212 * Close input file and return...
223 * End of "$Id: scsi.c 177 2006-06-21 00:20:03Z jlovell $".