diff options
| author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-18 01:59:41 +0800 | 
|---|---|---|
| committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-18 01:59:41 +0800 | 
| commit | d8844d9038e99e2d6175c4a2d99f36bde28deae9 (patch) | |
| tree | be50732bce9d0c098bf042347bac1339f7559f9d | |
| parent | 4aef78b56e9ee5f51ce80171288242c8881842f0 (diff) | |
Revert "Container for post and callback"
This reverts commit 0ca65138cf02d6c46e1857e911a142d08cdad761.
| -rw-r--r-- | icclient/typedefs.h | 15 | ||||
| -rw-r--r-- | 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 <cstddef>  #endif -  #ifdef __EMSCRIPTEN__ -  #include <emscripten/fetch.h> -  typedef emscripten_fetch_t icclient_response; -typedef char icclient_post; -  #else - -#include <curl/curl.h> -  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 @@ -8,6 +8,9 @@  #include <stdlib.h>  #include <stdarg.h>  #include <string.h> +#ifndef __EMSCRIPTEN__ +#include <curl/curl.h> +#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 |