summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-10 17:13:45 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-10 17:13:45 +0800
commit3f96d8c84f7362b1800fcc8fdf3d0395ec265ca5 (patch)
treeeaafdcbba77295106477c4c706f5e36118123b83 /client.c
parent06bea8ae54dd3cd714b231b3d8a8deef77136613 (diff)
Anticipate asynchronous data fetch
Diffstat (limited to 'client.c')
-rw-r--r--client.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/client.c b/client.c
index 8813db9..5feac65 100644
--- a/client.c
+++ b/client.c
@@ -8,13 +8,16 @@
#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;
@@ -37,13 +40,10 @@ bool icclient_init(const char *url, const char *certificate)
if (append)
strcat(server_url, "/");
}
- icclient_catalog_init();
return (bool)curl;
#endif
}
-extern size_t icclient_catalog_results(void *, size_t, size_t, void *);
-
void icclient_results(const char *prod_group,
void (*callback)(struct icclient_catalog *), struct icclient_catalog **catalog, icclient_handler handler)
{
@@ -52,8 +52,10 @@ void icclient_results(const char *prod_group,
char *space = NULL;
while ((space = strchr(nonspaced, ' ')))
*space = '-';
- request(handler ? handler : icclient_catalog_results, (void *)catalog, 0, "%s", nonspaced);
- callback(*catalog);
+ struct icclient_catalog_callback *catalog_callback = malloc(sizeof(struct icclient_catalog_callback));
+ catalog_callback->catalog = catalog;
+ catalog_callback->callback = callback;
+ request(handler ? handler : icclient_catalog_results, (void *)catalog_callback, 0, "%s", nonspaced);
}
void icclient_flypage(const char *sku, icclient_handler handler, struct icclient_product **productptr)