diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-19 17:23:52 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-19 17:23:52 +0800 |
commit | e39dff5001bdd36bd2a2ca546ff19ea39965f79c (patch) | |
tree | 7587573d78263cb15f5f67bad597ff3d9a0ed96e /client.c | |
parent | c3ede83912dd2d9e63806da18e71728b29f924ac (diff) |
One handle for one request
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 36 |
1 files changed, 14 insertions, 22 deletions
@@ -3,10 +3,12 @@ char *sampleurl; char *image_dir; -#ifdef __EMSCRIPTEN__ -emscripten_fetch_attr_t attr; -#else -CURL *curl; +char *certificate = NULL; + +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; @@ -18,10 +20,7 @@ size_t append(char *data, size_t size, size_t nmemb, icclient_response *response } #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) +void icclient_init(const char *url, const char *dir, const char *cert) { size_t length = strlen(url); size_t append = url[length - 1] != '/'; @@ -31,20 +30,11 @@ void icclient_init(const char *url, const char *dir, const char *certificate) strcat(sampleurl, "/"); image_dir = malloc(strlen(dir) + 1); strcpy(image_dir, dir); -#ifdef __EMSCRIPTEN__ - emscripten_fetch_attr_init(&attr); - attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; -#else + if (certificate) { + certificate = malloc(strlen(certificate) + 1); + strcpy(certificate, cert); + } 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_catalog(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *)) @@ -108,7 +98,9 @@ void icclient_cleanup() { #ifndef __EMSCRIPTEN__ free(sampleurl); - curl_easy_cleanup(curl); + free(image_dir); + if (certificate) + free(certificate); curl_global_cleanup(); #endif } |