]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change init null variables in handler top of methods
authorBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 19:08:48 +0000 (20:08 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 19:08:48 +0000 (20:08 +0100)
src/kds_s2000w_handler.c

index 3b17163c3694a82b2d30d70f0a4baa82b641bc6f..abb6dd9b242717a4c40a7d3453fcff04f25902e0 100644 (file)
@@ -17,7 +17,12 @@ blobdata pnm_image;
 void _get_current_metadata(handler* h)
 {
        debug_printf(ALL, "get_current_metadata");
-       response* resp = kds_s2000w_client_response_init();
+       json_object* metadataResp = NULL;
+       json_object* metadata = NULL;
+       json_object* mdata_value = NULL;
+       response* resp = NULL;
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_get_metadata(h->sessionid, h->current_scan_status->current_image_number, resp);
        if (resp->code != 200) {
                debug_printf_int(ERROR, "metadata response code", resp->code);
@@ -28,9 +33,6 @@ void _get_current_metadata(handler* h)
        }
 
        h->current_metadata->valid = 0;
-       json_object* metadataResp = NULL;
-       json_object* metadata = NULL;
-       json_object* mdata_value = NULL;
        h->current_metadata->channels = 1;
 
        metadataResp = json_tokener_parse(resp->data);
@@ -97,7 +99,9 @@ void _get_current_metadata(handler* h)
 void _delete_current_image(handler* h)
 {
        debug_printf(ALL, "delete_current_image");
-       response* resp = kds_s2000w_client_response_init();
+       response* resp = NULL;
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_delete_image(h->sessionid, h->current_scan_status->current_image_number, resp);
        if (resp->code != 200)
                debug_printf_int(ERROR, "delete current image response code", resp->code);
@@ -110,12 +114,15 @@ void _delete_current_image(handler* h)
 void _download_current_image(handler* h)
 {
        debug_printf(ALL, "download_current_image");
+       response* resp = NULL;
+
        if (image.size > 0) {
                free(image.data);
                image.data = NULL;
                image.size = 0;
        }
-       response* resp = kds_s2000w_client_response_init();
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_get_image(h->sessionid, h->current_scan_status->current_image_number, resp);
        if (resp->code != 200)
                debug_printf_int(ERROR, "download current image response code", resp->code);
@@ -134,8 +141,9 @@ void _get_current_scan_status(handler* h)
        json_object* status_resp_obj = NULL;
        json_object* status_obj = NULL;
        json_object* status_value_obj = NULL;
+       response* resp = NULL;
 
-       response* resp = kds_s2000w_client_response_init();
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_status_session(h->sessionid, resp);
        if (resp->code != 200)
                debug_printf_int(ERROR, "get current scan status response code", resp->code);
@@ -158,6 +166,7 @@ void _get_current_scan_status(handler* h)
 
 handler* init_handler()
 {
+       debug_printf(ALL, "init handler");
        handler* h = malloc(sizeof(handler));
        h->current_scan_status = malloc(sizeof(scan_status));
        h->current_metadata = malloc(sizeof(metadata));
@@ -191,6 +200,7 @@ handler* init_handler()
 
 void free_handler(handler* h)
 {
+       debug_printf(ALL, "free handler");
        free(h->current_scan_status);
        h->current_scan_status = NULL;
        free(h->current_metadata->image);
@@ -205,6 +215,7 @@ void free_handler(handler* h)
 
 void reset_handler(handler* h)
 {
+       debug_printf(ALL, "reset handler");
        free(h->current_metadata->image);
        h->current_metadata->image = NULL;
 
@@ -234,12 +245,15 @@ void reset_handler(handler* h)
 void kds_s2000w_handler_recreate_session(handler* h)
 {
        kds_s2000w_client_close_session(h->sessionid);
-       response* resp = kds_s2000w_client_response_init();
+       response* resp = NULL;
+       json_object* sessionJson = NULL;
+       json_object* value_object = NULL;
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_open_session(resp);
 
        if (resp->code == 200) {
-               json_object* sessionJson = json_tokener_parse(resp->data);
-               json_object* value_object = NULL;
+               sessionJson = json_tokener_parse(resp->data);
                json_object_object_get_ex(sessionJson, "SessionId", &value_object);
                h->sessionid = json_object_get_int64(value_object);
                h->state = OPENED;
@@ -249,8 +263,10 @@ void kds_s2000w_handler_recreate_session(handler* h)
                debug_printf_long(INFO, "SessionId", h->sessionid);
 
                // set old config parameters
+               kds_s2000w_client_response_free(resp);
+               resp = NULL;
                const char* json_string = json_object_to_json_string_ext(resp_config, JSON_C_TO_STRING_PLAIN);
-               response* resp = kds_s2000w_client_response_init();
+               resp = kds_s2000w_client_response_init();
                resp->size = sizeof(char) * strlen(json_string);
                resp->code = 0;
                resp->data = realloc(resp->data, resp->size);
@@ -258,9 +274,6 @@ void kds_s2000w_handler_recreate_session(handler* h)
                kds_s2000w_client_set_option(h->sessionid, resp);
                if (resp->code != 200)
                        debug_printf_int(ERROR, "set options response code", resp->code);
-
-               kds_s2000w_client_response_free(resp);
-               resp = NULL;
        }
 
        kds_s2000w_client_response_free(resp);
@@ -273,7 +286,10 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        if (strcmp(devicename, "kds_s2000w_net") != 0)
                return;
 
-       handler* h = init_handler();
+       handler* h = NULL;
+       response* resp = NULL;
+       json_object* value_object = NULL;
+       h = init_handler();
        *handle = h;
 
        image.size = 0;
@@ -281,7 +297,7 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        pnm_image.size = 0;
        pnm_image.data = NULL;
 
-       response* resp = kds_s2000w_client_response_init();
+       resp = kds_s2000w_client_response_init();
        int result = kds_s2000w_client_open_session(resp);
 
        if (resp->code == 408) {
@@ -306,7 +322,6 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
 
        if (resp->code == 200) {
                resp_config = json_tokener_parse(resp->data);
-               json_object* value_object = NULL;
                json_object_object_get_ex(resp_config, "SessionId", &value_object);
                h->sessionid = json_object_get_int64(value_object);
                h->state = OPENED;
@@ -340,7 +355,9 @@ void kds_s2000w_handler_close(handler* h)
 void kds_s2000w_handler_start_scan(handler* h)
 {
        debug_printf(ALL, "kds_s2000w_handler_start_scan");
-       response* resp = kds_s2000w_client_response_init();
+       response* resp = NULL;
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_start_scan(h->sessionid, resp);
        if (resp->code != 200)
                debug_printf_int(ERROR, "start scan response code", resp->code);
@@ -352,7 +369,9 @@ void kds_s2000w_handler_start_scan(handler* h)
 void kds_s2000w_handler_stop_scan(handler* h)
 {
        debug_printf(ALL, "kds_s2000w_handler_stop_scan");
-       response* resp = kds_s2000w_client_response_init();
+       response* resp = NULL;
+
+       resp = kds_s2000w_client_response_init();
        kds_s2000w_client_stop_scan(h->sessionid, resp);
        if (resp->code != 200)
                debug_printf_int(ERROR, "stop scan response code", resp->code);