summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'client.c')
-rw-r--r--client.c36
1 files changed, 20 insertions, 16 deletions
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
}