]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change init and close one time
authorBastian Dehn <hhaalo@arcor.de>
Sun, 29 Dec 2024 09:36:38 +0000 (10:36 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 29 Dec 2024 09:36:38 +0000 (10:36 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_client.h
src/kds_s2000w_handler.c
tests/kds_s2000w_net_tests.c

index 09ecf302552bc9d265117ed3cebdb8363b3b44fe..8de9b28d1bb47dff47dd552e3f9b1926b5275e4c 100644 (file)
@@ -7,6 +7,8 @@
 #include "kds_s2000w_client.h"
 #include "kds_s2000w_debug.h"
 
+CURL* curl = NULL;
+
 void _kds_s2000w_client_read_error_status(CURL* curl, response* resp)
 {
        struct curl_header* header = NULL;
@@ -55,6 +57,21 @@ response* kds_s2000w_client_response_init()
        return resp;
 }
 
+void kds_s2000w_client_init()
+{
+       debug_printf(ALL, "kds_s2000w_client_init");
+
+       curl = curl_easy_init();
+}
+
+void kds_s2000w_client_free()
+{
+       debug_printf(ALL, "kds_s2000w_client_free");
+
+       curl_easy_cleanup(curl);
+       curl = NULL;
+}
+
 void kds_s2000w_client_response_free(response* response)
 {
        debug_printf(ALL, "kds_s2000w_client_response_free");
@@ -75,6 +92,7 @@ int kds_s2000w_client_open_session(response* response)
        debug_printf(ALL, "kds_s2000w_client_open_session");
 
        _kds_s2000w_client_load_config();
+       curl_easy_reset(curl);
 
        char* url = NULL;
        char body[50] = {0};
@@ -113,8 +131,6 @@ int kds_s2000w_client_open_session(response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -130,9 +146,7 @@ void kds_s2000w_client_close_session(int64_t sessionid)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -158,8 +172,6 @@ void kds_s2000w_client_close_session(int64_t sessionid)
        url = NULL;
        curl_slist_free_all(headers);
        headers = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
 }
 
 int kds_s2000w_client_status_session(int64_t sessionid, response* response)
@@ -172,9 +184,7 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* response)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -208,8 +218,6 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -226,9 +234,7 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* response)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -262,8 +268,6 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -279,9 +283,7 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -316,8 +318,6 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -335,9 +335,7 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        char url_path[30];
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        sprintf(url_path, "api/session/image/%i", img_number);
@@ -371,8 +369,6 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -390,9 +386,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        char url_path[30];
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        sprintf(url_path, "api/session/image/%i", img_number);
@@ -426,8 +420,6 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -442,9 +434,7 @@ int kds_s2000w_client_get_capabilities(response* response)
 
        char* url = NULL;
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -474,8 +464,6 @@ int kds_s2000w_client_get_capabilities(response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -491,9 +479,7 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -527,8 +513,6 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
        free(buffer);
        buffer = NULL;
        free(sizeloc);
@@ -545,9 +529,7 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* response)
        struct curl_slist* headers = NULL;
        char header_str[80];
 
-       CURL* curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
+       curl_easy_reset(curl);
 
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, p_config.scanner_url, 0);
@@ -574,8 +556,6 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* response)
        url_handler = NULL;
        curl_free(url);
        url = NULL;
-       curl_easy_cleanup(curl);
-       curl = NULL;
 
        return result;
 }
\ No newline at end of file
index b79bb8afa42b09685a1a7f2f01ca251e96c34e0f..f2572a9ad16cf2e63b4783bf0177acd8a08b1c48 100644 (file)
@@ -10,6 +10,8 @@ typedef struct {
 
 response* kds_s2000w_client_response_init();
 void kds_s2000w_client_response_free(response* response);
+void kds_s2000w_client_init();
+void kds_s2000w_client_free();
 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);
index 7088e1644fc78ad4d75f883904916f866fdcb586..f4368653eceb57ea11c46c5706adde0116a4e1d6 100644 (file)
@@ -269,6 +269,8 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        handler* h = init_handler();
        *handle = h;
 
+       kds_s2000w_client_init();
+
        response* resp = kds_s2000w_client_response_init();
        int result = kds_s2000w_client_open_session(resp);
 
@@ -301,7 +303,6 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
                return;
        }
 
-
        h->image->size = 0;
        h->image->data = NULL;
 
@@ -330,6 +331,7 @@ void kds_s2000w_handler_close(handler* h)
                return;
 
        kds_s2000w_client_close_session(h->sessionid);
+       kds_s2000w_client_free();
        h->sessionid = 0;
        free_handler(h);
        h = NULL;
index c96edd5db451f4eee14303e76dbe2d72a94332dd..7c5dac945da52c36921b187a4681bafb04b38d66 100644 (file)
@@ -520,6 +520,7 @@ void sane_kds_s2000w_net_open()
        assert_int_equal(status, SANE_STATUS_GOOD);
 
        kds_s2000w_option_descriptor_free_option_descriptors();
+       kds_s2000w_client_free();
        free_handler(h);
        h = NULL;
        kds_s2000w_client_response_free(resp);
@@ -545,6 +546,7 @@ void sane_kds_s2000w_net_open_busy_device()
        assert_int_equal(status, SANE_STATUS_DEVICE_BUSY);
 
        kds_s2000w_option_descriptor_free_option_descriptors();
+       kds_s2000w_client_free();
        free_handler(h);
        h = NULL;
        kds_s2000w_client_response_free(resp);