From 1df77942aee0dbd6e79e5aa019d2bcb95c59e6ec 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 02:25:02 +0800 Subject: Leave request as the minimum of what needs to be shared --- client.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index fd34d3b..b43d1c5 100644 --- a/client.c +++ b/client.c @@ -3,7 +3,22 @@ char *sampleurl; char *image_dir; +#ifdef __EMSCRIPTEN__ +emscripten_fetch_attr_t attr; +#else +CURL *curl; +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 +extern inline void request(void (*)(icclient_response *), void (*)(void *), struct body *, char *, ...); extern void handle_results(icclient_response *); void icclient_init(const char *url, const char *dir, const char *certificate) @@ -16,7 +31,20 @@ void icclient_init(const char *url, const char *dir, const char *certificate) strcat(sampleurl, "/"); image_dir = malloc(strlen(dir) + 1); strcpy(image_dir, dir); - init(certificate); +#ifdef __EMSCRIPTEN__ + emscripten_fetch_attr_init(&attr); + attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; +#else + curl_global_init(CURL_GLOBAL_SSL); + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); + if (certificate) + curl_easy_setopt(curl, CURLOPT_CAINFO, certificate); +#ifdef DEBUG + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); +#endif +#endif } void icclient_results(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *)) @@ -67,9 +95,21 @@ void icclient_free_catalog(struct icclient_catalog *catalog) free(catalog); } +void icclient_free_response(icclient_response *response) +{ +#ifdef __EMSCRIPTEN__ + emscripten_fetch_close(response); +#else + if (response->userData) + free(response->userData); +#endif +} + void icclient_cleanup() { #ifndef __EMSCRIPTEN__ - cleanup(); + free(sampleurl); + curl_easy_cleanup(curl); + curl_global_cleanup(); #endif } -- cgit v1.2.3