summaryrefslogtreecommitdiff
path: root/backend/escl
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2025-06-09 14:27:29 +0200
committerJörg Frings-Fürst <debian@jff.email>2025-06-09 14:27:29 +0200
commit652efae78c00b812033ea162d76cd13bd40dcab6 (patch)
tree7c139f4d2a28061607cd7e2269693df993e5d60a /backend/escl
parentbfa2ae8e43fcbab696f272fffd164d0637e965c5 (diff)
New upstream version 1.4.0upstream/1.4.0upstream
Diffstat (limited to 'backend/escl')
-rw-r--r--backend/escl/escl.c81
-rw-r--r--backend/escl/escl.h6
-rw-r--r--backend/escl/escl_capabilities.c14
-rw-r--r--backend/escl/escl_crop.c8
-rw-r--r--backend/escl/escl_devices.c8
-rw-r--r--backend/escl/escl_jpeg.c4
-rw-r--r--backend/escl/escl_mupdf.c18
-rw-r--r--backend/escl/escl_newjob.c71
-rw-r--r--backend/escl/escl_pdf.c24
-rw-r--r--backend/escl/escl_png.c16
-rw-r--r--backend/escl/escl_reset.c42
-rw-r--r--backend/escl/escl_scan.c2
-rw-r--r--backend/escl/escl_status.c137
-rw-r--r--backend/escl/escl_tiff.c8
14 files changed, 275 insertions, 164 deletions
diff --git a/backend/escl/escl.c b/backend/escl/escl.c
index 77b753f..6bd3429 100644
--- a/backend/escl/escl.c
+++ b/backend/escl/escl.c
@@ -61,25 +61,6 @@ static const SANE_Device **devlist = NULL;
static ESCL_Device *list_devices_primary = NULL;
static int num_devices = 0;
-#ifdef CURL_SSLVERSION_MAX_DEFAULT
-static int proto_tls[] = {
- CURL_SSLVERSION_MAX_DEFAULT,
- #ifdef CURL_SSLVERSION_MAX_TLSv1_3
- CURL_SSLVERSION_MAX_TLSv1_3,
- #endif
- #ifdef CURL_SSLVERSION_MAX_TLSv1_2
- CURL_SSLVERSION_MAX_TLSv1_2,
- #endif
- #ifdef CURL_SSLVERSION_MAX_TLSv1_1
- CURL_SSLVERSION_MAX_TLSv1_1,
- #endif
- #ifdef CURL_SSLVERSION_MAX_TLSv1_0
- CURL_SSLVERSION_MAX_TLSv1_0,
- #endif
- -1
-};
-#endif
-
typedef struct Handled {
struct Handled *next;
@@ -120,17 +101,15 @@ escl_free_device(ESCL_Device *current)
}
-#ifdef CURL_SSLVERSION_MAX_DEFAULT
static int
-escl_tls_protocol_supported(char *url, int proto)
+escl_tls_protocol_supported(char *url)
{
CURLcode res = CURLE_UNSUPPORTED_PROTOCOL;
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
- /* ask libcurl to use TLS version 1.0 or later */
- curl_easy_setopt(curl, CURLOPT_SSLVERSION, proto);
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
@@ -145,33 +124,17 @@ escl_tls_protocol_supported(char *url, int proto)
static int
escl_is_tls(char * url, char *type)
{
- int tls_version = 0;
if(!strcmp(type, "_uscans._tcp") ||
!strcmp(type, "https"))
{
- while(proto_tls[tls_version] != -1)
- {
- if (escl_tls_protocol_supported(url, proto_tls[tls_version]) == CURLE_OK)
+ if (escl_tls_protocol_supported(url) == CURLE_OK)
{
- DBG(10, "curl tls compatible (%d)\n", proto_tls[tls_version]);
- break;
+ DBG(10, "curl tls compatible\n");
+ return 1;
}
- tls_version++;
- }
- if (proto_tls[tls_version] < 1)
- return 0;
}
- return proto_tls[tls_version];
-}
-#else
-static int
-escl_is_tls(char * url, char *type)
-{
- (void)url;
- (void)type;
return 0;
}
-#endif
void
escl_free_handler(escl_sane_t *handler)
@@ -416,7 +379,7 @@ convertFromESCLDev(ESCL_Device *cdev)
unix_path, cdev->https ? "s" : "", cdev->ip_address, cdev->port_nb);
sdev->name = tmp;
- DBG( 1, "Escl add device : %s\n", tmp);
+ DBG( 10, "Escl add device : %s\n", tmp);
sdev->vendor = get_vendor(cdev->model_name);
if (!sdev->vendor)
@@ -523,7 +486,7 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line,
line = sanei_config_get_string(line + 6, &name_str);
DBG (10, "New Escl_Device URL [%s].\n", (name_str ? name_str : "VIDE"));
if (!name_str || !*name_str) {
- DBG (1, "Escl_Device URL missing.\n");
+ DBG(10, "Escl_Device URL missing.\n");
return SANE_STATUS_INVAL;
}
if (*line) {
@@ -1163,19 +1126,19 @@ escl_parse_name(SANE_String_Const name, ESCL_Device *device)
device->type = strdup("http");
host = name + 7;
} else {
- DBG(1, "Unknown URL scheme in %s", name);
+ DBG(10, "Unknown URL scheme in %s", name);
return SANE_STATUS_INVAL;
}
port_str = strchr(host, ':');
if (port_str == NULL) {
- DBG(1, "Port missing from URL: %s", name);
+ DBG(10, "Port missing from URL: %s", name);
return SANE_STATUS_INVAL;
}
port_str++;
device->port_nb = atoi(port_str);
if (device->port_nb < 1 || device->port_nb > 65535) {
- DBG(1, "Invalid port number in URL: %s", name);
+ DBG(10, "Invalid port number in URL: %s", name);
return SANE_STATUS_INVAL;
}
@@ -1201,7 +1164,7 @@ _get_hack(SANE_String_Const name, ESCL_Device *device)
fp = sanei_config_open (ESCL_CONFIG_FILE);
if (!fp)
{
- DBG (2, "_get_hack: couldn't access %s\n", ESCL_CONFIG_FILE);
+ DBG(4, "_get_hack: couldn't access %s\n", ESCL_CONFIG_FILE);
DBG (3, "_get_hack: exit\n");
}
@@ -1236,7 +1199,7 @@ _get_blacklist_pdf(void)
fp = sanei_config_open (ESCL_CONFIG_FILE);
if (!fp)
{
- DBG (2, "_get_blacklit: couldn't access %s\n", ESCL_CONFIG_FILE);
+ DBG(4, "_get_blacklit: couldn't access %s\n", ESCL_CONFIG_FILE);
DBG (3, "_get_blacklist: exit\n");
}
@@ -1345,7 +1308,7 @@ sane_cancel(SANE_Handle h)
}
handler->scanner->work = SANE_FALSE;
handler->cancel = SANE_TRUE;
- escl_scanner(handler->device, handler->scanner->scanJob, handler->result);
+ escl_scanner(handler->device, handler->scanner->scanJob, handler->result, SANE_TRUE);
free(handler->result);
handler->result = NULL;
free(handler->scanner->scanJob);
@@ -1558,7 +1521,7 @@ sane_start(SANE_Handle h)
int bps = 0;
if (handler->device == NULL) {
- DBG(1, "Missing handler device.\n");
+ DBG(10, "Missing handler device.\n");
return (SANE_STATUS_INVAL);
}
handler->cancel = SANE_FALSE;
@@ -1566,6 +1529,7 @@ sane_start(SANE_Handle h)
handler->decompress_scan_data = SANE_FALSE;
handler->end_read = SANE_FALSE;
if (handler->scanner->work == SANE_FALSE) {
+ escl_reset_all_jobs(handler->device);
SANE_Status st = escl_status(handler->device,
handler->scanner->source,
NULL,
@@ -1887,24 +1851,23 @@ escl_curl_url(CURL *handle, const ESCL_Device *device, SANE_String_Const path)
(device->https ? "https" : "http"), device->ip_address,
device->port_nb, path);
- DBG( 1, "escl_curl_url: URL: %s\n", url );
+ DBG( 10, "escl_curl_url: URL: %s\n", url );
curl_easy_setopt(handle, CURLOPT_URL, url);
free(url);
- DBG( 1, "Before use hack\n");
+ DBG( 10, "Before use hack\n");
if (device->hack) {
- DBG( 1, "Use hack\n");
+ DBG( 10, "Use hack\n");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, device->hack);
}
- DBG( 1, "After use hack\n");
+ DBG( 10, "After use hack\n");
if (device->https) {
- DBG( 1, "Ignoring safety certificates, use https\n");
+ DBG( 10, "Ignoring safety certificates, use https\n");
+ curl_easy_setopt(handle, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
- if (device->tls > 0)
- curl_easy_setopt(handle, CURLOPT_SSLVERSION, device->tls);
}
if (device->unix_socket != NULL) {
- DBG( 1, "Using local socket %s\n", device->unix_socket );
+ DBG( 10, "Using local socket %s\n", device->unix_socket );
curl_easy_setopt(handle, CURLOPT_UNIX_SOCKET_PATH,
device->unix_socket);
}
diff --git a/backend/escl/escl.h b/backend/escl/escl.h
index b59a3ff..2dce59b 100644
--- a/backend/escl/escl.h
+++ b/backend/escl/escl.h
@@ -248,7 +248,11 @@ SANE_Status escl_scan(capabilities_t *scanner,
void escl_scanner(const ESCL_Device *device,
char *scanJob,
- char *result);
+ char *result,
+ SANE_Bool status);
+
+SANE_Status escl_reset_all_jobs(ESCL_Device *device);
+
typedef void CURL;
diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c
index 950efaa..05b3fd2 100644
--- a/backend/escl/escl_capabilities.c
+++ b/backend/escl/escl_capabilities.c
@@ -48,7 +48,7 @@ header_callback(void *str, size_t size, size_t nmemb, void *userp)
char *content = realloc(header->memory, header->size + realsize + 1);
if (content == NULL) {
- DBG( 1, "Not enough memory (realloc returned NULL)\n");
+ DBG( 10, "Not enough memory (realloc returned NULL)\n");
return (0);
}
header->memory = content;
@@ -201,10 +201,8 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner, int type)
{
const char *name = (const char *)node->name;
if (strcmp(name, "ColorMode") == 0) {
+#ifndef HAVE_POPPLER_GLIB
const char *color = (SANE_String_Const)xmlNodeGetContent(node);
-#if HAVE_POPPLER_GLIB
- if (type == PLATEN || strcmp(color, "BlackAndWhite1"))
-#else
if (strcmp(color, "BlackAndWhite1"))
#endif
scanner->caps[type].ColorModes = char_to_array(scanner->caps[type].ColorModes, &scanner->caps[type].ColorModesSize, (SANE_String_Const)xmlNodeGetContent(node), 1);
@@ -235,14 +233,14 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner, int type)
}
#endif
#if(defined HAVE_TIFFIO_H)
- else if(type == PLATEN && !strcmp(scanner->caps[type].DocumentFormats[i], "image/tiff"))
+ else if(!strcmp(scanner->caps[type].DocumentFormats[i], "image/tiff"))
{
have_tiff = SANE_TRUE;
scanner->caps[type].have_tiff = i;
}
#endif
#if HAVE_POPPLER_GLIB
- else if(type == PLATEN && !strcmp(scanner->caps[type].DocumentFormats[i], "application/pdf"))
+ else if(!strcmp(scanner->caps[type].DocumentFormats[i], "application/pdf"))
{
have_pdf = SANE_TRUE;
scanner->caps[type].have_pdf = i;
@@ -568,9 +566,9 @@ escl_capabilities(ESCL_Device *device, char *blacklist, SANE_Status *status)
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
CURLcode res = curl_easy_perform(curl_handle);
if (res == CURLE_OK)
- DBG( 1, "Create NewJob : the scanner header responded : [%s]\n", header->memory);
+ DBG( 10, "Create NewJob : the scanner header responded : [%s]\n", header->memory);
if (res != CURLE_OK) {
- DBG( 1, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
+ DBG( 10, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
*status = SANE_STATUS_INVAL;
goto clean_data;
}
diff --git a/backend/escl/escl_crop.c b/backend/escl/escl_crop.c
index 59284ac..a7e0fa0 100644
--- a/backend/escl/escl_crop.c
+++ b/backend/escl/escl_crop.c
@@ -44,7 +44,7 @@ escl_crop_surface(capabilities_t *scanner,
int real_h = 0;
unsigned char *surface_crop = NULL;
- DBG( 1, "Escl Image Crop\n");
+ DBG( 10, "Escl Image Crop\n");
ratio = (double)w / (double)scanner->caps[scanner->source].width;
scanner->caps[scanner->source].width = w;
if (scanner->caps[scanner->source].pos_x < 0)
@@ -62,18 +62,18 @@ escl_crop_surface(capabilities_t *scanner,
y_off = (int)((double)scanner->caps[scanner->source].pos_y * ratio);
real_h = scanner->caps[scanner->source].height - y_off;
- DBG( 1, "Escl Image Crop [%dx%d|%dx%d]\n", scanner->caps[scanner->source].pos_x, scanner->caps[scanner->source].pos_y,
+ DBG( 10, "Escl Image Crop [%dx%d|%dx%d]\n", scanner->caps[scanner->source].pos_x, scanner->caps[scanner->source].pos_y,
scanner->caps[scanner->source].width, scanner->caps[scanner->source].height);
*width = real_w;
*height = real_h;
- DBG( 1, "Escl Image Crop [%dx%d]\n", *width, *height);
+ DBG( 10, "Escl Image Crop [%dx%d]\n", *width, *height);
if (x_off > 0 || real_w < scanner->caps[scanner->source].width ||
y_off > 0 || real_h < scanner->caps[scanner->source].height) {
surface_crop = (unsigned char *)malloc (sizeof (unsigned char) * real_w
* real_h * bps);
if(!surface_crop) {
- DBG( 1, "Escl Crop : Surface_crop Memory allocation problem\n");
+ DBG( 10, "Escl Crop : Surface_crop Memory allocation problem\n");
free(surface);
surface = NULL;
goto finish;
diff --git a/backend/escl/escl_devices.c b/backend/escl/escl_devices.c
index a2fdb80..05598ed 100644
--- a/backend/escl/escl_devices.c
+++ b/backend/escl/escl_devices.c
@@ -193,21 +193,21 @@ escl_devices(SANE_Status *status)
*status = SANE_STATUS_GOOD;
if (!(simple_poll = avahi_simple_poll_new())) {
- DBG( 1, "Failed to create simple poll object.\n");
+ DBG( 10, "Failed to create simple poll object.\n");
*status = SANE_STATUS_INVAL;
goto fail;
}
client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0,
client_callback, NULL, &error);
if (!client) {
- DBG( 1, "Failed to create client: %s\n", avahi_strerror(error));
+ DBG( 10, "Failed to create client: %s\n", avahi_strerror(error));
*status = SANE_STATUS_INVAL;
goto fail;
}
if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC, "_uscan._tcp",
NULL, 0, browse_callback, client))) {
- DBG( 1, "Failed to create service browser: %s\n",
+ DBG( 10, "Failed to create service browser: %s\n",
avahi_strerror(avahi_client_errno(client)));
*status = SANE_STATUS_INVAL;
goto fail;
@@ -216,7 +216,7 @@ escl_devices(SANE_Status *status)
AVAHI_PROTO_UNSPEC,
"_uscans._tcp", NULL, 0,
browse_callback, client))) {
- DBG( 1, "Failed to create service browser: %s\n",
+ DBG( 10, "Failed to create service browser: %s\n",
avahi_strerror(avahi_client_errno(client)));
*status = SANE_STATUS_INVAL;
goto fail;
diff --git a/backend/escl/escl_jpeg.c b/backend/escl/escl_jpeg.c
index 62c20c0..9008dae 100644
--- a/backend/escl/escl_jpeg.c
+++ b/backend/escl/escl_jpeg.c
@@ -179,7 +179,7 @@ get_JPEG_data(capabilities_t *scanner, int *width, int *height, int *bps)
if (surface != NULL)
free(surface);
fseek(scanner->tmp, start, SEEK_SET);
- DBG( 1, "Escl Jpeg : Error reading jpeg\n");
+ DBG( 10, "Escl Jpeg : Error reading jpeg\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
@@ -241,7 +241,7 @@ get_JPEG_data(capabilities_t *scanner, int *width, int *height, int *bps)
surface = malloc(cinfo.output_width * cinfo.output_height * cinfo.output_components);
if (surface == NULL) {
jpeg_destroy_decompress(&cinfo);
- DBG( 1, "Escl Jpeg : Memory allocation problem\n");
+ DBG( 10, "Escl Jpeg : Memory allocation problem\n");
if (scanner->tmp) {
fclose(scanner->tmp);
scanner->tmp = NULL;
diff --git a/backend/escl/escl_mupdf.c b/backend/escl/escl_mupdf.c
index dd23482..f5b3b7e 100644
--- a/backend/escl/escl_mupdf.c
+++ b/backend/escl/escl_mupdf.c
@@ -137,7 +137,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
if (!ctx)
{
- DBG(1, "cannot create mupdf context\n");
+ DBG(10, "cannot create mupdf context\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
@@ -147,7 +147,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
fz_register_document_handlers(ctx);
fz_catch(ctx)
{
- DBG(1, "cannot register document handlers: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot register document handlers: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_context;
}
@@ -157,7 +157,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
stream = fz_open_file_ptr_escl(ctx, scanner->tmp);
fz_catch(ctx)
{
- DBG(1, "cannot open stream: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot open stream: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_context;
}
@@ -167,7 +167,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
fz_seek(ctx, stream, 0, SEEK_SET);
fz_catch(ctx)
{
- DBG(1, "cannot seek stream: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot seek stream: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_stream;
}
@@ -177,7 +177,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
doc = fz_open_document_with_stream(ctx, "filename.pdf", stream);
fz_catch(ctx)
{
- DBG(1, "cannot open document: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot open document: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_stream;
}
@@ -187,14 +187,14 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
page_count = fz_count_pages(ctx, doc);
fz_catch(ctx)
{
- DBG(1, "cannot count number of pages: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot count number of pages: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_document;
}
if (page_number < 0 || page_number >= page_count)
{
- DBG(1, "page number out of range: %d (page count %d)\n", page_number + 1, page_count);
+ DBG(10, "page number out of range: %d (page count %d)\n", page_number + 1, page_count);
status = SANE_STATUS_INVAL;
goto drop_document;
}
@@ -209,7 +209,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
pix = fz_new_pixmap_from_page_number(ctx, doc, 0, &ctm, fz_device_rgb(ctx), 0);
fz_catch(ctx)
{
- DBG(1, "cannot render page: %s\n", fz_caught_message(ctx));
+ DBG(10, "cannot render page: %s\n", fz_caught_message(ctx));
status = SANE_STATUS_INVAL;
goto drop_document;
}
@@ -220,7 +220,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, pix->w, pix->h, pix->n, width, height);
if (!surface) {
- DBG( 1, "Escl Pdf : Surface Memory allocation problem\n");
+ DBG( 10, "Escl Pdf : Surface Memory allocation problem\n");
status = SANE_STATUS_NO_MEM;
goto drop_pix;
}
diff --git a/backend/escl/escl_newjob.c b/backend/escl/escl_newjob.c
index cb48bd1..ed2f4b0 100644
--- a/backend/escl/escl_newjob.c
+++ b/backend/escl/escl_newjob.c
@@ -96,7 +96,7 @@ download_callback(void *str, size_t size, size_t nmemb, void *userp)
char *content = realloc(download->memory, download->size + realsize + 1);
if (content == NULL) {
- DBG( 1, "Not enough memory (realloc returned NULL)\n");
+ DBG( 10, "Not enough memory (realloc returned NULL)\n");
return (0);
}
download->memory = content;
@@ -144,19 +144,19 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
*status = SANE_STATUS_GOOD;
if (device == NULL || scanner == NULL) {
*status = SANE_STATUS_NO_MEM;
- DBG( 1, "Create NewJob : the name or the scan are invalid.\n");
+ DBG( 10, "Create NewJob : the name or the scan are invalid.\n");
return (NULL);
}
upload = (struct downloading *)calloc(1, sizeof(struct downloading));
if (upload == NULL) {
*status = SANE_STATUS_NO_MEM;
- DBG( 1, "Create NewJob : memory allocation failure\n");
+ DBG( 10, "Create NewJob : memory allocation failure\n");
return (NULL);
}
download = (struct downloading *)calloc(1, sizeof(struct downloading));
if (download == NULL) {
free(upload);
- DBG( 1, "Create NewJob : memory allocation failure\n");
+ DBG( 10, "Create NewJob : memory allocation failure\n");
*status = SANE_STATUS_NO_MEM;
return (NULL);
}
@@ -168,38 +168,21 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
int have_tiff = scanner->caps[scanner->source].have_tiff;
int have_pdf = scanner->caps[scanner->source].have_pdf;
- if ((scanner->source == PLATEN && have_pdf == -1) ||
- (scanner->source > PLATEN)) {
- if (have_tiff != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_tiff]);
- }
- else if (have_png != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_png]);
- }
- else if (have_jpeg != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_jpeg]);
- }
+ if (have_pdf != -1) {
+ scanner->caps[scanner->source].default_format =
+ strdup(scanner->caps[scanner->source].DocumentFormats[have_pdf]);
}
- else {
- if (have_pdf != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_pdf]);
- }
- else if (have_tiff != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_tiff]);
- }
- else if (have_png != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_png]);
- }
- else if (have_jpeg != -1) {
- scanner->caps[scanner->source].default_format =
- strdup(scanner->caps[scanner->source].DocumentFormats[have_jpeg]);
- }
+ else if (have_tiff != -1) {
+ scanner->caps[scanner->source].default_format =
+ strdup(scanner->caps[scanner->source].DocumentFormats[have_tiff]);
+ }
+ else if (have_png != -1) {
+ scanner->caps[scanner->source].default_format =
+ strdup(scanner->caps[scanner->source].DocumentFormats[have_png]);
+ }
+ else if (have_jpeg != -1) {
+ scanner->caps[scanner->source].default_format =
+ strdup(scanner->caps[scanner->source].DocumentFormats[have_jpeg]);
}
if (atof ((const char *)device->version) <= 2.0)
{
@@ -222,7 +205,7 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
" <scan:Duplex>%s</scan:Duplex>",
scanner->source == ADFDUPLEX ? "true" : "false");
}
- DBG( 1, "Create NewJob : %s\n", scanner->caps[scanner->source].default_format);
+ DBG( 10, "Create NewJob : %s\n", scanner->caps[scanner->source].default_format);
if (scanner->caps[scanner->source].pos_x > scanner->caps[scanner->source].width)
off_x = (scanner->caps[scanner->source].pos_x > scanner->caps[scanner->source].width) / 2;
if (scanner->caps[scanner->source].pos_y > scanner->caps[scanner->source].height)
@@ -295,7 +278,7 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
upload->memory = strdup(cap_data);
upload->size = strlen(cap_data);
wake_up_device:
- DBG( 1, "Create NewJob : %s\n", cap_data);
+ DBG( 10, "Create NewJob : %s\n", cap_data);
download->memory = malloc(1);
download->size = 0;
curl_handle = curl_easy_init();
@@ -310,12 +293,12 @@ wake_up_device:
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
CURLcode res = curl_easy_perform(curl_handle);
if (res != CURLE_OK) {
- DBG( 1, "Create NewJob : the scanner responded incorrectly: %s\n", curl_easy_strerror(res));
+ DBG( 10, "Create NewJob : the scanner responded incorrectly: %s\n", curl_easy_strerror(res));
*status = SANE_STATUS_INVAL;
}
else {
if (download->memory != NULL) {
- char *tmp_location = strstr(download->memory, "Location:");
+ char *tmp_location = strcasestr(download->memory, "Location:");
if (tmp_location) {
temporary = strchr(tmp_location, '\r');
if (temporary == NULL)
@@ -325,7 +308,7 @@ wake_up_device:
location = strrchr(tmp_location,'/');
if (location) {
result = strdup(location);
- DBG( 1, "Create NewJob : %s\n", result);
+ DBG( 10, "Create NewJob : %s\n", result);
*temporary = '\n';
*location = '\0';
location = strrchr(tmp_location,'/');
@@ -333,7 +316,7 @@ wake_up_device:
if (location) {
location++;
scanner->scanJob = strdup(location);
- DBG( 1, "Full location header [%s]\n", scanner->scanJob);
+ DBG( 10, "Full location header [%s]\n", scanner->scanJob);
}
else
scanner->scanJob = strdup("ScanJobs");
@@ -341,14 +324,14 @@ wake_up_device:
}
}
if (result == NULL) {
- DBG( 1, "Error : Create NewJob, no location: %s\n", download->memory);
+ DBG( 10, "Error : Create NewJob, no location: %s\n", download->memory);
*status = SANE_STATUS_INVAL;
}
free(download->memory);
download->memory = NULL;
}
else {
- DBG( 1, "Create NewJob : The creation of the failed job: %s\n", download->memory);
+ DBG( 10, "Create NewJob : The creation of the failed job: %s\n", download->memory);
// If "409 Conflict" appear it means that there is no paper in feeder
if (strstr(download->memory, "409 Conflict") != NULL)
*status = SANE_STATUS_NO_DOCS;
@@ -363,7 +346,7 @@ wake_up_device:
}
else {
*status = SANE_STATUS_NO_MEM;
- DBG( 1, "Create NewJob : The creation of the failed job\n");
+ DBG( 10, "Create NewJob : The creation of the failed job\n");
return (NULL);
}
}
diff --git a/backend/escl/escl_pdf.c b/backend/escl/escl_pdf.c
index 8277e1d..0bfa3b3 100644
--- a/backend/escl/escl_pdf.c
+++ b/backend/escl/escl_pdf.c
@@ -121,21 +121,21 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
file = g_mapped_file_new_from_fd (fileno (scanner->tmp), 0, NULL);
if (!file) {
- DBG(1, "Error : g_mapped_file_new_from_fd");
+ DBG(10, "Error : g_mapped_file_new_from_fd");
status = SANE_STATUS_INVAL;
goto close_file;
}
bytes = g_mapped_file_get_bytes (file);
if (!bytes) {
- DBG(1, "Error : g_mapped_file_get_bytes");
+ DBG(10, "Error : g_mapped_file_get_bytes");
status = SANE_STATUS_INVAL;
goto free_file;
}
doc = poppler_document_new_from_bytes (bytes, NULL, NULL);
if (!doc) {
- DBG(1, "Error : poppler_document_new_from_bytes");
+ DBG(10, "Error : poppler_document_new_from_bytes");
status = SANE_STATUS_INVAL;
goto free_bytes;
}
@@ -145,14 +145,14 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
data = (char*)set_file_in_buffer(scanner->tmp, &size);
if (!data) {
- DBG(1, "Error : set_file_in_buffer");
+ DBG(10, "Error : set_file_in_buffer");
status = SANE_STATUS_INVAL;
goto close_file;
}
doc = poppler_document_new_from_data (data, size, NULL, NULL);
if (!doc) {
- DBG(1, "Error : poppler_document_new_from_data");
+ DBG(10, "Error : poppler_document_new_from_data");
status = SANE_STATUS_INVAL;
goto free_data;
}
@@ -160,7 +160,7 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
page = poppler_document_get_page (doc, 0);
if (!page) {
- DBG(1, "Error : poppler_document_get_page");
+ DBG(10, "Error : poppler_document_get_page");
status = SANE_STATUS_INVAL;
goto free_doc;
}
@@ -172,14 +172,14 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
h = (int)ceil(dh);
cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
if (!cairo_surface) {
- DBG(1, "Error : cairo_image_surface_create");
+ DBG(10, "Error : cairo_image_surface_create");
status = SANE_STATUS_INVAL;
goto free_page;
}
cr = cairo_create (cairo_surface);
if (!cairo_surface) {
- DBG(1, "Error : cairo_create");
+ DBG(10, "Error : cairo_create");
status = SANE_STATUS_INVAL;
goto free_surface;
}
@@ -196,26 +196,26 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
int st = cairo_status(cr);
if (st)
{
- DBG(1, "%s", cairo_status_to_string (st));
+ DBG(10, "%s", cairo_status_to_string (st));
status = SANE_STATUS_INVAL;
goto destroy_cr;
}
*bps = 3;
- DBG(1, "Escl Pdf : Image Size [%dx%d]\n", w, h);
+ DBG(10, "Escl Pdf : Image Size [%dx%d]\n", w, h);
surface = cairo_surface_to_pixels (cairo_surface, *bps);
if (!surface) {
status = SANE_STATUS_NO_MEM;
- DBG(1, "Escl Pdf : Surface Memory allocation problem");
+ DBG(10, "Escl Pdf : Surface Memory allocation problem");
goto destroy_cr;
}
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, w, h, *bps, width, height);
if (!surface) {
- DBG(1, "Escl Pdf Crop: Surface Memory allocation problem");
+ DBG(10, "Escl Pdf Crop: Surface Memory allocation problem");
status = SANE_STATUS_NO_MEM;
}
diff --git a/backend/escl/escl_png.c b/backend/escl/escl_png.c
index 294ec00..fc8d02d 100644
--- a/backend/escl/escl_png.c
+++ b/backend/escl/escl_png.c
@@ -64,7 +64,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
// check for valid magic number
if (!png_check_sig (magic, sizeof (magic)))
{
- DBG( 1, "Escl Png : PNG error is not a valid PNG image!\n");
+ DBG( 10, "Escl Png : PNG error is not a valid PNG image!\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
@@ -73,7 +73,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
- DBG( 1, "Escl Png : PNG error create a png read struct\n");
+ DBG( 10, "Escl Png : PNG error create a png read struct\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
@@ -81,7 +81,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
png_infop info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
- DBG( 1, "Escl Png : PNG error create a png info struct\n");
+ DBG( 10, "Escl Png : PNG error create a png info struct\n");
png_destroy_read_struct (&png_ptr, NULL, NULL);
status = SANE_STATUS_INVAL;
goto close_file;
@@ -93,7 +93,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
if (surface)
free (surface);
- DBG( 1, "Escl Png : PNG read error.\n");
+ DBG( 10, "Escl Png : PNG read error.\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
@@ -115,7 +115,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
png_set_palette_to_rgb (png_ptr);
else if (color_type != PNG_COLOR_TYPE_RGB && color_type != PNG_COLOR_TYPE_RGB_ALPHA)
{
- DBG(1, "PNG format not supported.\n");
+ DBG(10, "PNG format not supported.\n");
status = SANE_STATUS_NO_MEM;
goto close_file;
}
@@ -145,7 +145,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
surface = (unsigned char *)malloc (sizeof (unsigned char) * w
* h * components);
if (!surface) {
- DBG( 1, "Escl Png : texels Memory allocation problem\n");
+ DBG( 10, "Escl Png : texels Memory allocation problem\n");
status = SANE_STATUS_NO_MEM;
goto close_file;
}
@@ -153,7 +153,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
// setup a pointer array. Each one points at the begening of a row.
row_pointers = (png_bytep *)malloc (sizeof (png_bytep) * h);
if (!row_pointers) {
- DBG( 1, "Escl Png : row_pointers Memory allocation problem\n");
+ DBG( 10, "Escl Png : row_pointers Memory allocation problem\n");
free(surface);
status = SANE_STATUS_NO_MEM;
goto close_file;
@@ -169,7 +169,7 @@ get_PNG_data(capabilities_t *scanner, int *width, int *height, int *bps)
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, w, h, components, width, height);
if (!surface) {
- DBG( 1, "Escl Png : Surface Memory allocation problem\n");
+ DBG( 10, "Escl Png : Surface Memory allocation problem\n");
status = SANE_STATUS_NO_MEM;
goto close_file;
}
diff --git a/backend/escl/escl_reset.c b/backend/escl/escl_reset.c
index 95e3f2d..ad3080b 100644
--- a/backend/escl/escl_reset.c
+++ b/backend/escl/escl_reset.c
@@ -44,7 +44,32 @@ write_callback(void __sane_unused__*str,
* This function is called in the 'sane_cancel' function.
*/
void
-escl_scanner(const ESCL_Device *device, char *scanJob, char *result)
+escl_delete(const ESCL_Device *device, char *uri)
+{
+ CURL *curl_handle = NULL;
+ long answer = 0;
+
+ if (uri == NULL)
+ return;
+ curl_handle = curl_easy_init();
+ if (curl_handle != NULL) {
+ escl_curl_url(curl_handle, device, uri);
+ curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
+ if (curl_easy_perform(curl_handle) == CURLE_OK) {
+ curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &answer);
+ return;
+ }
+ curl_easy_cleanup(curl_handle);
+ }
+}
+
+/**
+ * \fn void escl_scanner(const ESCL_Device *device, char *result)
+ * \brief Function that resets the scanner after each scan, using curl.
+ * This function is called in the 'sane_cancel' function.
+ */
+void
+escl_scanner(const ESCL_Device *device, char *scanJob, char *result, SANE_Bool status)
{
CURL *curl_handle = NULL;
const char *scan_jobs = "/eSCL/";
@@ -70,10 +95,15 @@ CURL_CALL:
if (i >= 15) return;
}
curl_easy_cleanup(curl_handle);
- if (SANE_STATUS_GOOD != escl_status(device,
- PLATEN,
- NULL,
- NULL))
- goto CURL_CALL;
+ char* end = strrchr(scan_cmd, '/');
+ *end = 0;
+ escl_delete(device, scan_cmd);
+ if (status) {
+ if (SANE_STATUS_GOOD != escl_status(device,
+ PLATEN,
+ NULL,
+ NULL))
+ goto CURL_CALL;
+ }
}
}
diff --git a/backend/escl/escl_scan.c b/backend/escl/escl_scan.c
index 8af6bb2..b7f344d 100644
--- a/backend/escl/escl_scan.c
+++ b/backend/escl/escl_scan.c
@@ -83,7 +83,7 @@ escl_scan(capabilities_t *scanner, const ESCL_Device *device, char *scanJob, cha
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, scanner);
CURLcode res = curl_easy_perform(curl_handle);
if (res != CURLE_OK) {
- DBG( 1, "Unable to scan: %s\n", curl_easy_strerror(res));
+ DBG( 10, "Unable to scan: %s\n", curl_easy_strerror(res));
scanner->real_read = 0;
fclose(scanner->tmp);
scanner->tmp = NULL;
diff --git a/backend/escl/escl_status.c b/backend/escl/escl_status.c
index 1f848a2..eec8041 100644
--- a/backend/escl/escl_status.c
+++ b/backend/escl/escl_status.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <libxml/parser.h>
@@ -52,7 +53,7 @@ memory_callback_s(void *contents, size_t size, size_t nmemb, void *userp)
char *str = realloc(mem->memory, mem->size + realsize + 1);
if (str == NULL) {
- DBG(1, "not enough memory (realloc returned NULL)\n");
+ DBG(10, "not enough memory (realloc returned NULL)\n");
return (0);
}
mem->memory = str;
@@ -224,7 +225,7 @@ reload:
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
CURLcode res = curl_easy_perform(curl_handle);
if (res != CURLE_OK) {
- DBG( 1, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
+ DBG( 10, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
status = SANE_STATUS_INVAL;
goto clean_data;
}
@@ -270,3 +271,135 @@ clean_data:
}
return (status);
}
+
+static void
+print_xml_job_finish(xmlNode *node,
+ SANE_Status *job)
+{
+ while (node) {
+ if (node->type == XML_ELEMENT_NODE) {
+ if (find_nodes_s(node)) {
+ if (strcmp((const char *)node->name, "JobState") == 0) {
+ const char *state = (const char *)xmlNodeGetContent(node);
+ if (!strcmp(state, "Canceled")) {
+ *job = SANE_STATUS_GOOD;
+ DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
+ }
+ else if (!strcmp(state, "Aborted")) {
+ *job = SANE_STATUS_GOOD;
+ DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
+ }
+ else if (!strcmp(state, "Completed")) {
+ *job = SANE_STATUS_GOOD;
+ DBG(10, "jobId Completed SANE_STATUS_GOOD\n");
+ }
+ }
+ }
+ }
+ print_xml_job_finish(node->children, job);
+ node = node->next;
+ }
+}
+
+static void
+print_xml_reset_all_jobs (xmlNode *node,
+ ESCL_Device *device)
+{
+ DBG(10, "print_xml_reset_all_jobs\n");
+ SANE_Status status = SANE_STATUS_DEVICE_BUSY;
+ while (node) {
+ if (node->type == XML_ELEMENT_NODE) {
+ if (find_nodes_s(node)) {
+ if (strcmp((const char *)node->name, "JobUri") == 0) {
+ DBG(10, "print_xml_reset_all_jobs: %s\n", node->name);
+ if (device != NULL) {
+ print_xml_job_finish (node, &status);
+ if (status == SANE_STATUS_DEVICE_BUSY) {
+ char *jobUri = (char *)xmlNodeGetContent(node);
+ char *job = strrchr((const char *)jobUri, '/');
+ char *scanj = NULL;
+ if (job != NULL) {
+ if (strstr(jobUri,"ScanJobs"))
+ scanj = strdup("ScanJobs");
+ else
+ scanj = strdup("ScanJob");
+ DBG(10, "print_xml_reset_all_jobs: %s/%s\n", scanj, job);
+ escl_scanner(device, scanj, job, SANE_FALSE);
+ free(scanj);
+ }
+ DBG(10, "print_xml_reset_all_jobs: sleep to finish the job\n");
+ }
+ }
+ }
+ }
+ }
+ print_xml_reset_all_jobs (node->children,
+ device);
+ node = node->next;
+ }
+}
+
+/**
+ * \fn SANE_Status escl_reset_all_jobs (ESCL_Device *device, , char *scanJob)
+ * \brief Function that forces the end of jobs, using curl.
+ * This function is called in the 'sane_start' function.
+ *
+ * \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
+ */
+SANE_Status
+escl_reset_all_jobs(ESCL_Device *device)
+{
+ CURL *curl_handle = NULL;
+ xmlDoc *data = NULL;
+ xmlNode *node = NULL;
+ struct idle *var = NULL;
+ const char *scanner_status = "/eSCL/ScannerStatus";
+ SANE_Status status = SANE_STATUS_DEVICE_BUSY;
+
+ DBG(10, "escl_reset_all_jobs\n");
+ if (device == NULL)
+ return (SANE_STATUS_NO_MEM);
+ DBG(10, "1 - escl_reset_all_jobs\n");
+ var = (struct idle*)calloc(1, sizeof(struct idle));
+ if (var == NULL)
+ return (SANE_STATUS_NO_MEM);
+ DBG(10, "2 - escl_reset_all_jobs\n");
+ var->memory = malloc(1);
+ var->size = 0;
+ curl_handle = curl_easy_init();
+
+ escl_curl_url(curl_handle, device, scanner_status);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, memory_callback_s);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)var);
+ curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);
+ CURLcode res = curl_easy_perform(curl_handle);
+ if (res != CURLE_OK) {
+ DBG( 10, "The scanner didn't respond: %s\n", curl_easy_strerror(res));
+ status = SANE_STATUS_INVAL;
+ goto clean_data1;
+ }
+ DBG(10, "3 - escl_reset_all_jobs\n");
+ DBG( 10, "eSCL : Status : %s.\n", var->memory);
+ data = xmlReadMemory(var->memory, var->size, "file.xml", NULL, 0);
+ if (data == NULL) {
+ status = SANE_STATUS_NO_MEM;
+ goto clean_data1;
+ }
+ node = xmlDocGetRootElement(data);
+ if (node == NULL) {
+ status = SANE_STATUS_NO_MEM;
+ goto clean1;
+ }
+ print_xml_reset_all_jobs (node, device);
+ status = SANE_STATUS_GOOD;
+clean1:
+ xmlFreeDoc(data);
+clean_data1:
+ xmlCleanupParser();
+ xmlMemoryDump();
+ curl_easy_cleanup(curl_handle);
+ free(var->memory);
+ free(var);
+ return status;
+}
diff --git a/backend/escl/escl_tiff.c b/backend/escl/escl_tiff.c
index e17554e..6270ff4 100644
--- a/backend/escl/escl_tiff.c
+++ b/backend/escl/escl_tiff.c
@@ -65,7 +65,7 @@ get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
lseek(fileno(scanner->tmp), 0, SEEK_SET);
tif = TIFFFdOpen(fileno(scanner->tmp), "temp", "r");
if (!tif) {
- DBG( 1, "Escl Tiff : Can not open, or not a TIFF file.\n");
+ DBG( 10, "Escl Tiff : Can not open, or not a TIFF file.\n");
status = SANE_STATUS_INVAL;
goto close_file;
}
@@ -76,14 +76,14 @@ get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
surface = (unsigned char*) malloc(npixels * sizeof (uint32_t));
if (surface == NULL)
{
- DBG( 1, "Escl Tiff : raster Memory allocation problem.\n");
+ DBG( 10, "Escl Tiff : raster Memory allocation problem.\n");
status = SANE_STATUS_INVAL;
goto close_tiff;
}
if (!TIFFReadRGBAImage(tif, w, h, (uint32_t *)surface, 0))
{
- DBG( 1, "Escl Tiff : Problem reading image data.\n");
+ DBG( 10, "Escl Tiff : Problem reading image data.\n");
status = SANE_STATUS_INVAL;
free(surface);
goto close_tiff;
@@ -94,7 +94,7 @@ get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
// If necessary, trim the image.
surface = escl_crop_surface(scanner, surface, w, h, components, width, height);
if (!surface) {
- DBG( 1, "Escl Tiff : Surface Memory allocation problem\n");
+ DBG( 10, "Escl Tiff : Surface Memory allocation problem\n");
status = SANE_STATUS_INVAL;
}