]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
set old config for new session
authorBastian Dehn <hhaalo@arcor.de>
Tue, 5 Mar 2024 16:49:47 +0000 (17:49 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 5 Mar 2024 16:49:47 +0000 (17:49 +0100)
src/kds_s2000w_handler.c

index 72b935f1f85694a93eb4169db31086921fc1eb30..3b17163c3694a82b2d30d70f0a4baa82b641bc6f 100644 (file)
@@ -238,15 +238,29 @@ void kds_s2000w_handler_recreate_session(handler* h)
        kds_s2000w_client_open_session(resp);
 
        if (resp->code == 200) {
-               json_object* resp_config = json_tokener_parse(resp->data);
+               json_object* sessionJson = json_tokener_parse(resp->data);
                json_object* value_object = NULL;
-               json_object_object_get_ex(resp_config, "SessionId", &value_object);
+               json_object_object_get_ex(sessionJson, "SessionId", &value_object);
                h->sessionid = json_object_get_int64(value_object);
                h->state = OPENED;
                value_object = NULL;
-               json_object_put(resp_config);
-               resp_config = NULL;
+               json_object_put(sessionJson);
+               sessionJson = NULL;
                debug_printf_long(INFO, "SessionId", h->sessionid);
+
+               // set old config parameters
+               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->size = sizeof(char) * strlen(json_string);
+               resp->code = 0;
+               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->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);