summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-18 21:30:01 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-18 21:30:01 +0800
commitc3ede83912dd2d9e63806da18e71728b29f924ac (patch)
tree62279d94f96b92b8ec2cfcaf003945df3ab07903
parentdfb76ba5abcc5b00411db4d880a39c16ad6b59b2 (diff)
Generalise function names
to using words like catalog and product instead of results and flypage.
-rw-r--r--client.c12
-rw-r--r--icclient.h16
-rw-r--r--ord.c42
3 files changed, 33 insertions, 37 deletions
diff --git a/client.c b/client.c
index 436ae99..b42bc16 100644
--- a/client.c
+++ b/client.c
@@ -47,24 +47,24 @@ void icclient_init(const char *url, const char *dir, const char *certificate)
#endif
}
-void icclient_results(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *))
+void icclient_catalog(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *))
{
char nonspaced[strlen(prod_group) + 1];
strcpy(nonspaced, prod_group);
char *space = NULL;
while ((space = strchr(nonspaced, ' ')))
*space = '-';
- request(handler ? handler : handle_results, (void *)callback, 0, "%s", nonspaced);
+ request(handler ? handler : handle_results, (void (*)(void *))callback, NULL, "%s", nonspaced);
}
-void icclient_flypage(const char *sku, void (*handler)(icclient_response *), struct icclient_product **productptr)
+void icclient_product(const char *sku, void (*handler)(icclient_response *), void (*callback)(struct icclient_product *))
{
- request(handler, (void *)productptr, 0, "%s", sku);
+ request(handler, (void (*)(void *))callback, NULL, "%s", sku);
}
-void icclient_page(const char *path, void (*handler)(icclient_response *), void **dataptr)
+void icclient_page(const char *path, void (*handler)(icclient_response *))
{
- request(handler, (void *)dataptr, 0, "%s", path);
+ request(handler, NULL, NULL, "%s", path);
}
void icclient_free_product(struct icclient_product *product)
diff --git a/icclient.h b/icclient.h
index c02e8f7..b962a24 100644
--- a/icclient.h
+++ b/icclient.h
@@ -26,11 +26,11 @@ struct icclient_catalog {
};
/*!
- * \brief For fetching data about all of the products that are active.
+ * \brief For fetching data about all active products.
* \param handler A pointer to the function when a custom handler is needed to arrange the data into the catalog.
* \param callback A pointer to the function that needs to be called after the catalog is ready.
*/
-#define icclient_allproducts(handler, callback) icclient_results("All-Products", handler, callback)
+#define icclient_allproducts(handler, callback) icclient_catalog("All-Products", handler, callback)
#ifdef __cplusplus
extern "C" {
@@ -50,17 +50,17 @@ void icclient_init(const char *sampleurl, const char *image_dir, const char *cer
* \param handler A pointer to the function when a custom handler is needed to arrange the data into the catalog.
* \param callback A pointer to the function that needs to be called after the catalog is ready.
*/
-void icclient_results(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *));
+void icclient_catalog(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *));
/*!
* \brief For fetching data about a specific product.
* \param sku The SKU of the product.
- * \param handler A pointer to a cURL write function callback.
- * \param productptr A pointer to pointer to the product to store the data.
- */
-void icclient_flypage(const char *sku, void (*handler)(icclient_response *), struct icclient_product **productptr);
+ * \param handler A pointer to the function when a custom handler is needed to arrange the data into the product.
+ * \param callback A pointer to the function that needs to be called after the product is ready.
+*/
+void icclient_product(const char *sku, void (*handler)(icclient_response *), void (*callback)(struct icclient_product *));
-void icclient_page(const char *path, void (*handler)(icclient_response *), void **dataptr);
+void icclient_page(const char *path, void (*handler)(icclient_response *));
void icclient_free_product(struct icclient_product *product);
diff --git a/ord.c b/ord.c
index f102a45..e0b407b 100644
--- a/ord.c
+++ b/ord.c
@@ -5,10 +5,6 @@
#include "icclient/member.h"
#include "icclient/ord.h"
-typedef struct icclient_catalog icclient_catalog;
-typedef struct icclient_product icclient_product;
-typedef struct icclient_ord_item icclient_ord_item;
-
void icclient_ord_init(struct icclient_ord_order *order)
{
order->subtotal = .0;
@@ -19,40 +15,40 @@ void icclient_ord_init(struct icclient_ord_order *order)
static int prodcmp(const void *product1, const void *product2)
{
- return strcmp((*(icclient_product * const *)product1)->sku
- , (*(icclient_product * const *)product2)->sku);
+ return strcmp((*(struct icclient_product * const *)product1)->sku
+ , (*(struct icclient_product * const *)product2)->sku);
}
static int itemcmp(const void *item1, const void *item2)
{
- return strcmp((*(icclient_ord_item * const *)item1)->product->sku
- , (*(icclient_ord_item * const *)item2)->product->sku);
+ return strcmp((*(struct icclient_ord_item * const *)item1)->product->sku
+ , (*(struct icclient_ord_item * const *)item2)->product->sku);
}
-void icclient_ord_order(const char *sku, const icclient_catalog *catalog,
+void icclient_ord_order(const char *sku, const struct icclient_catalog *catalog,
struct icclient_ord_order **orderptr)
{
- icclient_product **products = ((icclient_catalog *)catalog)->products;
- qsort(products, catalog->length, sizeof(icclient_product *), prodcmp);
- icclient_product *key_product = malloc(sizeof(icclient_product));
- memset(key_product, '\0', sizeof(icclient_product));
+ struct icclient_product **products = ((struct icclient_catalog *)catalog)->products;
+ qsort(products, catalog->length, sizeof(struct icclient_product *), prodcmp);
+ struct icclient_product *key_product = malloc(sizeof(struct icclient_product));
+ memset(key_product, '\0', sizeof(struct icclient_product));
key_product->sku = malloc(strlen(sku) + 1);
strcpy(key_product->sku, sku);
- icclient_product *product = *(icclient_product **)bsearch(&key_product
- , products, catalog->length, sizeof(icclient_product *)
+ struct icclient_product *product = *(struct icclient_product **)bsearch(&key_product
+ , products, catalog->length, sizeof(struct icclient_product *)
, prodcmp);
icclient_free_product(key_product);
struct icclient_ord_order *order = *orderptr;
- icclient_ord_item *item = NULL;
+ struct icclient_ord_item *item = NULL;
if (order) {
- icclient_ord_item **items = order->items;
- qsort(items, order->nitems, sizeof(icclient_ord_item *), itemcmp);
- icclient_ord_item *key_item = malloc(sizeof(icclient_ord_item));
+ struct icclient_ord_item **items = order->items;
+ qsort(items, order->nitems, sizeof(struct icclient_ord_item *), itemcmp);
+ struct icclient_ord_item *key_item = malloc(sizeof(struct icclient_ord_item));
key_item->product = product;
- icclient_ord_item **itemptr = bsearch(&key_item, items
- , order->nitems, sizeof(icclient_ord_item *)
+ struct icclient_ord_item **itemptr = bsearch(&key_item, items
+ , order->nitems, sizeof(struct icclient_ord_item *)
, itemcmp);
if (itemptr)
item = *itemptr;
@@ -68,9 +64,9 @@ void icclient_ord_order(const char *sku, const icclient_catalog *catalog,
else {
size_t i = order->nitems;
*orderptr = realloc(order, sizeof(struct icclient_ord_order)
- + (i + 1) * sizeof(icclient_ord_item));
+ + (i + 1) * sizeof(struct icclient_ord_item));
order = *orderptr;
- order->items[i] = malloc(sizeof(icclient_ord_item));
+ order->items[i] = malloc(sizeof(struct icclient_ord_item));
order->nitems++;
item = order->items[i];
item->product = product;