summaryrefslogtreecommitdiff
path: root/backend/escl
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
commite0d94cf4d39395df1e2c6bb4d967200298c13881 (patch)
treebe5c7cace6697afc753c152d13ad5145d0884a42 /backend/escl
parent527bedac30eb120915718eb7997e6dacd583512e (diff)
parent84357741a6a6e6430f199b2c3f7498e0e97da9ad (diff)
Update upstream source from tag 'upstream/1.2.1'
Update to upstream version '1.2.1' with Debian dir a9bb43f754a5c9a361b076af3635cc767b7e652e
Diffstat (limited to 'backend/escl')
-rw-r--r--backend/escl/escl.c97
-rw-r--r--backend/escl/escl.h3
-rw-r--r--backend/escl/escl_capabilities.c11
-rw-r--r--backend/escl/escl_devices.c77
-rw-r--r--backend/escl/escl_newjob.c85
-rw-r--r--backend/escl/escl_pdf.c51
-rw-r--r--backend/escl/escl_scan.c1
-rw-r--r--backend/escl/escl_tiff.c14
8 files changed, 253 insertions, 86 deletions
diff --git a/backend/escl/escl.c b/backend/escl/escl.c
index 5f02ec8..cbbdb60 100644
--- a/backend/escl/escl.c
+++ b/backend/escl/escl.c
@@ -61,6 +61,26 @@ 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;
ESCL_Device *device;
@@ -99,6 +119,60 @@ escl_free_device(ESCL_Device *current)
return NULL;
}
+
+#ifdef CURL_SSLVERSION_MAX_DEFAULT
+static int
+escl_tls_protocol_supported(char *url, int proto)
+{
+ 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_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);
+ /* Perform the request */
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+ }
+ return res;
+}
+
+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)
+ {
+ DBG(10, "curl tls compatible (%d)\n", proto_tls[tls_version]);
+ break;
+ }
+ 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)
{
@@ -187,8 +261,13 @@ escl_device_add(int port_nb,
{
char tmp[PATH_MAX] = { 0 };
char *model = NULL;
+ char url_port[512] = { 0 };
+ int tls_version = 0;
ESCL_Device *current = NULL;
DBG (10, "escl_device_add\n");
+ snprintf(url_port, sizeof(url_port), "https://%s:%d", ip_address, port_nb);
+ tls_version = escl_is_tls(url_port, type);
+
for (current = list_devices_primary; current; current = current->next) {
if ((strcmp(current->ip_address, ip_address) == 0) ||
(uuid && current->uuid && !strcmp(current->uuid, uuid)))
@@ -206,6 +285,7 @@ escl_device_add(int port_nb,
}
current->port_nb = port_nb;
current->https = SANE_TRUE;
+ current->tls = tls_version;
}
return (SANE_STATUS_GOOD);
}
@@ -226,6 +306,7 @@ escl_device_add(int port_nb,
} else {
current->https = SANE_FALSE;
}
+ current->tls = tls_version;
model = (char*)(tmp[0] != 0 ? tmp : model_name);
current->model_name = strdup(model);
current->ip_address = strdup(ip_address);
@@ -470,7 +551,6 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line,
}
escl_device->model_name = opt_model ? opt_model : strdup("Unknown model");
escl_device->is = strdup("flatbed or ADF scanner");
- escl_device->type = strdup("In url");
escl_device->uuid = NULL;
}
@@ -515,6 +595,9 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line,
}
escl_device->is = strdup("flatbed or ADF scanner");
escl_device->uuid = NULL;
+ char url_port[512] = { 0 };
+ snprintf(url_port, sizeof(url_port), "https://%s:%d", escl_device->ip_address, escl_device->port_nb);
+ escl_device->tls = escl_is_tls(url_port, escl_device->type);
status = escl_check_and_add_device(escl_device);
if (status == SANE_STATUS_GOOD)
escl_device = NULL;
@@ -956,7 +1039,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s)
s->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE;
if (s->scanner->brightness) {
s->opt[OPT_BRIGHTNESS].constraint.range = &s->brightness_range;
- s->val[OPT_BRIGHTNESS].w = s->scanner->brightness->normal;
+ s->val[OPT_BRIGHTNESS].w = s->scanner->brightness->value;
s->brightness_range.quant=1;
s->brightness_range.min=s->scanner->brightness->min;
s->brightness_range.max=s->scanner->brightness->max;
@@ -975,7 +1058,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s)
s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE;
if (s->scanner->contrast) {
s->opt[OPT_CONTRAST].constraint.range = &s->contrast_range;
- s->val[OPT_CONTRAST].w = s->scanner->contrast->normal;
+ s->val[OPT_CONTRAST].w = s->scanner->contrast->value;
s->contrast_range.quant=1;
s->contrast_range.min=s->scanner->contrast->min;
s->contrast_range.max=s->scanner->contrast->max;
@@ -994,7 +1077,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s)
s->opt[OPT_SHARPEN].constraint_type = SANE_CONSTRAINT_RANGE;
if (s->scanner->sharpen) {
s->opt[OPT_SHARPEN].constraint.range = &s->sharpen_range;
- s->val[OPT_SHARPEN].w = s->scanner->sharpen->normal;
+ s->val[OPT_SHARPEN].w = s->scanner->sharpen->value;
s->sharpen_range.quant=1;
s->sharpen_range.min=s->scanner->sharpen->min;
s->sharpen_range.max=s->scanner->sharpen->max;
@@ -1014,7 +1097,7 @@ init_options(SANE_String_Const name_source, escl_sane_t *s)
s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE;
if (s->scanner->threshold) {
s->opt[OPT_THRESHOLD].constraint.range = &s->thresold_range;
- s->val[OPT_THRESHOLD].w = s->scanner->threshold->normal;
+ s->val[OPT_THRESHOLD].w = s->scanner->threshold->value;
s->thresold_range.quant=1;
s->thresold_range.min= s->scanner->threshold->min;
s->thresold_range.max=s->scanner->threshold->max;
@@ -1069,9 +1152,11 @@ escl_parse_name(SANE_String_Const name, ESCL_Device *device)
if (strncmp(name, "https://", 8) == 0) {
device->https = SANE_TRUE;
+ device->type = strdup("https");
host = name + 8;
} else if (strncmp(name, "http://", 7) == 0) {
device->https = SANE_FALSE;
+ device->type = strdup("http");
host = name + 7;
} else {
DBG(1, "Unknown URL scheme in %s", name);
@@ -1811,6 +1896,8 @@ escl_curl_url(CURL *handle, const ESCL_Device *device, SANE_String_Const path)
DBG( 1, "Ignoring safety certificates, use https\n");
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 );
diff --git a/backend/escl/escl.h b/backend/escl/escl.h
index 142b4b4..f99bff9 100644
--- a/backend/escl/escl.h
+++ b/backend/escl/escl.h
@@ -92,10 +92,12 @@ typedef struct {
typedef struct ESCL_Device {
struct ESCL_Device *next;
+ double version;
char *model_name;
int port_nb;
char *ip_address;
char *is;
+ int tls;
char *uuid;
char *type;
SANE_Bool https;
@@ -146,6 +148,7 @@ typedef struct support
int min;
int max;
int normal;
+ int value;
int step;
} support_t;
diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c
index 7422896..efbd547 100644
--- a/backend/escl/escl_capabilities.c
+++ b/backend/escl/escl_capabilities.c
@@ -325,7 +325,8 @@ print_support(xmlNode *node)
cpt++;
}
else if (!strcmp((const char *)node->name, "Normal")) {
- sup->normal = atoi((const char *)xmlNodeGetContent(node));
+ sup->value = atoi((const char *)xmlNodeGetContent(node));
+ sup->normal = sup->value;
cpt++;
have_norm = 1;
}
@@ -338,7 +339,8 @@ print_support(xmlNode *node)
if (cpt == 4)
return sup;
if (cpt == 3 && have_norm == 0) {
- sup->normal = (sup->max / 2 );
+ sup->value = (sup->max / 2 );
+ sup->normal = sup->value;
return sup;
}
free(sup);
@@ -428,6 +430,10 @@ print_xml_c(xmlNode *node, ESCL_Device *device, capabilities_t *scanner, int typ
if (find_nodes_c(node) && type != -1)
find_true_variables(node, scanner, type);
}
+ if (!strcmp((const char *)node->name, "Version")&& node->ns && node->ns->prefix){
+ if (!strcmp((const char*)node->ns->prefix, "pwg"))
+ device->version = atof ((const char *)xmlNodeGetContent(node));
+ }
if (!strcmp((const char *)node->name, "MakeAndModel")){
device->model_name = strdup((const char *)xmlNodeGetContent(node));
}
@@ -582,6 +588,7 @@ escl_capabilities(ESCL_Device *device, char *blacklist, SANE_Status *status)
strstr(header->memory, "Server: HP_Compact_Server"))
device->hack = curl_slist_append(NULL, "Host: localhost");
+ device->version = 0.0;
scanner->source = 0;
scanner->Sources = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * 4);
for (i = 0; i < 4; i++)
diff --git a/backend/escl/escl_devices.c b/backend/escl/escl_devices.c
index 92e064b..a2fdb80 100644
--- a/backend/escl/escl_devices.c
+++ b/backend/escl/escl_devices.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <arpa/inet.h>
#include <avahi-client/lookup.h>
#include <avahi-common/error.h>
@@ -53,47 +54,65 @@ static int count_finish = 0;
*/
static void
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface,
- AVAHI_GCC_UNUSED AvahiProtocol protocol,
- AvahiResolverEvent event, const char *name,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
const char __sane_unused__ *type,
const char __sane_unused__ *domain,
const char __sane_unused__ *host_name,
- const AvahiAddress *address, uint16_t port, AvahiStringList *txt,
+ const AvahiAddress *address,
+ uint16_t port,
+ AvahiStringList *txt,
AvahiLookupResultFlags __sane_unused__ flags,
void __sane_unused__ *userdata)
{
- char a[AVAHI_ADDRESS_STR_MAX], *t;
+ char a[(AVAHI_ADDRESS_STR_MAX + 10)] = { 0 };
+ char *t;
const char *is;
const char *uuid;
AvahiStringList *s;
assert(r);
switch (event) {
- case AVAHI_RESOLVER_FAILURE:
- break;
- case AVAHI_RESOLVER_FOUND:
- avahi_address_snprint(a, sizeof(a), address);
- t = avahi_string_list_to_string(txt);
- if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) {
- char ip_add[PATH_MAX] = {0};
- s = avahi_string_list_find(txt, "is");
- if (s && s->size > 3)
- is = (const char*)s->text + 3;
- else
- is = (const char*)NULL;
- s = avahi_string_list_find(txt, "uuid");
- if (s && s->size > 5)
- uuid = (const char*)s->text + 5;
- else
- uuid = (const char*)NULL;
- DBG (10, "resolve_callback [%s]\n", a);
- if (strstr(a, "127.0.0.1") != NULL) {
- snprintf(ip_add, sizeof(ip_add), "%s", "localhost");
- DBG (10,"resolve_callback fix redirect [localhost]\n");
- }
+ case AVAHI_RESOLVER_FAILURE:
+ break;
+ case AVAHI_RESOLVER_FOUND:
+ {
+ char *psz_addr = ((void*)0);
+ char b[128] = { 0 };
+ avahi_address_snprint(b, (sizeof(b)/sizeof(b[0]))-1, address);
+#ifdef ENABLE_IPV6
+ if (protocol == AVAHI_PROTO_INET6 && strchr(b, ':'))
+ {
+ if ( asprintf( &psz_addr, "[%s]", b ) == -1 )
+ break;
+ }
else
- snprintf(ip_add, sizeof(ip_add), "%s", a);
- escl_device_add(port, name, ip_add, is, uuid, (char*)type);
- }
+#endif
+ {
+ if ( asprintf( &psz_addr, "%s", b ) == -1 )
+ break;
+ }
+ t = avahi_string_list_to_string(txt);
+ if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) {
+ s = avahi_string_list_find(txt, "is");
+ if (s && s->size > 3)
+ is = (const char*)s->text + 3;
+ else
+ is = (const char*)NULL;
+ s = avahi_string_list_find(txt, "uuid");
+ if (s && s->size > 5)
+ uuid = (const char*)s->text + 5;
+ else
+ uuid = (const char*)NULL;
+ DBG (10, "resolve_callback [%s]\n", a);
+ if (strstr(psz_addr, "127.0.0.1") != NULL) {
+ escl_device_add(port, name, "localhost", is, uuid, (char*)type);
+ DBG (10,"resolve_callback fix redirect [localhost]\n");
+ }
+ else
+ escl_device_add(port, name, psz_addr, is, uuid, (char*)type);
+ }
+ }
}
}
diff --git a/backend/escl/escl_newjob.c b/backend/escl/escl_newjob.c
index 98a953f..e1b326f 100644
--- a/backend/escl/escl_newjob.c
+++ b/backend/escl/escl_newjob.c
@@ -46,7 +46,7 @@ struct downloading
static const char settings[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
"<scan:ScanSettings xmlns:pwg=\"http://www.pwg.org/schemas/2010/12/sm\" xmlns:scan=\"http://schemas.hp.com/imaging/escl/2011/05/03\">" \
- " <pwg:Version>2.0</pwg:Version>" \
+ " <pwg:Version>%.2f</pwg:Version>" \
" <pwg:ScanRegions>" \
" <pwg:ScanRegion>" \
" <pwg:ContentRegionUnits>escl:ThreeHundredthsOfInches</pwg:ContentRegionUnits>" \
@@ -56,13 +56,11 @@ static const char settings[] =
" <pwg:YOffset>%d</pwg:YOffset>" \
" </pwg:ScanRegion>" \
" </pwg:ScanRegions>" \
- " <pwg:DocumentFormat>%s</pwg:DocumentFormat>" \
"%s" \
" <scan:ColorMode>%s</scan:ColorMode>" \
" <scan:XResolution>%d</scan:XResolution>" \
" <scan:YResolution>%d</scan:YResolution>" \
" <pwg:InputSource>%s</pwg:InputSource>" \
- " <scan:InputSource>%s</scan:InputSource>" \
"%s" \
"%s" \
"</scan:ScanSettings>";
@@ -138,8 +136,8 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
char *location = NULL;
char *result = NULL;
char *temporary = NULL;
- char *f_ext = "";
char *format_ext = NULL;
+ char f_ext_tmp[1024];
char duplex_mode[1024] = { 0 };
int wakup_count = 0;
@@ -189,16 +187,22 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
scanner->caps[scanner->source].default_format =
strdup(scanner->caps[scanner->source].DocumentFormats[have_pdf]);
}
- if (scanner->caps[scanner->source].format_ext == 1)
+ if (device->version <= 2.0)
{
- char f_ext_tmp[1024];
+ // For eSCL 2.0 and older clients
snprintf(f_ext_tmp, sizeof(f_ext_tmp),
- " <scan:DocumentFormatExt>%s</scan:DocumentFormatExt>",
+ " <pwg:DocumentFormat>%s</pwg:DocumentFormat>",
scanner->caps[scanner->source].default_format);
- format_ext = f_ext_tmp;
}
else
- format_ext = f_ext;
+ {
+ // For eSCL 2.1 and newer clients
+ snprintf(f_ext_tmp, sizeof(f_ext_tmp),
+ " <scan:DocumentFormatExt>%s</scan:DocumentFormatExt>",
+ scanner->caps[scanner->source].default_format);
+ }
+ format_ext = f_ext_tmp;
+
if(scanner->source > PLATEN && scanner->Sources[ADFDUPLEX]) {
snprintf(duplex_mode, sizeof(duplex_mode),
" <scan:Duplex>%s</scan:Duplex>",
@@ -215,52 +219,63 @@ escl_newjob (capabilities_t *scanner, const ESCL_Device *device, SANE_Status *st
char *source = (scanner->source == PLATEN ? "Platen" : "Feeder");
if (scanner->use_threshold)
{
- char *tmp = add_support_option("ThresholdSupport", scanner->val_threshold);
- if (support_options[0])
- strcat(support_options, tmp);
- else
- strcpy(support_options, tmp);
- free(tmp);
+ if (scanner->val_threshold != scanner->threshold->value)
+ {
+ char *tmp = add_support_option("ThresholdSupport", scanner->val_threshold);
+ if (support_options[0])
+ strcat(support_options, tmp);
+ else
+ strcpy(support_options, tmp);
+ free(tmp);
+ }
}
if (scanner->use_sharpen)
{
- char *tmp = add_support_option("SharpenSupport", scanner->val_sharpen);
- if (support_options[0])
- strcat(support_options, tmp);
- else
- strcpy(support_options, tmp);
- free(tmp);
+ if (scanner->val_sharpen != scanner->sharpen->value)
+ {
+ char *tmp = add_support_option("SharpenSupport", scanner->val_sharpen);
+ if (support_options[0])
+ strcat(support_options, tmp);
+ else
+ strcpy(support_options, tmp);
+ free(tmp);
+ }
}
if (scanner->use_contrast)
{
- char *tmp = add_support_option("ContrastSupport", scanner->val_contrast);
- if (support_options[0])
- strcat(support_options, tmp);
- else
- strcpy(support_options, tmp);
- free(tmp);
+ if (scanner->val_contrast != scanner->contrast->value)
+ {
+ char *tmp = add_support_option("ContrastSupport", scanner->val_contrast);
+ if (support_options[0])
+ strcat(support_options, tmp);
+ else
+ strcpy(support_options, tmp);
+ free(tmp);
+ }
}
if (scanner->use_brightness)
{
- char *tmp = add_support_option("BrightnessSupport", scanner->val_brightness);
- if (support_options[0])
- strcat(support_options, tmp);
- else
- strcpy(support_options, tmp);
- free(tmp);
+ if (scanner->val_brightness != scanner->brightness->value)
+ {
+ char *tmp = add_support_option("BrightnessSupport", scanner->val_brightness);
+ if (support_options[0])
+ strcat(support_options, tmp);
+ else
+ strcpy(support_options, tmp);
+ free(tmp);
+ }
}
snprintf(cap_data, sizeof(cap_data), settings,
+ device->version,
scanner->caps[scanner->source].height,
scanner->caps[scanner->source].width,
off_x,
off_y,
- scanner->caps[scanner->source].default_format,
format_ext,
scanner->caps[scanner->source].default_color,
scanner->caps[scanner->source].default_resolution,
scanner->caps[scanner->source].default_resolution,
source,
- source,
duplex_mode[0] == 0 ? " " : duplex_mode,
support_options[0] == 0 ? " " : support_options);
upload->memory = strdup(cap_data);
diff --git a/backend/escl/escl_pdf.c b/backend/escl/escl_pdf.c
index 02dce66..8277e1d 100644
--- a/backend/escl/escl_pdf.c
+++ b/backend/escl/escl_pdf.c
@@ -44,8 +44,9 @@
#if HAVE_POPPLER_GLIB
-#define INPUT_BUFFER_SIZE 4096
+#define ESCL_PDF_USE_MAPPED_FILE POPPLER_CHECK_VERSION(0,82,0)
+#if ! ESCL_PDF_USE_MAPPED_FILE
static unsigned char*
set_file_in_buffer(FILE *fp, int *size)
{
@@ -70,6 +71,7 @@ set_file_in_buffer(FILE *fp, int *size)
*size = nx;
return data;
}
+#endif
static unsigned char *
cairo_surface_to_pixels (cairo_surface_t *surface, int bps)
@@ -109,28 +111,52 @@ get_PDF_data(capabilities_t *scanner, int *width, int *height, int *bps)
PopplerPage *page;
PopplerDocument *doc;
double dw, dh;
- int w, h, size = 0;
- char *data = NULL;
+ int w, h;
unsigned char* surface = NULL;
SANE_Status status = SANE_STATUS_GOOD;
+#if ESCL_PDF_USE_MAPPED_FILE
+ GMappedFile *file;
+ GBytes *bytes;
+
+ file = g_mapped_file_new_from_fd (fileno (scanner->tmp), 0, NULL);
+ if (!file) {
+ DBG(1, "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");
+ 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");
+ status = SANE_STATUS_INVAL;
+ goto free_bytes;
+ }
+#else
+ int size = 0;
+ char *data = NULL;
data = (char*)set_file_in_buffer(scanner->tmp, &size);
if (!data) {
- DBG(1, "Error : poppler_document_new_from_data");
+ DBG(1, "Error : set_file_in_buffer");
status = SANE_STATUS_INVAL;
goto close_file;
}
- doc = poppler_document_new_from_data(data,
- size,
- NULL,
- NULL);
+ doc = poppler_document_new_from_data (data, size, NULL, NULL);
if (!doc) {
DBG(1, "Error : poppler_document_new_from_data");
status = SANE_STATUS_INVAL;
- goto free_file;
+ goto free_data;
}
+#endif
page = poppler_document_get_page (doc, 0);
if (!page) {
@@ -201,8 +227,15 @@ free_page:
g_object_unref (page);
free_doc:
g_object_unref (doc);
+#if ESCL_PDF_USE_MAPPED_FILE
+free_bytes:
+ g_bytes_unref (bytes);
free_file:
+ g_mapped_file_unref (file);
+#else
+free_data:
free(data);
+#endif
close_file:
if (scanner->tmp)
fclose(scanner->tmp);
diff --git a/backend/escl/escl_scan.c b/backend/escl/escl_scan.c
index 3350c83..8af6bb2 100644
--- a/backend/escl/escl_scan.c
+++ b/backend/escl/escl_scan.c
@@ -84,6 +84,7 @@ escl_scan(capabilities_t *scanner, const ESCL_Device *device, char *scanJob, cha
CURLcode res = curl_easy_perform(curl_handle);
if (res != CURLE_OK) {
DBG( 1, "Unable to scan: %s\n", curl_easy_strerror(res));
+ scanner->real_read = 0;
fclose(scanner->tmp);
scanner->tmp = NULL;
status = SANE_STATUS_INVAL;
diff --git a/backend/escl/escl_tiff.c b/backend/escl/escl_tiff.c
index e33498c..e17554e 100644
--- a/backend/escl/escl_tiff.c
+++ b/backend/escl/escl_tiff.c
@@ -26,6 +26,8 @@
#include "escl.h"
+#include "../include/_stdint.h"
+
#include "../include/sane/sanei.h"
#include <stdio.h>
@@ -53,11 +55,11 @@ SANE_Status
get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
{
TIFF* tif = NULL;
- uint32 w = 0;
- uint32 h = 0;
+ uint32_t w = 0;
+ uint32_t h = 0;
unsigned char *surface = NULL; /* image data*/
int components = 4;
- uint32 npixels = 0;
+ uint32_t npixels = 0;
SANE_Status status = SANE_STATUS_GOOD;
lseek(fileno(scanner->tmp), 0, SEEK_SET);
@@ -71,15 +73,15 @@ get_TIFF_data(capabilities_t *scanner, int *width, int *height, int *bps)
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
npixels = w * h;
- surface = (unsigned char*) malloc(npixels * sizeof (uint32));
- if (surface != NULL)
+ surface = (unsigned char*) malloc(npixels * sizeof (uint32_t));
+ if (surface == NULL)
{
DBG( 1, "Escl Tiff : raster Memory allocation problem.\n");
status = SANE_STATUS_INVAL;
goto close_tiff;
}
- if (!TIFFReadRGBAImage(tif, w, h, (uint32 *)surface, 0))
+ if (!TIFFReadRGBAImage(tif, w, h, (uint32_t *)surface, 0))
{
DBG( 1, "Escl Tiff : Problem reading image data.\n");
status = SANE_STATUS_INVAL;