summaryrefslogtreecommitdiff
path: root/backend/escl/escl_reset.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-03-30 21:30:45 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-03-30 21:30:45 +0200
commitee770c2346eb37e0dcb8b6cf3eaacf3d8efd6bbc (patch)
tree58f05092be1a17a939e861f8cadcda1b6ca2ecef /backend/escl/escl_reset.c
parent0da9e21872802cfc6e975b1ebaf9efb9e5934d84 (diff)
parentfef76e17ed4c607ea73b81279f9ef1d7121be900 (diff)
Merge branch 'release/experimental/1.0.29-1_experimental1'experimental/1.0.29-1_experimental1
Diffstat (limited to 'backend/escl/escl_reset.c')
-rw-r--r--backend/escl/escl_reset.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/backend/escl/escl_reset.c b/backend/escl/escl_reset.c
new file mode 100644
index 0000000..7722d89
--- /dev/null
+++ b/backend/escl/escl_reset.c
@@ -0,0 +1,75 @@
+/* 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 <stdlib.h>
+#include <string.h>
+
+#include <curl/curl.h>
+
+/**
+ * \fn void escl_scanner(SANE_String_Const name, 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(SANE_String_Const name, char *result)
+{
+ CURL *curl_handle = NULL;
+ const char *scan_jobs = "/eSCL/ScanJobs";
+ const char *scanner_start = "/NextDocument";
+ char scan_cmd[PATH_MAX] = { 0 };
+ int i = 0;
+ long answer = 0;
+
+ if (name == NULL || result == NULL)
+ return;
+CURL_CALL:
+ 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, "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);
+ }
+ if (curl_easy_perform(curl_handle) == CURLE_OK) {
+ curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &answer);
+ if (i < 3 && answer == 503) {
+ curl_easy_cleanup(curl_handle);
+ i++;
+ goto CURL_CALL;
+ }
+ }
+ curl_easy_cleanup(curl_handle);
+ }
+}