From: Bastian Dehn Date: Sun, 29 Dec 2024 09:36:38 +0000 (+0100) Subject: change init and close one time X-Git-Tag: v1.0.18^2~2 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=39975496d6fa407e1bc69a5b523f798160fc8b52;p=sane-kds-s2000w-net.git change init and close one time --- diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index 09ecf30..8de9b28 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -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 diff --git a/src/kds_s2000w_client.h b/src/kds_s2000w_client.h index b79bb8a..f2572a9 100644 --- a/src/kds_s2000w_client.h +++ b/src/kds_s2000w_client.h @@ -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); diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 7088e16..f436865 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -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; diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index c96edd5..7c5dac9 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -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);