From bd956b02d5384b8d5df22fece2b7b16bc33773ff Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Wed, 15 Jan 2025 22:18:47 +0100 Subject: [PATCH] add curl error buffer --- src/kds_s2000w_client.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index bb5bfe5..d10c10e 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -24,6 +24,7 @@ CURL* curl = NULL; program_config* config = NULL; +char errbuf[CURL_ERROR_SIZE]; void _kds_s2000w_client_print_error_status(CURL* curl) { @@ -41,6 +42,13 @@ void _kds_s2000w_client_print_error_result(CURLcode result) if (result == CURLE_OK) return; + size_t len = strlen(errbuf); + if (len > 0) { + debug_printf(ERROR, errbuf); + errbuf[0] = 0; + return; + } + debug_printf(ERROR, curl_easy_strerror(result)); } @@ -97,6 +105,7 @@ void kds_s2000w_client_init() config = load_config(config_stream); curl_global_init(CURL_GLOBAL_SSL); curl = curl_easy_init(); + errbuf[0] = 0; free(config_stream); config_stream = NULL; @@ -143,6 +152,7 @@ int kds_s2000w_client_open_session(response* resp) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -195,6 +205,7 @@ void kds_s2000w_client_close_session(int64_t sessionid) curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); _kds_s2000w_client_print_error_result(result); @@ -242,6 +253,7 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* resp) curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -300,6 +312,7 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* resp) curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -358,6 +371,7 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp) curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -418,6 +432,7 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -480,6 +495,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -533,6 +549,7 @@ int kds_s2000w_client_get_capabilities(response* resp) curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -588,6 +605,7 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* resp) curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); @@ -642,6 +660,7 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* resp) curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); _kds_s2000w_client_set_ssl_verification_off(curl); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); -- 2.39.5