diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 18:45:55 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 18:45:55 +0200 |
commit | a77bc1fcbdf83cfdac9570c0a0ac886b5534c90f (patch) | |
tree | d839746371ecb8ed64ac81d2e37c11fcd25a00ac /backend/escl/escl_scan.c | |
parent | 787fb1d54ec9ee5fb941ae897fb201feb9cb2fd1 (diff) | |
parent | 2b3e02411ecc09e7d41741b5587655c9b2f955b7 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'backend/escl/escl_scan.c')
-rw-r--r-- | backend/escl/escl_scan.c | 48 |
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); } |