|
Lines 13-28
Link Here
|
| 13 |
* |
13 |
* |
| 14 |
* Contents: |
14 |
* Contents: |
| 15 |
* |
15 |
* |
| 16 |
* list_devices() - List the available printers. |
16 |
* list_devices_libusb() - List the available printers. |
| 17 |
* print_device() - Print a file to a USB device. |
17 |
* print_device_libusb() - Print a file to a USB device. |
| 18 |
* close_device() - Close the connection to the USB printer. |
18 |
* close_device() - Close the connection to the USB printer. |
| 19 |
* find_device() - Find or enumerate USB printers. |
19 |
* find_device() - Find or enumerate USB printers. |
| 20 |
* get_device_id() - Get the IEEE-1284 device ID for the printer. |
20 |
* get_device_id() - Get the IEEE-1284 device ID for the printer. |
| 21 |
* list_cb() - List USB printers for discovery. |
21 |
* list_cb() - List USB printers for discovery. |
| 22 |
* make_device_uri() - Create a device URI for a USB printer. |
22 |
* make_device_uri() - Create a device URI for a USB printer. |
| 23 |
* open_device() - Open a connection to the USB printer. |
23 |
* open_device_libusb() - Open a connection to the USB printer. |
| 24 |
* print_cb() - Find a USB printer for printing. |
24 |
* print_cb() - Find a USB printer for printing. |
| 25 |
* side_cb() - Handle side-channel requests. |
25 |
* side_cb_libusb() - Handle side-channel requests. |
| 26 |
*/ |
26 |
*/ |
| 27 |
|
27 |
|
| 28 |
/* |
28 |
/* |
|
Lines 65-94
Link Here
|
| 65 |
static char *make_device_uri(usb_printer_t *printer, |
65 |
static char *make_device_uri(usb_printer_t *printer, |
| 66 |
const char *device_id, |
66 |
const char *device_id, |
| 67 |
char *uri, size_t uri_size); |
67 |
char *uri, size_t uri_size); |
| 68 |
static int open_device(usb_printer_t *printer, int verbose); |
68 |
static int open_device_libusb(usb_printer_t *printer, int verbose); |
| 69 |
static int print_cb(usb_printer_t *printer, const char *device_uri, |
69 |
static int print_cb(usb_printer_t *printer, const char *device_uri, |
| 70 |
const char *device_id, const void *data); |
70 |
const char *device_id, const void *data); |
| 71 |
static ssize_t side_cb(usb_printer_t *printer, int print_fd); |
71 |
static ssize_t side_cb_libusb(usb_printer_t *printer, int print_fd); |
| 72 |
|
72 |
|
| 73 |
|
73 |
|
| 74 |
/* |
74 |
/* |
| 75 |
* 'list_devices()' - List the available printers. |
75 |
* 'list_devices_libusb()' - List the available printers. |
| 76 |
*/ |
76 |
*/ |
| 77 |
|
77 |
|
| 78 |
void |
78 |
void |
| 79 |
list_devices(void) |
79 |
list_devices_libusb(void) |
| 80 |
{ |
80 |
{ |
| 81 |
fputs("DEBUG: list_devices\n", stderr); |
81 |
fputs("DEBUG: list_devices_libusb\n", stderr); |
| 82 |
find_device(list_cb, NULL); |
82 |
find_device(list_cb, NULL); |
| 83 |
} |
83 |
} |
| 84 |
|
84 |
|
| 85 |
|
85 |
|
| 86 |
/* |
86 |
/* |
| 87 |
* 'print_device()' - Print a file to a USB device. |
87 |
* 'print_device_libusb()' - Print a file to a USB device. |
| 88 |
*/ |
88 |
*/ |
| 89 |
|
89 |
|
| 90 |
int /* O - Exit status */ |
90 |
int /* O - Exit status */ |
| 91 |
print_device(const char *uri, /* I - Device URI */ |
91 |
print_device_libusb(const char *uri, /* I - Device URI */ |
| 92 |
const char *hostname, /* I - Hostname/manufacturer */ |
92 |
const char *hostname, /* I - Hostname/manufacturer */ |
| 93 |
const char *resource, /* I - Resource/modelname */ |
93 |
const char *resource, /* I - Resource/modelname */ |
| 94 |
char *options, /* I - Device options/serial number */ |
94 |
char *options, /* I - Device options/serial number */ |
|
Lines 105-123
Link Here
|
| 105 |
struct pollfd pfds[2]; /* Poll descriptors */ |
105 |
struct pollfd pfds[2]; /* Poll descriptors */ |
| 106 |
|
106 |
|
| 107 |
|
107 |
|
| 108 |
fputs("DEBUG: print_device\n", stderr); |
108 |
fputs("DEBUG: print_device_libusb\n", stderr); |
| 109 |
|
109 |
|
| 110 |
/* |
110 |
/* |
| 111 |
* Connect to the printer... |
111 |
* Connect to the printer... |
| 112 |
*/ |
112 |
*/ |
| 113 |
|
113 |
|
|
|
114 |
#if defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) |
| 115 |
if ((printer = find_device(print_cb, uri)) == NULL) |
| 116 |
return(-1); |
| 117 |
#else |
| 114 |
while ((printer = find_device(print_cb, uri)) == NULL) |
118 |
while ((printer = find_device(print_cb, uri)) == NULL) |
| 115 |
{ |
119 |
{ |
| 116 |
_cupsLangPuts(stderr, |
120 |
_cupsLangPuts(stderr, |
| 117 |
_("INFO: Waiting for printer to become available...\n")); |
121 |
_("INFO: Waiting for printer to become available...\n")); |
| 118 |
sleep(5); |
122 |
sleep(5); |
| 119 |
} |
123 |
} |
| 120 |
|
124 |
#endif |
| 121 |
|
125 |
|
| 122 |
/* |
126 |
/* |
| 123 |
* If we are printing data from a print driver on stdin, ignore SIGTERM |
127 |
* If we are printing data from a print driver on stdin, ignore SIGTERM |
|
Lines 189-195
Link Here
|
| 189 |
|
193 |
|
| 190 |
if (pfds[1].revents & (POLLIN | POLLHUP)) |
194 |
if (pfds[1].revents & (POLLIN | POLLHUP)) |
| 191 |
{ |
195 |
{ |
| 192 |
if ((bytes = side_cb(printer, print_fd)) < 0) |
196 |
if ((bytes = side_cb_libusb(printer, print_fd)) < 0) |
| 193 |
pfds[1].events = 0; /* Filter has gone away... */ |
197 |
pfds[1].events = 0; /* Filter has gone away... */ |
| 194 |
else |
198 |
else |
| 195 |
tbytes += bytes; |
199 |
tbytes += bytes; |
|
Lines 359-365
Link Here
|
| 359 |
printer.iface = iface; |
363 |
printer.iface = iface; |
| 360 |
printer.handle = NULL; |
364 |
printer.handle = NULL; |
| 361 |
|
365 |
|
| 362 |
if (!open_device(&printer, data != NULL)) |
366 |
if (!open_device_libusb(&printer, data != NULL)) |
| 363 |
{ |
367 |
{ |
| 364 |
if (!get_device_id(&printer, device_id, sizeof(device_id))) |
368 |
if (!get_device_id(&printer, device_id, sizeof(device_id))) |
| 365 |
{ |
369 |
{ |
|
Lines 583-588
Link Here
|
| 583 |
mfg = tempmfg; |
587 |
mfg = tempmfg; |
| 584 |
} |
588 |
} |
| 585 |
|
589 |
|
|
|
590 |
if (!strncasecmp(mdl, mfg, strlen(mfg))) |
| 591 |
{ |
| 592 |
mdl += strlen(mfg); |
| 593 |
|
| 594 |
while (isspace(*mdl & 255)) |
| 595 |
mdl ++; |
| 596 |
} |
| 597 |
|
| 586 |
/* |
598 |
/* |
| 587 |
* Generate the device URI from the manufacturer, model, serial number, |
599 |
* Generate the device URI from the manufacturer, model, serial number, |
| 588 |
* and interface number... |
600 |
* and interface number... |
|
Lines 611-621
Link Here
|
| 611 |
|
623 |
|
| 612 |
|
624 |
|
| 613 |
/* |
625 |
/* |
| 614 |
* 'open_device()' - Open a connection to the USB printer. |
626 |
* 'open_device_libusb()' - Open a connection to the USB printer. |
| 615 |
*/ |
627 |
*/ |
| 616 |
|
628 |
|
| 617 |
static int /* O - 0 on success, -1 on error */ |
629 |
static int /* O - 0 on success, -1 on error */ |
| 618 |
open_device(usb_printer_t *printer, /* I - Printer */ |
630 |
open_device_libusb(usb_printer_t *printer, /* I - Printer */ |
| 619 |
int verbose) /* I - Update connecting-to-device state? */ |
631 |
int verbose) /* I - Update connecting-to-device state? */ |
| 620 |
{ |
632 |
{ |
| 621 |
int number; /* Configuration/interface/altset numbers */ |
633 |
int number; /* Configuration/interface/altset numbers */ |
|
Lines 733-748
Link Here
|
| 733 |
const char *device_id, /* I - IEEE-1284 device ID */ |
745 |
const char *device_id, /* I - IEEE-1284 device ID */ |
| 734 |
const void *data) /* I - User data (make, model, S/N) */ |
746 |
const void *data) /* I - User data (make, model, S/N) */ |
| 735 |
{ |
747 |
{ |
| 736 |
return (!strcmp((char *)data, device_uri)); |
748 |
char *uri = (char *)data, |
|
|
749 |
*str1, |
| 750 |
*str2, |
| 751 |
buf[255], |
| 752 |
requested_uri[1024]; |
| 753 |
|
| 754 |
/* Work on a copy of uri */ |
| 755 |
strncpy(requested_uri, uri, sizeof(requested_uri)); |
| 756 |
requested_uri[sizeof(requested_uri) - 1] = '\0'; |
| 757 |
|
| 758 |
/* |
| 759 |
* libusb-discovered URIs can have an "interface" specification and this |
| 760 |
* never happens for usblp-discovered URIs, so remove the "interface" |
| 761 |
* specification from the URI which we are checking currently. This way a |
| 762 |
* queue for a usblp-discovered printer can now be accessed via libusb |
| 763 |
*/ |
| 764 |
if (((str1 = strstr(requested_uri, "interface=")) == NULL) && |
| 765 |
((str2 = strstr(device_uri, "interface=")) != NULL)) |
| 766 |
{ |
| 767 |
*(str2 - 1) = '\0'; |
| 768 |
} |
| 769 |
|
| 770 |
/* |
| 771 |
* Old URI with "serial=?". Cut this part off and consider this as |
| 772 |
* an URI without serial number |
| 773 |
*/ |
| 774 |
if ((str1 = strstr(requested_uri, "serial=?")) != NULL) |
| 775 |
*(str1 - 1) = '\0'; |
| 776 |
|
| 777 |
/* |
| 778 |
* Old URI without serial number. Match it also with URIs with serial |
| 779 |
* number |
| 780 |
*/ |
| 781 |
if (((str1 = strstr(requested_uri, "serial=")) == NULL) && |
| 782 |
((str2 = strstr(device_uri, "serial=")) != NULL)) |
| 783 |
*(str2 - 1) = '\0'; |
| 784 |
|
| 785 |
/* |
| 786 |
* libusb-discovered URIs can have a "serial" specification when the |
| 787 |
* usblp-discovered URI for the same printer does not have one, as |
| 788 |
* with libusb we can discover serial numbers also with other methods |
| 789 |
* than only via the device ID. Therefore we accept also a |
| 790 |
* usblp-discovered printer without serial number as a match. This we |
| 791 |
* do by removing the serial number from the queue's (libusb-discovered) |
| 792 |
* URI before comparing. Also warn the user because of the incapability |
| 793 |
* of the usblp-based access to distinguish printers by the serial |
| 794 |
* number. |
| 795 |
*/ |
| 796 |
if (((str1 = strstr(requested_uri, "serial=")) == NULL) && |
| 797 |
((str2 = strstr(device_uri, "serial=")) != NULL)) |
| 798 |
{ |
| 799 |
*(str2 - 1) = '\0'; |
| 800 |
if (backendGetMakeModel(device_id, buf, sizeof(buf)) == 0) |
| 801 |
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", |
| 802 |
buf); |
| 803 |
} |
| 804 |
|
| 805 |
return (!strcmp(requested_uri, device_uri)); |
| 737 |
} |
806 |
} |
| 738 |
|
807 |
|
| 739 |
|
808 |
|
| 740 |
/* |
809 |
/* |
| 741 |
* 'side_cb()' - Handle side-channel requests. |
810 |
* 'side_cb_libusb()' - Handle side-channel requests. |
| 742 |
*/ |
811 |
*/ |
| 743 |
|
812 |
|
| 744 |
static ssize_t /* O - Number of bytes written */ |
813 |
static ssize_t /* O - Number of bytes written */ |
| 745 |
side_cb(usb_printer_t *printer, /* I - Printer */ |
814 |
side_cb_libusb(usb_printer_t *printer, /* I - Printer */ |
| 746 |
int print_fd) /* I - File to print */ |
815 |
int print_fd) /* I - File to print */ |
| 747 |
{ |
816 |
{ |
| 748 |
ssize_t bytes, /* Bytes read/written */ |
817 |
ssize_t bytes, /* Bytes read/written */ |