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();
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
#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));
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;
}
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)
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;
}