diff options
| author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-13 08:40:26 +0800 |
|---|---|---|
| committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-13 08:40:26 +0800 |
| commit | daf858c02db1a5a12151d142ce55dfe9fbb2b715 (patch) | |
| tree | d6343c4f8b7ef9bad9e3a17264b201f6b8012791 /client.c | |
| parent | 0a6e2943843ca894abc562ba98bcbf3399769481 (diff) | |
Merge catalog and product to client
Diffstat (limited to 'client.c')
| -rw-r--r-- | client.c | 34 |
1 files changed, 30 insertions, 4 deletions
@@ -1,8 +1,6 @@ #include <stdbool.h> #include <string.h> #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(); |