resp->error_size = size;
}
-void _kds_s2000w_client_stream_to_response(FILE* stream, response* resp, size_t* size)
+void _kds_s2000w_client_stream_to_response(char* mem, response* resp, size_t* size)
{
debug_printf(ALL, "kds_s2000w_client_stream_to_response");
- resp->data = realloc(resp->data, sizeof(char) * *size + 1);
- fseek(stream, 0, SEEK_SET);
- fread(resp->data, sizeof(char), *size, stream);
- resp->data[*size] = '\0';
+ resp->data = realloc(resp->data, sizeof(char) * *size);
resp->size = *size;
+ memcpy(resp->data, mem, *size);
}
void _kds_s2000w_client_print_error_result(CURLcode result)
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
char* body = malloc(sizeof(char) * MAX_STR_BUFFER_LENGTH);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
body = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(header_str);
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(header_str);
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(header_str);
headers = curl_slist_append(headers, ACCEPT_IMAGE_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(url_path);
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(header_str);
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
headers = curl_slist_append(headers, ACCEPT_JSON_HEADER);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- char* buffer = malloc(sizeof(char));
+ char* mem = malloc(sizeof(char));
size_t* sizeloc = malloc(sizeof(size_t));
- FILE* stream = open_memstream(&buffer, sizeloc);
+ FILE* stream = open_memstream(&mem, sizeloc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stream);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
_kds_s2000w_client_read_error_status(curl, resp);
_kds_s2000w_client_print_error_result(result);
- fflush(stream);
- _kds_s2000w_client_stream_to_response(stream, resp, sizeloc);
fclose(stream);
+ _kds_s2000w_client_stream_to_response(mem, resp, sizeloc);
curl_url_cleanup(url_handler);
url_handler = NULL;
headers = NULL;
curl_free(url);
url = NULL;
- free(buffer);
- buffer = NULL;
+ free(mem);
+ mem = NULL;
free(sizeloc);
sizeloc = NULL;
free(header_str);