]>
git.ipfire.org Git - thirdparty/cups.git/blob - backend/usb.c
2 * "$Id: usb.c 5162 2006-02-24 03:15:13Z mike $"
4 * USB port backend for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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>
63 void list_devices(void);
64 int print_device(const char *uri
, const char *hostname
,
65 const char *resource
, const char *options
,
70 * Include the vendor-specific USB implementation...
74 # include "usb-darwin.c"
75 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
76 # include "usb-unix.c"
79 * Use dummy functions that do nothing on unsupported platforms...
80 * These can be used as templates for implementing USB printing on new
85 * 'list_devices()' - List all available USB devices to stdout.
92 * Don't have any devices to list... Use output of the form:
94 * direct usb:/make/model?serial=foo "Make Model" "USB Printer"
96 * Note that "Hewlett Packard" or any other variation MUST be mapped to
97 * "HP" for compatibility with the PPD and ICC specs.
103 * 'print_device()' - Print a file to a USB device.
106 int /* O - Exit status */
107 print_device(const char *uri
, /* I - Device URI */
108 const char *hostname
, /* I - Hostname/manufacturer */
109 const char *resource
, /* I - Resource/modelname */
110 const char *options
, /* I - Device options/serial number */
111 int fp
, /* I - File descriptor to print */
112 int copies
) /* I - Copies to print */
115 * Can't print, so just reference the arguments to eliminate compiler
116 * warnings and return and exit status of 1. Normally you would use the
117 * arguments to send a file to the printer and return 0 if everything
118 * worked OK and non-zero if there was an error.
128 return (CUPS_BACKEND_FAILED
);
130 #endif /* __APPLE__ */
134 * 'main()' - Send a file to the specified USB port.
138 * printer-uri job-id user title copies options [file]
141 int /* O - Exit status */
142 main(int argc
, /* I - Number of command-line arguments (6 or 7) */
143 char *argv
[]) /* I - Command-line arguments */
145 int fp
; /* Print file */
146 int copies
; /* Number of copies to print */
147 int status
; /* Exit status */
148 int port
; /* Port number (not used) */
149 const char *uri
; /* Device URI */
150 char method
[255], /* Method in URI */
151 hostname
[1024], /* Hostname */
152 username
[255], /* Username info (not used) */
153 resource
[1024], /* Resource info (device and options) */
154 *options
; /* Pointer to options */
155 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
156 struct sigaction action
; /* Actions for POSIX signals */
157 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
161 * Make sure status messages are not buffered...
164 setbuf(stderr
, NULL
);
167 * Ignore SIGPIPE signals...
171 sigset(SIGPIPE
, SIG_IGN
);
172 #elif defined(HAVE_SIGACTION)
173 memset(&action
, 0, sizeof(action
));
174 action
.sa_handler
= SIG_IGN
;
175 sigaction(SIGPIPE
, &action
, NULL
);
177 signal(SIGPIPE
, SIG_IGN
);
178 #endif /* HAVE_SIGSET */
181 * Check command-line...
187 return (CUPS_BACKEND_OK
);
189 else if (argc
< 6 || argc
> 7)
191 fputs("Usage: usb job-id user title copies options [file]\n", stderr
);
192 return (CUPS_BACKEND_FAILED
);
196 * Extract the device name and options from the URI...
199 uri
= cupsBackendDeviceURI(argv
);
201 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
,
202 method
, sizeof(method
), username
, sizeof(username
),
203 hostname
, sizeof(hostname
), &port
,
204 resource
, sizeof(resource
)) < HTTP_URI_OK
)
206 fputs("ERROR: No device URI found in argv[0] or in DEVICE_URI environment variable!\n", stderr
);
211 * See if there are any options...
214 if ((options
= strchr(resource
, '?')) != NULL
)
217 * Yup, terminate the device name string and move to the first
218 * character of the options...
225 * If we have 7 arguments, print the file named on the command-line.
226 * Otherwise, send stdin instead...
237 * Try to open the print file...
240 if ((fp
= open(argv
[6], O_RDONLY
)) < 0)
242 fprintf(stderr
, "ERROR: unable to open print file %s - %s\n",
243 argv
[6], strerror(errno
));
244 return (CUPS_BACKEND_FAILED
);
247 copies
= atoi(argv
[4]);
251 * Finally, send the print file...
254 status
= print_device(uri
, hostname
, resource
, options
, fp
, copies
);
257 * Close the input file and return...
268 * End of "$Id: usb.c 5162 2006-02-24 03:15:13Z mike $".