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. --- icclient/typedefs.h | 15 --------------- request.h | 22 +++++++++------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/icclient/typedefs.h b/icclient/typedefs.h index 73d8adf..80e09b1 100644 --- a/icclient/typedefs.h +++ b/icclient/typedefs.h @@ -4,30 +4,15 @@ #ifdef __cplusplus #include #endif - #ifdef __EMSCRIPTEN__ - #include - typedef emscripten_fetch_t icclient_response; -typedef char icclient_post; - #else - -#include - typedef struct { void *userData; char *data; size_t numBytes; } icclient_response; -typedef struct curl_httppost icclient_post; - #endif -struct icclient_post_callback { - icclient_post *post; - void (*callback)(void *); -}; - #endif 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