headers = NULL;
curl_easy_cleanup(curl);
curl = NULL;
+}
+
+int kds_s2000w_client_get_option(int64_t sessionid, 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/session", 0);
+ char query[75];
+ sprintf(query, "SessionId=%li", sessionid);
+ curl_url_set(url_handler, CURLUPART_QUERY, query, CURLU_APPENDQUERY | CURLU_URLENCODE);
+ 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, write_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;
}
\ No newline at end of file
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 session_id);
+void kds_s2000w_client_close_session(int64_t sessionid);
+int kds_s2000w_client_get_option(int64_t sessionid, response* response);
#endif
\ No newline at end of file
void kds_s2000w_handler_get_option(int option, void* value)
{
- CURL *curl = curl_easy_init();
- if(!curl)
- return;
-
if (option != 0)
return;
- response resp = {0};
- CURLU* url_handler = curl_url();
- curl_url_set(url_handler, CURLUPART_URL, "http://scanner.lan.hhaalo.de/api/session", 0);
- char query[75];
- sprintf(query, "SessionId=%li", _sessionid);
- curl_url_set(url_handler, CURLUPART_QUERY, query, CURLU_APPENDQUERY | CURLU_URLENCODE);
- 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, write_callback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) &resp);
- CURLcode result = curl_easy_perform(curl);
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp.code);
-
- if (result != CURLE_OK || resp.code == 404)
+ response* resp = kds_s2000w_client_response_init();
+ int result = kds_s2000w_client_get_option(_sessionid, resp);
+
+ if (result != 0 || resp->code == 404)
return;
- json_object* resObj = json_tokener_parse(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 = 0;
*num_options = json_object_object_length(config);
*num_options++;
- curl_url_cleanup(url_handler);
- url_handler = NULL;
- curl_free(url);
- url = NULL;
- free(resp.data);
+ kds_s2000w_client_response_free(resp);
}
void kds_s2000w_handler_set_option(int option, void* value)