]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add curl error buffer
authorBastian Dehn <hhaalo@arcor.de>
Wed, 15 Jan 2025 21:18:47 +0000 (22:18 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 15 Jan 2025 21:18:47 +0000 (22:18 +0100)
src/kds_s2000w_client.c

index bb5bfe55c41deb630560171ac4a0cad6aa633c57..d10c10e41d7621427d24d98dd645f843a4432477 100644 (file)
@@ -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);