diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-25 10:20:12 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-25 10:20:12 +0800 |
commit | 7f934ce683df5252fa6350dcc15e187b1c7623cf (patch) | |
tree | f600fc0cdfc9f4397580e44044468858167d0aa9 | |
parent | a606c79d52d2027afaafd424a25fa6a4598aa8d7 (diff) |
Rename remaining icclient to interchange
-rw-r--r-- | Makefile.am | 12 | ||||
-rw-r--r-- | admin.c | 32 | ||||
-rw-r--r-- | icclient/admin.h | 39 | ||||
-rw-r--r-- | icclient/ord.h | 37 | ||||
-rw-r--r-- | interchange.c (renamed from client.c) | 22 | ||||
-rw-r--r-- | interchange.h (renamed from icclient.h) | 32 | ||||
-rw-r--r-- | interchange/admin.h | 39 | ||||
-rw-r--r-- | interchange/member.h (renamed from icclient/member.h) | 24 | ||||
-rw-r--r-- | interchange/ord.h | 37 | ||||
-rw-r--r-- | interchange/typedefs.h (renamed from icclient/typedefs.h) | 8 | ||||
-rw-r--r-- | login.c | 2 | ||||
-rw-r--r-- | login.h | 6 | ||||
-rw-r--r-- | main.c | 24 | ||||
-rw-r--r-- | member.c | 16 | ||||
-rw-r--r-- | ord.c | 60 | ||||
-rw-r--r-- | request.c | 12 | ||||
-rw-r--r-- | request.h | 4 |
17 files changed, 203 insertions, 203 deletions
diff --git a/Makefile.am b/Makefile.am index 625a358..19549fd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libinterchange.la libinterchange_la_SOURCES = \ - client.c \ + interchange.c \ request.c \ ord.c \ login.c \ @@ -18,9 +18,9 @@ if STRAP libinterchange_la_SOURCES += strap.c libinterchange_la_CPPFLAGS = $(libinterchange_la_CPPFLAGS) $(TIDY_CFLAGS) endif -include_HEADERS = icclient.h +include_HEADERS = interchange.h pkginclude_HEADERS = \ - icclient/typedefs.h \ - icclient/ord.h \ - icclient/member.h \ - icclient/admin.h + interchange/typedefs.h \ + interchange/ord.h \ + interchange/member.h \ + interchange/admin.h @@ -1,19 +1,19 @@ #include <stdlib.h> #include <stdbool.h> #include "login.h" -#include "icclient.h" -#include "icclient/member.h" -#include "icclient/ord.h" -#include "icclient/admin.h" +#include "interchange.h" +#include "interchange/member.h" +#include "interchange/ord.h" +#include "interchange/admin.h" -void icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_response *), - void (*callback)(struct icclient_admin *)) +void interchange_admin_login(const char *username, const char *password, void (*handler)(interchange_response *), + void (*callback)(struct interchange_admin *)) { login(username, password, NULL, "MMLogin", handler, (void (*)(void *))callback); } -void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super, - enum icclient_admin_group group, void (*handler)(icclient_response *)) +void interchange_admin_new_admin(const char *username, const char *password, const char *name, bool super, + enum interchange_admin_group group, void (*handler)(interchange_response *)) { request(handler, NULL, &(struct body){ 13, { { "mv_todo", "set" }, @@ -28,13 +28,13 @@ void icclient_admin_new_admin(const char *username, const char *password, const { "username", username }, { "password", password }, { "super", super ? "1" : "0" }, - { "groups", group == ICCLIENT_ADMIN_GROUP_CONTENT ? ":CONTENT" - : group == ICCLIENT_ADMIN_GROUP_MERCH ? ":MERCH" : ":ORDERS" } + { "groups", group == INTERCHANGE_ADMIN_GROUP_CONTENT ? ":CONTENT" + : group == INTERCHANGE_ADMIN_GROUP_MERCH ? ":MERCH" : ":ORDERS" } }}, "%s", "ui"); } -void icclient_admin_new_item(const char *description, const char *comment, const char *price, - const char *image_path, void (*handler)(icclient_response *)) +void interchange_admin_new_item(const char *description, const char *comment, const char *price, + const char *image_path, void (*handler)(interchange_response *)) { request(handler, NULL, &(struct body){ 15, { { "mv_click", "process_filter" }, @@ -63,9 +63,9 @@ void icclient_admin_new_item(const char *description, const char *comment, const }}, "%s", "admin/item_edit"); } -void icclient_admin_new_transaction(const struct icclient_ord_order *order, - const struct icclient_member *member, bool new_customer_id, - void (*handler)(icclient_response *)) +void interchange_admin_new_transaction(const struct interchange_ord_order *order, + const struct interchange_member *member, bool new_customer_id, + void (*handler)(interchange_response *)) { request(handler, NULL, &(struct body){ 12, { { "mv_values_space", "order_entry" }, @@ -83,7 +83,7 @@ void icclient_admin_new_transaction(const struct icclient_ord_order *order, }}, "%s", "process"); } -void icclient_admin_logout(struct icclient_admin *admin, void (*handler)(icclient_response *)) +void interchange_admin_logout(struct interchange_admin *admin, void (*handler)(interchange_response *)) { request(handler, NULL, NULL, "%s", "admin/login"); if (admin->name) diff --git a/icclient/admin.h b/icclient/admin.h deleted file mode 100644 index 08e4751..0000000 --- a/icclient/admin.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef ICCLIENT_ADMIN_H -#define ICCLIENT_ADMIN_H - -#include "typedefs.h" - -enum icclient_admin_group { - ICCLIENT_ADMIN_GROUP_CONTENT, - ICCLIENT_ADMIN_GROUP_MERCH, - ICCLIENT_ADMIN_GROUP_ORDERS -}; - -struct icclient_admin { - char *username; - char *password; - char *name; - bool super; - enum icclient_admin_group group; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -void icclient_admin_login(const char *username, const char *password, void (*handler)(icclient_response *), - void (*callback)(struct icclient_admin *)); -void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super, - enum icclient_admin_group group, void (*handler)(icclient_response *)); -void icclient_admin_new_item(const char *description, const char *comment, const char *price, - const char *image_path, void (*handler)(icclient_response *)); -void icclient_admin_new_transaction(const struct icclient_ord_order *order, - const struct icclient_member *member, bool new_customer_id, - void (*handler)(icclient_response *)); -void icclient_admin_logout(struct icclient_admin *admin, void (*handler)(icclient_response *)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/icclient/ord.h b/icclient/ord.h deleted file mode 100644 index eccc822..0000000 --- a/icclient/ord.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef ICCLIENT_ORD_H -#define ICCLIENT_ORD_H - -struct icclient_ord_item { - struct icclient_product *product; - unsigned int quantity; -}; - -struct icclient_ord_order { - double subtotal; - double shipping; - double total_cost; - char *profile; - size_t nitems; - struct icclient_ord_item *items[]; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/*! - * \brief For putting an item to a cart. - * \param sku The SKU of the item to order. - * \param catalog The catalog from which the item is. - * \param order The address of an order instance. - */ -void icclient_ord_order(const char *sku, const struct icclient_catalog *catalog, - struct icclient_ord_order **order); -void icclient_ord_checkout(const struct icclient_ord_order *order, const struct icclient_member *member); -void icclient_ord_free(struct icclient_ord_order *order); - -#ifdef __cplusplus -} -#endif - -#endif @@ -1,7 +1,7 @@ #include <stdlib.h> #include <string.h> #include "request.h" -#include "icclient.h" +#include "interchange.h" char *image_dir; #ifdef __EMSCRIPTEN__ @@ -11,9 +11,9 @@ char *sampleurl; char *cainfo = NULL; #endif -extern void handle_results(icclient_response *); +extern void handle_results(interchange_response *); -void icclient_init(const char *url, const char *dir, const char *certificate) +void interchange_init(const char *url, const char *dir, const char *certificate) { image_dir = malloc(strlen(dir) + 1); strcpy(image_dir, dir); @@ -35,7 +35,7 @@ void icclient_init(const char *url, const char *dir, const char *certificate) #endif } -void icclient_catalog(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *)) +void interchange_catalog(const char *prod_group, void (*handler)(interchange_response *), void (*callback)(struct interchange_catalog *)) { char nonspaced[strlen(prod_group) + 1]; strcpy(nonspaced, prod_group); @@ -45,17 +45,17 @@ void icclient_catalog(const char *prod_group, void (*handler)(icclient_response 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 *)) +void interchange_product(const char *sku, void (*handler)(interchange_response *), void (*callback)(struct interchange_product *)) { request(handler, (void (*)(void *))callback, NULL, "%s", sku); } -void icclient_page(const char *path, void (*handler)(icclient_response *)) +void interchange_page(const char *path, void (*handler)(interchange_response *)) { request(handler, NULL, NULL, "%s", path); } -void icclient_free_product(struct icclient_product *product) +void interchange_free_product(struct interchange_product *product) { if (product->crosssell) for (size_t i = 0; i < product->crosssell->length; i++) @@ -76,14 +76,14 @@ void icclient_free_product(struct icclient_product *product) free(product); } -void icclient_free_catalog(struct icclient_catalog *catalog) +void interchange_free_catalog(struct interchange_catalog *catalog) { for (size_t i = 0; i < catalog->length; i++) - icclient_free_product(catalog->products[i]); + interchange_free_product(catalog->products[i]); free(catalog); } -void icclient_free_response(icclient_response *response) +void interchange_free_response(interchange_response *response) { if (response->userData) free(response->userData); @@ -96,7 +96,7 @@ void icclient_free_response(icclient_response *response) #endif } -void icclient_cleanup() +void interchange_cleanup() { free(image_dir); #ifndef __EMSCRIPTEN__ diff --git a/icclient.h b/interchange.h index b962a24..91a2222 100644 --- a/icclient.h +++ b/interchange.h @@ -1,9 +1,9 @@ -#ifndef ICCLIENT_H -#define ICCLIENT_H +#ifndef INTERCHANGE_H +#define INTERCHANGE_H -#include "icclient/typedefs.h" +#include "interchange/typedefs.h" -struct icclient_product { +struct interchange_product { char *sku; char *description; char *comment; @@ -14,15 +14,15 @@ struct icclient_product { char *category; double weight; char *author; - struct icclient_product_crosssell { + struct interchange_product_crosssell { size_t length; char *skus[]; } *crosssell; }; -struct icclient_catalog { +struct interchange_catalog { size_t length; - struct icclient_product *products[]; + struct interchange_product *products[]; }; /*! @@ -30,7 +30,7 @@ struct icclient_catalog { * \param handler A pointer to the function when a custom handler is needed to arrange the data into the catalog. * \param callback A pointer to the function that needs to be called after the catalog is ready. */ -#define icclient_allproducts(handler, callback) icclient_catalog("All-Products", handler, callback) +#define interchange_allproducts(handler, callback) interchange_catalog("All-Products", handler, callback) #ifdef __cplusplus extern "C" { @@ -42,7 +42,7 @@ extern "C" { * \param image_dir The value of the IMAGE_DIR setting in products/variable.txt. * \param certificate Path to the CA certificate file. */ -void icclient_init(const char *sampleurl, const char *image_dir, const char *certificate); +void interchange_init(const char *sampleurl, const char *image_dir, const char *certificate); /*! * \brief For fetching data about products that belong a specific group. @@ -50,7 +50,7 @@ void icclient_init(const char *sampleurl, const char *image_dir, const char *cer * \param handler A pointer to the function when a custom handler is needed to arrange the data into the catalog. * \param callback A pointer to the function that needs to be called after the catalog is ready. */ -void icclient_catalog(const char *prod_group, void (*handler)(icclient_response *), void (*callback)(struct icclient_catalog *)); +void interchange_catalog(const char *prod_group, void (*handler)(interchange_response *), void (*callback)(struct interchange_catalog *)); /*! * \brief For fetching data about a specific product. @@ -58,17 +58,17 @@ void icclient_catalog(const char *prod_group, void (*handler)(icclient_response * \param handler A pointer to the function when a custom handler is needed to arrange the data into the product. * \param callback A pointer to the function that needs to be called after the product is ready. */ -void icclient_product(const char *sku, void (*handler)(icclient_response *), void (*callback)(struct icclient_product *)); +void interchange_product(const char *sku, void (*handler)(interchange_response *), void (*callback)(struct interchange_product *)); -void icclient_page(const char *path, void (*handler)(icclient_response *)); +void interchange_page(const char *path, void (*handler)(interchange_response *)); -void icclient_free_product(struct icclient_product *product); +void interchange_free_product(struct interchange_product *product); -void icclient_free_catalog(struct icclient_catalog *catalog); +void interchange_free_catalog(struct interchange_catalog *catalog); -void icclient_free_response(icclient_response *response); +void interchange_free_response(interchange_response *response); -void icclient_cleanup(); +void interchange_cleanup(); #ifdef __cplusplus } diff --git a/interchange/admin.h b/interchange/admin.h new file mode 100644 index 0000000..d0e47d7 --- /dev/null +++ b/interchange/admin.h @@ -0,0 +1,39 @@ +#ifndef INTERCHANGE_ADMIN_H +#define INTERCHANGE_ADMIN_H + +#include "typedefs.h" + +enum interchange_admin_group { + INTERCHANGE_ADMIN_GROUP_CONTENT, + INTERCHANGE_ADMIN_GROUP_MERCH, + INTERCHANGE_ADMIN_GROUP_ORDERS +}; + +struct interchange_admin { + char *username; + char *password; + char *name; + bool super; + enum interchange_admin_group group; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +void interchange_admin_login(const char *username, const char *password, void (*handler)(interchange_response *), + void (*callback)(struct interchange_admin *)); +void interchange_admin_new_admin(const char *username, const char *password, const char *name, bool super, + enum interchange_admin_group group, void (*handler)(interchange_response *)); +void interchange_admin_new_item(const char *description, const char *comment, const char *price, + const char *image_path, void (*handler)(interchange_response *)); +void interchange_admin_new_transaction(const struct interchange_ord_order *order, + const struct interchange_member *member, bool new_customer_id, + void (*handler)(interchange_response *)); +void interchange_admin_logout(struct interchange_admin *admin, void (*handler)(interchange_response *)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/icclient/member.h b/interchange/member.h index 6b9d2ee..0e9ca91 100644 --- a/icclient/member.h +++ b/interchange/member.h @@ -1,15 +1,15 @@ -#ifndef ICCLIENT_MEMBER_H -#define ICCLIENT_MEMBER_H +#ifndef INTERCHANGE_MEMBER_H +#define INTERCHANGE_MEMBER_H #include <stdbool.h> #include "typedefs.h" -struct icclient_member_preferences { +struct interchange_member_preferences { bool mv_same_billing; bool email_copy; }; -struct icclient_member { +struct interchange_member { char *username; char *usernick; char *password; @@ -47,7 +47,7 @@ struct icclient_member { char *phone_night; char *address_book; char *accounts; - struct icclient_member_preferences *preferences; + struct interchange_member_preferences *preferences; char *carts; char *owner; char *file_acl; @@ -63,14 +63,14 @@ struct icclient_member { extern "C" { #endif - void icclient_member_newaccount(const char *username, const char *password, const char *verify, - void (*handler)(icclient_response *), void (*callback)(struct icclient_member *)); - void icclient_member_login(const char *username, const char *password, void (*handler)(icclient_response *), - void (*callback)(struct icclient_member *)); - void icclient_member_account(const char *fname, const char *lname, const char *address1, const char *address2, + void interchange_member_newaccount(const char *username, const char *password, const char *verify, + void (*handler)(interchange_response *), void (*callback)(struct interchange_member *)); + void interchange_member_login(const char *username, const char *password, void (*handler)(interchange_response *), + void (*callback)(struct interchange_member *)); + void interchange_member_account(const char *fname, const char *lname, const char *address1, const char *address2, const char *city, const char *state, const char *zip, const char *email, const char *phone_day); - void icclient_member_changepassword(const char *password_old, const char *password, const char *verify); - void icclient_member_logout(struct icclient_member *member); + void interchange_member_changepassword(const char *password_old, const char *password, const char *verify); + void interchange_member_logout(struct interchange_member *member); #ifdef __cplusplus } diff --git a/interchange/ord.h b/interchange/ord.h new file mode 100644 index 0000000..c62bcf0 --- /dev/null +++ b/interchange/ord.h @@ -0,0 +1,37 @@ +#ifndef INTERCHANGE_ORD_H +#define INTERCHANGE_ORD_H + +struct interchange_ord_item { + struct interchange_product *product; + unsigned int quantity; +}; + +struct interchange_ord_order { + double subtotal; + double shipping; + double total_cost; + char *profile; + size_t nitems; + struct interchange_ord_item *items[]; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * \brief For putting an item to a cart. + * \param sku The SKU of the item to order. + * \param catalog The catalog from which the item is. + * \param order The address of an order instance. + */ +void interchange_ord_order(const char *sku, const struct interchange_catalog *catalog, + struct interchange_ord_order **order); +void interchange_ord_checkout(const struct interchange_ord_order *order, const struct interchange_member *member); +void interchange_ord_free(struct interchange_ord_order *order); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/icclient/typedefs.h b/interchange/typedefs.h index 4bb6dcc..02a412f 100644 --- a/icclient/typedefs.h +++ b/interchange/typedefs.h @@ -1,10 +1,10 @@ -#ifndef ICCLIENT_TYPEDEFS_H -#define ICCLIENT_TYPEDEFS_H +#ifndef INTERCHANGE_TYPEDEFS_H +#define INTERCHANGE_TYPEDEFS_H #include <stddef.h> #ifdef __EMSCRIPTEN__ #include <emscripten/fetch.h> -typedef emscripten_fetch_t icclient_response; +typedef emscripten_fetch_t interchange_response; #else #include <curl/curl.h> typedef struct { @@ -12,7 +12,7 @@ typedef struct { char *data; size_t numBytes; CURL *curl; -} icclient_response; +} interchange_response; #endif #endif @@ -1,3 +1,3 @@ #include "login.h" -extern inline void login(const char *, const char *, const char *, const char *, void (*)(icclient_response *), void (*)(void *)); +extern inline void login(const char *, const char *, const char *, const char *, void (*)(interchange_response *), void (*)(void *)); @@ -1,10 +1,10 @@ -#ifndef ICCLIENT_LOGIN_H -#define ICCLIENT_LOGIN_H +#ifndef INTERCHANGE_LOGIN_H +#define INTERCHANGE_LOGIN_H #include "request.h" static inline void login(const char *username, const char *password, const char *verify, const char *click, - void (*handler)(icclient_response *), void (*callback)(void *)) + void (*handler)(interchange_response *), void (*callback)(void *)) { request(handler, callback, &(struct body){ 4, { { "mv_username", username }, @@ -2,14 +2,14 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> -#include "icclient.h" -#include "icclient/member.h" -#include "icclient/admin.h" +#include "interchange.h" +#include "interchange/member.h" +#include "interchange/admin.h" -static void print_catalog(struct icclient_catalog *catalog) +static void print_catalog(struct interchange_catalog *catalog) { for (size_t i = 0; i < catalog->length; i++) { - struct icclient_product *product = catalog->products[i]; + struct interchange_product *product = catalog->products[i]; printf("sku: %s | " "desc: %s | " "img: %s | " @@ -22,19 +22,19 @@ static void print_catalog(struct icclient_catalog *catalog) product->category ); } - icclient_free_catalog(catalog); + interchange_free_catalog(catalog); } -static void print(icclient_response *response) +static void print(interchange_response *response) { printf("%s\n", response->data); } int main(int argc, char *argv[]) { - icclient_init("https://demo.interchangecommerce.org/i/demo", "/demo/images", NULL); - icclient_allproducts(NULL, print_catalog); - icclient_admin_login("demo", "demo", print, NULL); - icclient_member_login("kirk@icdevgroup.net", "kirk", print, NULL); - icclient_cleanup(); + interchange_init("https://demo.interchangecommerce.org/i/demo", "/demo/images", NULL); + interchange_allproducts(NULL, print_catalog); + interchange_admin_login("demo", "demo", print, NULL); + interchange_member_login("kirk@icdevgroup.net", "kirk", print, NULL); + interchange_cleanup(); } @@ -1,20 +1,20 @@ #include <stdlib.h> #include "login.h" -#include "icclient/member.h" +#include "interchange/member.h" -void icclient_member_newaccount(const char *username, const char *password, const char *verify, - void (*handler)(icclient_response *), void (*callback)(struct icclient_member *)) +void interchange_member_newaccount(const char *username, const char *password, const char *verify, + void (*handler)(interchange_response *), void (*callback)(struct interchange_member *)) { login(username, password, verify, "NewAccount", handler, (void (*)(void *))callback); } -void icclient_member_login(const char *username, const char *password, void (*handler)(icclient_response *), - void (*callback)(struct icclient_member *)) +void interchange_member_login(const char *username, const char *password, void (*handler)(interchange_response *), + void (*callback)(struct interchange_member *)) { login(username, password, NULL, "Login", handler, (void (*)(void *))callback); } -void icclient_member_account(const char *fname, const char *lname, const char *address1, +void interchange_member_account(const char *fname, const char *lname, const char *address1, const char *address2, const char *city, const char *state, const char *zip, const char *email, const char *phone_day) { @@ -35,7 +35,7 @@ void icclient_member_account(const char *fname, const char *lname, const char *a }}, "%s", "process"); } -void icclient_member_changepassword(const char *password_old, const char *password, const char *verify) +void interchange_member_changepassword(const char *password_old, const char *password, const char *verify) { request(NULL, NULL, &(struct body){ 6, { { "mv_action", "return" }, @@ -47,7 +47,7 @@ void icclient_member_changepassword(const char *password_old, const char *passwo }}, "%s", "member/change_password"); } -void icclient_member_logout(struct icclient_member *member) +void interchange_member_logout(struct interchange_member *member) { request(NULL, NULL, NULL, "%s", "logout"); if (member->username) @@ -1,56 +1,56 @@ #include <stdlib.h> #include <string.h> #include "request.h" -#include "icclient.h" -#include "icclient/member.h" -#include "icclient/ord.h" +#include "interchange.h" +#include "interchange/member.h" +#include "interchange/ord.h" static int prodcmp(const void *product1, const void *product2) { - return strcmp((*(struct icclient_product * const *)product1)->sku, - (*(struct icclient_product * const *)product2)->sku); + return strcmp((*(struct interchange_product * const *)product1)->sku, + (*(struct interchange_product * const *)product2)->sku); } static int itemcmp(const void *item1, const void *item2) { - return strcmp((*(struct icclient_ord_item * const *)item1)->product->sku, - (*(struct icclient_ord_item * const *)item2)->product->sku); + return strcmp((*(struct interchange_ord_item * const *)item1)->product->sku, + (*(struct interchange_ord_item * const *)item2)->product->sku); } -void icclient_ord_order(const char *sku, const struct icclient_catalog *catalog, - struct icclient_ord_order **order) +void interchange_ord_order(const char *sku, const struct interchange_catalog *catalog, + struct interchange_ord_order **order) { - struct icclient_product **products = ((struct icclient_catalog *)catalog)->products; - qsort(products, catalog->length, sizeof(struct icclient_product *), prodcmp); - struct icclient_product *key_product = malloc(sizeof(struct icclient_product)); - memset(key_product, '\0', sizeof(struct icclient_product)); + struct interchange_product **products = ((struct interchange_catalog *)catalog)->products; + qsort(products, catalog->length, sizeof(struct interchange_product *), prodcmp); + struct interchange_product *key_product = malloc(sizeof(struct interchange_product)); + memset(key_product, '\0', sizeof(struct interchange_product)); key_product->sku = malloc(strlen(sku) + 1); strcpy(key_product->sku, sku); - struct icclient_product *product = *(struct icclient_product **)bsearch(&key_product, products, - catalog->length, sizeof(struct icclient_product *), prodcmp); - icclient_free_product(key_product); - struct icclient_ord_item *item = NULL; + struct interchange_product *product = *(struct interchange_product **)bsearch(&key_product, products, + catalog->length, sizeof(struct interchange_product *), prodcmp); + interchange_free_product(key_product); + struct interchange_ord_item *item = NULL; if (*order) { - struct icclient_ord_item **items = (*order)->items; - qsort(items, (*order)->nitems, sizeof(struct icclient_ord_item *), itemcmp); - struct icclient_ord_item *key_item = malloc(sizeof(struct icclient_ord_item)); + struct interchange_ord_item **items = (*order)->items; + qsort(items, (*order)->nitems, sizeof(struct interchange_ord_item *), itemcmp); + struct interchange_ord_item *key_item = malloc(sizeof(struct interchange_ord_item)); key_item->product = product; - struct icclient_ord_item **itemptr = bsearch(&key_item, items, (*order)->nitems, - sizeof(struct icclient_ord_item *), itemcmp); + struct interchange_ord_item **itemptr = bsearch(&key_item, items, (*order)->nitems, + sizeof(struct interchange_ord_item *), itemcmp); if (itemptr) item = *itemptr; free(key_item); } else { - *order = malloc(sizeof(struct icclient_ord_order)); - memset(*order, '\0', sizeof(struct icclient_ord_order)); + *order = malloc(sizeof(struct interchange_ord_order)); + memset(*order, '\0', sizeof(struct interchange_ord_order)); } if (item) item->quantity++; else { size_t i = (*order)->nitems; - *order = realloc(*order, sizeof(struct icclient_ord_order) + (i + 1) - * sizeof(struct icclient_ord_item)); - (*order)->items[i] = malloc(sizeof(struct icclient_ord_item)); + *order = realloc(*order, sizeof(struct interchange_ord_order) + (i + 1) + * sizeof(struct interchange_ord_item)); + (*order)->items[i] = malloc(sizeof(struct interchange_ord_item)); (*order)->nitems++; item = (*order)->items[i]; item->product = product; @@ -61,7 +61,7 @@ void icclient_ord_order(const char *sku, const struct icclient_catalog *catalog, request(NULL, NULL, NULL, "%s%s", "order?mv_arg=", sku); } -void icclient_ord_checkout(const struct icclient_ord_order *order, const struct icclient_member *member) +void interchange_ord_checkout(const struct interchange_ord_order *order, const struct interchange_member *member) { request(NULL, NULL, &(struct body){ 14, { { "mv_todo", "submit" }, @@ -81,8 +81,8 @@ void icclient_ord_checkout(const struct icclient_ord_order *order, const struct }}, "%s", "ord/checkout"); } -void icclient_ord_free(struct icclient_ord_order *order) +void interchange_ord_free(struct interchange_ord_order *order) { for (size_t i = 0; i < order->nitems; i++) - icclient_free_product(order->items[i]->product); + interchange_free_product(order->items[i]->product); } @@ -26,11 +26,11 @@ extern char *cainfo; struct container { struct curl_httppost *post; - void (*handler)(icclient_response *); - icclient_response *response; + void (*handler)(interchange_response *); + interchange_response *response; }; -static size_t append(char *data, size_t size, size_t nmemb, icclient_response *response) +static size_t append(char *data, size_t size, size_t nmemb, interchange_response *response) { size_t realsize = size * nmemb; response->data = realloc(response->data, response->numBytes + realsize + 1); @@ -64,7 +64,7 @@ async(void *arg) #ifdef DEBUG const char *error = curl_easy_strerror(res); #ifdef __ANDROID__ - __android_log_print(ANDROID_LOG_ERROR, "libicclient.so", "%s", error); + __android_log_print(ANDROID_LOG_ERROR, "libinterchange.so", "%s", error); #else fprintf(stderr, "%s\n", error); #endif @@ -79,7 +79,7 @@ async(void *arg) } #endif -void request(void (*handler)(icclient_response *), void (*callback)(void *), struct body *body, char *fmt, ...) +void request(void (*handler)(interchange_response *), void (*callback)(void *), struct body *body, char *fmt, ...) { va_list ap; char *p, *sval; @@ -177,7 +177,7 @@ void request(void (*handler)(icclient_response *), void (*callback)(void *), str #endif curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append); - icclient_response *response = malloc(sizeof(icclient_response)); + interchange_response *response = malloc(sizeof(interchange_response)); response->data = malloc(1); response->numBytes = 0; response->userData = callback; @@ -1,7 +1,7 @@ #ifndef REQUEST_H #define REQUEST_H -#include "icclient/typedefs.h" +#include "interchange/typedefs.h" struct body { size_t num_pairs; @@ -11,6 +11,6 @@ struct body { } pairs[16]; }; -void request(void (*)(icclient_response *), void (*)(void *), struct body *, char *, ...); +void request(void (*)(interchange_response *), void (*)(void *), struct body *, char *, ...); #endif |