]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
2 * "$Id: usb.c,v 1.54 2004/03/30 19:19:30 mike Exp $"
4 * USB port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2004 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-3142 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/cups.h>
46 #include <cups/string.h>
54 void list_devices(void);
55 int print_device(const char *uri
, const char *hostname
,
56 const char *resource
, const char *options
,
61 * Include the vendor-specific USB implementation...
65 # include "usb-darwin.c"
66 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
67 # include "usb-unix.c"
70 * Use dummy functions that do nothing on unsupported platforms...
71 * These can be used as templates for implementing USB printing on new
76 * 'list_devices()' - List all available USB devices to stdout.
83 * Don't have any devices to list... Use output of the form:
85 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
87 * Note that "Hewlett Packard" or any other variation MUST be mapped to
88 * "HP" for compatibility with the PPD and ICC specs.
94 * 'print_device()' - Print a file to a USB device.
97 int /* O - Exit status */
98 print_device(const char *uri
, /* I - Device URI */
99 const char *hostname
, /* I - Hostname/manufacturer */
100 const char *resource
, /* I - Resource/modelname */
101 const char *options
, /* I - Device options/serial number */
102 int fp
, /* I - File descriptor to print */
103 int copies
) /* I - Copies to print */
106 * Can't print, so just reference the arguments to eliminate compiler
107 * warnings and return and exit status of 1. Normally you would use the
108 * arguments to send a file to the printer and return 0 if everything
109 * worked OK and non-zero if there was an error.
121 #endif /* __APPLE__ */
125 * 'main()' - Send a file to the specified USB port.
129 * printer-uri job-id user title copies options [file]
132 int /* O - Exit status */
133 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
134 char *argv
[]) /* I - Command-line arguments */
136 int fp
; /* Print file */
137 int copies
; /* Number of copies to print */
138 int status
; /* Exit status */
139 int port
; /* Port number (not used) */
140 const char *uri
; /* Device URI */
141 char method
[255], /* Method in URI */
142 hostname
[1024], /* Hostname */
143 username
[255], /* Username info (not used) */
144 resource
[1024], /* Resource info (device and options) */
145 *options
; /* Pointer to options */
146 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
147 struct sigaction action
; /* Actions for POSIX signals */
148 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
152 * Make sure status messages are not buffered...
155 setbuf(stderr
, NULL
);
158 * Ignore SIGPIPE signals...
162 sigset(SIGPIPE
, SIG_IGN
);
163 #elif defined(HAVE_SIGACTION)
164 memset(&action
, 0, sizeof(action
));
165 action
.sa_handler
= SIG_IGN
;
166 sigaction(SIGPIPE
, &action
, NULL
);
168 signal(SIGPIPE
, SIG_IGN
);
169 #endif /* HAVE_SIGSET */
172 * Check command-line...
180 else if (argc
< 6 || argc
> 7)
182 fputs("Usage: usb job-id user title copies options [file]\n", stderr
);
187 * Extract the device name and options from the URI...
190 if (strncmp(argv
[0], "usb:", 4))
191 uri
= getenv("DEVICE_URI");
197 fputs("ERROR: No device URI found in argv[0] or in DEVICE_URI environment variable!\n", stderr
);
201 httpSeparate(argv
[0], method
, username
, hostname
, &port
, resource
);
204 * See if there are any options...
207 if ((options
= strchr(resource
, '?')) != NULL
)
210 * Yup, terminate the device name string and move to the first
211 * character of the options...
218 * If we have 7 arguments, print the file named on the command-line.
219 * Otherwise, send stdin instead...
230 * Try to open the print file...
233 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
235 fprintf(stderr
, "ERROR: unable to open print file %s - %s\n",
236 argv
[6], strerror(errno
));
240 copies
= atoi(argv
[4]);
244 * Finally, send the print file...
247 status
= print_device(uri
, hostname
, resource
, options
, fp
, copies
);
250 * Close the input file and return...
257 fputs("INFO: Ready to print.\n", stderr
);
264 * End of "$Id: usb.c,v 1.54 2004/03/30 19:19:30 mike Exp $".