]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
2 * "$Id: usb.c 6414 2007-03-30 13:40:57Z mike $"
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>
48 #include <cups/i18n.h>
64 void list_devices(void);
65 int print_device(const char *uri
, const char *hostname
,
66 const char *resource
, const char *options
,
67 int print_fd
, int copies
, int argc
, char *argv
[]);
71 * Include the vendor-specific USB implementation...
75 # include "usb-darwin.c"
76 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
77 # include "usb-unix.c"
80 * Use dummy functions that do nothing on unsupported platforms...
81 * These can be used as templates for implementing USB printing on new
86 * 'list_devices()' - List all available USB devices to stdout.
93 * Don't have any devices to list... Use output of the form:
95 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
97 * Note that "Hewlett Packard" or any other variation MUST be mapped to
98 * "HP" for compatibility with the PPD and ICC specs.
104 * 'print_device()' - Print a file to a USB device.
107 int /* O - Exit status */
108 print_device(const char *uri
, /* I - Device URI */
109 const char *hostname
, /* I - Hostname/manufacturer */
110 const char *resource
, /* I - Resource/modelname */
111 const char *options
, /* I - Device options/serial number */
112 int print_fd
, /* I - File descriptor to print */
113 int copies
, /* I - Copies to print */
114 int argc
, /* I - Number of command-line arguments (6 or 7) */
115 char *argv
[]) /* I - Command-line arguments */
118 * Can't print, so just reference the arguments to eliminate compiler
119 * warnings and return and exit status of 1. Normally you would use the
120 * arguments to send a file to the printer and return 0 if everything
121 * worked OK and non-zero if there was an error.
133 return (CUPS_BACKEND_FAILED
);
135 #endif /* __APPLE__ */
139 * 'main()' - Send a file to the specified USB port.
143 * printer-uri job-id user title copies options [file]
146 int /* O - Exit status */
147 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
148 char *argv
[]) /* I - Command-line arguments */
150 int print_fd
; /* Print file */
151 int copies
; /* Number of copies to print */
152 int status
; /* Exit status */
153 int port
; /* Port number (not used) */
154 const char *uri
; /* Device URI */
155 char method
[255], /* Method in URI */
156 hostname
[1024], /* Hostname */
157 username
[255], /* Username info (not used) */
158 resource
[1024], /* Resource info (device and options) */
159 *options
; /* Pointer to options */
160 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
161 struct sigaction action
; /* Actions for POSIX signals */
162 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
166 * Make sure status messages are not buffered...
169 setbuf(stderr
, NULL
);
172 * Ignore SIGPIPE signals...
176 sigset(SIGPIPE
, SIG_IGN
);
177 #elif defined(HAVE_SIGACTION)
178 memset(&action
, 0, sizeof(action
));
179 action
.sa_handler
= SIG_IGN
;
180 sigaction(SIGPIPE
, &action
, NULL
);
182 signal(SIGPIPE
, SIG_IGN
);
183 #endif /* HAVE_SIGSET */
186 * Check command-line...
192 return (CUPS_BACKEND_OK
);
194 else if (argc
< 6 || argc
> 7)
196 fprintf(stderr
, _("Usage: %s job-id user title copies options [file]\n"),
198 return (CUPS_BACKEND_FAILED
);
202 * Extract the device name and options from the URI...
205 uri
= cupsBackendDeviceURI(argv
);
207 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
208 method
, sizeof(method
), username
, sizeof(username
),
209 hostname
, sizeof(hostname
), &port
,
210 resource
, sizeof(resource
)) < HTTP_URI_OK
)
212 fputs(_("ERROR: No device URI found in argv[0] or in DEVICE_URI "
213 "environment variable!\n"), stderr
);
218 * See if there are any options...
221 if ((options
= strchr(resource
, '?')) != NULL
)
224 * Yup, terminate the device name string and move to the first
225 * character of the options...
232 * If we have 7 arguments, print the file named on the command-line.
233 * Otherwise, send stdin instead...
244 * Try to open the print file...
247 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
249 fprintf(stderr
, _("ERROR: Unable to open print file %s - %s\n"),
250 argv
[6], strerror(errno
));
251 return (CUPS_BACKEND_FAILED
);
254 copies
= atoi(argv
[4]);
258 * Finally, send the print file...
261 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
265 * Close the input file and return...
276 * End of "$Id: usb.c 6414 2007-03-30 13:40:57Z mike $".