From d8844d9038e99e2d6175c4a2d99f36bde28deae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Fri, 18 Jun 2021 01:59:41 +0800 Subject: Revert "Container for post and callback" This reverts commit 0ca65138cf02d6c46e1857e911a142d08cdad761. --- request.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'request.h') diff --git a/request.h b/request.h index ec6720a..a946afb 100644 --- a/request.h +++ b/request.h @@ -8,6 +8,9 @@ #include #include #include +#ifndef __EMSCRIPTEN__ +#include +#endif #include "icclient/typedefs.h" struct body { @@ -126,10 +129,7 @@ static inline void request(void (*handler)(icclient_response *), void (*callback attr.requestHeaders = headers; attr.requestData = post; attr.requestDataSize = length + 1; - struct icclient_post_callback *post_callback = malloc(sizeof(struct icclient_post_callback)); - post_callback->post = post; - post_callback->callback = callback; - attr.userData = post_callback; + attr.userData = post; } else { strcpy(attr.requestMethod, "GET"); attr.userData = callback; @@ -138,7 +138,8 @@ static inline void request(void (*handler)(icclient_response *), void (*callback #else curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append); - icclient_response response = { .numBytes = 0 }; + icclient_response response = { .userData = callback, .numBytes = 0 }; + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); struct curl_httppost *post, *last = NULL; if (body) { for (size_t i = 0; i < body->num_pairs; i++) { @@ -152,16 +153,11 @@ static inline void request(void (*handler)(icclient_response *), void (*callback } last = NULL; curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); - struct icclient_post_callback *post_callback = malloc(sizeof(struct icclient_post_callback)); - post_callback->post = post; - post_callback->callback = callback; - response.userData = post_callback; - } else { + } else curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); - response.userData = callback; - } - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); CURLcode res = curl_easy_perform(curl); + if (post) + curl_formfree(post); if (res == CURLE_OK && handler) handler(&response); #ifdef DEBUG -- cgit v1.2.3