]>
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 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 <cups/backend.h>
34 #include <cups/cups.h>
38 #include <cups/string.h>
39 #include <cups/i18n.h>
55 void list_devices(void);
56 int print_device(const char *uri
, const char *hostname
,
57 const char *resource
, const char *options
,
58 int print_fd
, int copies
, int argc
, char *argv
[]);
62 * Include the vendor-specific USB implementation...
66 # include "usb-darwin.c"
67 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
68 # include "usb-unix.c"
71 * Use dummy functions that do nothing on unsupported platforms...
72 * These can be used as templates for implementing USB printing on new
77 * 'list_devices()' - List all available USB devices to stdout.
84 * Don't have any devices to list... Use output of the form:
86 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
88 * Note that "Hewlett Packard" or any other variation MUST be mapped to
89 * "HP" for compatibility with the PPD and ICC specs.
95 * 'print_device()' - Print a file to a USB device.
98 int /* O - Exit status */
99 print_device(const char *uri
, /* I - Device URI */
100 const char *hostname
, /* I - Hostname/manufacturer */
101 const char *resource
, /* I - Resource/modelname */
102 const char *options
, /* I - Device options/serial number */
103 int print_fd
, /* I - File descriptor to print */
104 int copies
, /* I - Copies to print */
105 int argc
, /* I - Number of command-line arguments (6 or 7) */
106 char *argv
[]) /* I - Command-line arguments */
109 * Can't print, so just reference the arguments to eliminate compiler
110 * warnings and return and exit status of 1. Normally you would use the
111 * arguments to send a file to the printer and return 0 if everything
112 * worked OK and non-zero if there was an error.
124 return (CUPS_BACKEND_FAILED
);
126 #endif /* __APPLE__ */
130 * 'main()' - Send a file to the specified USB port.
134 * printer-uri job-id user title copies options [file]
137 int /* O - Exit status */
138 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
139 char *argv
[]) /* I - Command-line arguments */
141 int print_fd
; /* Print file */
142 int copies
; /* Number of copies to print */
143 int status
; /* Exit status */
144 int port
; /* Port number (not used) */
145 const char *uri
; /* Device URI */
146 char method
[255], /* Method in URI */
147 hostname
[1024], /* Hostname */
148 username
[255], /* Username info (not used) */
149 resource
[1024], /* Resource info (device and options) */
150 *options
; /* Pointer to options */
151 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
152 struct sigaction action
; /* Actions for POSIX signals */
153 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
157 * Make sure status messages are not buffered...
160 setbuf(stderr
, NULL
);
163 * Ignore SIGPIPE signals...
167 sigset(SIGPIPE
, SIG_IGN
);
168 #elif defined(HAVE_SIGACTION)
169 memset(&action
, 0, sizeof(action
));
170 action
.sa_handler
= SIG_IGN
;
171 sigaction(SIGPIPE
, &action
, NULL
);
173 signal(SIGPIPE
, SIG_IGN
);
174 #endif /* HAVE_SIGSET */
177 * Check command-line...
183 return (CUPS_BACKEND_OK
);
185 else if (argc
< 6 || argc
> 7)
187 _cupsLangPrintf(stderr
,
188 _("Usage: %s job-id user title copies options [file]\n"),
190 return (CUPS_BACKEND_FAILED
);
194 * Extract the device name and options from the URI...
197 uri
= cupsBackendDeviceURI(argv
);
199 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
200 method
, sizeof(method
), username
, sizeof(username
),
201 hostname
, sizeof(hostname
), &port
,
202 resource
, sizeof(resource
)) < HTTP_URI_OK
)
204 _cupsLangPuts(stderr
,
205 _("ERROR: No device URI found in argv[0] or in DEVICE_URI "
206 "environment variable!\n"));
211 * See if there are any options...
214 if ((options
= strchr(resource
, '?')) != NULL
)
217 * Yup, terminate the device name string and move to the first
218 * character of the options...
225 * If we have 7 arguments, print the file named on the command-line.
226 * Otherwise, send stdin instead...
237 * Try to open the print file...
240 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
242 _cupsLangPrintf(stderr
, _("ERROR: Unable to open print file %s - %s\n"),
243 argv
[6], strerror(errno
));
244 return (CUPS_BACKEND_FAILED
);
247 copies
= atoi(argv
[4]);
251 * Finally, send the print file...
254 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
258 * Close the input file and return...