]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
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/".
15 * Include necessary headers.
19 /* A header order dependency requires this be first */
20 # include <ApplicationServices/ApplicationServices.h>
21 #endif /* __APPLE__ */
23 #include "backend-private.h"
38 void list_devices(void);
39 int print_device(const char *uri
, const char *hostname
,
40 const char *resource
, char *options
,
41 int print_fd
, int copies
, int argc
, char *argv
[]);
45 * Include the vendor-specific USB implementation...
49 # include "usb-libusb.c"
50 #elif defined(__APPLE__)
51 # include "usb-darwin.c"
52 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
53 # include "usb-unix.c"
56 * Use dummy functions that do nothing on unsupported platforms...
57 * These can be used as templates for implementing USB printing on new
62 * 'list_devices()' - List all available USB devices to stdout.
69 * Don't have any devices to list... Use output of the form:
71 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
73 * Note that "Hewlett Packard" or any other variation MUST be mapped to
74 * "HP" for compatibility with the PPD and ICC specs.
80 * 'print_device()' - Print a file to a USB device.
83 int /* O - Exit status */
84 print_device(const char *uri
, /* I - Device URI */
85 const char *hostname
, /* I - Hostname/manufacturer */
86 const char *resource
, /* I - Resource/modelname */
87 char *options
, /* I - Device options/serial number */
88 int print_fd
, /* I - File descriptor to print */
89 int copies
, /* I - Copies to print */
90 int argc
, /* I - Number of command-line arguments (6 or 7) */
91 char *argv
[]) /* I - Command-line arguments */
94 * Can't print, so just reference the arguments to eliminate compiler
95 * warnings and return and exit status of 1. Normally you would use the
96 * arguments to send a file to the printer and return 0 if everything
97 * worked OK and non-zero if there was an error.
109 return (CUPS_BACKEND_FAILED
);
111 #endif /* HAVE_LIBUSB */
115 * 'main()' - Send a file to the specified USB port.
119 * printer-uri job-id user title copies options [file]
122 int /* O - Exit status */
123 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
124 char *argv
[]) /* I - Command-line arguments */
126 int print_fd
; /* Print file */
127 int copies
; /* Number of copies to print */
128 int status
; /* Exit status */
129 int port
; /* Port number (not used) */
130 const char *uri
; /* Device URI */
131 char method
[255], /* Method in URI */
132 hostname
[1024], /* Hostname */
133 username
[255], /* Username info (not used) */
134 resource
[1024], /* Resource info (device and options) */
135 *options
; /* Pointer to options */
136 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
137 struct sigaction action
; /* Actions for POSIX signals */
138 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
142 * Make sure status messages are not buffered...
145 setbuf(stderr
, NULL
);
148 * Ignore SIGPIPE signals...
152 sigset(SIGPIPE
, SIG_IGN
);
153 #elif defined(HAVE_SIGACTION)
154 memset(&action
, 0, sizeof(action
));
155 action
.sa_handler
= SIG_IGN
;
156 sigaction(SIGPIPE
, &action
, NULL
);
158 signal(SIGPIPE
, SIG_IGN
);
159 #endif /* HAVE_SIGSET */
162 * Check command-line...
168 return (CUPS_BACKEND_OK
);
170 else if (argc
< 6 || argc
> 7)
172 _cupsLangPrintf(stderr
,
173 _("Usage: %s job-id user title copies options [file]"),
175 return (CUPS_BACKEND_FAILED
);
179 * Extract the device name and options from the URI...
182 uri
= cupsBackendDeviceURI(argv
);
184 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
185 method
, sizeof(method
), username
, sizeof(username
),
186 hostname
, sizeof(hostname
), &port
,
187 resource
, sizeof(resource
)) < HTTP_URI_OK
)
189 _cupsLangPrintFilter(stderr
, "ERROR",
190 _("No device URI found in argv[0] or in DEVICE_URI "
191 "environment variable."));
196 * See if there are any options...
199 if ((options
= strchr(resource
, '?')) != NULL
)
202 * Yup, terminate the device name string and move to the first
203 * character of the options...
210 * If we have 7 arguments, print the file named on the command-line.
211 * Otherwise, send stdin instead...
222 * Try to open the print file...
225 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
227 _cupsLangPrintError("ERROR", _("Unable to open print file"));
228 return (CUPS_BACKEND_FAILED
);
231 copies
= atoi(argv
[4]);
235 * Finally, send the print file...
238 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
242 * Close the input file and return...