From 6374c26a020f7c0f551ee62078f7cfac61e14128 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: Sat, 19 Jun 2021 18:39:17 +0800 Subject: request not inline any more --- client.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index d88bafb..865fe9e 100644 --- a/client.c +++ b/client.c @@ -1,40 +1,34 @@ +#include +#include +#ifndef __EMSCRIPTEN__ +#include +#endif #include "request.h" #include "icclient.h" -char *sampleurl; char *image_dir; +#ifndef __EMSCRIPTEN__ +char *sampleurl; char *certificate = NULL; +#endif -extern inline void request(void (*)(icclient_response *), void (*)(void *), struct body *, char *, ...); extern void handle_results(icclient_response *); -#ifndef __EMSCRIPTEN__ -size_t append(char *data, size_t size, size_t nmemb, icclient_response *response) -{ - size_t realsize = size * nmemb; - response->data = realloc(response->data, response->numBytes + realsize + 1); - memcpy(&(response->data[response->numBytes]), data, realsize); - response->numBytes += realsize; - response->data[response->numBytes] = '\0'; - return realsize; -} -#endif - void icclient_init(const char *url, const char *dir, const char *cert) { + image_dir = malloc(strlen(dir) + 1); + strcpy(image_dir, dir); +#ifndef __EMSCRIPTEN__ size_t length = strlen(url); size_t append = url[length - 1] != '/'; sampleurl = malloc(length + append + 1); strcpy(sampleurl, url); if (append) strcat(sampleurl, "/"); - image_dir = malloc(strlen(dir) + 1); - strcpy(image_dir, dir); if (certificate) { certificate = malloc(strlen(certificate) + 1); strcpy(certificate, cert); } -#ifndef __EMSCRIPTEN__ curl_global_init(CURL_GLOBAL_SSL); #endif } @@ -93,14 +87,17 @@ void icclient_free_response(icclient_response *response) free(response->userData); #ifdef __EMSCRIPTEN__ emscripten_fetch_close(response); +#else + free(response->data); + free(response); #endif } void icclient_cleanup() { + free(image_dir); #ifndef __EMSCRIPTEN__ free(sampleurl); - free(image_dir); if (certificate) free(certificate); curl_global_cleanup(); -- cgit v1.2.3