]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change handler load config and set parameters
authorBastian Dehn <hhaalo@arcor.de>
Sun, 2 Mar 2025 19:30:26 +0000 (20:30 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 2 Mar 2025 19:30:26 +0000 (20:30 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_client.h
src/kds_s2000w_handler.c

index 79dd71aa143707618b70a7da1a50f4a2514f238a..13ef1714bc56a238f77f0a3067eea7bef8225cff 100644 (file)
@@ -1,10 +1,7 @@
-#include <stdbool.h>
 #include <string.h>
 #include <stdlib.h>
 #include <curl/curl.h>
-#include "config.h"
 #include "kds_s2000w_client.h"
-#include "kds_s2000w_config.h"
 #include "kds_s2000w_heartbeat.h"
 #include "kds_s2000w_debug.h"
 
@@ -90,28 +87,6 @@ void kds_s2000w_client_init()
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_client_init");
 
-       char* config_stream = kds_s2000w_config_read(CONFIG_FILE);
-       program_config* config = kds_s2000w_config_load(config_stream);
-
-       heartbeat = config->heartbeat;
-
-       size_t str_len = strlen(config->scanner_url) + 1;
-       scanner_url = malloc(sizeof(char) * str_len);
-       memset(scanner_url, 0, str_len);
-       strcpy(scanner_url, config->scanner_url);
-
-       str_len = strlen(config->username) + 1;
-       username = malloc(sizeof(char) * str_len);
-       memset(username, 0, str_len);
-       strcpy(username, config->username);
-
-       kds_s2000w_debug_set_default_log_level(config->log_level);
-
-       free(config_stream);
-       config_stream = NULL;
-       kds_s2000w_config_free(config);
-       config = NULL;
-
        curl_global_init(CURL_GLOBAL_ALL);
        curl = curl_easy_init();
        errbuf = malloc(CURL_ERROR_SIZE);
@@ -122,11 +97,6 @@ void kds_s2000w_client_free()
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_client_free");
 
-       // sanei use strdup it must be free static variable
-       char* config_dir = sanei_config_get_paths();
-       free(config_dir);
-       config_dir = NULL;
-
        free(scanner_url);
        scanner_url = NULL;
        free(username);
@@ -163,6 +133,40 @@ void kds_s2000w_client_response_free(response* resp)
        resp = NULL;
 }
 
+void kds_s2000w_client_set_scanner_url(const char* url)
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_client_set_scanner_url");
+
+       size_t str_len = strlen(url) + 1;
+       scanner_url = malloc(sizeof(char) * str_len);
+       memset(scanner_url, 0, str_len);
+       strcpy(scanner_url, url);
+}
+
+void kds_s2000w_client_set_username(const char* name)
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_client_set_username");
+
+       size_t str_len = strlen(name) + 1;
+       username = malloc(sizeof(char) * str_len);
+       memset(username, 0, str_len);
+       strcpy(username, name);
+}
+
+void kds_s2000w_client_set_ssl_verify(bool ssl)
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_client_set_ssl_verify");
+
+       ssl_verify = ssl;
+}
+
+void Kds_s2000w_client_set_heartbeat(uint8_t seconds)
+{
+       kds_s2000w_debug_printf(ALL, "Kds_s2000w_client_set_heartbeat");
+
+       heartbeat = seconds;
+}
+
 uint8_t kds_s2000w_client_open_session(response* resp)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_client_open_session");
index 29e6432c1771ffdfe61076891276f4f9f859d72c..679c1c5d70f521b0a83c957b7299799e86c19a8b 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef KDS_S2000W_CLIENT_H
 #define KDS_S2000W_CLIENT_H
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 
@@ -15,6 +16,11 @@ void kds_s2000w_client_free();
 response* kds_s2000w_client_response_init();
 void kds_s2000w_client_response_free(response* resp);
 
+void kds_s2000w_client_set_scanner_url(const char* url);
+void kds_s2000w_client_set_username(const char* name);
+void kds_s2000w_client_set_ssl_verify(bool ssl);
+void Kds_s2000w_client_set_heartbeat(uint8_t seconds);
+
 uint8_t kds_s2000w_client_open_session(response* resp);
 void kds_s2000w_client_close_session(int64_t sessionid);
 
index a367b151ab7b7b49d4266204c11b373385cab0fc..4834e3bc0ff4595aeba6d0b53dcfb3a887a1a36a 100644 (file)
@@ -1,6 +1,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <math.h>
+#include "config.h"
+#include "kds_s2000w_config.h"
 #include "kds_s2000w_handler.h"
 #include "kds_s2000w_handler_opts.h"
 #include "kds_s2000w_client.h"
@@ -33,6 +35,23 @@ uint32_t _kds_s2000w_handler_find_first_data_byte(imagedata* image)
        return byte_count;
 }
 
+void _kds_s2000w_handler_load_config()
+{
+       char* config_stream = kds_s2000w_config_read(CONFIG_FILE);
+       program_config* config = kds_s2000w_config_load(config_stream);
+
+       kds_s2000w_client_set_scanner_url(config->scanner_url);
+       kds_s2000w_client_set_username(config->username);
+       Kds_s2000w_client_set_heartbeat(config->heartbeat);
+       kds_s2000w_client_set_ssl_verify(config->ssl_verify);
+       kds_s2000w_debug_set_default_log_level(config->log_level);
+
+       free(config_stream);
+       config_stream = NULL;
+       kds_s2000w_config_free(config);
+       config = NULL;
+}
+
 handler* kds_s2000w_handler_init()
 {
        kds_s2000w_debug_printf(ALL, "init handler");
@@ -66,6 +85,11 @@ void kds_s2000w_handler_free(handler* h)
        if (h == NULL)
                return;
 
+       // sanei use strdup it must be free static variable
+       char* config_dir = sanei_config_get_paths();
+       free(config_dir);
+       config_dir = NULL;
+
        json_object_put(h->current_scanner_config);
        h->current_scanner_config = NULL;
        free(h->current_scan_status);
@@ -109,6 +133,7 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        handler* h = kds_s2000w_handler_init();
        *handle = h;
 
+       _kds_s2000w_handler_load_config();
        kds_s2000w_client_init();
 
        // status code 408 waking up repeat open session