]> git.pld-linux.org Git - packages/cups.git/blame - cups-usb.patch
- rel 2; fix http auth for browsers like google chrome
[packages/cups.git] / cups-usb.patch
CommitLineData
2cd6a49c
BZ
1#! /bin/sh /usr/share/dpatch/dpatch-run
2## usb-backend-both-usblp-and-libusb.dpatch by <till.kamppeter@gmail.com>
3##
4## DP: http://www.cups.org/str.php?L3357
5
6@DPATCH@
7diff -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
10@@ -267,7 +267,7 @@
11 echo Linking $@...
12 $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \
13 $(BACKLIBS) $(LIBS)
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
16
17
18 #
19diff -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
22@@ -275,6 +275,7 @@
23 cups_option_t *values; /* Keys and values in device ID */
24 const char *mfg, /* Manufacturer */
25 *mdl, /* Model */
26+ *des, /* Description */
27 *sern; /* Serial number */
28 char temp[256], /* Temporary manufacturer string */
29 *tempptr; /* Pointer into temp string */
30@@ -305,10 +306,20 @@
31 }
32 else
33 {
34- strlcpy(temp, make_model, sizeof(temp));
35+ /*
36+ * No manufacturer? Use the model string or description...
37+ */
38+
39+ if (mdl)
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));
44+ else
45+ strlcpy(temp, "Unknown", sizeof(temp));
46
47 if ((tempptr = strchr(temp, ' ')) != NULL)
48- *tempptr = '\0';
49+ *tempptr = '\0';
50
51 mfg = temp;
52 }
53diff -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
56@@ -0,0 +1,87 @@
57+/*
58+ * "$Id$"
59+ *
60+ * USB port backend for the Common UNIX Printing System (CUPS).
61+ *
62+ * This file is included from "usb.c" when compiled on Linux.
63+ *
64+ * Copyright 2007-2008 by Apple Inc.
65+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
66+ *
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/".
72+ *
73+ * This file is subject to the Apple OS-Developed Software exception.
74+ *
75+ * Contents:
76+ *
77+ * print_device() - Print a file to a USB device.
78+ * list_devices() - List all USB devices.
79+ */
80+
81+/*
82+ * Include necessary headers.
83+ */
84+
85+#include <sys/select.h>
86+
87+/*
88+ * Include the two USB implementations used under Linux ...
89+ */
90+
91+#include "usb-libusb.c"
92+#include "usb-unix.c"
93+
94+/*
95+ * 'print_device()' - Print a file to a USB device.
96+ */
97+
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 */
107+{
108+ int result;
109+ for(;;)
110+ {
111+ result = print_device_unix(uri, hostname, resource, options, print_fd,
112+ copies, argc, argv);
113+ if (result == -1)
114+ {
115+ result = print_device_libusb(uri, hostname, resource, options, print_fd,
116+ copies, argc, argv);
117+ if (result == -1)
118+ sleep(5);
119+ else
120+ return(result);
121+ }
122+ else
123+ return(result);
124+ }
125+}
126+
127+/*
128+ * 'list_devices()' - List all USB devices.
129+ */
130+
131+void
132+list_devices(void)
133+{
134+ /* Try both discovery methods, each device will appear only under one
135+ of them */
136+ list_devices_libusb();
137+ list_devices_unix();
138+}
139+
140+
141+/*
142+ * End of "$Id$".
143+ */
144diff -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
147@@ -13,16 +13,16 @@
148 *
149 * Contents:
150 *
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.
165 */
166
167 /*
168@@ -65,30 +65,30 @@
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);
178
179
180 /*
181- * 'list_devices()' - List the available printers.
182+ * 'list_devices_libusb()' - List the available printers.
183 */
184
185 void
186-list_devices(void)
187+list_devices_libusb(void)
188 {
189- fputs("DEBUG: list_devices\n", stderr);
190+ fputs("DEBUG: list_devices_libusb\n", stderr);
191 find_device(list_cb, NULL);
192 }
193
194
195 /*
196- * 'print_device()' - Print a file to a USB device.
197+ * 'print_device_libusb()' - Print a file to a USB device.
198 */
199
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 */
208
209
210- fputs("DEBUG: print_device\n", stderr);
211+ fputs("DEBUG: print_device_libusb\n", stderr);
212
213 /*
214 * Connect to the printer...
215 */
216
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)
219+ return(-1);
220+#else
221 while ((printer = find_device(print_cb, uri)) == NULL)
222 {
223 _cupsLangPuts(stderr,
224 _("INFO: Waiting for printer to become available...\n"));
225 sleep(5);
226 }
227-
228+#endif
229
230 /*
231 * If we are printing data from a print driver on stdin, ignore SIGTERM
232@@ -189,7 +193,7 @@
233
234 if (pfds[1].revents & (POLLIN | POLLHUP))
235 {
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... */
239 else
240 tbytes += bytes;
241@@ -359,7 +363,7 @@
242 printer.iface = iface;
243 printer.handle = NULL;
244
245- if (!open_device(&printer, data != NULL))
246+ if (!open_device_libusb(&printer, data != NULL))
247 {
248 if (!get_device_id(&printer, device_id, sizeof(device_id)))
249 {
250@@ -583,6 +587,14 @@
251 mfg = tempmfg;
252 }
253
254+ if (!strncasecmp(mdl, mfg, strlen(mfg)))
255+ {
256+ mdl += strlen(mfg);
257+
258+ while (isspace(*mdl & 255))
259+ mdl ++;
260+ }
261+
262 /*
263 * Generate the device URI from the manufacturer, model, serial number,
264 * and interface number...
265@@ -611,11 +623,11 @@
266
267
268 /*
269- * 'open_device()' - Open a connection to the USB printer.
270+ * 'open_device_libusb()' - Open a connection to the USB printer.
271 */
272
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? */
277 {
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) */
282 {
283- return (!strcmp((char *)data, device_uri));
284+ char *uri = (char *)data,
285+ *str1,
286+ *str2,
287+ buf[255],
288+ requested_uri[1024];
289+
290+ /* Work on a copy of uri */
291+ strncpy(requested_uri, uri, sizeof(requested_uri));
292+ requested_uri[sizeof(requested_uri) - 1] = '\0';
293+
294+ /*
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
299+ */
300+ if (((str1 = strstr(requested_uri, "interface=")) == NULL) &&
301+ ((str2 = strstr(device_uri, "interface=")) != NULL))
302+ {
303+ *(str2 - 1) = '\0';
304+ }
305+
306+ /*
307+ * Old URI with "serial=?". Cut this part off and consider this as
308+ * an URI without serial number
309+ */
310+ if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
311+ *(str1 - 1) = '\0';
312+
313+ /*
314+ * Old URI without serial number. Match it also with URIs with serial
315+ * number
316+ */
317+ if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
318+ ((str2 = strstr(device_uri, "serial=")) != NULL))
319+ *(str2 - 1) = '\0';
320+
321+ /*
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
330+ * number.
331+ */
332+ if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
333+ ((str2 = strstr(device_uri, "serial=")) != NULL))
334+ {
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",
338+ buf);
339+ }
340+
341+ return (!strcmp(requested_uri, device_uri));
342 }
343
344
345 /*
346- * 'side_cb()' - Handle side-channel requests.
347+ * 'side_cb_libusb()' - Handle side-channel requests.
348 */
349
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 */
354 {
355 ssize_t bytes, /* Bytes read/written */
356diff -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
359@@ -18,10 +18,10 @@
360 *
361 * Contents:
362 *
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...
371 */
372
373 /*
374@@ -35,17 +35,17 @@
375 * Local functions...
376 */
377
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);
383
384
385 /*
386- * 'print_device()' - Print a file to a USB device.
387+ * 'print_device_unix()' - Print a file to a USB device.
388 */
389
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 */
396@@ -102,7 +102,7 @@
397 strncasecmp(hostname, "Minolta", 7);
398 #endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__ */
399
400- if ((device_fd = open_device(uri, &use_bc)) == -1)
401+ if ((device_fd = open_device_unix(uri, &use_bc)) == -1)
402 {
403 if (getenv("CLASS") != NULL)
404 {
405@@ -132,6 +132,10 @@
406 _("INFO: Printer busy; will retry in 10 seconds...\n"));
407 sleep(10);
408 }
409+#ifdef HAVE_USB_H
410+ else
411+ return (-1);
412+#else
413 else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
414 errno == ENODEV)
415 {
416@@ -147,6 +151,7 @@
417 resource, strerror(errno));
418 return (CUPS_BACKEND_FAILED);
419 }
420+#endif
421 }
422 }
423 while (device_fd < 0);
f72ae4ea
AM
424@@ -197,7 +197,7 @@
425 tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, NULL);
2cd6a49c
BZ
426
427 #else
f72ae4ea
AM
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);
2cd6a49c
BZ
430 #endif /* __sun */
431
432 if (print_fd != 0 && tbytes >= 0)
433@@ -214,11 +219,11 @@
434
435
436 /*
437- * 'list_devices()' - List all USB devices.
438+ * 'list_devices_unix()' - List all USB devices.
439 */
440
441 void
442-list_devices(void)
443+list_devices_unix(void)
444 {
445 #ifdef __linux
446 int i; /* Looping var */
447@@ -320,11 +325,11 @@
448
449
450 /*
451- * 'open_device()' - Open a USB device...
452+ * 'open_device_unix()' - Open a USB device...
453 */
454
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 */
459 {
460 int fd; /* File descriptor */
461@@ -357,9 +362,12 @@
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 */
466-
467+ device_uri[1024], /* Device URI string */
468+ requested_uri[1024], /* Device URI string */
469+ *str1,
470+ *str2;
471
472+
473 /*
474 * Find the correct USB device...
475 */
476@@ -407,7 +415,55 @@
477 device_uri[0] = '\0';
478 }
479
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';
484+
485+ /*
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
490+ * module
491+ */
492+ if ((str1 = strstr(requested_uri, "interface=")) != NULL)
493+ *(str1 - 1) = '\0';
494+
495+ /*
496+ * Old URI with "serial=?". Cut this part off and consider this as
497+ * an URI without serial number
498+ */
499+ if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
500+ *(str1 - 1) = '\0';
501+
502+ /*
503+ * Old URI without serial number. Match it also with URIs with serial
504+ * number
505+ */
506+ if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
507+ ((str2 = strstr(device_uri, "serial=")) != NULL))
508+ *(str2 - 1) = '\0';
509+
510+ /*
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
519+ * number.
520+ */
521+ if (((str1 = strstr(requested_uri, "serial=")) != NULL) &&
522+ ((str2 = strstr(device_uri, "serial=")) == NULL))
523+ {
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",
526+ make_model);
527+ }
528+
529+ if (!strcmp(requested_uri, device_uri))
530 {
531 /*
532 * Yes, return this file descriptor...
533@@ -433,10 +489,14 @@
534 */
535
536 if (busy)
537+ {
538 _cupsLangPuts(stderr,
539 _("INFO: Printer busy; will retry in 5 seconds...\n"));
540
541- sleep(5);
542+ sleep(5);
543+ }
544+ else
545+ return -1;
546 }
547 }
548 #elif defined(__sun) && defined(ECPPIOC_GETDEVID)
549@@ -557,11 +617,11 @@
550
551
552 /*
553- * 'side_cb()' - Handle side-channel requests...
554+ * 'side_cb_unix()' - Handle side-channel requests...
555 */
556
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) */
563diff -urNad cups-1.4.2~/backend/usb-unix.c.rej cups-1.4.2/backend/usb-unix.c.rej
564diff -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
567@@ -56,7 +56,7 @@
568 */
569
570 #ifdef HAVE_USB_H
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__)
This page took 0.140065 seconds and 4 git commands to generate.