summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--icclient/product.h27
-rw-r--r--icclient/request.h50
-rw-r--r--product.c23
-rw-r--r--request.c4
5 files changed, 108 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 942a013..dd8ee02 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,8 @@
noinst_LIBRARIES = libicclient.a
libicclient_a_SOURCES = \
+ icclient/request.h \
+ icclient/product.h \
icclient/client.h \
+ request.c \
+ product.c \
client.c
diff --git a/icclient/product.h b/icclient/product.h
new file mode 100644
index 0000000..f912b17
--- /dev/null
+++ b/icclient/product.h
@@ -0,0 +1,27 @@
+#ifndef ICCLIENT_PRODUCT_H
+#define ICCLIENT_PRODUCT_H
+
+struct ic_product {
+ char *sku, *description, *comment, *image;
+ double price;
+};
+
+struct ic_catalog {
+ unsigned int length;
+ struct ic_product *products[];
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void icclient_product_all(struct ic_catalog **catalogptr
+ , size_t (*callback)(void *contents, size_t size
+ , size_t nmemb, void *userdata));
+ void rtclient_product_freecatalog(struct ic_catalog *catalog);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ICCLIENT_PRODUCT_H
diff --git a/icclient/request.h b/icclient/request.h
new file mode 100644
index 0000000..192a154
--- /dev/null
+++ b/icclient/request.h
@@ -0,0 +1,50 @@
+#ifndef ICCLIENT_REQUEST_H
+#define ICCLIENT_REQUEST_H
+
+#ifdef DEBUG
+#ifdef ANDROID
+#include <android/log.h>
+#else
+#include <stdio.h>
+#endif // ANDROID
+#endif // DEBUG
+#include <string.h>
+#include <curl/curl.h>
+
+extern CURL *curl;
+extern char *server_url;
+
+inline void request(const char *path
+ , size_t (*writefunction)(void *, size_t, size_t, void *)
+ , void *writedata, struct curl_httppost *post)
+{
+ char url[strlen(server_url) + strlen(path) + 1];
+ sprintf(url, "%s%s", server_url, path);
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction);
+ if (writedata)
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, writedata);
+ else
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
+ if (post)
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
+ else
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
+
+#ifdef DEBUG
+ CURLcode res =
+#endif // DEBUG
+ curl_easy_perform(curl);
+#ifdef DEBUG
+ if (res != CURLE_OK) {
+ const char *error = curl_easy_strerror(res);
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_ERROR, "libicclient", "%s: %s"
+ , __func__, error);
+#else
+ fprintf(stderr, "%s: %s\n", __func__, error);
+#endif // ANDROID
+ }
+#endif // DEBUG
+}
+#endif // ICCLIENT_REQUEST_H
diff --git a/product.c b/product.c
new file mode 100644
index 0000000..d5d9bbe
--- /dev/null
+++ b/product.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include "icclient/request.h"
+#include "icclient/product.h"
+
+void icclient_product_all(struct ic_catalog **catalogptr
+ , size_t (*callback)(void *, size_t, size_t, void *))
+{
+ request("All-Products", callback, (void *)catalogptr, NULL);
+}
+
+void rtclient_product_freecatalog(struct ic_catalog *catalog)
+{
+ for (unsigned short i = 0; i < catalog->length; i++) {
+ struct ic_product *product = catalog->products[i];
+ free(product->image);
+ free(product->comment);
+ free(product->description);
+ free(product->sku);
+ free(product);
+ }
+ free(catalog);
+ catalog = NULL;
+}
diff --git a/request.c b/request.c
new file mode 100644
index 0000000..1aae970
--- /dev/null
+++ b/request.c
@@ -0,0 +1,4 @@
+#include "icclient/request.h"
+
+extern inline void request(const char *, size_t (*)(void *, size_t, size_t, void *)
+ , void *, struct curl_httppost *);