]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
4 * USB port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2009 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * "LICENSE" which should have been included with this file. If this
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * list_devices() - List all available USB devices to stdout.
20 * print_device() - Print a file to a USB device.
21 * main() - Send a file to the specified USB port.
25 * Include necessary headers.
29 /* A header order dependency requires this be first */
30 # include <ApplicationServices/ApplicationServices.h>
31 #endif /* __APPLE__ */
33 #include "backend-private.h"
48 void list_devices(void);
49 int print_device(const char *uri
, const char *hostname
,
50 const char *resource
, char *options
,
51 int print_fd
, int copies
, int argc
, char *argv
[]);
55 * Include the vendor-specific USB implementation...
59 # include "usb-libusb.c"
60 #elif defined(__APPLE__)
61 # include "usb-darwin.c"
62 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
63 # include "usb-unix.c"
66 * Use dummy functions that do nothing on unsupported platforms...
67 * These can be used as templates for implementing USB printing on new
72 * 'list_devices()' - List all available USB devices to stdout.
79 * Don't have any devices to list... Use output of the form:
81 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
83 * Note that "Hewlett Packard" or any other variation MUST be mapped to
84 * "HP" for compatibility with the PPD and ICC specs.
90 * 'print_device()' - Print a file to a USB device.
93 int /* O - Exit status */
94 print_device(const char *uri
, /* I - Device URI */
95 const char *hostname
, /* I - Hostname/manufacturer */
96 const char *resource
, /* I - Resource/modelname */
97 char *options
, /* I - Device options/serial number */
98 int print_fd
, /* I - File descriptor to print */
99 int copies
, /* I - Copies to print */
100 int argc
, /* I - Number of command-line arguments (6 or 7) */
101 char *argv
[]) /* I - Command-line arguments */
104 * Can't print, so just reference the arguments to eliminate compiler
105 * warnings and return and exit status of 1. Normally you would use the
106 * arguments to send a file to the printer and return 0 if everything
107 * worked OK and non-zero if there was an error.
119 return (CUPS_BACKEND_FAILED
);
121 #endif /* __APPLE__ */
125 * 'main()' - Send a file to the specified USB port.
129 * printer-uri job-id user title copies options [file]
132 int /* O - Exit status */
133 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
134 char *argv
[]) /* I - Command-line arguments */
136 int print_fd
; /* Print file */
137 int copies
; /* Number of copies to print */
138 int status
; /* Exit status */
139 int port
; /* Port number (not used) */
140 const char *uri
; /* Device URI */
141 char method
[255], /* Method in URI */
142 hostname
[1024], /* Hostname */
143 username
[255], /* Username info (not used) */
144 resource
[1024], /* Resource info (device and options) */
145 *options
; /* Pointer to options */
146 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
147 struct sigaction action
; /* Actions for POSIX signals */
148 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
152 * Make sure status messages are not buffered...
155 setbuf(stderr
, NULL
);
158 * Ignore SIGPIPE signals...
162 sigset(SIGPIPE
, SIG_IGN
);
163 #elif defined(HAVE_SIGACTION)
164 memset(&action
, 0, sizeof(action
));
165 action
.sa_handler
= SIG_IGN
;
166 sigaction(SIGPIPE
, &action
, NULL
);
168 signal(SIGPIPE
, SIG_IGN
);
169 #endif /* HAVE_SIGSET */
172 * Check command-line...
178 return (CUPS_BACKEND_OK
);
180 else if (argc
< 6 || argc
> 7)
182 _cupsLangPrintf(stderr
,
183 _("Usage: %s job-id user title copies options [file]\n"),
185 return (CUPS_BACKEND_FAILED
);
189 * Extract the device name and options from the URI...
192 uri
= cupsBackendDeviceURI(argv
);
194 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
195 method
, sizeof(method
), username
, sizeof(username
),
196 hostname
, sizeof(hostname
), &port
,
197 resource
, sizeof(resource
)) < HTTP_URI_OK
)
199 _cupsLangPuts(stderr
,
200 _("ERROR: No device URI found in argv[0] or in DEVICE_URI "
201 "environment variable\n"));
206 * See if there are any options...
209 if ((options
= strchr(resource
, '?')) != NULL
)
212 * Yup, terminate the device name string and move to the first
213 * character of the options...
220 * If we have 7 arguments, print the file named on the command-line.
221 * Otherwise, send stdin instead...
232 * Try to open the print file...
235 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
237 _cupsLangPrintf(stderr
, _("ERROR: Unable to open print file %s - %s\n"),
238 argv
[6], strerror(errno
));
239 return (CUPS_BACKEND_FAILED
);
242 copies
= atoi(argv
[4]);
246 * Finally, send the print file...
249 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
253 * Close the input file and return...