Closed michaelrsweet closed 12 years ago
CUPS.org User: till.kamppeter
Updated the patch for CUPS 1.4.3.
CUPS.org User: till.kamppeter
As talked about with Mike Sweet on the OpenPrinting Summit 2010 I have updated the patch. With this an easy transition between usblp and libusb without need to change the URIs of existing queues is possible and users of binary packages in distributions can choose whether they want to use usblp or libusb.
The patch is already in use in the Debian and Ubuntu distributions for several months and there are no user complaints about it.
CUPS.org User: sbd
Great patch, but there's no allowance made for "--disable-libusb", so I've posted a revison that does.
CUPS.org User: mike
Sorry, we have decided this issue will not be addressed in a CUPS release.
"usb-backend-both-usblp-and-libusb.patch":
--- backend/Makefile.orig 2009-09-29 14:22:59.000000000 +0200 +++ backend/Makefile 2009-09-29 14:24:47.000000000 +0200 @@ -267,7 +267,7 @@ echo Linking $@... $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \ $(BACKLIBS) $(LIBS) -usb.o: usb.c usb-darwin.c usb-libusb.c usb-unix.c +usb.o: usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c
# --- backend/ieee1284.c.orig 2009-09-29 16:53:31.000000000 +0200 +++ backend/ieee1284.c 2009-09-29 17:01:15.000000000 +0200 @@ -275,6 +275,7 @@ cups_option_t values; / Keys and values in device ID / const char *mfg, / Manufacturer / *mdl, / Model */
strlcpy(temp, "Unknown", sizeof(temp));
if ((tempptr = strchr(temp, ' ')) != NULL)
*tempptr = '\0';
mfg = temp; } --- backend/usb-hybrid.c.orig 2009-09-30 10:11:29.000000000 +0200 +++ backend/usb-hybrid.c 2009-09-30 09:29:52.000000000 +0200 @@ -0,0 +1,87 @@ +/*
/ @@ -65,30 +65,30 @@ static char make_device_uri(usb_printer_t printer, const char device_id, char uri, size_t uri_size); -static int open_device(usb_printer_t printer, int verbose); +static int open_device_libusb(usb_printer_t printer, int verbose); static int print_cb(usb_printer_t printer, const char device_uri, const char device_id, const void data); -static ssize_t side_cb(usb_printer_t printer, int print_fd); +static ssize_t side_cb_libusb(usb_printer_t *printer, int print_fd);
/*
void -list_devices(void) +list_devices_libusb(void) {
fputs("DEBUG: list_devices_libusb\n", stderr); find_device(list_cb, NULL); }
/*
int /* O - Exit status _/ -printdevice(const char *uri, / I - Device URI _/ +print_devicelibusb(const char *uri, / I - Device URI / const char *hostname, / I - Hostname/manufacturer / const char *resource, / I - Resource/modelname / char *options, / I - Device options/serial number / @@ -105,19 +105,23 @@ struct pollfd pfds[2]; / Poll descriptors */
fputs("DEBUG: print_device_libusb\n", stderr);
/*
+#if defined(linux) || defined(sun) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD) || defined(DragonFly) || defined(FreeBSD_kernel)
return(-1); +#else while ((printer = find_device(print_cb, uri)) == NULL) { cupsLangPuts(stderr, ("INFO: Waiting for printer to become available...\n")); sleep(5);
+#endif
/*
if (pfds[1].revents & (POLLIN | POLLHUP)) {
if ((bytes = side_cb_libusb(printer, print_fd)) < 0)
pfds[1].events = 0; /* Filter has gone away... */ else tbytes += bytes; @@ -359,12 +363,13 @@ printer.iface = iface; printer.handle = NULL;
if (!open_device(&printer, data != NULL))
fprintf(stderr, "XXX 1 |%s|\n", device_uri);
if ((*cb)(&printer, device_uri, device_id, data))
{
@@ -583,6 +588,14 @@ mfg = tempmfg; }
} + /*
/*
static int /* O - 0 on success, -1 on error _/ -open_device(usb_printert *printer, / I - Printer _/ +open_device_libusb(usb_printert *printer, / I - Printer / int verbose) / I - Update connecting-to-device state? / { int number; / Configuration/interface/altset numbers _/ @@ -733,16 +746,54 @@ const char deviceid, / I - IEEE-1284 device ID _/ const void data) /_ I - User data (make, model, S/N) */ {
return (!strcmp(uri, device_uri)); }
/*
static ssizet /* O - Number of bytes written / -side_cb(usb_printert *printer, / I - Printer _/ +side_cb_libusb(usb_printert *printer, / I - Printer _/ int printfd) / I - File to print _/ { ssizet bytes, / Bytes read/written / --- backend/usb-unix.c.orig 2009-09-29 14:06:25.000000000 +0200 +++ backend/usb-unix.c 2009-09-30 10:35:23.000000000 +0200 @@ -18,10 +18,10 @@
/* @@ -35,17 +35,17 @@
-static int open_device(const char uri, int use_bc); -static int side_cb(int print_fd, int device_fd, int snmp_fd, +static int open_device_unix(const char uri, int use_bc); +static int side_cb_unix(int print_fd, int device_fd, int snmp_fd, http_addr_t *addr, int use_bc);
/*
int /* O - Exit status _/ -printdevice(const char *uri, / I - Device URI _/ +print_deviceunix(const char *uri, / I - Device URI / const char *hostname, / I - Hostname/manufacturer / const char *resource, / I - Resource/modelname / char *options, / I - Device options/serial number _/ @@ -102,7 +102,7 @@ strncasecmp(hostname, "Minolta", 7);
return (-1); +#else else if (errno == ENXIO || errno == EIO || errno == ENOENT || errno == ENODEV) { @@ -147,6 +151,7 @@ resource, strerror(errno)); return (CUPS_BACKEND_FAILED); } +#endif } } while (device_fd < 0); @@ -190,7 +195,7 @@ tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, NULL);
tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, side_cb_unix);
if (print_fd != 0 && tbytes >= 0) @@ -214,11 +219,11 @@
/*
void -list_devices(void) +list_devices_unix(void) {
int i; /* Looping var */ @@ -320,11 +325,11 @@
/*
static int /* O - File descriptor or -1 on error _/ -opendevice(const char *uri, / I - Device URI _/ +open_deviceunix(const char *uri, / I - Device URI _/ int usebc) / O - Set to 0 for unidirectional / { int fd; / File descriptor / @@ -357,8 +362,21 @@ char device[255], / Device filename _/ deviceid[1024], / Device ID string _/ makemodel[1024], / Make and model /
*str2;
}
/*
fprintf(stderr, "XXX U |%s|%s|\n", uri, device_uri); if (!strcmp(uri, device_uri)) { / @@ -433,10 +471,14 @@ /
if (busy)
{
cupsLangPuts(stderr, ("INFO: Printer busy; will retry in 5 seconds...\n"));
sleep(5);
return -1; } }
@@ -557,11 +599,11 @@
/*
-static void -side_cb(int printfd, /* I - Print file / +static int +side_cb_unix(int printfd, / I - Print file _/ int devicefd, / I - Device file _/ int snmpfd, / I - SNMP socket (unused) _/ http_addrt *addr, / I - Device address (unused) / --- backend/usb.c.orig 2008-06-24 03:28:36.000000000 +0200 +++ backend/usb.c 2009-09-29 14:21:51.000000000 +0200 @@ -56,7 +56,7 @@ /
-# include "usb-libusb.c" +# include "usb-hybrid.c"
"usb-backend-both-usblp-and-libusb-2.diff":
diff -up -rN cups-1.4.3.orig/backend/Makefile cups-1.4.3/backend/Makefile --- cups-1.4.3.orig/backend/Makefile 2010-06-09 20:58:19.641591399 +1200 +++ cups-1.4.3/backend/Makefile 2010-06-09 20:51:06.025595868 +1200 @@ -267,7 +267,7 @@ usb: usb.o ../cups/$(LIBCUPS) libbackend echo Linking $@... $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \ $(BACKLIBS) $(LIBS) -usb.o: usb.c usb-darwin.c usb-libusb.c usb-unix.c +usb.o: usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c
# diff -up -rN cups-1.4.3.orig/backend/ieee1284.c cups-1.4.3/backend/ieee1284.c --- cups-1.4.3.orig/backend/ieee1284.c 2009-12-08 15:13:42.000000000 +1300 +++ cups-1.4.3/backend/ieee1284.c 2010-06-09 20:51:06.357598941 +1200 @@ -255,6 +255,7 @@ backendGetDeviceID( cups_option_t values; / Keys and values in device ID / const char *mfg, / Manufacturer / *mdl, / Model */
strlcpy(temp, "Unknown", sizeof(temp));
if ((tempptr = strchr(temp, ' ')) != NULL)
*tempptr = '\0';
mfg = temp; } diff -up -rN cups-1.4.3.orig/backend/usb-hybrid.c cups-1.4.3/backend/usb-hybrid.c --- cups-1.4.3.orig/backend/usb-hybrid.c 1970-01-01 12:00:00.000000000 +1200 +++ cups-1.4.3/backend/usb-hybrid.c 2010-06-09 20:51:06.441597823 +1200 @@ -0,0 +1,88 @@ +/*
/ @@ -65,30 +65,30 @@ static int list_cb(usb_printer_t print static char make_device_uri(usb_printer_t printer, const char device_id, char uri, size_t uri_size); -static int open_device(usb_printer_t printer, int verbose); +static int open_device_libusb(usb_printer_t printer, int verbose); static int print_cb(usb_printer_t printer, const char device_uri, const char device_id, const void data); -static ssize_t side_cb(usb_printer_t printer, int print_fd); +static ssize_t side_cb_libusb(usb_printer_t printer, int print_fd);
/*
void -list_devices(void) +list_devices_libusb(void) {
fputs("DEBUG: list_devices_libusb\n", stderr); find_device(list_cb, NULL); }
/*
int /* O - Exit status _/ -printdevice(const char *uri, / I - Device URI _/ +print_devicelibusb(const char *uri, / I - Device URI / const char *hostname, / I - Hostname/manufacturer / const char *resource, / I - Resource/modelname / char *options, / I - Device options/serial number _/ @@ -105,19 +105,23 @@ printdevice(const char *uri, / I - De struct pollfd pfds[2]; /* Poll descriptors */
fputs("DEBUG: print_device_libusb\n", stderr);
/*
+#if defined(linux) || defined(sun) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD) || defined(DragonFly) || defined(FreeBSD_kernel)
return(-1); +#else while ((printer = find_device(print_cb, uri)) == NULL) { cupsLangPuts(stderr, ("INFO: Waiting for printer to become available...\n")); sleep(5);
+#endif
/*
if (pfds[1].revents & (POLLIN | POLLHUP)) {
if ((bytes = side_cb_libusb(printer, print_fd)) < 0)
pfds[1].events = 0; /* Filter has gone away... _/ else tbytes += bytes; @@ -359,7 +363,7 @@ find_device(usb_cbt cb, / I - Callb printer.iface = iface; printer.handle = NULL;
if (!open_device(&printer, data != NULL))
if (!open_device_libusb(&printer, data != NULL))
{
if (!get_device_id(&printer, device_id, sizeof(device_id)))
{
@@ -583,6 +587,14 @@ make_device_uri( mfg = tempmfg; }
} + /*
/*
static int /* O - 0 on success, -1 on error _/ -open_device(usb_printert *printer, / I - Printer _/ +open_device_libusb(usb_printert *printer, / I - Printer / int verbose) / I - Update connecting-to-device state? / { int number; / Configuration/interface/altset numbers _/ @@ -733,16 +745,73 @@ print_cb(usb_printert *printer, / I - const char _deviceid, / I - IEEE-1284 device ID / const void *data) / I - User data (make, model, S/N) */ {
return (!strcmp(requested_uri, device_uri)); }
/*
static ssizet /* O - Number of bytes written / -side_cb(usb_printert *printer, / I - Printer _/ +side_cb_libusb(usb_printert *printer, / I - Printer _/ int printfd) / I - File to print _/ { ssizet bytes, / Bytes read/written / diff -up -rN cups-1.4.3.orig/backend/usb-unix.c cups-1.4.3/backend/usb-unix.c --- cups-1.4.3.orig/backend/usb-unix.c 2009-12-08 15:13:42.000000000 +1300 +++ cups-1.4.3/backend/usb-unix.c 2010-06-09 20:51:06.613600058 +1200 @@ -25,6 +25,16 @@ /
/*
@@ -132,6 +142,10 @@ print_device(const char uri, / I - De _("INFO: Printer busy; will retry in 10 seconds...\n")); sleep(10); } +#ifdef HAVE_USB_H
*str2;
/*
if (!strcmp(uri, device_uri))
if (!strcmp(requested_uri, device_uri))
{ /*
if (busy)
{
cupsLangPuts(stderr, ("INFO: Printer busy; will retry in 5 seconds...\n"));
sleep(5);
@@ -625,6 +694,10 @@ side_cb(int print_fd, /* I - Pr return (cupsSideChannelWrite(command, status, data, datalen, 1.0)); }
+#undef print_device +#undef list_devices +#undef open_device +#undef side_cb
/*
End of "$Id: usb-unix.c 8912 2009-12-08 02:13:42Z mike $". diff -up -rN cups-1.4.3.orig/backend/usb.c cups-1.4.3/backend/usb.c --- cups-1.4.3.orig/backend/usb.c 2008-06-24 13:28:36.000000000 +1200 +++ cups-1.4.3/backend/usb.c 2010-06-09 20:51:06.801599220 +1200 @@ -56,7 +56,7 @@ int print_device(const char uri, const /
-# include "usb-libusb.c" +# include "usb-hybrid.c"
Version: -feature CUPS.org User: till.kamppeter
On Linux (and perhaps some other Unixes), the "usb" backend can currently be either compiled to access the printers through the "usblp" kernel module (/dev/usb/lp*) or through libusb (low-level USB), but one cannot have one backend which uses both access methods.
This causes a problem when transferring Linux distributions from the use of the kernel module to the use of libusb. Reasons why to switch libusb are:
Problems of the switchover are caused by the absence of the usblp kernel module, for example printer firmware upload through /dev/usb/lp*, ecputil, libinklevel, ... Also URIs have changed and so printers created with the usb backend of CUPS 1.3.x will not work with the new 1ibusb-based backend.
The attached patch make one "usb" backend out of the two. This new backend
The attached patch is done in a somehow minimum invasive way, keeping the changes small. Probably one can simplify the code. It was also not tested whether whether it works with all possibilities of conditional compiling. I have tested on both the HP LaserJet 3390 and the HP PhotoSmart C8100. On both printers one can print with and without "usblp" loaded and without needing to re-create the print queues.
The patch is for CUPS 1.4.1.