]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
move wakeup call to handler
authorBastian Dehn <hhaalo@arcor.de>
Mon, 29 Jan 2024 18:50:51 +0000 (19:50 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 29 Jan 2024 18:50:51 +0000 (19:50 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_handler.c

index 3506cd12c971c33b30b46fe1dc98ca11807c81f2..a14edeb362c4940eace3dba04299a62ef43c8d66 100644 (file)
@@ -1,6 +1,5 @@
 #include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <curl/curl.h>
 #include "kds_s2000w_client.h"
 
@@ -67,12 +66,6 @@ int kds_s2000w_client_open_session(const char* username, response* response)
        CURLcode result = curl_easy_perform(curl);
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response->code);
 
-       if (response->code == 408) {
-               sleep(1);
-               CURLcode result = curl_easy_perform(curl);
-               curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response->code);
-       }
-
        curl_url_cleanup(url_handler);
        url_handler = NULL;
        curl_free(url);
index 4115a784b65c9ca564c6109821668947d19b4d7a..835e5c8575350b9fa1c9e13e6534ee971c79fdb2 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
+#include <unistd.h>
 #include <curl/curl.h>
 #include <json-c/json.h>
 #include "kds_s2000w_handler.h"
@@ -74,20 +75,33 @@ current_state* kds_s2000w_handler_open()
        resp = kds_s2000w_client_response_init();
        int result = kds_s2000w_client_open_session("hhaalo", resp);
 
-       if (result != 0 || resp->code == 404)
+       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("hhaalo", resp);
+       }
+
+       if (result != 0 || resp->code == 404) {
+               kds_s2000w_client_response_free(resp);
+               resp = NULL;
                return state;
+       }
 
-       if (resp->code == 423)
+       if (resp->code == 423) {
+               kds_s2000w_client_response_free(resp);
+               resp = NULL;
                state->state = BUSY;
+       }
 
-       json_object* resObj = NULL;
        if (resp->code == 200) {
                resObj = json_tokener_parse(resp->data);
-               json_object* valueObj = NULL;
-               json_object_object_get_ex(resObj, "SessionId", &valueObj);
-               state->sessionid = json_object_get_int64(valueObj);
-               valueObj = NULL;
+               json_object* value_object = NULL;
+               json_object_object_get_ex(resObj, "SessionId", &value_object);
+               state->sessionid = json_object_get_int64(value_object);
                state->state = OPENED;
+               value_object = NULL;
        }
 
        json_object_put(resObj);