From: Bastian Dehn Date: Tue, 21 May 2024 18:24:23 +0000 (+0200) Subject: change get option with memory stream X-Git-Tag: v1.0.3^2~1^2~1 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=8b605aec2f4774ddde35d7d6ba4bee417223f9ab;p=sane-kds-s2000w-net.git change get option with memory stream --- diff --git a/src/kds_s2000w_client.c b/src/kds_s2000w_client.c index 9ed4a62..07fb624 100644 --- a/src/kds_s2000w_client.c +++ b/src/kds_s2000w_client.c @@ -551,6 +551,9 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response) struct curl_slist* headers = NULL; char header_str[80]; CURLcode result = 0; + FILE* stream = NULL; + char* buffer = NULL; + size_t* sizeloc = NULL; curl = curl_easy_init(); if(!curl) @@ -567,8 +570,10 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response) curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 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); + buffer = malloc(sizeof(char)); + sizeloc = malloc(sizeof(size_t)); + stream = open_memstream(&buffer, sizeloc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); result = curl_easy_perform(curl); @@ -578,12 +583,20 @@ int kds_s2000w_client_get_option(int64_t sessionid, response* response) if (result != CURLE_OK) fprintf(stderr, "ERROR: curl_easy_perform: %s\n", curl_easy_strerror(result)); + fflush(stream); + _kds_s2000w_client_stream_to_response(stream, response, sizeloc); + fclose(stream); + curl_url_cleanup(url_handler); url_handler = NULL; curl_free(url); url = NULL; curl_easy_cleanup(curl); curl = NULL; + free(buffer); + buffer = NULL; + free(sizeloc); + sizeloc = NULL; return result; }