summaryrefslogtreecommitdiff
path: root/print/cups/patches/patch-am
blob: 3ab3f71d9dbf59db8700f0c8bd205ffc6f234147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
$NetBSD: patch-am,v 1.9 2010/06/05 23:09:29 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
@@ -18,10 +18,10 @@
  *
  * Contents:
  *
- *   print_device() - Print a file to a USB device.
- *   list_devices() - List all USB devices.
- *   open_device()  - Open a USB device...
- *   side_cb()      - Handle side-channel requests...
+ *   print_device_unix() - Print a file to a USB device.
+ *   list_devices_unix() - List all USB devices.
+ *   open_device_unix()  - Open a USB device...
+ *   side_cb_unix()      - Handle side-channel requests...
  */
 
 /*
@@ -35,17 +35,17 @@
  * Local functions...
  */
 
-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);
 
 
 /*
- * 'print_device()' - Print a file to a USB device.
+ * 'print_device_unix()' - Print a file to a USB device.
  */
 
 int					/* O - Exit status */
-print_device(const char *uri,		/* I - Device URI */
+print_device_unix(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 @@ print_device(const char *uri,		/* I - De
              strncasecmp(hostname, "Minolta", 7);
 #endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__ */
 
-    if ((device_fd = open_device(uri, &use_bc)) == -1)
+    if ((device_fd = open_device_unix(uri, &use_bc)) == -1)
     {
       if (getenv("CLASS") != NULL)
       {
@@ -132,6 +132,10 @@ print_device(const char *uri,		/* I - De
 	              _("INFO: Printer busy; will retry in 10 seconds...\n"));
 	sleep(10);
       }
+#ifdef HAVE_USB_H
+      else
+	return (-1);
+#else
       else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
                errno == ENODEV)
       {
@@ -147,6 +151,7 @@ print_device(const char *uri,		/* I - De
 			resource, strerror(errno));
 	return (CUPS_BACKEND_FAILED);
       }
+#endif
     }
   }
   while (device_fd < 0);
@@ -190,7 +195,7 @@ print_device(const char *uri,		/* I - De
     tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, NULL);
 
 #else
-    tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, side_cb);
+    tbytes = backendRunLoop(print_fd, device_fd, -1, NULL, use_bc, 1, side_cb_unix);
 #endif /* __sun */
 
     if (print_fd != 0 && tbytes >= 0)
@@ -214,11 +219,11 @@ print_device(const char *uri,		/* I - De
 
 
 /*
- * 'list_devices()' - List all USB devices.
+ * 'list_devices_unix()' - List all USB devices.
  */
 
 void
-list_devices(void)
+list_devices_unix(void)
 {
 #ifdef __linux
   int	i;				/* Looping var */
@@ -320,11 +325,11 @@ list_devices(void)
 
 
 /*
- * 'open_device()' - Open a USB device...
+ * 'open_device_unix()' - Open a USB device...
  */
 
 static int				/* O - File descriptor or -1 on error */
-open_device(const char *uri,		/* I - Device URI */
+open_device_unix(const char *uri,		/* I - Device URI */
             int        *use_bc)		/* O - Set to 0 for unidirectional */
 {
   int	fd;				/* File descriptor */
@@ -357,9 +362,12 @@ open_device(const char *uri,		/* I - Dev
     char	device[255],		/* Device filename */
 		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;
 
+    
    /*
     * Find the correct USB device...
     */
@@ -407,7 +415,55 @@ open_device(const char *uri,		/* I - Dev
 	  device_uri[0] = '\0';
         }
 
-        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))
 	{
 	 /*
 	  * Yes, return this file descriptor...
@@ -433,10 +489,14 @@ 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;
     }
   }
 #elif defined(__sun) && defined(ECPPIOC_GETDEVID)
@@ -557,11 +617,11 @@ open_device(const char *uri,		/* I - Dev
 
 
 /*
- * 'side_cb()' - Handle side-channel requests...
+ * 'side_cb_unix()' - Handle side-channel requests...
  */
 
 static int				/* O - 0 on success, -1 on error */
-side_cb(int         print_fd,		/* I - Print file */
+side_cb_unix(int         print_fd,		/* I - Print file */
         int         device_fd,		/* I - Device file */
         int         snmp_fd,		/* I - SNMP socket (unused) */
 	http_addr_t *addr,		/* I - Device address (unused) */