From: Bastian Dehn Date: Sat, 25 Jan 2025 16:30:01 +0000 (+0100) Subject: change client method order X-Git-Tag: v1.0.29^2~4^2~15 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ec85d6a403dc1fd3d40baf2069a44c0b880ffed1;p=sane-kds-s2000w-net.git change client method order --- diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index 396c3c1..316cfc8 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -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; } diff --git a/src/kds_s2000w_client.h b/src/kds_s2000w_client.h index 9175b4f..c981df5 100644 --- a/src/kds_s2000w_client.h +++ b/src/kds_s2000w_client.h @@ -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);