From c328f6c002446245ae81fc5f6009555ef71d071c 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: Mon, 28 Jun 2021 10:58:50 +0800 Subject: Handle whose status is other than 200 At the same time, refactor the JSON handling. --- pikul.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pikul.c') diff --git a/pikul.c b/pikul.c index be4dba3..dd6ea33 100644 --- a/pikul.c +++ b/pikul.c @@ -6,7 +6,8 @@ json_tokener *tokener; static struct shipping shipping; extern inline void headers(struct shipping *shipping, const char *fields[], char *provisions[]); -extern inline void handle(const char *, size_t, struct container *); +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, @@ -92,6 +93,8 @@ static int servicecmp(const void *service1, const void *service2) double pikul_cost(const char *origin, const char *destination, double weight, const char *code) { struct pikul_services *services = pikul_services(origin, destination, weight); + if (!services) + return .0; qsort(services->list, services->length, sizeof(struct pikul_service *), servicecmp); struct pikul_service *key_service = malloc(sizeof(struct pikul_service)); memset(key_service, '\0', sizeof(struct pikul_service)); -- cgit v1.2.3