]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
4 * USB port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * list_devices() - List all available USB devices to stdout.
29 * print_device() - Print a file to a USB device.
30 * main() - Send a file to the specified USB port.
34 * Include necessary headers.
38 /* A header order dependency requires this be first */
39 # include <ApplicationServices/ApplicationServices.h>
40 #endif /* __APPLE__ */
42 #include <cups/backend.h>
43 #include <cups/cups.h>
47 #include <cups/string.h>
63 void list_devices(void);
64 int print_device(const char *uri
, const char *hostname
,
65 const char *resource
, const char *options
,
66 int print_fd
, int copies
, int argc
, char *argv
[]);
70 * Include the vendor-specific USB implementation...
74 # include "usb-darwin.c"
75 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
76 # include "usb-unix.c"
79 * Use dummy functions that do nothing on unsupported platforms...
80 * These can be used as templates for implementing USB printing on new
85 * 'list_devices()' - List all available USB devices to stdout.
92 * Don't have any devices to list... Use output of the form:
94 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
96 * Note that "Hewlett Packard" or any other variation MUST be mapped to
97 * "HP" for compatibility with the PPD and ICC specs.
103 * 'print_device()' - Print a file to a USB device.
106 int /* O - Exit status */
107 print_device(const char *uri
, /* I - Device URI */
108 const char *hostname
, /* I - Hostname/manufacturer */
109 const char *resource
, /* I - Resource/modelname */
110 const char *options
, /* I - Device options/serial number */
111 int print_fd
, /* I - File descriptor to print */
112 int copies
, /* I - Copies to print */
113 int argc
, /* I - Number of command-line arguments (6 or 7) */
114 char *argv
[]) /* I - Command-line arguments */
117 * Can't print, so just reference the arguments to eliminate compiler
118 * warnings and return and exit status of 1. Normally you would use the
119 * arguments to send a file to the printer and return 0 if everything
120 * worked OK and non-zero if there was an error.
132 return (CUPS_BACKEND_FAILED
);
134 #endif /* __APPLE__ */
138 * 'main()' - Send a file to the specified USB port.
142 * printer-uri job-id user title copies options [file]
145 int /* O - Exit status */
146 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
147 char *argv
[]) /* I - Command-line arguments */
149 int print_fd
; /* Print file */
150 int copies
; /* Number of copies to print */
151 int status
; /* Exit status */
152 int port
; /* Port number (not used) */
153 const char *uri
; /* Device URI */
154 char method
[255], /* Method in URI */
155 hostname
[1024], /* Hostname */
156 username
[255], /* Username info (not used) */
157 resource
[1024], /* Resource info (device and options) */
158 *options
; /* Pointer to options */
159 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
160 struct sigaction action
; /* Actions for POSIX signals */
161 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
165 * Make sure status messages are not buffered...
168 setbuf(stderr
, NULL
);
171 * Ignore SIGPIPE signals...
175 sigset(SIGPIPE
, SIG_IGN
);
176 #elif defined(HAVE_SIGACTION)
177 memset(&action
, 0, sizeof(action
));
178 action
.sa_handler
= SIG_IGN
;
179 sigaction(SIGPIPE
, &action
, NULL
);
181 signal(SIGPIPE
, SIG_IGN
);
182 #endif /* HAVE_SIGSET */
185 * Check command-line...
191 return (CUPS_BACKEND_OK
);
193 else if (argc
< 6 || argc
> 7)
195 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
197 return (CUPS_BACKEND_FAILED
);
201 * Extract the device name and options from the URI...
204 uri
= cupsBackendDeviceURI(argv
);
206 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
207 method
, sizeof(method
), username
, sizeof(username
),
208 hostname
, sizeof(hostname
), &port
,
209 resource
, sizeof(resource
)) < HTTP_URI_OK
)
211 fputs(_("ERROR: No device URI found in argv[0] or in DEVICE_URI "
212 "environment variable!\n"), stderr
);
217 * See if there are any options...
220 if ((options
= strchr(resource
, '?')) != NULL
)
223 * Yup, terminate the device name string and move to the first
224 * character of the options...
231 * If we have 7 arguments, print the file named on the command-line.
232 * Otherwise, send stdin instead...
243 * Try to open the print file...
246 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
248 fprintf(stderr
, _("ERROR: Unable to open print file %s - %s\n"),
249 argv
[6], strerror(errno
));
250 return (CUPS_BACKEND_FAILED
);
253 copies
= atoi(argv
[4]);
257 * Finally, send the print file...
260 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
264 * Close the input file and return...