]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
read option numbers
authorBastian Dehn <hhaalo@arcor.de>
Sun, 21 Jan 2024 16:50:59 +0000 (17:50 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 21 Jan 2024 16:50:59 +0000 (17:50 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_net.c

index dfe5183fa5179c333d2cbfa5c8daec53451dbbd9..a7dceb85d54eebbedd2432bd03252cc84a67d923 100644 (file)
@@ -29,11 +29,11 @@ size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
        return fullsize;
 }
 
-void* kds_s2000w_handler_get_option(int option)
+void kds_s2000w_handler_get_option(int option, void* value)
 {
        CURL *curl = curl_easy_init();
        if(!curl)
-               return NULL;
+               return;
 
        response resp = {0};
        CURLU* url_handler = curl_url();
@@ -52,14 +52,18 @@ void* kds_s2000w_handler_get_option(int option)
        CURLcode result = curl_easy_perform(curl);
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp.code);
 
-       printf("%s", resp.data);
+       json_object* resObj = json_tokener_parse(resp.data);
+       json_object* config = json_object_object_get(resObj, "Configuration");
+       int* num_options = (int*) value;
+       num_options = malloc(sizeof(int));
+       *num_options = 0;
+       *num_options = json_object_object_length(config);
 
        curl_url_cleanup(url_handler);
        url_handler = NULL;
        curl_free(url);
        url = NULL;
        free(resp.data);
-       return NULL;
 }
 
 void kds_s2000w_handler_set_option(int option, void* value)
index 97532199010fa8050b940682dbe81fbb84af226f..bed32eaeb4a2d376cabff02d904751909057e710 100644 (file)
@@ -7,7 +7,7 @@ typedef enum {
 
 device_state kds_s2000w_handler_open();
 void kds_s2000w_handler_close();
-void* kds_s2000w_handler_get_option(int option);
+void kds_s2000w_handler_get_option(int option, void* value);
 void kds_s2000w_handler_set_option(int option, void* value);
 void kds_s2000w_handler_set_option_auto(int option);
 #endif
\ No newline at end of file
index 4597578d04617d1d225e36638a9183577ae73098..9810eec92f7b3109eb1bb4fea9153942d64ce768 100644 (file)
@@ -91,7 +91,7 @@ SANE_Status _sane_kds_s2000w_net_control_option(SANE_Handle handle,
        printf("kds_s2000w_net control option\n");
 
        if (action == SANE_ACTION_GET_VALUE)
-               value = kds_s2000w_handler_get_option(option);
+               kds_s2000w_handler_get_option(option, value);
 
        if (action == SANE_ACTION_SET_VALUE)
                kds_s2000w_handler_set_option(option, value);