summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-25 10:20:12 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-25 10:20:12 +0800
commit7f934ce683df5252fa6350dcc15e187b1c7623cf (patch)
treef600fc0cdfc9f4397580e44044468858167d0aa9 /client.c
parenta606c79d52d2027afaafd424a25fa6a4598aa8d7 (diff)
Rename remaining icclient to interchange
Diffstat (limited to 'client.c')
-rw-r--r--client.c107
1 files changed, 0 insertions, 107 deletions
diff --git a/client.c b/client.c
deleted file mode 100644
index d7c8f70..0000000
--- a/client.c
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "request.h"
-#include "icclient.h"
-
-char *image_dir;
-#ifdef __EMSCRIPTEN__
-emscripten_fetch_attr_t attr;
-#else
-char *sampleurl;
-char *cainfo = NULL;
-#endif
-
-extern void handle_results(icclient_response *);
-
-void icclient_init(const char *url, const char *dir, const char *certificate)
-{
- image_dir = malloc(strlen(dir) + 1);
- strcpy(image_dir, dir);
-#ifdef __EMSCRIPTEN__
- emscripten_fetch_attr_init(&attr);
- attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
-#else
- size_t length = strlen(url);
- size_t append = url[length - 1] != '/';
- sampleurl = malloc(length + append + 1);
- strcpy(sampleurl, url);
- if (append)
- strcat(sampleurl, "/");
- curl_global_init(CURL_GLOBAL_SSL);
- if (certificate) {
- cainfo = malloc(strlen(certificate) + 1);
- strcpy(cainfo, certificate);
- }
-#endif
-}
-
-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 (*)(void *))callback, NULL, "%s", nonspaced);
-}
-
-void icclient_product(const char *sku, void (*handler)(icclient_response *), void (*callback)(struct icclient_product *))
-{
- request(handler, (void (*)(void *))callback, NULL, "%s", sku);
-}
-
-void icclient_page(const char *path, void (*handler)(icclient_response *))
-{
- request(handler, NULL, NULL, "%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_free_response(icclient_response *response)
-{
- if (response->userData)
- free(response->userData);
-#ifdef __EMSCRIPTEN__
- emscripten_fetch_close(response);
-#else
- free(response->data);
- curl_easy_cleanup(response->curl);
- free(response);
-#endif
-}
-
-void icclient_cleanup()
-{
- free(image_dir);
-#ifndef __EMSCRIPTEN__
- free(cainfo);
- free(sampleurl);
- curl_global_cleanup();
-#endif
-}