From a3b91bf175b9d51fdd3674112e60a773f13c8ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sat, 20 Jun 2020 11:24:12 +0800 Subject: Move product freeing implementation to product's own implementation --- Makefile.am | 3 ++- client.c | 23 ++--------------------- icclient/client.h | 1 - icclient/product.h | 10 ++++++++++ ord.c | 4 ++-- product.c | 21 +++++++++++++++++++++ 6 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 product.c 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 diff --git a/client.c b/client.c index 9af1be5..604e849 100644 --- a/client.c +++ b/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 diff --git a/ord.c b/ord.c index 4122b57..c1c2d4c 100644 --- a/ord.c +++ b/ord.c @@ -1,10 +1,10 @@ #include #include -#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 +#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; +} -- cgit v1.2.3