1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## usb-backend-both-usblp-and-libusb.dpatch by <till.kamppeter@gmail.com>
4 ## DP: http://www.cups.org/str.php?L3357
7 diff -urNad cups-1.4.2~/backend/Makefile cups-1.4.2/backend/Makefile
8 --- cups-1.4.2~/backend/Makefile 2009-11-12 14:50:53.092720352 +0100
9 +++ cups-1.4.2/backend/Makefile 2009-11-12 14:50:53.482720894 +0100
12 $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \
14 -usb.o: usb.c usb-darwin.c usb-libusb.c usb-unix.c
15 +usb.o: usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c
19 diff -urNad cups-1.4.2~/backend/ieee1284.c cups-1.4.2/backend/ieee1284.c
20 --- cups-1.4.2~/backend/ieee1284.c 2009-08-08 00:24:14.000000000 +0200
21 +++ cups-1.4.2/backend/ieee1284.c 2009-11-12 14:50:53.482720894 +0100
23 cups_option_t *values; /* Keys and values in device ID */
24 const char *mfg, /* Manufacturer */
26 + *des, /* Description */
27 *sern; /* Serial number */
28 char temp[256], /* Temporary manufacturer string */
29 *tempptr; /* Pointer into temp string */
34 - strlcpy(temp, make_model, sizeof(temp));
36 + * No manufacturer? Use the model string or description...
40 + _ppdNormalizeMakeAndModel(mdl, temp, sizeof(temp));
41 + else if ((des = cupsGetOption("DESCRIPTION", num_values, values)) != NULL ||
42 + (des = cupsGetOption("DES", num_values, values)) != NULL)
43 + _ppdNormalizeMakeAndModel(des, temp, sizeof(temp));
45 + strlcpy(temp, "Unknown", sizeof(temp));
47 if ((tempptr = strchr(temp, ' ')) != NULL)
53 diff -urNad cups-1.4.2~/backend/usb-hybrid.c cups-1.4.2/backend/usb-hybrid.c
54 --- cups-1.4.2~/backend/usb-hybrid.c 1970-01-01 01:00:00.000000000 +0100
55 +++ cups-1.4.2/backend/usb-hybrid.c 2009-11-12 14:50:53.482720894 +0100
60 + * USB port backend for the Common UNIX Printing System (CUPS).
62 + * This file is included from "usb.c" when compiled on Linux.
64 + * Copyright 2007-2008 by Apple Inc.
65 + * Copyright 1997-2007 by Easy Software Products, all rights reserved.
67 + * These coded instructions, statements, and computer programs are the
68 + * property of Apple Inc. and are protected by Federal copyright
69 + * law. Distribution and use rights are outlined in the file "LICENSE.txt"
70 + * "LICENSE" which should have been included with this file. If this
71 + * file is missing or damaged, see the license at "http://www.cups.org/".
73 + * This file is subject to the Apple OS-Developed Software exception.
77 + * print_device() - Print a file to a USB device.
78 + * list_devices() - List all USB devices.
82 + * Include necessary headers.
85 +#include <sys/select.h>
88 + * Include the two USB implementations used under Linux ...
91 +#include "usb-libusb.c"
92 +#include "usb-unix.c"
95 + * 'print_device()' - Print a file to a USB device.
98 +int /* O - Exit status */
99 +print_device(const char *uri, /* I - Device URI */
100 + const char *hostname, /* I - Hostname/manufacturer */
101 + const char *resource, /* I - Resource/modelname */
102 + char *options, /* I - Device options/serial number */
103 + int print_fd, /* I - File descriptor to print */
104 + int copies, /* I - Copies to print */
105 + int argc, /* I - Number of command-line arguments (6 or 7) */
106 + char *argv[]) /* I - Command-line arguments */
111 + result = print_device_unix(uri, hostname, resource, options, print_fd,
112 + copies, argc, argv);
115 + result = print_device_libusb(uri, hostname, resource, options, print_fd,
116 + copies, argc, argv);
128 + * 'list_devices()' - List all USB devices.
134 + /* Try both discovery methods, each device will appear only under one
136 + list_devices_libusb();
137 + list_devices_unix();
144 diff -urNad cups-1.4.2~/backend/usb-libusb.c cups-1.4.2/backend/usb-libusb.c
145 --- cups-1.4.2~/backend/usb-libusb.c 2009-09-11 22:03:31.000000000 +0200
146 +++ cups-1.4.2/backend/usb-libusb.c 2009-11-12 14:50:53.482720894 +0100
151 - * list_devices() - List the available printers.
152 - * print_device() - Print a file to a USB device.
153 + * list_devices_libusb() - List the available printers.
154 + * print_device_libusb() - Print a file to a USB device.
155 * close_device() - Close the connection to the USB printer.
156 * find_device() - Find or enumerate USB printers.
157 * get_device_id() - Get the IEEE-1284 device ID for the printer.
158 * list_cb() - List USB printers for discovery.
159 * make_device_uri() - Create a device URI for a USB printer.
160 - * open_device() - Open a connection to the USB printer.
161 + * open_device_libusb() - Open a connection to the USB printer.
162 * print_cb() - Find a USB printer for printing.
163 - * side_cb() - Handle side-channel requests.
164 + * side_cb_libusb() - Handle side-channel requests.
169 static char *make_device_uri(usb_printer_t *printer,
170 const char *device_id,
171 char *uri, size_t uri_size);
172 -static int open_device(usb_printer_t *printer, int verbose);
173 +static int open_device_libusb(usb_printer_t *printer, int verbose);
174 static int print_cb(usb_printer_t *printer, const char *device_uri,
175 const char *device_id, const void *data);
176 -static ssize_t side_cb(usb_printer_t *printer, int print_fd);
177 +static ssize_t side_cb_libusb(usb_printer_t *printer, int print_fd);
181 - * 'list_devices()' - List the available printers.
182 + * 'list_devices_libusb()' - List the available printers.
187 +list_devices_libusb(void)
189 - fputs("DEBUG: list_devices\n", stderr);
190 + fputs("DEBUG: list_devices_libusb\n", stderr);
191 find_device(list_cb, NULL);
196 - * 'print_device()' - Print a file to a USB device.
197 + * 'print_device_libusb()' - Print a file to a USB device.
200 int /* O - Exit status */
201 -print_device(const char *uri, /* I - Device URI */
202 +print_device_libusb(const char *uri, /* I - Device URI */
203 const char *hostname, /* I - Hostname/manufacturer */
204 const char *resource, /* I - Resource/modelname */
205 char *options, /* I - Device options/serial number */
206 @@ -105,19 +105,23 @@
207 struct pollfd pfds[2]; /* Poll descriptors */
210 - fputs("DEBUG: print_device\n", stderr);
211 + fputs("DEBUG: print_device_libusb\n", stderr);
214 * Connect to the printer...
217 +#if defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
218 + if ((printer = find_device(print_cb, uri)) == NULL)
221 while ((printer = find_device(print_cb, uri)) == NULL)
223 _cupsLangPuts(stderr,
224 _("INFO: Waiting for printer to become available...\n"));
231 * If we are printing data from a print driver on stdin, ignore SIGTERM
234 if (pfds[1].revents & (POLLIN | POLLHUP))
236 - if ((bytes = side_cb(printer, print_fd)) < 0)
237 + if ((bytes = side_cb_libusb(printer, print_fd)) < 0)
238 pfds[1].events = 0; /* Filter has gone away... */
242 printer.iface = iface;
243 printer.handle = NULL;
245 - if (!open_device(&printer, data != NULL))
246 + if (!open_device_libusb(&printer, data != NULL))
248 if (!get_device_id(&printer, device_id, sizeof(device_id)))
254 + if (!strncasecmp(mdl, mfg, strlen(mfg)))
256 + mdl += strlen(mfg);
258 + while (isspace(*mdl & 255))
263 * Generate the device URI from the manufacturer, model, serial number,
264 * and interface number...
265 @@ -611,11 +623,11 @@
269 - * 'open_device()' - Open a connection to the USB printer.
270 + * 'open_device_libusb()' - Open a connection to the USB printer.
273 static int /* O - 0 on success, -1 on error */
274 -open_device(usb_printer_t *printer, /* I - Printer */
275 +open_device_libusb(usb_printer_t *printer, /* I - Printer */
276 int verbose) /* I - Update connecting-to-device state? */
278 int number; /* Configuration/interface/altset numbers */
279 @@ -733,16 +745,73 @@
280 const char *device_id, /* I - IEEE-1284 device ID */
281 const void *data) /* I - User data (make, model, S/N) */
283 - return (!strcmp((char *)data, device_uri));
284 + char *uri = (char *)data,
288 + requested_uri[1024];
290 + /* Work on a copy of uri */
291 + strncpy(requested_uri, uri, sizeof(requested_uri));
292 + requested_uri[sizeof(requested_uri) - 1] = '\0';
295 + * libusb-discovered URIs can have an "interface" specification and this
296 + * never happens for usblp-discovered URIs, so remove the "interface"
297 + * specification from the URI which we are checking currently. This way a
298 + * queue for a usblp-discovered printer can now be accessed via libusb
300 + if (((str1 = strstr(requested_uri, "interface=")) == NULL) &&
301 + ((str2 = strstr(device_uri, "interface=")) != NULL))
303 + *(str2 - 1) = '\0';
307 + * Old URI with "serial=?". Cut this part off and consider this as
308 + * an URI without serial number
310 + if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
311 + *(str1 - 1) = '\0';
314 + * Old URI without serial number. Match it also with URIs with serial
317 + if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
318 + ((str2 = strstr(device_uri, "serial=")) != NULL))
319 + *(str2 - 1) = '\0';
322 + * libusb-discovered URIs can have a "serial" specification when the
323 + * usblp-discovered URI for the same printer does not have one, as
324 + * with libusb we can discover serial numbers also with other methods
325 + * than only via the device ID. Therefore we accept also a
326 + * usblp-discovered printer without serial number as a match. This we
327 + * do by removing the serial number from the queue's (libusb-discovered)
328 + * URI before comparing. Also warn the user because of the incapability
329 + * of the usblp-based access to distinguish printers by the serial
332 + if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
333 + ((str2 = strstr(device_uri, "serial=")) != NULL))
335 + *(str2 - 1) = '\0';
336 + if (backendGetMakeModel(device_id, buf, sizeof(buf)) == 0)
337 + fprintf(stderr, "WARNING: If you have more than one %s printer connected to this machine, please make sure that the \"usblp\" kernel module is always unloaded (and blacklisted) and re-create the queues for these printers. Otherwise CUPS will not be able to distinguish them.\n",
341 + return (!strcmp(requested_uri, device_uri));
346 - * 'side_cb()' - Handle side-channel requests.
347 + * 'side_cb_libusb()' - Handle side-channel requests.
350 static ssize_t /* O - Number of bytes written */
351 -side_cb(usb_printer_t *printer, /* I - Printer */
352 +side_cb_libusb(usb_printer_t *printer, /* I - Printer */
353 int print_fd) /* I - File to print */
355 ssize_t bytes, /* Bytes read/written */
356 diff -urNad cups-1.4.2~/backend/usb-unix.c cups-1.4.2/backend/usb-unix.c
357 --- cups-1.4.2~/backend/usb-unix.c 2009-09-22 20:47:36.000000000 +0200
358 +++ cups-1.4.2/backend/usb-unix.c 2009-11-12 14:51:47.080261855 +0100
363 - * print_device() - Print a file to a USB device.
364 - * list_devices() - List all USB devices.
365 - * open_device() - Open a USB device...
366 - * side_cb() - Handle side-channel requests...
367 + * print_device_unix() - Print a file to a USB device.
368 + * list_devices_unix() - List all USB devices.
369 + * open_device_unix() - Open a USB device...
370 + * side_cb_unix() - Handle side-channel requests...
378 -static int open_device(const char *uri, int *use_bc);
379 -static int side_cb(int print_fd, int device_fd, int snmp_fd,
380 +static int open_device_unix(const char *uri, int *use_bc);
381 +static int side_cb_unix(int print_fd, int device_fd, int snmp_fd,
382 http_addr_t *addr, int use_bc);
386 - * 'print_device()' - Print a file to a USB device.
387 + * 'print_device_unix()' - Print a file to a USB device.
390 int /* O - Exit status */
391 -print_device(const char *uri, /* I - Device URI */
392 +print_device_unix(const char *uri, /* I - Device URI */
393 const char *hostname, /* I - Hostname/manufacturer */
394 const char *resource, /* I - Resource/modelname */
395 char *options, /* I - Device options/serial number */
397 strncasecmp(hostname, "Minolta", 7);
398 #endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__ */
400 - if ((device_fd = open_device(uri, &use_bc)) == -1)
401 + if ((device_fd = open_device_unix(uri, &use_bc)) == -1)
403 if (getenv("CLASS") != NULL)
406 _("INFO: Printer busy; will retry in 10 seconds...\n"));
413 else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
417 resource, strerror(errno));
418 return (CUPS_BACKEND_FAILED);
423 while (device_fd < 0);
425 tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, NULL);
428 - tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, side_cb);
429 + tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, side_cb_unix);
432 if (print_fd != 0 && tbytes >= 0)
433 @@ -214,11 +219,11 @@
437 - * 'list_devices()' - List all USB devices.
438 + * 'list_devices_unix()' - List all USB devices.
443 +list_devices_unix(void)
446 int i; /* Looping var */
447 @@ -320,11 +325,11 @@
451 - * 'open_device()' - Open a USB device...
452 + * 'open_device_unix()' - Open a USB device...
455 static int /* O - File descriptor or -1 on error */
456 -open_device(const char *uri, /* I - Device URI */
457 +open_device_unix(const char *uri, /* I - Device URI */
458 int *use_bc) /* O - Set to 0 for unidirectional */
460 int fd; /* File descriptor */
462 char device[255], /* Device filename */
463 device_id[1024], /* Device ID string */
464 make_model[1024], /* Make and model */
465 - device_uri[1024]; /* Device URI string */
467 + device_uri[1024], /* Device URI string */
468 + requested_uri[1024], /* Device URI string */
474 * Find the correct USB device...
477 device_uri[0] = '\0';
480 - if (!strcmp(uri, device_uri))
481 + /* Work on a copy of uri */
482 + strncpy(requested_uri, uri, sizeof(requested_uri));
483 + requested_uri[sizeof(requested_uri) - 1] = '\0';
486 + * libusb-discovered URIs can have an "interface" specification and this
487 + * never happens for usblp-discovered URIs, so remove the "interface"
488 + * specification from the URI of the print queue. This way a queue for
489 + * a libusb-discovered printer can now be accessed via the usblip kernel
492 + if ((str1 = strstr(requested_uri, "interface=")) != NULL)
493 + *(str1 - 1) = '\0';
496 + * Old URI with "serial=?". Cut this part off and consider this as
497 + * an URI without serial number
499 + if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
500 + *(str1 - 1) = '\0';
503 + * Old URI without serial number. Match it also with URIs with serial
506 + if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
507 + ((str2 = strstr(device_uri, "serial=")) != NULL))
508 + *(str2 - 1) = '\0';
511 + * libusb-discovered URIs can have a "serial" specification when the
512 + * usblp-discovered URI for the same printer does not have one, as
513 + * with libusb we can discover serial numbers also with other methods
514 + * than only via the device ID. Therefore we accept also a
515 + * usblp-discovered printer without serial number as a match. This we
516 + * do by removing the serial number from the queue's (libusb-discovered)
517 + * URI before comparing. Also warn the user because of the incapability
518 + * of the usblp-based access to distinguish printers by the serial
521 + if (((str1 = strstr(requested_uri, "serial=")) != NULL) &&
522 + ((str2 = strstr(device_uri, "serial=")) == NULL))
524 + *(str1 - 1) = '\0';
525 + fprintf(stderr, "WARNING: If you have more than one %s printer connected to this machine, please unload (and blacklist) the \"usblp\" kernel module as otherwise CUPS will not be able to distinguish your printers.\n",
529 + if (!strcmp(requested_uri, device_uri))
532 * Yes, return this file descriptor...
533 @@ -433,10 +489,14 @@
538 _cupsLangPuts(stderr,
539 _("INFO: Printer busy; will retry in 5 seconds...\n"));
548 #elif defined(__sun) && defined(ECPPIOC_GETDEVID)
549 @@ -557,11 +617,11 @@
553 - * 'side_cb()' - Handle side-channel requests...
554 + * 'side_cb_unix()' - Handle side-channel requests...
557 static int /* O - 0 on success, -1 on error */
558 -side_cb(int print_fd, /* I - Print file */
559 +side_cb_unix(int print_fd, /* I - Print file */
560 int device_fd, /* I - Device file */
561 int snmp_fd, /* I - SNMP socket (unused) */
562 http_addr_t *addr, /* I - Device address (unused) */
563 diff -urNad cups-1.4.2~/backend/usb-unix.c.rej cups-1.4.2/backend/usb-unix.c.rej
564 diff -urNad cups-1.4.2~/backend/usb.c cups-1.4.2/backend/usb.c
565 --- cups-1.4.2~/backend/usb.c 2008-06-24 03:28:36.000000000 +0200
566 +++ cups-1.4.2/backend/usb.c 2009-11-12 14:50:53.482720894 +0100
571 -# include "usb-libusb.c"
572 +# include "usb-hybrid.c"
573 #elif defined(__APPLE__)
574 # include "usb-darwin.c"
575 #elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)