From daf858c02db1a5a12151d142ce55dfe9fbb2b715 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: Sun, 13 Jun 2021 08:40:26 +0800 Subject: Merge catalog and product to client --- client.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index a5b45e0..62d4163 100644 --- a/client.c +++ b/client.c @@ -1,8 +1,6 @@ #include #include #include "request.h" -#include "icclient/product.h" -#include "icclient/catalog.h" #include "icclient/client.h" #ifdef __EMSCRIPTEN__ @@ -11,9 +9,9 @@ extern void icclient_catalog_results(emscripten_fetch_t *); extern size_t icclient_catalog_results(void *, size_t, size_t, void *); #endif -bool icclient_init(const char *url, const char *certificate) +void icclient_init(const char *url, const char *certificate) { - return icclient_request_init(url, certificate); + icclient_request_init(url, certificate); } void icclient_results(const char *prod_group, void (*callback)(struct icclient_catalog *), icclient_handler handler) @@ -36,6 +34,34 @@ void icclient_page(const char *path, icclient_handler handler, void **dataptr) request(handler, (void *)dataptr, 0, "%s", path); } +void icclient_free_product(struct icclient_product *product) +{ + if (product->crosssell) + for (size_t i = 0; i < product->crosssell->length; i++) + free(product->crosssell->skus[i]); + if (product->author) + free(product->author); + if (product->prod_group) + free(product->prod_group); + if (product->image) + free(product->image); + if (product->thumb) + free(product->thumb); + if (product->comment) + free(product->comment); + if (product->description) + free(product->description); + free(product->sku); + free(product); +} + +void icclient_free_catalog(struct icclient_catalog *catalog) +{ + for (size_t i = 0; i < catalog->length; i++) + icclient_free_product(catalog->products[i]); + free(catalog); +} + void icclient_cleanup() { icclient_request_cleanup(); -- cgit v1.2.3