]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
a3b6fba097f74d15f2c445be43553c133c51d691
2 * USB printer backend for CUPS.
4 * Copyright 2007-2012 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * "LICENSE" which should have been included with this file. If this
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers.
21 /* A header order dependency requires this be first */
22 # include <ApplicationServices/ApplicationServices.h>
23 #endif /* __APPLE__ */
25 #include "backend-private.h"
40 void list_devices(void);
41 int print_device(const char *uri
, const char *hostname
,
42 const char *resource
, char *options
,
43 int print_fd
, int copies
, int argc
, char *argv
[]);
47 * Include the vendor-specific USB implementation...
51 # include "usb-libusb.c"
52 #elif defined(__APPLE__)
53 # include "usb-darwin.c"
54 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
55 # include "usb-unix.c"
58 * Use dummy functions that do nothing on unsupported platforms...
59 * These can be used as templates for implementing USB printing on new
64 * 'list_devices()' - List all available USB devices to stdout.
71 * Don't have any devices to list... Use output of the form:
73 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
75 * Note that "Hewlett Packard" or any other variation MUST be mapped to
76 * "HP" for compatibility with the PPD and ICC specs.
82 * 'print_device()' - Print a file to a USB device.
85 int /* O - Exit status */
86 print_device(const char *uri
, /* I - Device URI */
87 const char *hostname
, /* I - Hostname/manufacturer */
88 const char *resource
, /* I - Resource/modelname */
89 char *options
, /* I - Device options/serial number */
90 int print_fd
, /* I - File descriptor to print */
91 int copies
, /* I - Copies to print */
92 int argc
, /* I - Number of command-line arguments (6 or 7) */
93 char *argv
[]) /* I - Command-line arguments */
96 * Can't print, so just reference the arguments to eliminate compiler
97 * warnings and return and exit status of 1. Normally you would use the
98 * arguments to send a file to the printer and return 0 if everything
99 * worked OK and non-zero if there was an error.
111 return (CUPS_BACKEND_FAILED
);
113 #endif /* HAVE_LIBUSB */
117 * 'main()' - Send a file to the specified USB port.
121 * printer-uri job-id user title copies options [file]
124 int /* O - Exit status */
125 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
126 char *argv
[]) /* I - Command-line arguments */
128 int print_fd
; /* Print file */
129 int copies
; /* Number of copies to print */
130 int status
; /* Exit status */
131 int port
; /* Port number (not used) */
132 const char *uri
; /* Device URI */
133 char method
[255], /* Method in URI */
134 hostname
[1024], /* Hostname */
135 username
[255], /* Username info (not used) */
136 resource
[1024], /* Resource info (device and options) */
137 *options
; /* Pointer to options */
138 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
139 struct sigaction action
; /* Actions for POSIX signals */
140 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
144 * Make sure status messages are not buffered...
147 setbuf(stderr
, NULL
);
150 * Ignore SIGPIPE signals...
154 sigset(SIGPIPE
, SIG_IGN
);
155 #elif defined(HAVE_SIGACTION)
156 memset(&action
, 0, sizeof(action
));
157 action
.sa_handler
= SIG_IGN
;
158 sigaction(SIGPIPE
, &action
, NULL
);
160 signal(SIGPIPE
, SIG_IGN
);
161 #endif /* HAVE_SIGSET */
164 * Check command-line...
170 return (CUPS_BACKEND_OK
);
172 else if (argc
< 6 || argc
> 7)
174 _cupsLangPrintf(stderr
,
175 _("Usage: %s job-id user title copies options [file]"),
177 return (CUPS_BACKEND_FAILED
);
181 * Extract the device name and options from the URI...
184 uri
= cupsBackendDeviceURI(argv
);
186 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
187 method
, sizeof(method
), username
, sizeof(username
),
188 hostname
, sizeof(hostname
), &port
,
189 resource
, sizeof(resource
)) < HTTP_URI_OK
)
191 _cupsLangPrintFilter(stderr
, "ERROR",
192 _("No device URI found in argv[0] or in DEVICE_URI "
193 "environment variable."));
198 * See if there are any options...
201 if ((options
= strchr(resource
, '?')) != NULL
)
204 * Yup, terminate the device name string and move to the first
205 * character of the options...
212 * If we have 7 arguments, print the file named on the command-line.
213 * Otherwise, send stdin instead...
224 * Try to open the print file...
227 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
229 _cupsLangPrintError("ERROR", _("Unable to open print file"));
230 return (CUPS_BACKEND_FAILED
);
233 copies
= atoi(argv
[4]);
237 * Finally, send the print file...
240 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
244 * Close the input file and return...