From: Bastian Dehn Date: Mon, 22 Jan 2024 19:14:34 +0000 (+0100) Subject: move curl call close session to client X-Git-Tag: v1.0.0^2~476 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ff7cfd55a8c803711c47f5d26f2367cbc4953e0a;p=sane-kds-s2000w-net.git move curl call close session to client --- diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index e072f83..d3b8828 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -66,4 +66,25 @@ int kds_s2000w_client_open_session(const char* username, response* response) url = NULL; return result; +} + +void kds_s2000w_client_close_session(int64_t sessionid) +{ + CURL *curl = curl_easy_init(); + if(!curl) + return; + + struct curl_slist* headers = NULL; + char header_str[80]; + sprintf(header_str, "SessionId: %li", sessionid); + headers = curl_slist_append(headers, header_str); + curl_easy_setopt(curl, CURLOPT_URL, "http://scanner.lan.hhaalo.de/api/session"); + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + curl_easy_perform(curl); + + curl_slist_free_all(headers); + headers = NULL; + curl_easy_cleanup(curl); + curl = NULL; } \ No newline at end of file diff --git a/src/kds_s2000w_client.h b/src/kds_s2000w_client.h index 22e816a..ceac714 100644 --- a/src/kds_s2000w_client.h +++ b/src/kds_s2000w_client.h @@ -11,4 +11,5 @@ size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata); 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); #endif \ No newline at end of file diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index a70ce32..d0d3d28 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -103,18 +103,6 @@ void kds_s2000w_handler_close() if(!curl) return; - struct curl_slist* headers = NULL; - char header_str[80]; - sprintf(header_str, "SessionId: %li", sessionid); - headers = curl_slist_append(headers, header_str); - curl_easy_setopt(curl, CURLOPT_URL, "http://scanner.lan.hhaalo.de/api/session"); - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - curl_easy_perform(curl); - + kds_s2000w_client_close_session(sessionid); sessionid = 0; - curl_slist_free_all(headers); - headers = NULL; - curl_easy_cleanup(curl); - curl = NULL; } \ No newline at end of file