From 7e15b32baaf737d28e0086b516b9ed307ab3f0c5 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: Fri, 16 Jul 2021 10:44:12 +0800 Subject: No need for shipping to be passed as pointer when it needs to be global anyway. --- pikul.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index 1ccf717..f410006 100644 --- a/pikul.c +++ b/pikul.c @@ -3,14 +3,14 @@ CURL *curl; json_tokener *tokener; -static struct shipping shipping; +struct shipping shipping; -extern inline void headers(const char *[], char *[], struct shipping *); +extern inline void headers(const char *[], char *[]); extern inline void handle_services(const char *, size_t, const char *[], const char *[], const char *[], struct pikul_services **); -extern void anteraja_init(char *[], struct shipping *); -extern void anteraja_services(const char *, const char *, double, struct shipping *, char **, char **); +extern void anteraja_init(char *[]); +extern void anteraja_services(const char *, const char *, double, char **, char **); extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); void pikul_init(enum pikul_company company, char *provisions[]) @@ -23,7 +23,7 @@ void pikul_init(enum pikul_company company, char *provisions[]) shipping.company = company; switch (company) { case PIKUL_ANTERAJA: - anteraja_init(provisions, &shipping); + anteraja_init(provisions); break; default: break; @@ -51,7 +51,7 @@ struct pikul_services *pikul_services(const char *origin, const char *destinatio size_t (*handler)(const char *, size_t, size_t, struct pikul_services **); switch (shipping.company) { case PIKUL_ANTERAJA: - anteraja_services(origin, destination, weight, &shipping, &url, &post); + anteraja_services(origin, destination, weight, &url, &post); handler = anteraja_services_handle; break; default: -- cgit v1.2.3 From 920878096a1721fd6e0c1b7008abac51803c5aa4 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: Fri, 16 Jul 2021 10:51:24 +0800 Subject: Generalise the response handler so the common part gets to be reused. --- pikul.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index f410006..5dd0750 100644 --- a/pikul.c +++ b/pikul.c @@ -6,8 +6,8 @@ json_tokener *tokener; struct shipping shipping; extern inline void headers(const char *[], char *[]); -extern inline void handle_services(const char *, size_t, const char *[], const char *[], const char *[], - struct pikul_services **); +extern inline void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], + void *); extern void anteraja_init(char *[]); extern void anteraja_services(const char *, const char *, double, char **, char **); -- cgit v1.2.3 From 6f78942176d5909349305db37b5424a1c6ceccef 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: Fri, 16 Jul 2021 11:02:02 +0800 Subject: Order functionality draft Not tested yet. Now the item object is still flattened as an array, initially to hurry the interfacing with the Perl module. But we were stuck with having to typemap char *** anyway, so we switch to SWIG because of the potential of ease. Still, we need to typemap char ***, but now that we're at SWIG, we might as well typemap a custom item struct. --- pikul.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index 5dd0750..d299cbe 100644 --- a/pikul.c +++ b/pikul.c @@ -4,6 +4,7 @@ CURL *curl; json_tokener *tokener; struct shipping shipping; +static char *waybill = NULL; extern inline void headers(const char *[], char *[]); extern inline void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], @@ -12,6 +13,11 @@ extern inline void handle(enum type, const char *, size_t, const char *[], const extern void anteraja_init(char *[]); extern void anteraja_services(const char *, const char *, double, char **, char **); extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); +extern void anteraja_order(const char *, const char *, const char *, const char *, const char *, + const char *, const char *, const char *, const char *, const char *, int, + char **[], double, char **, char **); +extern size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); +extern void anteraja_cleanup(); void pikul_init(enum pikul_company company, char *provisions[]) { @@ -106,8 +112,45 @@ double pikul_cost(const char *origin, const char *destination, double weight, co return cost; } +char *pikul_order(const char *trx_id, const char *service, const char *sender_name, + const char *sender_phone, const char *origin, const char *sender_address, + const char *receiver_name, const char *receiver_phone, const char *destination, + const char *receiver_address, int nitems, char **items[], double subtotal) +{ + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &waybill); + char *url; + char *post = NULL; + size_t (*handler)(const char *, size_t, size_t, char **); + switch (shipping.company) { + case PIKUL_ANTERAJA: + anteraja_order(trx_id, service, sender_name, sender_phone, origin, sender_address, + receiver_name, receiver_phone, destination, receiver_address, + nitems, items, subtotal, &url, &post); + handler = anteraja_order_handle; + break; + default: + break; + } + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handler); + curl_easy_perform(curl); + if (post) + free(post); + free(url); + return waybill; +} + void pikul_cleanup() { + switch (shipping.company) { + case PIKUL_ANTERAJA: + anteraja_cleanup(); + break; + default: + break; + } + if (waybill) + free(waybill); free(shipping.base); json_tokener_free(tokener); curl_slist_free_all(shipping.headers); -- cgit v1.2.3 From 4482f46ee073110c7c52d73bc8a8006437eba6f2 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: Fri, 16 Jul 2021 23:02:24 +0800 Subject: use_insurance turns out to be required This one follows the example given for the boolean JSON value, which is written as true or false. The response is error 500, internal server error. Despite the example, it says max length is 1 in the middle part of the doc, so maybe it should be written as 1 or 0. Will be tried next. --- pikul.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index d299cbe..a08b101 100644 --- a/pikul.c +++ b/pikul.c @@ -15,7 +15,7 @@ extern void anteraja_services(const char *, const char *, double, char **, char extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); extern void anteraja_order(const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, int, - char **[], double, char **, char **); + char **[], _Bool, double, char **, char **); extern size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); extern void anteraja_cleanup(); @@ -115,7 +115,7 @@ double pikul_cost(const char *origin, const char *destination, double weight, co char *pikul_order(const char *trx_id, const char *service, const char *sender_name, const char *sender_phone, const char *origin, const char *sender_address, const char *receiver_name, const char *receiver_phone, const char *destination, - const char *receiver_address, int nitems, char **items[], double subtotal) + const char *receiver_address, int nitems, char **items[], _Bool insurance, double subtotal) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &waybill); char *url; @@ -125,7 +125,7 @@ char *pikul_order(const char *trx_id, const char *service, const char *sender_na case PIKUL_ANTERAJA: anteraja_order(trx_id, service, sender_name, sender_phone, origin, sender_address, receiver_name, receiver_phone, destination, receiver_address, - nitems, items, subtotal, &url, &post); + nitems, items, insurance, subtotal, &url, &post); handler = anteraja_order_handle; break; default: -- cgit v1.2.3 From dfa57092e26c242c2ab64dc1d029e5dff44eee67 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: Sat, 17 Jul 2021 11:05:19 +0800 Subject: Rename trx_id to order_number --- pikul.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index a08b101..5f04136 100644 --- a/pikul.c +++ b/pikul.c @@ -112,7 +112,7 @@ double pikul_cost(const char *origin, const char *destination, double weight, co return cost; } -char *pikul_order(const char *trx_id, const char *service, const char *sender_name, +char *pikul_order(const char *order_number, const char *service, const char *sender_name, const char *sender_phone, const char *origin, const char *sender_address, const char *receiver_name, const char *receiver_phone, const char *destination, const char *receiver_address, int nitems, char **items[], _Bool insurance, double subtotal) @@ -123,9 +123,9 @@ char *pikul_order(const char *trx_id, const char *service, const char *sender_na size_t (*handler)(const char *, size_t, size_t, char **); switch (shipping.company) { case PIKUL_ANTERAJA: - anteraja_order(trx_id, service, sender_name, sender_phone, origin, sender_address, - receiver_name, receiver_phone, destination, receiver_address, - nitems, items, insurance, subtotal, &url, &post); + anteraja_order(order_number, service, sender_name, sender_phone, origin, + sender_address, receiver_name, receiver_phone, destination, + receiver_address, nitems, items, insurance, subtotal, &url, &post); handler = anteraja_order_handle; break; default: -- cgit v1.2.3 From b999dd2f128bcf209c62d3419a559e70222e7b04 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: Sat, 17 Jul 2021 15:29:20 +0800 Subject: Postal codes for both sender & receiver --- pikul.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index 5f04136..cb74feb 100644 --- a/pikul.c +++ b/pikul.c @@ -14,8 +14,8 @@ extern void anteraja_init(char *[]); extern void anteraja_services(const char *, const char *, double, char **, char **); extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); extern void anteraja_order(const char *, const char *, const char *, const char *, const char *, - const char *, const char *, const char *, const char *, const char *, int, - char **[], _Bool, double, char **, char **); + const char *, const char *, const char *, const char *, const char *, const char *, + const char *, int, char **[], _Bool, double, char **, char **); extern size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); extern void anteraja_cleanup(); @@ -114,8 +114,9 @@ double pikul_cost(const char *origin, const char *destination, double weight, co char *pikul_order(const char *order_number, const char *service, const char *sender_name, const char *sender_phone, const char *origin, const char *sender_address, - const char *receiver_name, const char *receiver_phone, const char *destination, - const char *receiver_address, int nitems, char **items[], _Bool insurance, double subtotal) + const char *sender_postal, const char *receiver_name, const char *receiver_phone, + const char *destination, const char *receiver_address, const char *receiver_postal, + int nitems, char **items[], _Bool insurance, double subtotal) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &waybill); char *url; @@ -124,8 +125,9 @@ char *pikul_order(const char *order_number, const char *service, const char *sen switch (shipping.company) { case PIKUL_ANTERAJA: anteraja_order(order_number, service, sender_name, sender_phone, origin, - sender_address, receiver_name, receiver_phone, destination, - receiver_address, nitems, items, insurance, subtotal, &url, &post); + sender_address, sender_postal, receiver_name, receiver_phone, + destination, receiver_address, receiver_postal, nitems, items, + insurance, subtotal, &url, &post); handler = anteraja_order_handle; break; default: -- cgit v1.2.3 From 2419d61c5171479586ba606834dcbfaa138c9bb3 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: Sat, 17 Jul 2021 20:47:59 +0800 Subject: Rename waybill to tracking_number --- pikul.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index cb74feb..b3e6352 100644 --- a/pikul.c +++ b/pikul.c @@ -4,7 +4,7 @@ CURL *curl; json_tokener *tokener; struct shipping shipping; -static char *waybill = NULL; +static char *tracking_number = NULL; extern inline void headers(const char *[], char *[]); extern inline void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], @@ -118,7 +118,7 @@ char *pikul_order(const char *order_number, const char *service, const char *sen const char *destination, const char *receiver_address, const char *receiver_postal, int nitems, char **items[], _Bool insurance, double subtotal) { - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &waybill); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &tracking_number); char *url; char *post = NULL; size_t (*handler)(const char *, size_t, size_t, char **); @@ -139,7 +139,7 @@ char *pikul_order(const char *order_number, const char *service, const char *sen if (post) free(post); free(url); - return waybill; + return tracking_number; } void pikul_cleanup() @@ -151,8 +151,8 @@ void pikul_cleanup() default: break; } - if (waybill) - free(waybill); + if (tracking_number) + free(tracking_number); free(shipping.base); json_tokener_free(tokener); curl_slist_free_all(shipping.headers); -- cgit v1.2.3 From 12150c2dff8d226987beb78c8d37f595d90502eb 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: Sat, 17 Jul 2021 21:52:06 +0800 Subject: Should be the user's responsibility to free it --- pikul.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index b3e6352..ed11d9c 100644 --- a/pikul.c +++ b/pikul.c @@ -4,7 +4,6 @@ CURL *curl; json_tokener *tokener; struct shipping shipping; -static char *tracking_number = NULL; extern inline void headers(const char *[], char *[]); extern inline void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], @@ -118,6 +117,7 @@ char *pikul_order(const char *order_number, const char *service, const char *sen const char *destination, const char *receiver_address, const char *receiver_postal, int nitems, char **items[], _Bool insurance, double subtotal) { + char *tracking_number = NULL; curl_easy_setopt(curl, CURLOPT_WRITEDATA, &tracking_number); char *url; char *post = NULL; @@ -151,8 +151,6 @@ void pikul_cleanup() default: break; } - if (tracking_number) - free(tracking_number); free(shipping.base); json_tokener_free(tokener); curl_slist_free_all(shipping.headers); -- cgit v1.2.3 From b53957a8fd25bcce8eb98f71b6e9e711b48ce605 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, 18 Jul 2021 11:59:55 +0800 Subject: Insurance is not determined by user's decision It depends on some weight threshhold. --- pikul.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index ed11d9c..8d776a4 100644 --- a/pikul.c +++ b/pikul.c @@ -14,7 +14,7 @@ extern void anteraja_services(const char *, const char *, double, char **, char extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); extern void anteraja_order(const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, - const char *, int, char **[], _Bool, double, char **, char **); + const char *, int, char **[], double, char **, char **); extern size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); extern void anteraja_cleanup(); @@ -115,7 +115,7 @@ char *pikul_order(const char *order_number, const char *service, const char *sen const char *sender_phone, const char *origin, const char *sender_address, const char *sender_postal, const char *receiver_name, const char *receiver_phone, const char *destination, const char *receiver_address, const char *receiver_postal, - int nitems, char **items[], _Bool insurance, double subtotal) + int nitems, char **items[], double subtotal) { char *tracking_number = NULL; curl_easy_setopt(curl, CURLOPT_WRITEDATA, &tracking_number); @@ -127,7 +127,7 @@ char *pikul_order(const char *order_number, const char *service, const char *sen anteraja_order(order_number, service, sender_name, sender_phone, origin, sender_address, sender_postal, receiver_name, receiver_phone, destination, receiver_address, receiver_postal, nitems, items, - insurance, subtotal, &url, &post); + subtotal, &url, &post); handler = anteraja_order_handle; break; default: -- cgit v1.2.3 From 39190eb032cc6a8c2fe9d07ca85f712a229c0b69 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, 18 Jul 2021 13:18:44 +0800 Subject: The qualifiers have been unnecessary --- pikul.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index 8d776a4..636aeb3 100644 --- a/pikul.c +++ b/pikul.c @@ -5,18 +5,17 @@ CURL *curl; json_tokener *tokener; struct shipping shipping; -extern inline void headers(const char *[], char *[]); -extern inline void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], - void *); +void headers(const char *[], char *[]); +void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], void *); -extern void anteraja_init(char *[]); -extern void anteraja_services(const char *, const char *, double, char **, char **); -extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); -extern void anteraja_order(const char *, const char *, const char *, const char *, const char *, - const char *, const char *, const char *, const char *, const char *, const char *, - const char *, int, char **[], double, char **, char **); -extern size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); -extern void anteraja_cleanup(); +void anteraja_init(char *[]); +void anteraja_services(const char *, const char *, double, char **, char **); +size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); +void anteraja_order(const char *, const char *, const char *, const char *, const char *, const char *, + const char *, const char *, const char *, const char *, const char *, const char *, int, + char **[], double, char **, char **); +size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); +void anteraja_cleanup(); void pikul_init(enum pikul_company company, char *provisions[]) { -- cgit v1.2.3