all: Start merging common enumeration tasks, starting with url-ification.
This commit is contained in:
parent
b8a64a2be0
commit
0e82760201
|
@ -119,20 +119,54 @@ static int send_data(struct libusb_device_handle *dev, uint8_t endp,
|
|||
{
|
||||
int num;
|
||||
|
||||
int ret = libusb_bulk_transfer(dev, endp,
|
||||
buf, len,
|
||||
&num, 10000);
|
||||
|
||||
if (ret < 0 || len != num) {
|
||||
ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len, endp);
|
||||
return ret;
|
||||
while (len) {
|
||||
int ret = libusb_bulk_transfer(dev, endp,
|
||||
buf, len,
|
||||
&num, 10000);
|
||||
if (ret < 0) {
|
||||
ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len, endp);
|
||||
return ret;
|
||||
}
|
||||
len -= num;
|
||||
buf += num;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int terminate = 0;
|
||||
|
||||
void sigterm_handler(int signum) {
|
||||
static void sigterm_handler(int signum) {
|
||||
terminate = 1;
|
||||
INFO("Job Cancelled");
|
||||
}
|
||||
|
||||
static void print_scan_output(struct libusb_device_handle *dev,
|
||||
unsigned char *product, unsigned char *serial,
|
||||
char *manuf, char *prefix)
|
||||
{
|
||||
/* URL-ify model. */
|
||||
char buf[128]; // XXX ugly..
|
||||
int j = 0, k = 0;
|
||||
char *ieee_id;
|
||||
while (*(product + j + strlen(manuf))) {
|
||||
buf[k] = *(product + j + strlen(manuf) + 1);
|
||||
if(buf[k] == ' ') {
|
||||
buf[k++] = '%';
|
||||
buf[k++] = '2';
|
||||
buf[k] = '0';
|
||||
}
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
ieee_id = get_device_id(dev);
|
||||
|
||||
fprintf(stdout, "direct %s%s/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n",
|
||||
prefix, manuf,
|
||||
buf, serial, product, product,
|
||||
ieee_id);
|
||||
|
||||
if (ieee_id)
|
||||
free(ieee_id);
|
||||
|
||||
}
|
||||
|
|
|
@ -140,28 +140,8 @@ static int find_and_enumerate(struct libusb_context *ctx,
|
|||
desc.idProduct, product, serial);
|
||||
|
||||
if (scan_only) {
|
||||
/* URL-ify model. */
|
||||
char buf[128]; // XXX ugly..
|
||||
int j = 0, k = 0;
|
||||
char *ieee_id;
|
||||
while (*(product + j + strlen("Kodak"))) {
|
||||
buf[k] = *(product + j + strlen("Kodak "));
|
||||
if(buf[k] == ' ') {
|
||||
buf[k++] = '%';
|
||||
buf[k++] = '2';
|
||||
buf[k] = '0';
|
||||
}
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
ieee_id = get_device_id(dev);
|
||||
|
||||
fprintf(stdout, "direct %sKodak/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX,
|
||||
buf, serial, product, product,
|
||||
ieee_id);
|
||||
|
||||
if (ieee_id)
|
||||
free(ieee_id);
|
||||
print_scan_output(dev, product, serial,
|
||||
"Kodak", URI_PREFIX);
|
||||
}
|
||||
|
||||
/* If a serial number was passed down, use it. */
|
||||
|
|
|
@ -122,28 +122,8 @@ static int find_and_enumerate(struct libusb_context *ctx,
|
|||
desc.idProduct, product, serial);
|
||||
|
||||
if (scan_only) {
|
||||
/* URL-ify model. */
|
||||
char buf[128]; // XXX ugly..
|
||||
int j = 0, k = 0;
|
||||
char *ieee_id;
|
||||
while (*(product + j + strlen("Kodak"))) {
|
||||
buf[k] = *(product + j + strlen("Kodak "));
|
||||
if(buf[k] == ' ') {
|
||||
buf[k++] = '%';
|
||||
buf[k++] = '2';
|
||||
buf[k] = '0';
|
||||
}
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
ieee_id = get_device_id(dev);
|
||||
|
||||
fprintf(stdout, "direct %sKodak/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX,
|
||||
buf, serial, product, product,
|
||||
ieee_id);
|
||||
|
||||
if (ieee_id)
|
||||
free(ieee_id);
|
||||
print_scan_output(dev, product, serial,
|
||||
"Kodak", URI_PREFIX);
|
||||
}
|
||||
|
||||
/* If a serial number was passed down, use it. */
|
||||
|
|
|
@ -475,28 +475,8 @@ static int find_and_enumerate(struct libusb_context *ctx,
|
|||
desc.idProduct, product, serial);
|
||||
|
||||
if (valid && scan_only) {
|
||||
/* URL-ify model. */
|
||||
char buf[128]; // XXX ugly..
|
||||
int j = 0, k = 0;
|
||||
char *ieee_id;
|
||||
while (*(product + j + strlen("Canon"))) {
|
||||
buf[k] = *(product + j + strlen("Canon "));
|
||||
if(buf[k] == ' ') {
|
||||
buf[k++] = '%';
|
||||
buf[k++] = '2';
|
||||
buf[k] = '0';
|
||||
}
|
||||
k++;
|
||||
j++;
|
||||
}
|
||||
ieee_id = get_device_id(dev);
|
||||
|
||||
fprintf(stdout, "direct %sCanon/%s?serial=%s \"%s\" \"%s\" \"%s\" \"\"\n", URI_PREFIX,
|
||||
buf, serial, product, product,
|
||||
ieee_id);
|
||||
|
||||
if (ieee_id)
|
||||
free(ieee_id);
|
||||
print_scan_output(dev, product, serial,
|
||||
"Canon", URI_PREFIX);
|
||||
}
|
||||
|
||||
/* If a serial number was passed down, use it. */
|
||||
|
|
Loading…
Reference in a new issue