]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers.
16 /* A header order dependency requires this be first */
17 # include <ApplicationServices/ApplicationServices.h>
18 #endif /* __APPLE__ */
20 #include "backend-private.h"
35 void list_devices(void);
36 int print_device(const char *uri
, const char *hostname
,
37 const char *resource
, char *options
,
38 int print_fd
, int copies
, int argc
, char *argv
[]);
42 * Include the vendor-specific USB implementation...
46 # include "usb-libusb.c"
47 #elif defined(__APPLE__)
48 # include "usb-darwin.c"
49 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
50 # include "usb-unix.c"
53 * Use dummy functions that do nothing on unsupported platforms...
54 * These can be used as templates for implementing USB printing on new
59 * 'list_devices()' - List all available USB devices to stdout.
66 * Don't have any devices to list... Use output of the form:
68 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
70 * Note that "Hewlett Packard" or any other variation MUST be mapped to
71 * "HP" for compatibility with the PPD and ICC specs.
77 * 'print_device()' - Print a file to a USB device.
80 int /* O - Exit status */
81 print_device(const char *uri
, /* I - Device URI */
82 const char *hostname
, /* I - Hostname/manufacturer */
83 const char *resource
, /* I - Resource/modelname */
84 char *options
, /* I - Device options/serial number */
85 int print_fd
, /* I - File descriptor to print */
86 int copies
, /* I - Copies to print */
87 int argc
, /* I - Number of command-line arguments (6 or 7) */
88 char *argv
[]) /* I - Command-line arguments */
91 * Can't print, so just reference the arguments to eliminate compiler
92 * warnings and return and exit status of 1. Normally you would use the
93 * arguments to send a file to the printer and return 0 if everything
94 * worked OK and non-zero if there was an error.
106 return (CUPS_BACKEND_FAILED
);
108 #endif /* HAVE_LIBUSB */
112 * 'main()' - Send a file to the specified USB port.
116 * printer-uri job-id user title copies options [file]
119 int /* O - Exit status */
120 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
121 char *argv
[]) /* I - Command-line arguments */
123 int print_fd
; /* Print file */
124 int copies
; /* Number of copies to print */
125 int status
; /* Exit status */
126 int port
; /* Port number (not used) */
127 const char *uri
; /* Device URI */
128 char method
[255], /* Method in URI */
129 hostname
[1024], /* Hostname */
130 username
[255], /* Username info (not used) */
131 resource
[1024], /* Resource info (device and options) */
132 *options
; /* Pointer to options */
133 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
134 struct sigaction action
; /* Actions for POSIX signals */
135 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
139 * Make sure status messages are not buffered...
142 setbuf(stderr
, NULL
);
145 * Ignore SIGPIPE signals...
149 sigset(SIGPIPE
, SIG_IGN
);
150 #elif defined(HAVE_SIGACTION)
151 memset(&action
, 0, sizeof(action
));
152 action
.sa_handler
= SIG_IGN
;
153 sigaction(SIGPIPE
, &action
, NULL
);
155 signal(SIGPIPE
, SIG_IGN
);
156 #endif /* HAVE_SIGSET */
159 * Check command-line...
165 return (CUPS_BACKEND_OK
);
167 else if (argc
< 6 || argc
> 7)
169 _cupsLangPrintf(stderr
,
170 _("Usage: %s job-id user title copies options [file]"),
172 return (CUPS_BACKEND_FAILED
);
176 * Extract the device name and options from the URI...
179 uri
= cupsBackendDeviceURI(argv
);
181 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
182 method
, sizeof(method
), username
, sizeof(username
),
183 hostname
, sizeof(hostname
), &port
,
184 resource
, sizeof(resource
)) < HTTP_URI_OK
)
186 _cupsLangPrintFilter(stderr
, "ERROR",
187 _("No device URI found in argv[0] or in DEVICE_URI "
188 "environment variable."));
193 * See if there are any options...
196 if ((options
= strchr(resource
, '?')) != NULL
)
199 * Yup, terminate the device name string and move to the first
200 * character of the options...
207 * If we have 7 arguments, print the file named on the command-line.
208 * Otherwise, send stdin instead...
219 * Try to open the print file...
222 if ((print_fd
= open(argv
[6], O_RDONLY
)) < 0)
224 _cupsLangPrintError("ERROR", _("Unable to open print file"));
225 return (CUPS_BACKEND_FAILED
);
228 copies
= atoi(argv
[4]);
232 * Finally, send the print file...
235 status
= print_device(uri
, hostname
, resource
, options
, print_fd
, copies
,
239 * Close the input file and return...