$NetBSD: patch-am,v 1.10 2010/06/09 09:01:43 sbd Exp $

Incorporate
usb-backend-both-usblp-and-libusb.dpatch by  <till.kamppeter@gmail.com>
http://www.cups.org/str.php?L3357

--- backend/usb-unix.c.orig	2009-12-08 02:13:42.000000000 +0000
+++ backend/usb-unix.c
@@ -26,4 +26,14 @@
 
 /*
+ *   If USB_HYBRID is define append "_unix" to functions.
+ */
+#ifdef USB_HYBRID
+# define print_device	print_device_unix
+# define list_devices	list_devices_unix
+# define open_device	open_device_unix
+# define side_cb	side_cb_unix
+#endif
+
+/*
  * Include necessary headers.
  */
@@ -133,4 +143,8 @@ print_device(const char *uri,		/* I - De
 	sleep(10);
       }
+#ifdef HAVE_USB_H
+      else
+	return (-1);
+#else
       else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
                errno == ENODEV)
@@ -148,4 +162,5 @@ print_device(const char *uri,		/* I - De
 	return (CUPS_BACKEND_FAILED);
       }
+#endif
     }
   }
@@ -358,6 +373,8 @@ open_device(const char *uri,		/* I - Dev
 		device_id[1024],	/* Device ID string */
 		make_model[1024],	/* Make and model */
-		device_uri[1024];	/* Device URI string */
-
+		device_uri[1024],	/* Device URI string */
+		requested_uri[1024],	/* Device URI string */
+		*str1,
+		*str2;
 
    /*
@@ -408,5 +425,53 @@ open_device(const char *uri,		/* I - Dev
         }
 
-        if (!strcmp(uri, device_uri))
+	/* Work on a copy of uri */
+	strncpy(requested_uri, uri, sizeof(requested_uri));
+	requested_uri[sizeof(requested_uri) - 1] = '\0';
+
+	/*
+	 * libusb-discovered URIs can have an "interface" specification and this
+	 * never happens for usblp-discovered URIs, so remove the "interface"
+	 * specification from the URI of the print queue. This way a queue for
+	 * a libusb-discovered printer can now be accessed via the usblip kernel
+	 * module
+	 */
+	if ((str1 = strstr(requested_uri, "interface=")) != NULL)
+	  *(str1 - 1) = '\0';
+
+	/*
+	 * Old URI with "serial=?". Cut this part off and consider this as
+	 * an URI without serial number
+	 */
+	if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
+	 *(str1 - 1) = '\0';
+
+	/*
+	 * Old URI without serial number. Match it also with URIs with serial
+	 * number
+	 */
+	if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
+	    ((str2 = strstr(device_uri, "serial=")) != NULL))
+	    *(str2 - 1) = '\0';
+
+	/*
+	 * libusb-discovered URIs can have a "serial" specification when the
+	 * usblp-discovered URI for the same printer does not have one, as
+	 * with libusb we can discover serial numbers also with other methods
+	 * than only via the device ID. Therefore we accept also a
+	 * usblp-discovered printer without serial number as a match. This we
+	 * do by removing the serial number from the queue's (libusb-discovered)
+	 * URI before comparing. Also warn the user because of the incapability
+	 * of the usblp-based access to distinguish printers by the serial
+	 * number.
+	 */
+	if (((str1 = strstr(requested_uri, "serial=")) != NULL) &&
+	    ((str2 = strstr(device_uri, "serial=")) == NULL))
+	{
+	  *(str1 - 1) = '\0';
+	  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",
+		  make_model);
+	}
+
+        if (!strcmp(requested_uri, device_uri))
 	{
 	 /*
@@ -434,8 +499,12 @@ open_device(const char *uri,		/* I - Dev
 
       if (busy)
+      {
 	_cupsLangPuts(stderr,
 	              _("INFO: Printer busy; will retry in 5 seconds...\n"));
 
-      sleep(5);
+	sleep(5);
+      }
+      else
+	return -1;
     }
   }
@@ -626,4 +695,8 @@ side_cb(int         print_fd,		/* I - Pr
 }
 
+#undef print_device
+#undef list_devices
+#undef open_device
+#undef side_cb
 
 /*
