kopia lustrzana https://gitlab.com/sane-project/backends
Merge branch 'escl-debug' into 'master'
Log message improvements. See merge request sane-project/backends!302merge-requests/317/merge
commit
42b2562470
|
@ -35,7 +35,6 @@
|
|||
#include "../include/sane/sanei.h"
|
||||
#include "../include/sane/sanei_backend.h"
|
||||
#include "../include/sane/sanei_config.h"
|
||||
#include "../include/sane/sanei_debug.h"
|
||||
|
||||
#define min(A,B) (((A)<(B)) ? (A) : (B))
|
||||
#define max(A,B) (((A)>(B)) ? (A) : (B))
|
||||
|
@ -150,6 +149,7 @@ convertFromESCLDev(ESCL_Device *cdev)
|
|||
snprintf(tmp, sizeof(tmp), "http://%s:%d", cdev->ip_address, cdev->port_nb);
|
||||
else
|
||||
snprintf(tmp, sizeof(tmp), "https://%s:%d", cdev->ip_address, cdev->port_nb);
|
||||
DBG( 1, "Escl add device : %s\n", tmp);
|
||||
sdev->name = strdup(tmp);
|
||||
sdev->model = strdup(cdev->model_name);
|
||||
sdev->vendor = strdup("ESCL");
|
||||
|
|
|
@ -48,6 +48,19 @@
|
|||
#define BACKEND_NAME escl
|
||||
#endif
|
||||
|
||||
#define DEBUG_NOT_STATIC
|
||||
#include "../include/sane/sanei_debug.h"
|
||||
|
||||
#ifndef DBG_LEVEL
|
||||
#define DBG_LEVEL PASTE(sanei_debug_, BACKEND_NAME)
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
# define DBGDUMP(level, buf, size) \
|
||||
do { if (DBG_LEVEL >= (level)) sanei_escl_dbgdump(buf, size); } while (0)
|
||||
#else
|
||||
# define DBGDUMP(level, buf, size)
|
||||
#endif
|
||||
|
||||
#define ESCL_CONFIG_FILE "escl.conf"
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
|
@ -346,15 +348,17 @@ escl_capabilities(SANE_String_Const name, SANE_Status *status)
|
|||
curl_handle = curl_easy_init();
|
||||
strcpy(tmp, name);
|
||||
strcat(tmp, scanner_capabilities);
|
||||
DBG( 1, "Get Capabilities : %s\n", tmp);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, tmp);
|
||||
if (strncmp(name, "https", 5) == 0) {
|
||||
DBG( 1, "Ignoring safety certificates, use https\n");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, memory_callback_c);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)var);
|
||||
if (curl_easy_perform(curl_handle) != CURLE_OK) {
|
||||
fprintf(stderr, "THERE IS NO SCANNER\n");
|
||||
DBG( 1, "The scanner didn't respond.\n");
|
||||
*status = SANE_STATUS_INVAL;
|
||||
}
|
||||
data = xmlReadMemory(var->memory, var->size, "file.xml", NULL, 0);
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -142,21 +145,21 @@ escl_devices(SANE_Status *status)
|
|||
|
||||
*status = SANE_STATUS_GOOD;
|
||||
if (!(simple_poll = avahi_simple_poll_new())) {
|
||||
fprintf(stderr, "Failed to create simple poll object.\n");
|
||||
DBG( 1, "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) {
|
||||
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
|
||||
DBG( 1, "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))) {
|
||||
fprintf(stderr, "Failed to create service browser: %s\n",
|
||||
DBG( 1, "Failed to create service browser: %s\n",
|
||||
avahi_strerror(avahi_client_errno(client)));
|
||||
*status = SANE_STATUS_INVAL;
|
||||
goto fail;
|
||||
|
@ -165,7 +168,7 @@ escl_devices(SANE_Status *status)
|
|||
AVAHI_PROTO_UNSPEC,
|
||||
"_uscans._tcp", NULL, 0,
|
||||
browse_callback, client))) {
|
||||
fprintf(stderr, "Failed to create service browser: %s\n",
|
||||
DBG( 1, "Failed to create service browser: %s\n",
|
||||
avahi_strerror(avahi_client_errno(client)));
|
||||
*status = SANE_STATUS_INVAL;
|
||||
goto fail;
|
||||
|
|
|
@ -1,3 +1,29 @@
|
|||
/* sane - Scanner Access Now Easy.
|
||||
|
||||
Copyright (C) 2019 Touboul Nathane
|
||||
Copyright (C) 2019 Thierry HUCHARD <thierry@ordissimo.com>
|
||||
|
||||
This file is part of the SANE package.
|
||||
|
||||
SANE is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
SANE is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with sane; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include "../include/sane/sanei.h"
|
||||
|
@ -148,6 +174,7 @@ get_JPEG_data(capabilities_t *scanner, int *w, int *h, int *bps)
|
|||
jpeg_destroy_decompress(&cinfo);
|
||||
if (surface != NULL)
|
||||
free(surface);
|
||||
DBG( 1, "Escl Jpeg : Error reading jpeg\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
@ -164,6 +191,7 @@ get_JPEG_data(capabilities_t *scanner, int *w, int *h, int *bps)
|
|||
if (surface == NULL) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fseek(scanner->tmp, start, SEEK_SET);
|
||||
DBG( 1, "Escl Jpeg : Memory allocation problem\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -108,7 +111,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) {
|
||||
fprintf(stderr, "not enough memory (realloc returned NULL)\n");
|
||||
DBG( 1, "Not enough memory (realloc returned NULL)\n");
|
||||
return (0);
|
||||
}
|
||||
download->memory = content;
|
||||
|
@ -145,16 +148,19 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
*status = SANE_STATUS_GOOD;
|
||||
if (name == NULL || scanner == NULL) {
|
||||
*status = SANE_STATUS_NO_MEM;
|
||||
DBG( 1, "Create NewJob : the name or the scan are invalid.\n");
|
||||
return (NULL);
|
||||
}
|
||||
upload = (struct uploading *)calloc(1, sizeof(struct uploading));
|
||||
if (upload == NULL) {
|
||||
*status = SANE_STATUS_NO_MEM;
|
||||
DBG( 1, "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");
|
||||
*status = SANE_STATUS_NO_MEM;
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -172,11 +178,12 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
}
|
||||
else
|
||||
format_ext = f_ext;
|
||||
DBG( 1, "Create NewJob : %s\n", scanner->default_format);
|
||||
if (curl_handle != NULL) {
|
||||
snprintf(cap_data, sizeof(cap_data), settings, scanner->height, scanner->width, 0, 0, scanner->default_format,
|
||||
format_ext,
|
||||
scanner->default_color, scanner->default_resolution, scanner->default_resolution);
|
||||
// fprintf(stderr, "CAP_DATA = %s\n", cap_data);
|
||||
DBG( 1, "Create NewJob : %s\n", cap_data);
|
||||
upload->read_data = strdup(cap_data);
|
||||
upload->size = strlen(cap_data);
|
||||
download->memory = malloc(1);
|
||||
|
@ -194,7 +201,7 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, download_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, (void *)download);
|
||||
if (curl_easy_perform(curl_handle) != CURLE_OK) {
|
||||
fprintf(stderr, "THERE IS NO SCANNER\n");
|
||||
DBG( 1, "Create NewJob : the scanner responded incorrectly.\n");
|
||||
*status = SANE_STATUS_INVAL;
|
||||
}
|
||||
else {
|
||||
|
@ -209,16 +216,18 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu
|
|||
*location = '\0';
|
||||
result = strdup(temporary);
|
||||
}
|
||||
DBG( 1, "Create NewJob : %s\n", result);
|
||||
}
|
||||
free(download->memory);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "THERE IS NO LOCATION\n");
|
||||
DBG( 1, "Create NewJob : The creation of the failed job\n");
|
||||
*status = SANE_STATUS_INVAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*status = SANE_STATUS_NO_MEM;
|
||||
DBG( 1, "Create NewJob : The creation of the failed job\n");
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,29 @@
|
|||
/* sane - Scanner Access Now Easy.
|
||||
|
||||
Copyright (C) 2019 Touboul Nathane
|
||||
Copyright (C) 2019 Thierry HUCHARD <thierry@ordissimo.com>
|
||||
|
||||
This file is part of the SANE package.
|
||||
|
||||
SANE is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
SANE is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with sane; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include "../include/sane/sanei.h"
|
||||
|
@ -37,7 +63,7 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
// check for valid magic number
|
||||
if (!png_check_sig (magic, sizeof (magic)))
|
||||
{
|
||||
fprintf(stderr,"PNG error: is not a valid PNG image!\n");
|
||||
DBG( 1, "Escl Png : PNG error is not a valid PNG image!\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
@ -49,6 +75,8 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
DBG( 1, "Escl Png : PNG error create a png read struct\n");
|
||||
if (scanner->tmp)
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
@ -59,6 +87,7 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
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");
|
||||
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
|
@ -78,6 +107,7 @@ get_PNG_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
}
|
||||
DBG( 1, "Escl Png : PNG read error.\n");
|
||||
return (SANE_STATUS_INVAL);
|
||||
}
|
||||
// setup libpng for using standard C fread() function
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -53,7 +56,9 @@ CURL_CALL:
|
|||
strcat(scan_cmd, result);
|
||||
strcat(scan_cmd, scanner_start);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, scan_cmd);
|
||||
DBG( 1, "Reset Job : %s.\n", scan_cmd);
|
||||
if (strncmp(name, "https", 5) == 0) {
|
||||
DBG( 1, "Ignoring safety certificates, use https\n");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -72,7 +75,9 @@ escl_scan(capabilities_t __sane_unused__ *scanner, SANE_String_Const name, char
|
|||
strcat(scan_cmd, result);
|
||||
strcat(scan_cmd, scanner_start);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, scan_cmd);
|
||||
if (strncmp(name, "https", 5) == 0) {
|
||||
DBG( 1, "Scan : %s.\n", scan_cmd);
|
||||
if (strncmp(name, "https", 5) == 0) {
|
||||
DBG( 1, "Ignoring safety certificates, use https\n");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -50,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) {
|
||||
fprintf(stderr, "not enough memory (realloc returned NULL)\n");
|
||||
DBG(1, "not enough memory (realloc returned NULL)\n");
|
||||
return (0);
|
||||
}
|
||||
mem->memory = str;
|
||||
|
@ -136,14 +139,16 @@ escl_status(SANE_String_Const name)
|
|||
strcpy(tmp, name);
|
||||
strcat(tmp, scanner_status);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, tmp);
|
||||
DBG( 1, "Get Status : %s.\n", tmp);
|
||||
if (strncmp(name, "https", 5) == 0) {
|
||||
DBG( 1, "Ignoring safety certificates, use https\n");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
}
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, memory_callback_s);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)var);
|
||||
if (curl_easy_perform(curl_handle) != CURLE_OK) {
|
||||
fprintf(stderr, "THERE IS NO SCANNER\n");
|
||||
DBG( 1, "The scanner didn't respond.\n");
|
||||
status = SANE_STATUS_INVAL;
|
||||
goto clean_data;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,29 @@
|
|||
/* sane - Scanner Access Now Easy.
|
||||
|
||||
Copyright (C) 2019 Touboul Nathane
|
||||
Copyright (C) 2019 Thierry HUCHARD <thierry@ordissimo.com>
|
||||
|
||||
This file is part of the SANE package.
|
||||
|
||||
SANE is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
SANE is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with sane; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
This file implements a SANE backend for eSCL scanners. */
|
||||
|
||||
#define DEBUG_DECLARE_ONLY
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include "escl.h"
|
||||
|
||||
#include "../include/sane/sanei.h"
|
||||
|
@ -36,7 +62,7 @@ get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
lseek(fileno(scanner->tmp), 0, SEEK_SET);
|
||||
tif = TIFFFdOpen(fileno(scanner->tmp), "temp", "r");
|
||||
if (!tif) {
|
||||
fprintf(stderr, "Can not open, or not a TIFF file.\n");
|
||||
DBG( 1, "Escl Tiff : Can not open, or not a TIFF file.\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
@ -50,7 +76,7 @@ get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
raster = (unsigned char*) malloc(npixels * sizeof (uint32));
|
||||
if (raster != NULL)
|
||||
{
|
||||
fprintf(stderr, "Memory allocation problem.\n");
|
||||
DBG( 1, "Escl Tiff : Memory allocation problem.\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
@ -60,7 +86,7 @@ get_TIFF_data(capabilities_t *scanner, int *w, int *h, int *components)
|
|||
|
||||
if (!TIFFReadRGBAImage(tif, width, height, (uint32 *)raster, 0))
|
||||
{
|
||||
fprintf(stderr, "Problem reading image data.\n");
|
||||
DBG( 1, "Escl Tiff : Problem reading image data.\n");
|
||||
if (scanner->tmp) {
|
||||
fclose(scanner->tmp);
|
||||
scanner->tmp = NULL;
|
||||
|
|
Ładowanie…
Reference in New Issue