]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change to print error into client
authorBastian Dehn <hhaalo@arcor.de>
Sat, 4 Jan 2025 08:48:22 +0000 (09:48 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 4 Jan 2025 08:48:22 +0000 (09:48 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_client.h
src/kds_s2000w_handler.c

index d3a8b46841dc6ec72a8902abe2862d0d5681fb1d..0a4637238cc0dbbdf9b4a15282db7f5e522d3374 100644 (file)
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <curl/curl.h>
 #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);
index abd7bd049f03a8cbacfa3e114e669baf2415507c..5aa6af40b7ad00662e500e2c4ffc4db28cc48d0f 100644 (file)
@@ -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();
index 60e4241bdf9712f05e6cb60b86e0cf6d7030be1c..ad6fe6f316cf39d660dc846ce506ee2e3cf62fb0 100644 (file)
@@ -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;