From 1c51604909c9953acd874e24abe90ba565c650d2 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: Wed, 14 Jul 2021 20:41:14 +0800 Subject: Macros for Anteraja services --- anteraja.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'anteraja.c') diff --git a/anteraja.c b/anteraja.c index 462ff5d..2fc265c 100644 --- a/anteraja.c +++ b/anteraja.c @@ -1,12 +1,14 @@ #include "shipping.h" #include "handler.h" -#define POST \ +#define SERVICES_PATH "serviceRates" +#define SERVICES_POST \ "{\ \"origin\":\"%s\",\ \"destination\":\"%s\",\ \"weight\":%d\ }" + extern CURL *curl; static const char *status_trail[] = { "status", NULL }; @@ -24,12 +26,11 @@ void anteraja_init(char *provisions[], struct shipping *shipping) void anteraja_services(const char *origin, const char *destination, double weight, struct shipping *shipping, char **url, char **post) { - static const char *path = "serviceRates"; - *url = malloc(strlen(shipping->base) + strlen(path) + 1); - sprintf(*url, "%s%s", shipping->base, path); - *post = malloc(strlen(POST) + strlen(origin) + strlen(destination) + strlen("50000") + *url = malloc(strlen(shipping->base) + strlen(SERVICES_PATH) + 1); + sprintf(*url, "%s%s", shipping->base, SERVICES_PATH); + *post = malloc(strlen(SERVICES_POST) + strlen(origin) + strlen(destination) + strlen("50000") - 2 * strlen("%s") - strlen("%d") + 1); - sprintf(*post, POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000); + sprintf(*post, SERVICES_POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, *post); } -- cgit v1.2.3