From c6e5f421e2738b6005f6c3da6700b1343214f7e5 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: Wed, 9 Jun 2021 19:51:18 +0800 Subject: Add support for Emscripten --- client.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index fa59587..0dad4c9 100644 --- a/client.c +++ b/client.c @@ -6,11 +6,20 @@ #include "icclient/catalog.h" #include "icclient/client.h" +#ifdef __EMSCRIPTEN__ +emscripten_fetch_attr_t attr; +#else CURL *curl = NULL; char *server_url = NULL; +#endif bool icclient_init(const char *url, const char *certificate) { +#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) { @@ -28,47 +37,42 @@ bool icclient_init(const char *url, const char *certificate) if (append) strcat(server_url, "/"); } - return (bool)curl; +#endif } -void icclient_results(const char *prod_group, - size_t (*handler)(void *, size_t, size_t, void *), - struct icclient_catalog **catalogptr) +void icclient_results(const char *prod_group, icclient_handler handler, struct icclient_catalog **catalogptr) { char nonspaced[strlen(prod_group) + 1]; strcpy(nonspaced, prod_group); char *space = NULL; while ((space = strchr(nonspaced, ' '))) *space = '-'; - request(handler, (void *)catalogptr, NULL, "%s", nonspaced); + request(handler, (void *)catalogptr, 0, "%s", nonspaced); } -void icclient_allproducts(size_t (*handler)(void *, size_t, size_t, void *), - struct icclient_catalog **catalogptr) +void icclient_allproducts(icclient_handler handler, struct icclient_catalog **catalogptr) { - request(handler, (void *)catalogptr, NULL, "%s", "All-Products"); + request(handler, (void *)catalogptr, 0, "%s", "All-Products"); } -void icclient_flypage(const char *sku, - size_t (*handler)(void *, size_t, size_t, void *), - struct icclient_product **productptr) +void icclient_flypage(const char *sku, icclient_handler handler, struct icclient_product **productptr) { - request(handler, (void *)productptr, NULL, "%s", sku); + request(handler, (void *)productptr, 0, "%s", sku); } -void icclient_page(const char *path, - size_t (*handler)(void *, size_t, size_t, void *), - void **dataptr) +void icclient_page(const char *path, icclient_handler handler, void **dataptr) { - request(handler, (void *)dataptr, NULL, "%s", path); + request(handler, (void *)dataptr, 0, "%s", path); } void icclient_cleanup() { +#ifndef __EMSCRIPTEN__ if (curl) { free(server_url); curl_easy_cleanup(curl); } curl_global_cleanup(); +#endif } -- cgit v1.2.3