]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add load option from session
authorBastian Dehn <hhaalo@arcor.de>
Fri, 26 Jan 2024 16:22:23 +0000 (17:22 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 26 Jan 2024 16:22:23 +0000 (17:22 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_client.h
src/kds_s2000w_handler.c
src/kds_s2000w_net.c

index 93d7a76788751e33e6f8554e30a12826ba578f7c..36f926a528b6a0921d28769ac23e5d20b7b52a2f 100644 (file)
@@ -96,32 +96,6 @@ void kds_s2000w_client_close_session(int64_t sessionid)
        curl = NULL;
 }
 
-int kds_s2000w_client_get_all_options(response* response)
-{
-       CURL *curl = curl_easy_init();
-       if(!curl)
-               return CURLE_FAILED_INIT;
-
-       CURLU* url_handler = curl_url();
-       curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/scanner/capabilities", 0);
-       char* url = NULL;
-       curl_url_get(url_handler, CURLUPART_URL, &url, 0);
-
-       curl_easy_setopt(curl, CURLOPT_URL, url);
-       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
-       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _kds_s2000w_client_callback);
-       curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) response);
-       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);
-       url = NULL;
-
-       return result;
-}
-
 int kds_s2000w_client_get_option(int64_t sessionid, response* response)
 {
        CURL *curl = curl_easy_init();
index 316889c2d75a2d4e65aaa59f10736749179ebe3c..ca0b123f73ecf76f476e0cafde1574a994ad40f9 100644 (file)
@@ -9,6 +9,5 @@ response* kds_s2000w_client_response_init();
 void kds_s2000w_client_response_free(response* response);
 int kds_s2000w_client_open_session(const char* username, response* response);
 void kds_s2000w_client_close_session(int64_t sessionid);
-int kds_s2000w_client_get_all_options(response* response);
 int kds_s2000w_client_get_option(int64_t sessionid, response* response);
 #endif
\ No newline at end of file
index 1fa74828dd8af2839fc8b1c3d98099519b2b6708..6aaaaf64d7e2ea55e7348f87bd469af848be3083 100644 (file)
@@ -7,22 +7,8 @@
 #include "kds_s2000w_handler.h"
 #include "kds_s2000w_client.h"
 
-json_object* _all_options = NULL;
 current_state* state;
 
-void _get_all_options()
-{
-       response* resp = kds_s2000w_client_response_init();
-       int result = kds_s2000w_client_get_all_options(resp);
-
-       if (result != 0 || resp->code == 404)
-               return;
-
-       _all_options = json_tokener_parse(resp->data);
-       kds_s2000w_client_response_free(resp);
-       resp = NULL;
-}
-
 current_state* kds_s2000w_handler_open()
 {
        state = malloc(sizeof(current_state));
@@ -68,14 +54,8 @@ void kds_s2000w_handler_close()
        if (state == NULL || state->sessionid == 0)
                return;
 
-       CURL *curl = curl_easy_init();
-       if(!curl)
-               return;
-
        kds_s2000w_client_close_session(state->sessionid);
        state->sessionid = 0;
-       json_object_put(_all_options);
-       _all_options = NULL;
        free(state);
        state = NULL;
 }
@@ -87,28 +67,32 @@ current_state* kds_s2000w_handler_current_state()
 
 void kds_s2000w_handler_get_option(int option, void* value)
 {
-       if (option == 0)
-               _get_all_options();
+       response* resp = kds_s2000w_client_response_init();
+       int result = kds_s2000w_client_get_option(state->sessionid, resp);
+       json_object* resObj = json_tokener_parse(resp->data);
+       json_object* config = json_object_object_get(resObj, "Configuration");
 
-       if (_all_options == NULL)
+       if (result != 0 || resp->code == 404)
                return;
 
+       json_object* dpi_value_object = NULL;
        switch(option) {
+               case 0:
+                       int* ignore_value = (int*) value;
+                       *ignore_value = 0;
+                       break;
                case 1:
+                       dpi_value_object = json_object_object_get(config, "DPI");
+                       int dpi_value = json_object_get_int(dpi_value_object);
                        int* int_value = (int*) value;
-                       *int_value = 300;
+                       *int_value = dpi_value;
                        break;
                default:
-                       json_object* config = json_object_object_get(_all_options, "Configuration");
-                       int* num_options = (int*) value;
-                       *num_options = 0;
-                       *num_options = json_object_object_length(config);
-                       *num_options++;
-                       state->size = sizeof(int);
-                       state->length = 1;
-                       state->type = INT;
                        break;
        }
+
+       kds_s2000w_client_response_free(resp);
+       json_object_put(resObj);
 }
 
 void kds_s2000w_handler_set_option(int option, void* value)
index 0ce53272388ecf5893a7d4c90af5d38dcddf9061..5ba9ea6a071cd146ff9b89833e09d48858047f2d 100644 (file)
@@ -85,27 +85,8 @@ const SANE_Option_Descriptor* _sane_kds_s2000w_net_get_option_descriptor(
                        optionDescripor->constraint_type = SANE_CONSTRAINT_NONE;
                        optionDescripor->constraint.string_list = NULL;
                        break;
-               case 0:
-                       optionDescripor->name = "";
-                       optionDescripor->title = "";
-                       optionDescripor->desc = "";
-                       optionDescripor->type = SANE_TYPE_INT;
-                       optionDescripor->unit = SANE_UNIT_NONE;
-                       optionDescripor->size = sizeof(SANE_Int);
-                       optionDescripor->cap = 0;
-                       optionDescripor->constraint_type = SANE_CONSTRAINT_NONE;
-                       optionDescripor->constraint.string_list = NULL;
-                       break;
                default:
-                       optionDescripor->name = "";
-                       optionDescripor->title = "count of options";
-                       optionDescripor->desc = "count of options";
-                       optionDescripor->type = state->type;
-                       optionDescripor->unit = SANE_UNIT_NONE;
-                       optionDescripor->size = state->size;
-                       optionDescripor->cap = 0;
-                       optionDescripor->constraint_type = SANE_CONSTRAINT_NONE;
-                       optionDescripor->constraint.string_list = NULL;
+                       optionDescripor = NULL;
                        break;
        }