]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change usernmae and url from config file
authorBastian Dehn <hhaalo@arcor.de>
Sat, 2 Mar 2024 21:39:01 +0000 (22:39 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 2 Mar 2024 21:39:01 +0000 (22:39 +0100)
src/CMakeLists.txt
src/kds_s2000w_client.c
src/kds_s2000w_client.h
src/kds_s2000w_handler.c
src/kds_s2000w_net.conf

index 5e74deae105e343b14c34e72e274b1b7ad8653a0..ef3861515ddbc72bc468824d124ed0498587ccea 100644 (file)
@@ -40,5 +40,7 @@ target_link_libraries("sane-kds_s2000w_net"
 install(TARGETS "sane-kds_s2000w_net"
        DESTINATION ${SANE_LIBRARY_BACKEND_PATH})
 
-install(FILES "kds_s2000w_net.conf"
-       DESTINATION ${SANE_CONFIG_PATH})
\ No newline at end of file
+if (NOT EXISTS ${SANE_CONFIG_PATH}/kds_s2000w_net.conf)
+       install(FILES "kds_s2000w_net.conf"
+               DESTINATION ${SANE_CONFIG_PATH})
+endif()
\ No newline at end of file
index 5624219fa1168cfd2f95531c3116e6c41e82cf8f..900f63cee45b0c344888caa185d40d8de3ec5be7 100644 (file)
@@ -3,6 +3,17 @@
 #include <curl/curl.h>
 #include "kds_s2000w_client.h"
 #include "kds_s2000w_debug.h"
+#include "kds_s2000w_config.h"
+
+program_config p_config;
+
+void _kds_s2000w_client_load_config()
+{
+       const char* config_file = "/etc/sane.d/kds_s2000w_net.conf";
+       char* config_stream = NULL;
+       read_config_file(config_file, &config_stream);
+       load_config(&p_config, config_stream);
+}
 
 size_t _kds_s2000w_client_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
 {
@@ -47,20 +58,23 @@ void kds_s2000w_client_response_free(response* response)
        response = NULL;
 }
 
-int kds_s2000w_client_open_session(const char* username, response* response)
+int kds_s2000w_client_open_session(response* response)
 {
        debug_printf(ALL, "kds_s2000w_client_open_session");
+       _kds_s2000w_client_load_config();
+
        CURL *curl = curl_easy_init();
        if(!curl)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
        char body[50] = {0};
-       sprintf(body, "{\"OCPUserName\": \"%s\"}", username);
+       sprintf(body, "{\"OCPUserName\": \"%s\"}", p_config.username);
 
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
@@ -110,7 +124,8 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session/status", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session/status", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
@@ -144,7 +159,8 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session/startscan", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session/startscan", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
@@ -179,7 +195,8 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session/stopscan", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session/stopscan", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
@@ -216,7 +233,7 @@ int kds_s2000w_client_get_metadata(int64_t sessionid, int img_number, response*
        CURLU* url_handler = curl_url();
        char url_path[30];
        sprintf(url_path, "api/session/metadata/%i", img_number);
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
        curl_url_set(url_handler, CURLUPART_PATH, url_path, 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
@@ -253,7 +270,7 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        CURLU* url_handler = curl_url();
        char url_path[30];
        sprintf(url_path, "api/session/image/%i", img_number);
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
        curl_url_set(url_handler, CURLUPART_PATH, url_path, 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
@@ -290,7 +307,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        CURLU* url_handler = curl_url();
        char url_path[30];
        sprintf(url_path, "api/session/image/%i", img_number);
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
        curl_url_set(url_handler, CURLUPART_PATH, url_path, 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
@@ -325,7 +342,8 @@ int kds_s2000w_client_get_capabilities(response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/scanner/capabilities?V2", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/scanner/capabilities?V2", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
@@ -354,7 +372,8 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session/configuration", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session/configuration", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
@@ -388,7 +407,8 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* response)
                return CURLE_FAILED_INIT;
 
        CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session/configuration", 0);
+       curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, "/api/session/configuration", 0);
        char* url = NULL;
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
 
index 572e5c846bb4c6ce59a3b7b87027998c916a10c7..d7e40c8168c7dfaad94c3d713aa5f1751c8f081d 100644 (file)
@@ -8,7 +8,7 @@ typedef struct {
 
 response* kds_s2000w_client_response_init();
 void kds_s2000w_client_response_free(response* response);
-int kds_s2000w_client_open_session(const char* username, response* response);
+int kds_s2000w_client_open_session(response* response);
 void kds_s2000w_client_close_session(int64_t sessionid);
 int kds_s2000w_client_status_session(int64_t sessionid, response* response);
 int kds_s2000w_client_start_scan(int64_t sessionid, response* response);
index b55ad3b657e17aad0a3512483999656c9e99dea9..72b935f1f85694a93eb4169db31086921fc1eb30 100644 (file)
@@ -235,7 +235,7 @@ void kds_s2000w_handler_recreate_session(handler* h)
 {
        kds_s2000w_client_close_session(h->sessionid);
        response* resp = kds_s2000w_client_response_init();
-       kds_s2000w_client_open_session("hhaalo", resp);
+       kds_s2000w_client_open_session(resp);
 
        if (resp->code == 200) {
                json_object* resp_config = json_tokener_parse(resp->data);
@@ -268,14 +268,14 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        pnm_image.data = NULL;
 
        response* resp = kds_s2000w_client_response_init();
-       int result = kds_s2000w_client_open_session("hhaalo", resp);
+       int result = kds_s2000w_client_open_session(resp);
 
        if (resp->code == 408) {
                kds_s2000w_client_response_free(resp);
                resp = NULL;
                sleep(1);
                resp = kds_s2000w_client_response_init();
-               result = kds_s2000w_client_open_session("hhaalo", resp);
+               result = kds_s2000w_client_open_session(resp);
        }
 
        if (result != 0 || resp->code == 404) {
index 698f116301c2e49b221e6ab0de53ed4cd7c34501..ac44887cad7393cdcaca5a194b415957e90e93a7 100644 (file)
@@ -1,2 +1,2 @@
 scanner_url = http://scanner.example.com
-username = muster
+username = muster
\ No newline at end of file