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
213
214
215
216
217
|
$NetBSD: patch-al,v 1.8 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-libusb.c.orig 2009-09-11 20:03:31.000000000 +0000
+++ backend/usb-libusb.c
@@ -13,16 +13,16 @@
*
* Contents:
*
- * list_devices() - List the available printers.
- * print_device() - Print a file to a USB device.
+ * list_devices_libusb() - List the available printers.
+ * print_device_libusb() - Print a file to a USB device.
* close_device() - Close the connection to the USB printer.
* find_device() - Find or enumerate USB printers.
* get_device_id() - Get the IEEE-1284 device ID for the printer.
* list_cb() - List USB printers for discovery.
* make_device_uri() - Create a device URI for a USB printer.
- * open_device() - Open a connection to the USB printer.
+ * open_device_libusb() - Open a connection to the USB printer.
* print_cb() - Find a USB printer for printing.
- * side_cb() - Handle side-channel requests.
+ * side_cb_libusb() - Handle side-channel requests.
*/
/*
@@ -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);
/*
- * 'list_devices()' - List the available printers.
+ * 'list_devices_libusb()' - List the available printers.
*/
void
-list_devices(void)
+list_devices_libusb(void)
{
- fputs("DEBUG: list_devices\n", stderr);
+ fputs("DEBUG: list_devices_libusb\n", stderr);
find_device(list_cb, NULL);
}
/*
- * 'print_device()' - Print a file to a USB device.
+ * 'print_device_libusb()' - Print a file to a USB device.
*/
int /* O - Exit status */
-print_device(const char *uri, /* I - Device URI */
+print_device_libusb(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 @@ print_device(const char *uri, /* I - De
struct pollfd pfds[2]; /* Poll descriptors */
- fputs("DEBUG: print_device\n", stderr);
+ fputs("DEBUG: print_device_libusb\n", stderr);
/*
* Connect to the printer...
*/
+#if defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
+ if ((printer = find_device(print_cb, uri)) == NULL)
+ 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 we are printing data from a print driver on stdin, ignore SIGTERM
@@ -189,7 +193,7 @@ print_device(const char *uri, /* I - De
if (pfds[1].revents & (POLLIN | POLLHUP))
{
- if ((bytes = side_cb(printer, print_fd)) < 0)
+ 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_cb_t 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;
}
+ if (!strncasecmp(mdl, mfg, strlen(mfg)))
+ {
+ mdl += strlen(mfg);
+
+ while (isspace(*mdl & 255))
+ mdl ++;
+ }
+
/*
* Generate the device URI from the manufacturer, model, serial number,
* and interface number...
@@ -611,11 +623,11 @@ make_device_uri(
/*
- * 'open_device()' - Open a connection to the USB printer.
+ * 'open_device_libusb()' - Open a connection to the USB printer.
*/
static int /* O - 0 on success, -1 on error */
-open_device(usb_printer_t *printer, /* I - Printer */
+open_device_libusb(usb_printer_t *printer, /* I - Printer */
int verbose) /* I - Update connecting-to-device state? */
{
int number; /* Configuration/interface/altset numbers */
@@ -733,16 +745,73 @@ print_cb(usb_printer_t *printer, /* I -
const char *device_id, /* I - IEEE-1284 device ID */
const void *data) /* I - User data (make, model, S/N) */
{
- return (!strcmp((char *)data, device_uri));
+ char *uri = (char *)data,
+ *str1,
+ *str2,
+ buf[255],
+ requested_uri[1024];
+
+ /* 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 which we are checking currently. This way a
+ * queue for a usblp-discovered printer can now be accessed via libusb
+ */
+ if (((str1 = strstr(requested_uri, "interface=")) == NULL) &&
+ ((str2 = strstr(device_uri, "interface=")) != NULL))
+ {
+ *(str2 - 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))
+ {
+ *(str2 - 1) = '\0';
+ if (backendGetMakeModel(device_id, buf, sizeof(buf)) == 0)
+ 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",
+ buf);
+ }
+
+ return (!strcmp(requested_uri, device_uri));
}
/*
- * 'side_cb()' - Handle side-channel requests.
+ * 'side_cb_libusb()' - Handle side-channel requests.
*/
static ssize_t /* O - Number of bytes written */
-side_cb(usb_printer_t *printer, /* I - Printer */
+side_cb_libusb(usb_printer_t *printer, /* I - Printer */
int print_fd) /* I - File to print */
{
ssize_t bytes, /* Bytes read/written */
|