From 0a6e2943843ca894abc562ba98bcbf3399769481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sun, 13 Jun 2021 08:20:19 +0800 Subject: Remove non default handler --- Makefile.am | 10 ++------ catalog.c | 75 ------------------------------------------------------------ client.c | 2 +- configure.ac | 1 - 4 files changed, 3 insertions(+), 85 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1f34163..49507c4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,11 +10,11 @@ libicclient_la_SOURCES = \ login.c \ member.c \ admin.c -libicclient_la_CPPFLAGS = -I${prefix}/include $(DEPS_CFLAGS) +libicclient_la_CPPFLAGS = -I${prefix}/include if WASM libicclient_la_LDFLAGS = -static else -libicclient_la_LDFLAGS = $(DEPS_LIBS) -lcurl +libicclient_la_LDFLAGS = -lcurl endif if IOS libicclient_la_LDFLAGS += -static @@ -27,9 +27,3 @@ pkginclude_HEADERS = \ icclient/ord.h \ icclient/member.h \ icclient/admin.h -#if !WASM -#bin_PROGRAMS = icclient -#icclient_SOURCES = main.c client.c catalog.c product.c request.c ord.c login.c member.c admin.c -#icclient_CPPFLAGS = -I${prefix}/include $(DEPS_CFLAGS) -#icclient_LDFLAGS = $(DEPS_LIBS) -lcurl -#endif diff --git a/catalog.c b/catalog.c index 92dce73..6faf0eb 100644 --- a/catalog.c +++ b/catalog.c @@ -1,81 +1,6 @@ -#include #include -#include -#include #include "icclient/product.h" #include "icclient/catalog.h" -#ifdef __EMSCRIPTEN__ -#include -#define ICCLIENT_HANDLER_REALSIZE fetch->numBytes -#define ICCLIENT_HANDLER_RETURN -#define ICCLIENT_HANDLER_STRUCT fetch-> -#else -#define ICCLIENT_HANDLER_REALSIZE size * nmemb -#define ICCLIENT_HANDLER_RETURN realsize -#define ICCLIENT_HANDLER_STRUCT -#endif - -#ifdef __EMSCRIPTEN__ -void icclient_catalog_results(emscripten_fetch_t *fetch) -#else -size_t icclient_catalog_results(void *data, size_t size, size_t nmemb, void *userData) -#endif -{ - size_t realsize = ICCLIENT_HANDLER_REALSIZE; - json_tokener *tokener = json_tokener_new(); - json_object *products = json_tokener_parse_ex(tokener, ICCLIENT_HANDLER_STRUCT data, realsize); - enum json_tokener_error error = json_tokener_get_error(tokener); - if (!products) { - if (error == json_tokener_continue) - return ICCLIENT_HANDLER_RETURN; - else { - json_tokener_reset(tokener); - return ICCLIENT_HANDLER_RETURN; - } - } else if (!json_object_is_type(products, json_type_array) || error != json_tokener_success) - return ICCLIENT_HANDLER_RETURN; - json_tokener_free(tokener); - size_t length = json_object_array_length(products); - struct icclient_catalog *catalog = malloc(sizeof(struct icclient_catalog) + sizeof(struct icclient_product *[length])); - catalog->length = length; - for (size_t i = 0; i < length; i++) { - catalog->products[i] = malloc(sizeof(struct icclient_product)); - struct icclient_product *product = catalog->products[i]; - memset(product, '\0', sizeof(struct icclient_product)); - json_object *object = json_object_array_get_idx(products, i); - struct json_object_iterator iterator = json_object_iter_begin(object); - struct json_object_iterator iterator_end = json_object_iter_end(object); - while (!json_object_iter_equal(&iterator, &iterator_end)) { - const char *key = json_object_iter_peek_name(&iterator); - json_object *val = json_object_iter_peek_value(&iterator); - if (!strcmp(key, "price")) - product->price = json_object_get_double(val); - else { - int len = json_object_get_string_len(val); - if (len) { - char *value = malloc(len + 1); - strcpy(value, json_object_get_string(val)); - if (!strcmp(key, "sku")) - product->sku = value; - else if (!strcmp(key, "thumb")) - product->thumb = value; - else if (!strcmp(key, "image")) - product->image = value; - else if (!strcmp(key, "description")) - product->description = value; - else if (!strcmp(key, "prod_group")) - product->prod_group = value; - } - } - json_object_iter_next(&iterator); - } - } - ((void (*)(struct icclient_catalog *))ICCLIENT_HANDLER_STRUCT userData)(catalog); -#ifdef __EMSCRIPTEN__ - emscripten_fetch_close(fetch); -#endif - return ICCLIENT_HANDLER_RETURN; -} void icclient_catalog_free(struct icclient_catalog *catalog) { diff --git a/client.c b/client.c index d693996..a5b45e0 100644 --- a/client.c +++ b/client.c @@ -23,7 +23,7 @@ void icclient_results(const char *prod_group, void (*callback)(struct icclient_c char *space = NULL; while ((space = strchr(nonspaced, ' '))) *space = '-'; - request(handler ? handler : icclient_catalog_results, (void *)callback, 0, "%s", nonspaced); + request(handler, (void *)callback, 0, "%s", nonspaced); } void icclient_flypage(const char *sku, icclient_handler handler, struct icclient_product **productptr) diff --git a/configure.ac b/configure.ac index 1758af6..91d0b6d 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,6 @@ AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) -PKG_CHECK_MODULES([DEPS], [json-c]) AC_CHECK_HEADER_STDBOOL AC_C_INLINE AC_CHECK_FUNCS([memset]) -- cgit v1.2.3