summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anteraja.c20
-rw-r--r--pikul.c12
-rw-r--r--shipping.h10
3 files changed, 20 insertions, 22 deletions
diff --git a/anteraja.c b/anteraja.c
index 2fc265c..cd2932f 100644
--- a/anteraja.c
+++ b/anteraja.c
@@ -13,21 +13,19 @@ extern CURL *curl;
static const char *status_trail[] = { "status", NULL };
-void anteraja_init(char *provisions[], struct shipping *shipping)
+void anteraja_init(char *provisions[])
{
- enum { BASE_PATH, ACCESS_KEY };
- shipping->base = malloc(strlen(provisions[BASE_PATH]) + 1);
- strcpy(shipping->base, provisions[BASE_PATH]);
- headers((const char *[]){ "access-key-id", "secret-access-key", NULL },
- &provisions[ACCESS_KEY], shipping);
- shipping->headers = curl_slist_append(shipping->headers, "Content-Type:application/json");
+ enum { BASE_PATH, ACCESS_KEY_ID, SECRET_ACCESS_KEY, PREFIX };
+ shipping.base = malloc(strlen(provisions[BASE_PATH]) + 1);
+ strcpy(shipping.base, provisions[BASE_PATH]);
+ headers((const char *[]){ "access-key-id", "secret-access-key", NULL }, &provisions[ACCESS_KEY_ID]);
+ shipping.headers = curl_slist_append(shipping.headers, "Content-Type:application/json");
}
-void anteraja_services(const char *origin, const char *destination, double weight,
- struct shipping *shipping, char **url, char **post)
+void anteraja_services(const char *origin, const char *destination, double weight, char **url, char **post)
{
- *url = malloc(strlen(shipping->base) + strlen(SERVICES_PATH) + 1);
- sprintf(*url, "%s%s", shipping->base, SERVICES_PATH);
+ *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, SERVICES_POST, origin, destination, weight < 1.0 ? 1000 : (int)weight * 1000);
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:
diff --git a/shipping.h b/shipping.h
index e1c5ba5..37ac20f 100644
--- a/shipping.h
+++ b/shipping.h
@@ -2,18 +2,18 @@
#include <curl/curl.h>
#include "pikul.h"
-struct shipping {
+extern struct shipping {
enum pikul_company company;
char *base;
struct curl_slist *headers;
-};
+} shipping;
-inline void headers(const char *fields[], char *provisions[], struct shipping *shipping)
+inline void headers(const char *fields[], char *provisions[])
{
- shipping->headers = NULL;
+ shipping.headers = NULL;
while (*fields) {
char header[strlen(*fields) + strlen(*provisions) + 2];
sprintf(header, "%s:%s", *fields++, *provisions++);
- shipping->headers = curl_slist_append(shipping->headers, header);
+ shipping.headers = curl_slist_append(shipping.headers, header);
}
}