summaryrefslogtreecommitdiff
path: root/backend/escl/escl_scan.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-09-10 19:11:27 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-09-10 19:11:27 +0200
commit7e9455b3b15671ff99ed168638c405e2acedb6df (patch)
tree444e59ece236e09dc153f665e42160aeb0208c24 /backend/escl/escl_scan.c
parentbc8a517abd2e11e1435f4ef042cfcc8648b62ef7 (diff)
parentbce41b3c37c2a68e7dab234ce0247755a61ceb40 (diff)
Merge branch 'release/debian/1.0.31-1_experimental1' into masterdebian/1.0.31-1_experimental1
Diffstat (limited to 'backend/escl/escl_scan.c')
-rw-r--r--backend/escl/escl_scan.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/backend/escl/escl_scan.c b/backend/escl/escl_scan.c
index 8f077a1..9fce801 100644
--- a/backend/escl/escl_scan.c
+++ b/backend/escl/escl_scan.c
@@ -43,13 +43,14 @@
static size_t
write_callback(void *str, size_t size, size_t nmemb, void *userp)
{
- size_t to_write = fwrite(str, size, nmemb, (FILE *)userp);
-
+ capabilities_t *scanner = (capabilities_t *)userp;
+ size_t to_write = fwrite(str, size, nmemb, scanner->tmp);
+ scanner->real_read += to_write;
return (to_write);
}
/**
- * \fn SANE_Status escl_scan(capabilities_t *scanner, SANE_String_Const name, char *result)
+ * \fn SANE_Status escl_scan(capabilities_t *scanner, const ESCL_Device *device, char *result)
* \brief Function that, after recovering the 'new job', scans the image writed in the
* temporary file, using curl.
* This function is called in the 'sane_start' function and it's the equivalent of
@@ -58,7 +59,7 @@ write_callback(void *str, size_t size, size_t nmemb, void *userp)
* \return status (if everything is OK, status = SANE_STATUS_GOOD, otherwise, SANE_STATUS_NO_MEM/SANE_STATUS_INVAL)
*/
SANE_Status
-escl_scan(capabilities_t __sane_unused__ *scanner, SANE_String_Const name, char *result)
+escl_scan(capabilities_t *scanner, const ESCL_Device *device, char *result)
{
CURL *curl_handle = NULL;
const char *scan_jobs = "/eSCL/ScanJobs";
@@ -66,34 +67,41 @@ escl_scan(capabilities_t __sane_unused__ *scanner, SANE_String_Const name, char
char scan_cmd[PATH_MAX] = { 0 };
SANE_Status status = SANE_STATUS_GOOD;
- if (name == NULL)
+ if (device == NULL)
return (SANE_STATUS_NO_MEM);
+ scanner->real_read = 0;
curl_handle = curl_easy_init();
if (curl_handle != NULL) {
- strcpy(scan_cmd, name);
- strcat(scan_cmd, scan_jobs);
- strcat(scan_cmd, result);
- strcat(scan_cmd, scanner_start);
- curl_easy_setopt(curl_handle, CURLOPT_URL, scan_cmd);
- 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);
- }
+ snprintf(scan_cmd, sizeof(scan_cmd), "%s%s%s",
+ scan_jobs, result, scanner_start);
+ escl_curl_url(curl_handle, device, scan_cmd);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback);
+ if (scanner->tmp)
+ fclose(scanner->tmp);
scanner->tmp = tmpfile();
if (scanner->tmp != NULL) {
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, scanner->tmp);
- if (curl_easy_perform(curl_handle) != CURLE_OK) {
+ 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));
+ fclose(scanner->tmp);
+ scanner->tmp = NULL;
status = SANE_STATUS_INVAL;
+ goto cleanup;
}
- else
- curl_easy_cleanup(curl_handle);
fseek(scanner->tmp, 0, SEEK_SET);
}
else
status = SANE_STATUS_NO_MEM;
+cleanup:
+ curl_easy_cleanup(curl_handle);
+ }
+ DBG(10, "eSCL scan : [%s]\treal read (%ld)\n", sane_strstatus(status), scanner->real_read);
+ if (scanner->real_read == 0)
+ {
+ fclose(scanner->tmp);
+ scanner->tmp = NULL;
+ return SANE_STATUS_NO_DOCS;
}
return (status);
}