]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
refactor load options method
authorBastian Dehn <hhaalo@arcor.de>
Sun, 28 Jan 2024 20:49:49 +0000 (21:49 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 28 Jan 2024 21:00:03 +0000 (22:00 +0100)
src/kds_s2000w_handler.c

index f21bf002741ffcbc8b9dc39529bb2134d748eba6..c59962bbe87e100d83d069f82287fa0f861758f9 100644 (file)
@@ -38,6 +38,28 @@ void _write_int_value_to_json(json_object* value_object, void* value)
        json_object_set_int(value_object, *int_value_ptr);
 }
 
+void _load_options()
+{
+       json_object_put(resObj);
+       resObj = NULL;
+
+       resp = kds_s2000w_client_response_init();
+       int result = kds_s2000w_client_get_option(state->sessionid, resp);
+       resObj = json_tokener_parse(resp->data);
+       config = json_object_object_get(resObj, "Configuration");
+
+       if (result != 0 || resp->code == 404) {
+               kds_s2000w_client_response_free(resp);
+               resp = NULL;
+               json_object_put(resObj);
+               resObj = NULL;
+               return;
+       }
+
+       kds_s2000w_client_response_free(resp);
+       resp = NULL;
+}
+
 current_state* kds_s2000w_handler_open()
 {
        state = malloc(sizeof(current_state));
@@ -102,23 +124,9 @@ void kds_s2000w_handler_get_option(int option, void* value)
        json_object* value_object = NULL;
        switch(option) {
                case 0:
-                       resp = kds_s2000w_client_response_init();
-                       int result = kds_s2000w_client_get_option(state->sessionid, resp);
-                       resObj = json_tokener_parse(resp->data);
-                       config = json_object_object_get(resObj, "Configuration");
-
-                       if (result != 0 || resp->code == 404) {
-                               kds_s2000w_client_response_free(resp);
-                               resp = NULL;
-                               json_object_put(resObj);
-                               resObj = NULL;
-                               return;
-                       }
-
+                       _load_options();
                        int* int_value_ptr = (int*) value;
                        *int_value_ptr = json_object_object_length(config) + 3;
-                       kds_s2000w_client_response_free(resp);
-                       resp = NULL;
                        break;
                case 2:
                        value_object = json_object_object_get(config, "DPI");
@@ -330,7 +338,10 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info)
 
                        resp = NULL;
                        json_object_put(capabilities);
+                       capabilities = NULL;
                        *info = RELOAD_OPTIONS;
+                       _load_options();
+                       return;
                        break;
                default:
                        break;