summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 08:40:26 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 08:40:26 +0800
commitdaf858c02db1a5a12151d142ce55dfe9fbb2b715 (patch)
treed6343c4f8b7ef9bad9e3a17264b201f6b8012791
parent0a6e2943843ca894abc562ba98bcbf3399769481 (diff)
Merge catalog and product to client
-rw-r--r--Makefile.am4
-rw-r--r--catalog.c10
-rw-r--r--client.c34
-rw-r--r--icclient/catalog.h19
-rw-r--r--icclient/client.h27
-rw-r--r--icclient/product.h32
-rw-r--r--product.c23
-rw-r--r--request.c2
-rw-r--r--request.h13
9 files changed, 60 insertions, 104 deletions
diff --git a/Makefile.am b/Makefile.am
index 49507c4..c376466 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,8 +3,6 @@ libicclient_la_SOURCES = \
client.c \
request.h \
request.c \
- catalog.c \
- product.c \
ord.c \
login.h \
login.c \
@@ -21,8 +19,6 @@ libicclient_la_LDFLAGS += -static
endif
pkginclude_HEADERS = \
icclient/client.h \
- icclient/catalog.h \
- icclient/product.h \
icclient/typedefs.h \
icclient/ord.h \
icclient/member.h \
diff --git a/catalog.c b/catalog.c
deleted file mode 100644
index 6faf0eb..0000000
--- a/catalog.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <stdlib.h>
-#include "icclient/product.h"
-#include "icclient/catalog.h"
-
-void icclient_catalog_free(struct icclient_catalog *catalog)
-{
- for (size_t i = 0; i < catalog->length; i++)
- icclient_product_free(catalog->products[i]);
- free(catalog);
-}
diff --git a/client.c b/client.c
index a5b45e0..62d4163 100644
--- a/client.c
+++ b/client.c
@@ -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();
diff --git a/icclient/catalog.h b/icclient/catalog.h
deleted file mode 100644
index 32dc33e..0000000
--- a/icclient/catalog.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef ICCLIENT_CATALOG_H
-#define ICCLIENT_CATALOG_H
-
-struct icclient_catalog {
- size_t length;
- struct icclient_product *products[];
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- void icclient_catalog_free(struct icclient_catalog *catalog);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/icclient/client.h b/icclient/client.h
index ae2a766..bcf8170 100644
--- a/icclient/client.h
+++ b/icclient/client.h
@@ -3,8 +3,24 @@
#define icclient_allproducts(callback, handler) icclient_results("All-Products", callback, handler)
-struct icclient_product;
-struct icclient_catalog;
+struct icclient_catalog {
+ size_t length;
+ struct icclient_product {
+ char *sku;
+ char *description;
+ char *comment;
+ char *thumb;
+ char *image;
+ double price;
+ char *prod_group;
+ double weight;
+ char *author;
+ struct icclient_product_crosssell {
+ size_t length;
+ char *skus[];
+ } *crosssell;
+ } *products[];
+};
#ifdef __cplusplus
extern "C" {
@@ -16,7 +32,7 @@ extern "C" {
* \param certificate Path to the CA certificate file.
* \return True if the initialisation works, false otherwise.
*/
-bool icclient_init(const char *url, const char *certificate);
+void icclient_init(const char *url, const char *certificate);
/*!
* \brief For fetching data about products that belong a specific group.
@@ -35,6 +51,11 @@ void icclient_results(const char *prod_group, void (*callback)(struct icclient_c
void icclient_flypage(const char *sku, icclient_handler handler, struct icclient_product **productptr);
void icclient_page(const char *path, icclient_handler handler, void **dataptr);
+
+void icclient_free_product(struct icclient_product *product);
+
+void icclient_free_catalog(struct icclient_catalog *catalog);
+
void icclient_cleanup();
#ifdef __cplusplus
diff --git a/icclient/product.h b/icclient/product.h
deleted file mode 100644
index 8fa6bc3..0000000
--- a/icclient/product.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef ICCLIENT_PRODUCT_H
-#define ICCLIENT_PRODUCT_H
-
-struct icclient_product_crosssell {
- size_t length;
- char *skus[];
-};
-
-struct icclient_product {
- char *sku;
- char *description;
- char *comment;
- char *thumb;
- char *image;
- double price;
- char *prod_group;
- double weight;
- char *author;
- struct icclient_product_crosssell *crosssell;
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- void icclient_product_free(struct icclient_product *product);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/product.c b/product.c
deleted file mode 100644
index 0323192..0000000
--- a/product.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdlib.h>
-#include "icclient/product.h"
-
-void icclient_product_free(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);
-}
diff --git a/request.c b/request.c
index 2bd95d5..75c3073 100644
--- a/request.c
+++ b/request.c
@@ -7,6 +7,6 @@ CURL *curl;
char *server_url;
#endif
-extern inline bool icclient_request_init(const char *, const char *);
+extern inline void icclient_request_init(const char *, const char *);
extern inline void request(icclient_handler, void *, struct icclient_request_data *, char *, ...);
extern inline void icclient_request_cleanup();
diff --git a/request.h b/request.h
index a43a44a..19ed118 100644
--- a/request.h
+++ b/request.h
@@ -4,11 +4,10 @@
#if defined __ANDROID__ && defined DEBUG
#include <android/log.h>
#endif
-#include <string.h>
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdbool.h>
+#include <stdarg.h>
+#include <string.h>
#ifndef __EMSCRIPTEN__
#include <curl/curl.h>
#endif
@@ -29,12 +28,11 @@ extern CURL *curl;
extern char *server_url;
#endif
-inline bool icclient_request_init(const char *url, const char *certificate)
+inline void icclient_request_init(const char *url, const char *certificate)
{
#ifdef __EMSCRIPTEN__
emscripten_fetch_attr_init(&attr);
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
- return true;
#else
curl_global_init(CURL_GLOBAL_SSL);
curl = curl_easy_init();
@@ -47,13 +45,12 @@ inline bool icclient_request_init(const char *url, const char *certificate)
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
size_t length = strlen(url);
- bool append = !(bool)(url[length - 1] == '/');
- server_url = malloc(length + (size_t)append + 1);
+ size_t append = !(url[length - 1] == '/');
+ server_url = malloc(length + append + 1);
strcpy(server_url, url);
if (append)
strcat(server_url, "/");
}
- return (bool)curl;
#endif
}