diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2020-06-20 11:24:12 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2020-06-20 11:24:12 +0800 |
commit | a3b91bf175b9d51fdd3674112e60a773f13c8ea9 (patch) | |
tree | c297742f6f068afed7fe7e901192cd21d2f7b9ee | |
parent | 0d45381125b73feea759213b8341deb4e08d600c (diff) |
Move product freeing implementation to product's own implementation
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | client.c | 23 | ||||
-rw-r--r-- | icclient/client.h | 1 | ||||
-rw-r--r-- | icclient/product.h | 10 | ||||
-rw-r--r-- | ord.c | 4 | ||||
-rw-r--r-- | product.c | 21 |
6 files changed, 37 insertions, 25 deletions
diff --git a/Makefile.am b/Makefile.am index 7a82730..0ac0146 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,9 +3,10 @@ lib_LTLIBRARIES = libicclient.la libicclient_la_SOURCES = \ request.h \ request.c \ + product.c \ + ord.c \ login.h \ login.c \ - ord.c \ member.c \ admin.c \ client.c @@ -89,7 +89,7 @@ void icclient_order(icclient_ord_order **orderptr, const char *sku icclient_product *product = *(icclient_product **)bsearch(&key_product , products, catalog->length, sizeof(icclient_product *) , prodcmp); - icclient_freeproduct(key_product); + icclient_product_free(key_product); icclient_ord_order *order = *orderptr; icclient_ord_item *item = NULL; @@ -167,29 +167,10 @@ void icclient_page(const char *path, size_t (*handler)(void *, size_t, size_t request(handler, (void *)dataptr, NULL, "%s", path); } -void icclient_freeproduct(icclient_product *product) -{ - if (product->author) - free(product->author); - if (product->prodgroup) - free(product->prodgroup); - 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); - product = NULL; -} - void icclient_freecatalog(icclient_catalog *catalog) { for (size_t i = 0; i < catalog->length; i++) - icclient_freeproduct(catalog->products[i]); + icclient_product_free(catalog->products[i]); free(catalog); catalog = NULL; } diff --git a/icclient/client.h b/icclient/client.h index 995c948..4a9ac6a 100644 --- a/icclient/client.h +++ b/icclient/client.h @@ -73,7 +73,6 @@ extern "C" { size_t (*handler)(void *contents, size_t size, size_t nmemb, void *userdata), void **dataptr); - void icclient_freeproduct(struct icclient_product *product); void icclient_freecatalog(struct icclient_catalog *catalog); void icclient_cleanup(); diff --git a/icclient/product.h b/icclient/product.h index 4d7f0c7..ba999b3 100644 --- a/icclient/product.h +++ b/icclient/product.h @@ -19,4 +19,14 @@ struct icclient_product { struct icclient_product_crosssell *crosssell; }; +#ifdef __cplusplus +extern "C" { +#endif + + void icclient_product_free(struct icclient_product *product); + +#ifdef __cplusplus +} +#endif + #endif // ICCLIENT_PRODUCT_H @@ -1,10 +1,10 @@ #include <stdlib.h> #include <stdbool.h> -#include "icclient/client.h" +#include "icclient/product.h" #include "icclient/ord.h" void icclient_ord_free(struct icclient_ord_order *order) { for (size_t i = 0; i < order->nitems; i++) - icclient_freeproduct(order->items[i]->product); + icclient_product_free(order->items[i]->product); } diff --git a/product.c b/product.c new file mode 100644 index 0000000..6fb70b6 --- /dev/null +++ b/product.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include "icclient/product.h" + +void icclient_product_free(struct icclient_product *product) +{ + if (product->author) + free(product->author); + if (product->prodgroup) + free(product->prodgroup); + 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); + product = NULL; +} |