summaryrefslogtreecommitdiff
path: root/catalog.c
diff options
context:
space:
mode:
Diffstat (limited to 'catalog.c')
-rw-r--r--catalog.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/catalog.c b/catalog.c
index b7f7665..77d5030 100644
--- a/catalog.c
+++ b/catalog.c
@@ -1,6 +1,10 @@
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <json.h>
+#ifdef __EMSCRIPTEN__
+#include <emscripten/fetch.h>
+#endif
#include "icclient/product.h"
#include "icclient/catalog.h"
@@ -11,7 +15,11 @@ void icclient_catalog_init()
tokener = json_tokener_new();
}
+#ifdef __EMSCRIPTEN__
+void icclient_catalog_results(emscripten_fetch_t *fetch)
+#else
size_t icclient_catalog_results(void *contents, size_t size, size_t nmemb, void *userData)
+#endif
{
size_t realsize =
#ifdef __EMSCRIPTEN__
@@ -20,9 +28,11 @@ size_t icclient_catalog_results(void *contents, size_t size, size_t nmemb, void
size * nmemb
#endif
;
+#ifndef __EMSCRIPTEN__
char data[realsize];
memcpy(data, contents, realsize - 1);
data[realsize - 1] = '\0';
+#endif
json_object *products = json_tokener_parse_ex(tokener,
#ifdef __EMSCRIPTEN__
fetch->
@@ -51,11 +61,12 @@ size_t icclient_catalog_results(void *contents, size_t size, size_t nmemb, void
#endif
;
size_t length = json_object_array_length(products);
- struct icclient_catalog **catalogptr = (struct icclient_catalog **)
+ struct icclient_catalog_callback *catalog_callback = (struct icclient_catalog_callback *)
#ifdef __EMSCRIPTEN__
fetch->
#endif
userData;
+ struct icclient_catalog **catalogptr = catalog_callback->catalog;
*catalogptr = malloc(sizeof(struct icclient_catalog) + sizeof(struct icclient_product *[length]));
struct icclient_catalog *catalog = *catalogptr;
catalog->length = length;
@@ -91,6 +102,8 @@ size_t icclient_catalog_results(void *contents, size_t size, size_t nmemb, void
json_object_iter_next(&iterator);
}
}
+ catalog_callback->callback(catalog);
+ free(catalog_callback);
#ifdef __EMSCRIPTEN__
emscripten_fetch_close(fetch);
#else