]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change client method order
authorBastian Dehn <hhaalo@arcor.de>
Sat, 25 Jan 2025 16:30:01 +0000 (17:30 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 25 Jan 2025 16:30:01 +0000 (17:30 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_client.h

index 396c3c1e5c9f830eaec95d83e4798c48643b90b2..316cfc8376115b9f18b8269dfa82c291edfc66e5 100644 (file)
@@ -71,31 +71,6 @@ void _kds_s2000w_client_set_ssl_verification_off(CURL* curl)
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
 }
 
-response* kds_s2000w_client_response_init()
-{
-       debug_printf(ALL, "kds_s2000w_client_response_init");
-
-       response* resp = malloc(sizeof(response));
-       resp->data = NULL;
-       resp->size = 0;
-       resp->code = 0L;
-
-       return resp;
-}
-
-void kds_s2000w_client_response_free(response* resp)
-{
-       debug_printf(ALL, "kds_s2000w_client_response_free");
-
-       if (resp == NULL)
-               return;
-
-       free(resp->data);
-       resp->data = NULL;
-       free(resp);
-       resp = NULL;
-}
-
 void kds_s2000w_client_init()
 {
        debug_printf(ALL, "kds_s2000w_client_init");
@@ -121,6 +96,31 @@ void kds_s2000w_client_free()
        curl_global_cleanup();
 }
 
+response* kds_s2000w_client_response_init()
+{
+       debug_printf(ALL, "kds_s2000w_client_response_init");
+
+       response* resp = malloc(sizeof(response));
+       resp->data = NULL;
+       resp->size = 0;
+       resp->code = 0L;
+
+       return resp;
+}
+
+void kds_s2000w_client_response_free(response* resp)
+{
+       debug_printf(ALL, "kds_s2000w_client_response_free");
+
+       if (resp == NULL)
+               return;
+
+       free(resp->data);
+       resp->data = NULL;
+       free(resp);
+       resp = NULL;
+}
+
 int kds_s2000w_client_open_session(response* resp)
 {
        debug_printf(ALL, "kds_s2000w_client_open_session");
@@ -220,27 +220,20 @@ void kds_s2000w_client_close_session(int64_t sessionid)
        header_str = NULL;
 }
 
-int kds_s2000w_client_status_session(int64_t sessionid, response* resp)
+int kds_s2000w_client_get_capabilities(response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_status_session");
-
-       join_thread();
-       wait_seconds(&config->heartbeat);
+       debug_printf(ALL, "kds_s2000w_client_get_capabilities");
 
        curl_easy_reset(curl);
 
        char* url = NULL;
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, config->scanner_url, 0);
-       curl_url_set(url_handler, CURLUPART_PATH, STATUS_PATH, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, CAPABILITIES_PATH, 0);
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
        struct curl_slist* headers = NULL;
-       char* header_str = malloc(sizeof(char) * MAX_STR_BUFFER_LENGTH);
-       memset(header_str, 0, MAX_STR_BUFFER_LENGTH);
-       sprintf(header_str, "SessionId: %li", sessionid);
-       headers = curl_slist_append(headers, header_str);
        headers = curl_slist_append(headers, CONTENT_TYPE_HEADER);
        headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
@@ -276,22 +269,23 @@ int kds_s2000w_client_status_session(int64_t sessionid, response* resp)
        mem = NULL;
        free(sizeloc);
        sizeloc = NULL;
-       free(header_str);
-       header_str = NULL;
 
        return result;
 }
 
-int kds_s2000w_client_start_scan(int64_t sessionid, response* resp)
+int kds_s2000w_client_status_session(int64_t sessionid, response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_start_scan");
+       debug_printf(ALL, "kds_s2000w_client_status_session");
+
+       join_thread();
+       wait_seconds(&config->heartbeat);
 
        curl_easy_reset(curl);
 
        char* url = NULL;
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, config->scanner_url, 0);
-       curl_url_set(url_handler, CURLUPART_PATH, STARTSCAN_PATH, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, STATUS_PATH, 0);
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
@@ -309,8 +303,7 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* resp)
        FILE* stream = open_memstream(mem, sizeloc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
 
-       curl_easy_setopt(curl, CURLOPT_POST, 1L);
-       curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L);
+       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
        _kds_s2000w_client_set_ssl_verification_off(curl);
 
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
@@ -342,16 +335,16 @@ int kds_s2000w_client_start_scan(int64_t sessionid, response* resp)
        return result;
 }
 
-int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp)
+int kds_s2000w_client_start_scan(int64_t sessionid, response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_stop_scan");
+       debug_printf(ALL, "kds_s2000w_client_start_scan");
 
        curl_easy_reset(curl);
 
        char* url = NULL;
        CURLU* url_handler = curl_url();
        curl_url_set(url_handler, CURLUPART_URL, config->scanner_url, 0);
-       curl_url_set(url_handler, CURLUPART_PATH, STOPSCAN_PATH, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, STARTSCAN_PATH, 0);
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
@@ -402,19 +395,16 @@ int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp)
        return result;
 }
 
-int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* resp)
+int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_get_image");
+       debug_printf(ALL, "kds_s2000w_client_stop_scan");
 
        curl_easy_reset(curl);
 
        char* url = NULL;
        CURLU* url_handler = curl_url();
-       char* url_path = malloc(sizeof(char) * MAX_STR_BUFFER_LENGTH);
-       memset(url_path, 0, MAX_STR_BUFFER_LENGTH);
-       sprintf(url_path, "%s/%i", IMAGE_PATH, img_number);
        curl_url_set(url_handler, CURLUPART_URL, config->scanner_url, 0);
-       curl_url_set(url_handler, CURLUPART_PATH, url_path, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, STOPSCAN_PATH, 0);
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
@@ -424,7 +414,7 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        sprintf(header_str, "SessionId: %li", sessionid);
        headers = curl_slist_append(headers, header_str);
        headers = curl_slist_append(headers, CONTENT_TYPE_HEADER);
-       headers = curl_slist_append(headers, ACCEPT_IMAGE_HEADER);
+       headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 
        char** mem = malloc(sizeof(char*));
@@ -432,7 +422,8 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        FILE* stream = open_memstream(mem, sizeloc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
 
-       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
+       curl_easy_setopt(curl, CURLOPT_POST, 1L);
+       curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L);
        _kds_s2000w_client_set_ssl_verification_off(curl);
 
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
@@ -458,17 +449,15 @@ int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* res
        mem = NULL;
        free(sizeloc);
        sizeloc = NULL;
-       free(url_path);
-       url_path = NULL;
        free(header_str);
        header_str = NULL;
 
        return result;
 }
 
-int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* resp)
+int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_delete_image");
+       debug_printf(ALL, "kds_s2000w_client_get_image");
 
        curl_easy_reset(curl);
 
@@ -488,7 +477,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        sprintf(header_str, "SessionId: %li", sessionid);
        headers = curl_slist_append(headers, header_str);
        headers = curl_slist_append(headers, CONTENT_TYPE_HEADER);
-       headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
+       headers = curl_slist_append(headers, ACCEPT_IMAGE_HEADER);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 
        char** mem = malloc(sizeof(char*));
@@ -496,7 +485,7 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        FILE* stream = open_memstream(mem, sizeloc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
 
-       curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
+       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
        _kds_s2000w_client_set_ssl_verification_off(curl);
 
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
@@ -512,8 +501,6 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
 
        curl_url_cleanup(url_handler);
        url_handler = NULL;
-       free(url_path);
-       url_path = NULL;
        curl_slist_free_all(headers);
        headers = NULL;
        curl_free(url);
@@ -524,26 +511,35 @@ int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response*
        mem = NULL;
        free(sizeloc);
        sizeloc = NULL;
+       free(url_path);
+       url_path = NULL;
        free(header_str);
        header_str = NULL;
 
        return result;
 }
 
-int kds_s2000w_client_get_capabilities(response* resp)
+int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* resp)
 {
-       debug_printf(ALL, "kds_s2000w_client_get_capabilities");
+       debug_printf(ALL, "kds_s2000w_client_delete_image");
 
        curl_easy_reset(curl);
 
        char* url = NULL;
        CURLU* url_handler = curl_url();
+       char* url_path = malloc(sizeof(char) * MAX_STR_BUFFER_LENGTH);
+       memset(url_path, 0, MAX_STR_BUFFER_LENGTH);
+       sprintf(url_path, "%s/%i", IMAGE_PATH, img_number);
        curl_url_set(url_handler, CURLUPART_URL, config->scanner_url, 0);
-       curl_url_set(url_handler, CURLUPART_PATH, CAPABILITIES_PATH, 0);
+       curl_url_set(url_handler, CURLUPART_PATH, url_path, 0);
        curl_url_get(url_handler, CURLUPART_URL, &url, 0);
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
        struct curl_slist* headers = NULL;
+       char* header_str = malloc(sizeof(char) * MAX_STR_BUFFER_LENGTH);
+       memset(header_str, 0, MAX_STR_BUFFER_LENGTH);
+       sprintf(header_str, "SessionId: %li", sessionid);
+       headers = curl_slist_append(headers, header_str);
        headers = curl_slist_append(headers, CONTENT_TYPE_HEADER);
        headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
@@ -553,7 +549,7 @@ int kds_s2000w_client_get_capabilities(response* resp)
        FILE* stream = open_memstream(mem, sizeloc);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
 
-       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
+       curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
        _kds_s2000w_client_set_ssl_verification_off(curl);
 
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
@@ -569,6 +565,8 @@ int kds_s2000w_client_get_capabilities(response* resp)
 
        curl_url_cleanup(url_handler);
        url_handler = NULL;
+       free(url_path);
+       url_path = NULL;
        curl_slist_free_all(headers);
        headers = NULL;
        curl_free(url);
@@ -579,6 +577,8 @@ int kds_s2000w_client_get_capabilities(response* resp)
        mem = NULL;
        free(sizeloc);
        sizeloc = NULL;
+       free(header_str);
+       header_str = NULL;
 
        return result;
 }
index 9175b4f81605484eecb118c5d1ca4feb47729f43..c981df50833ea2a711af2f4f0d53ef908a166611 100644 (file)
@@ -9,18 +9,24 @@ typedef struct {
        long code;
 } response;
 
-response* kds_s2000w_client_response_init();
-void kds_s2000w_client_response_free(response* resp);
 void kds_s2000w_client_init();
 void kds_s2000w_client_free();
+
+response* kds_s2000w_client_response_init();
+void kds_s2000w_client_response_free(response* resp);
+
 int kds_s2000w_client_open_session(response* resp);
 void kds_s2000w_client_close_session(int64_t sessionid);
+
+int kds_s2000w_client_get_capabilities(response* resp);
 int kds_s2000w_client_status_session(int64_t sessionid, response* resp);
+
 int kds_s2000w_client_start_scan(int64_t sessionid, response* resp);
 int kds_s2000w_client_stop_scan(int64_t sessionid, response* resp);
+
 int kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* resp);
 int kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* resp);
-int kds_s2000w_client_get_capabilities(response* resp);
+
 int kds_s2000w_client_get_option(int64_t sessionid, response* resp);
 int kds_s2000w_client_set_option(int64_t sessionid, response* resp);