summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--client.c22
-rw-r--r--icclient/catalog.h9
-rw-r--r--icclient/client.h3
-rw-r--r--icclient/product.h20
-rw-r--r--product.c19
6 files changed, 41 insertions, 38 deletions
diff --git a/Makefile.am b/Makefile.am
index 35121d3..2240f39 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,15 +1,15 @@
noinst_LIBRARIES = libicclient.a
libicclient_a_SOURCES = \
- icclient/request.h \
- icclient/login.h \
icclient/product.h \
+ icclient/catalog.h \
icclient/ord.h \
icclient/member.h \
icclient/admin.h \
icclient/client.h \
+ request.h \
request.c \
+ login.h \
login.c \
- product.c \
member.c \
admin.c \
client.c
diff --git a/client.c b/client.c
index 56dbf79..94de4c9 100644
--- a/client.c
+++ b/client.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include "login.h"
#include "icclient/product.h"
+#include "icclient/catalog.h"
#include "icclient/client.h"
typedef struct icclient_catalog icclient_catalog;
@@ -65,6 +66,27 @@ void icclient_page(const char *path, size_t (*handler)(void *, size_t, size_t
request(handler, (void *)dataptr, NULL, "%s", path);
}
+void icclient_freeproduct(struct icclient_product *product)
+{
+ if (product->image)
+ free(product->image);
+ 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]);
+ free(catalog);
+ catalog = NULL;
+}
+
void icclient_cleanup()
{
if (curl) {
diff --git a/icclient/catalog.h b/icclient/catalog.h
new file mode 100644
index 0000000..b38434b
--- /dev/null
+++ b/icclient/catalog.h
@@ -0,0 +1,9 @@
+#ifndef ICCLIENT_CATALOG_H
+#define ICCLIENT_CATALOG_H
+
+struct icclient_catalog {
+ size_t length;
+ struct icclient_product *products[];
+};
+
+#endif // ICCLIENT_CATALOG_H
diff --git a/icclient/client.h b/icclient/client.h
index 053eee5..e49af36 100644
--- a/icclient/client.h
+++ b/icclient/client.h
@@ -1,6 +1,7 @@
#ifndef ICCLIENT_CLIENT_H
#define ICCLIENT_CLIENT_H
+struct icclient_product;
struct icclient_catalog;
#ifdef __cplusplus
@@ -22,6 +23,8 @@ 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();
#ifdef __cplusplus
diff --git a/icclient/product.h b/icclient/product.h
index 0b0e509..4e879e0 100644
--- a/icclient/product.h
+++ b/icclient/product.h
@@ -2,23 +2,11 @@
#define ICCLIENT_PRODUCT_H
struct icclient_product {
- char *sku, *description, *comment, *image;
+ char *sku;
+ char *description;
+ char *comment;
+ char *image;
double price;
};
-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 // ICCLIENT_PRODUCT_H
diff --git a/product.c b/product.c
deleted file mode 100644
index 33286cd..0000000
--- a/product.c
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <stdlib.h>
-#include "icclient/product.h"
-
-void icclient_catalog_free(struct icclient_catalog *catalog)
-{
- for (size_t i = 0; i < catalog->length; i++) {
- struct icclient_product *product = catalog->products[i];
- if (product->image)
- free(product->image);
- if (product->comment)
- free(product->comment);
- if (product->description)
- free(product->description);
- free(product->sku);
- free(product);
- }
- free(catalog);
- catalog = NULL;
-}