From 3947ac9a60018f395558731027e26db8953090bb 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, 12 Jun 2021 14:44:30 +0800 Subject: Move all libcurl related stuff to request --- client.c | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 5feac65..04368c8 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,4 @@ #include -#include #include #include "request.h" #include "icclient/product.h" @@ -7,41 +6,15 @@ #include "icclient/client.h" #ifdef __EMSCRIPTEN__ -emscripten_fetch_attr_t attr; extern void icclient_catalog_results(emscripten_fetch_t *); #else -CURL *curl = NULL; -char *server_url = NULL; extern size_t icclient_catalog_results(void *, size_t, size_t, void *); #endif bool icclient_init(const char *url, const char *certificate) { icclient_catalog_init(); -#ifdef __EMSCRIPTEN__ - emscripten_fetch_attr_init(&attr); - attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; - return true; -#else - curl_global_init(CURL_GLOBAL_SSL); - curl = curl_easy_init(); - if (curl) { - 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 - size_t length = strlen(url); - bool append = !(bool)(url[length - 1] == '/'); - server_url = malloc(length + (size_t)append + 1); - strcpy(server_url, url); - if (append) - strcat(server_url, "/"); - } - return (bool)curl; -#endif + return icclient_request_init(url, certificate); } void icclient_results(const char *prod_group, @@ -70,11 +43,5 @@ void icclient_page(const char *path, icclient_handler handler, void **dataptr) void icclient_cleanup() { -#ifndef __EMSCRIPTEN__ - if (curl) { - free(server_url); - curl_easy_cleanup(curl); - } - curl_global_cleanup(); -#endif + icclient_request_cleanup(); } -- cgit v1.2.3