From: Bastian Dehn Date: Sat, 4 Jan 2025 08:48:22 +0000 (+0100) Subject: change to print error into client X-Git-Tag: v1.0.23^2~11 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=2254013f3194784d71cee4c78f711396596f4bba;p=sane-kds-s2000w-net.git change to print error into client --- diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index d3a8b46..0a46372 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "config.h" #include "kds_s2000w_config.h" @@ -25,7 +26,7 @@ CURL* curl = NULL; program_config* config = NULL; -void _kds_s2000w_client_read_error_status(CURL* curl, response* resp) +void _kds_s2000w_client_print_error_status(CURL* curl) { struct curl_header* header = NULL; curl_easy_header(curl, X_STATUS_HEADER, 0, CURLH_HEADER, -1, &header); @@ -33,10 +34,7 @@ void _kds_s2000w_client_read_error_status(CURL* curl, response* resp) if (header == NULL) return; - size_t size = strlen(header->value) + 1; - resp->error_status = realloc(resp->error_status, size); - memcpy(resp->error_status, header->value, size); - resp->error_size = size; + fprintf(stderr, "%s\n", header->value); } void _kds_s2000w_client_stream_to_response(char* mem, response* resp, size_t* size) @@ -71,11 +69,9 @@ response* kds_s2000w_client_response_init() response* resp = malloc(sizeof(response)); resp->data = malloc(sizeof(char)); - resp->error_status = malloc(sizeof(char)); resp->data[0] = '\0'; resp->size = 0; resp->code = 0L; - resp->error_size = 0; return resp; } @@ -87,8 +83,6 @@ void kds_s2000w_client_response_free(response* resp) if (resp == NULL) return; - free(resp->error_status); - resp->error_status = NULL; free(resp->data); resp->data = NULL; free(resp); @@ -147,7 +141,7 @@ int kds_s2000w_client_open_session(response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -244,7 +238,7 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -300,7 +294,7 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -356,7 +350,7 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -414,7 +408,7 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -474,7 +468,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -525,7 +519,7 @@ int kds_s2000w_client_get_capabilities(response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -578,7 +572,7 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); fclose(stream); @@ -630,7 +624,7 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* resp) CURLcode result = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->code); - _kds_s2000w_client_read_error_status(curl, resp); + _kds_s2000w_client_print_error_status(curl); _kds_s2000w_client_print_error_result(result); curl_url_cleanup(url_handler); diff --git a/src/kds_s2000w_client.h b/src/kds_s2000w_client.h index abd7bd0..5aa6af4 100644 --- a/src/kds_s2000w_client.h +++ b/src/kds_s2000w_client.h @@ -4,8 +4,6 @@ typedef struct { char* data; size_t size; long code; - char* error_status; - size_t error_size; } response; response* kds_s2000w_client_response_init(); diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 60e4241..ad6fe6f 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -178,10 +178,6 @@ void kds_s2000w_handler_delete_current_image(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_delete_image(h->sessionid, h->current_scan_status->current_image_number, resp); - - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); - h->current_scan_status->available_images--; kds_s2000w_client_response_free(resp); @@ -198,10 +194,6 @@ void kds_s2000w_handler_download_current_image(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_get_image(h->sessionid, h->current_scan_status->current_image_number, resp); - - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); - h->image->size = resp->size; h->image->data = malloc(sizeof(char) * resp->size); memcpy(h->image->data, resp->data, resp->size); @@ -220,9 +212,6 @@ void kds_s2000w_net_handler_get_current_scan_status(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_status_session(h->sessionid, resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); - debug_printf(DEBUG, resp->data); json_object* status_resp_obj = json_tokener_parse(resp->data); @@ -248,8 +237,6 @@ void kds_s2000w_handler_recreate_session(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_open_session(resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); if (resp->code != 200) { kds_s2000w_client_response_free(resp); @@ -278,8 +265,6 @@ void kds_s2000w_handler_recreate_session(handler* h) resp->data = realloc(resp->data, resp->size); resp->data = memcpy(resp->data, json_string, resp->size); kds_s2000w_client_set_option(h->sessionid, resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); kds_s2000w_client_response_free(resp); resp = NULL; @@ -300,17 +285,12 @@ void kds_s2000w_handler_open(const char* devicename, void** handle) response* resp = kds_s2000w_client_response_init(); int result = kds_s2000w_client_open_session(resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); - 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(resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); } if (result != 0 || resp->code == 404) { @@ -370,9 +350,6 @@ void kds_s2000w_handler_start_scan(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_start_scan(h->sessionid, resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); - kds_s2000w_client_response_free(resp); resp = NULL; } @@ -383,8 +360,6 @@ void kds_s2000w_handler_stop_scan(handler* h) response* resp = kds_s2000w_client_response_init(); kds_s2000w_client_stop_scan(h->sessionid, resp); - if (resp->error_size > 0) - fprintf(stderr, "%s\n", resp->error_status); kds_s2000w_client_response_free(resp); resp = NULL;