summaryrefslogtreecommitdiff
path: root/src/cups/backend_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cups/backend_common.c')
-rw-r--r--src/cups/backend_common.c101
1 files changed, 73 insertions, 28 deletions
diff --git a/src/cups/backend_common.c b/src/cups/backend_common.c
index 73c6dba..0a2aaba 100644
--- a/src/cups/backend_common.c
+++ b/src/cups/backend_common.c
@@ -1,7 +1,7 @@
/*
* CUPS Backend common code
*
- * Copyright (c) 2007-2014 Solomon Peachy <pizza@shaftnet.org>
+ * Copyright (c) 2007-2015 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*
@@ -27,7 +27,7 @@
#include "backend_common.h"
-#define BACKEND_VERSION "0.48G"
+#define BACKEND_VERSION "0.54G"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@@ -48,6 +48,11 @@ static char *get_device_id(struct libusb_device_handle *dev)
int iface = 0;
char *buf = malloc(ID_BUF_SIZE + 1);
+ if (!buf) {
+ ERROR("Memory allocation failure (%d bytes)\n", ID_BUF_SIZE+1);
+ return NULL;
+ }
+
if (libusb_kernel_driver_active(dev, iface))
libusb_detach_kernel_driver(dev, iface);
@@ -180,11 +185,23 @@ int read_data(struct libusb_device_handle *dev, uint8_t endp,
goto done;
}
- if (dyesub_debug > 1) {
- int i;
+ if (dyesub_debug) {
+ DEBUG("Received %d bytes from printer\n", *readlen);
+ }
+
+ if ((dyesub_debug > 1 && buflen < 4096) ||
+ dyesub_debug > 2) {
+ int i = *readlen;
+
DEBUG("<- ");
- for (i = 0 ; i < *readlen; i++) {
- DEBUG2("%02x ", *(buf+i));
+ while(i > 0) {
+ if ((*readlen-i) != 0 &&
+ (*readlen-i) % 16 == 0) {
+ DEBUG2("\n");
+ DEBUG(" ");
+ }
+ DEBUG2("%02x ", buf[*readlen-i]);
+ i--;
}
DEBUG2("\n");
}
@@ -208,11 +225,19 @@ int send_data(struct libusb_device_handle *dev, uint8_t endp,
buf, len2,
&num, 15000);
- if (dyesub_debug > 1) {
- int i;
+ if ((dyesub_debug > 1 && len < 4096) ||
+ dyesub_debug > 2) {
+ int i = num;
+
DEBUG("-> ");
- for (i = 0 ; i < num; i++) {
- DEBUG2("%02x ", *(buf+i));
+ while(i > 0) {
+ if ((num-i) != 0 &&
+ (num-i) % 16 == 0) {
+ DEBUG2("\n");
+ DEBUG(" ");
+ }
+ DEBUG2("%02x ", buf[num-i]);
+ i--;
}
DEBUG2("\n");
}
@@ -267,6 +292,11 @@ static char from_hex(char ch) {
static char *url_encode(char *str) {
char *pstr = str, *buf = malloc(strlen(str) * 3 + 1), *pbuf = buf;
+ if (!buf) {
+ ERROR("Memory allocation failure (%d bytes)\n", (int) strlen(str)*3 + 1);
+ return NULL;
+ }
+
while (*pstr) {
if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
*pbuf++ = *pstr;
@@ -281,6 +311,12 @@ static char *url_encode(char *str) {
}
static char *url_decode(char *str) {
char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf;
+
+ if (!buf) {
+ ERROR("Memory allocation failure (%d bytes)\n", (int) strlen(str) + 1);
+ return NULL;
+ }
+
while (*pstr) {
if (*pstr == '%') {
if (pstr[1] && pstr[2]) {
@@ -373,6 +409,11 @@ static int print_scan_output(struct libusb_device *device,
char *product2 = url_decode(product);
char *manuf3 = url_decode(manuf);
descr = malloc(256);
+ if (!descr) {
+ ERROR("Memory allocation failure (%d bytes)\n", 256);
+ return found;
+ }
+
sprintf(descr, "%s %s", manuf3, product2);
free(product2);
free(manuf3);
@@ -485,7 +526,9 @@ static struct dyesub_backend *backends[] = {
&shinkos2145_backend,
&updr150_backend,
&mitsu70x_backend,
+ &mitsu9550_backend,
&dnpds40_backend,
+ &cw01_backend,
NULL,
};
@@ -575,7 +618,7 @@ static struct dyesub_backend *find_backend(char *uri_prefix)
static void print_license_blurb(void)
{
const char *license = "\n\
-Copyright 2007-2014 Solomon Peachy <pizza AT shaftnet DOT org>\n\
+Copyright 2007-2015 Solomon Peachy <pizza AT shaftnet DOT org>\n\
\n\
This program is free software; you can redistribute it and/or modify it\n\
under the terms of the GNU General Public License as published by the Free\n\
@@ -590,7 +633,7 @@ for more details.\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\
-\n [http://www.gnu.org/licenses/gpl-3.0.html]\n\n";
+\n [http://www.gnu.org/licenses/gpl-2.0.html]\n\n";
fprintf(stderr, "%s", license);
}
@@ -645,7 +688,7 @@ static void print_help(char *argv0, struct dyesub_backend *backend)
i = libusb_init(&ctx);
if (i) {
ERROR("Failed to initialize libusb (%d)\n", i);
- exit(4); /* CUPS_BACKEND_STOP */
+ exit(CUPS_BACKEND_STOP);
}
find_and_enumerate(ctx, &list, backend, NULL, P_ANY, 1);
libusb_free_device_list(list, 1);
@@ -671,7 +714,7 @@ int main (int argc, char **argv)
int claimed;
int backend_cmd = 0;
- int ret = 0;
+ int ret = CUPS_BACKEND_OK;
int iface = 0;
int found = -1;
int copies = 1;
@@ -684,7 +727,7 @@ int main (int argc, char **argv)
DEBUG("Multi-Call Dye-sublimation CUPS Backend version %s\n",
BACKEND_VERSION);
- DEBUG("Copyright 2007-2014 Solomon Peachy\n");
+ DEBUG("Copyright 2007-2015 Solomon Peachy\n");
DEBUG("This free software comes with ABSOLUTELY NO WARRANTY! \n");
DEBUG("Licensed under the GNU GPL. Run with '-G' for more details.\n");
DEBUG("\n");
@@ -717,7 +760,7 @@ int main (int argc, char **argv)
/* Reset arg parsing */
optind = 1;
opterr = 0;
- while ((i = getopt(argc, argv, "B:dDGhP:S:T:V:")) >= 0) {
+ while ((i = getopt(argc, argv, "B:d:DGhP:S:T:V:")) >= 0) {
switch(i) {
case 'B':
backend = find_backend(optarg);
@@ -877,7 +920,7 @@ int main (int argc, char **argv)
if (fname && backend->early_parse) {
printer_type = backend->early_parse(backend_ctx, data_fd);
if (printer_type < 0) {
- ret = 5; /* CUPS_BACKEND_CANCEL */
+ ret = CUPS_BACKEND_CANCEL;
goto done;
}
}
@@ -886,7 +929,7 @@ int main (int argc, char **argv)
ret = libusb_init(&ctx);
if (ret) {
ERROR("Failed to initialize libusb (%d)\n", ret);
- ret = 4;
+ ret = CUPS_BACKEND_STOP;
goto done;
}
@@ -896,13 +939,14 @@ int main (int argc, char **argv)
#if 1
if (found == -1) {
ERROR("Printer open failure (No suitable printers found!)\n");
- ret = 4; /* CUPS_BACKEND_STOP */
+ ret = CUPS_BACKEND_HOLD;
goto done;
}
ret = libusb_open(list[found], &dev);
if (ret) {
ERROR("Printer open failure (Need to be root?) (%d)\n", ret);
+ ret = CUPS_BACKEND_STOP;
goto done;
}
@@ -910,20 +954,23 @@ int main (int argc, char **argv)
if (claimed) {
ret = libusb_detach_kernel_driver(dev, iface);
if (ret) {
- ERROR("Printer open failure (Could not detach printer from kernel)\n");
+ ERROR("Printer open failure (Could not detach printer from kernel) (%d)\n", ret);
+ ret = CUPS_BACKEND_STOP;
goto done_close;
}
}
ret = libusb_claim_interface(dev, iface);
if (ret) {
- ERROR("Printer open failure (Could not claim printer interface)\n");
+ ERROR("Printer open failure (Could not claim printer interface) (%d)\n", ret);
+ ret = CUPS_BACKEND_STOP;
goto done_close;
}
ret = libusb_get_active_config_descriptor(list[found], &config);
if (ret) {
- ERROR("Printer open failure (Could not fetch config descriptor)\n");
+ ERROR("Printer open failure (Could not fetch config descriptor) (%d)\n", ret);
+ ret = CUPS_BACKEND_STOP;
goto done_close;
}
@@ -951,14 +998,12 @@ int main (int argc, char **argv)
newpage:
/* Do early parsing if needed for subsequent pages */
- if (pages && backend->early_parse) {
- ret = backend->early_parse(backend_ctx, data_fd);
- if (ret < 0)
+ if (pages && backend->early_parse &&
+ backend->early_parse(backend_ctx, data_fd) < 0)
goto done_multiple;
- }
/* Read in data */
- if (backend->read_parse(backend_ctx, data_fd)) {
+ if ((ret = backend->read_parse(backend_ctx, data_fd))) {
if (pages)
goto done_multiple;
else
@@ -981,7 +1026,7 @@ done_multiple:
/* Done printing */
INFO("All printing done (%d pages * %d copies)\n", pages, copies);
- ret = 0;
+ ret = CUPS_BACKEND_OK;
done_claimed:
libusb_release_interface(dev, iface);