From 463439283a3f346a8869df6d17a70f20a0a02419 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 2 Feb 2023 03:49:38 +0100 Subject: [PATCH] Minor header tweaks. --- http.c | 20 ++++++++++---------- snac.c | 6 ++++-- snac.h | 16 +++++++++------- xs_curl.h | 14 ++++++++------ 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/http.c b/http.c index 881a7e0..1948f2b 100644 --- a/http.c +++ b/http.c @@ -11,19 +11,19 @@ #include "snac.h" -d_char *http_signed_request(snac *snac, char *method, char *url, - d_char *headers, - d_char *body, int b_size, - int *status, d_char **payload, int *p_size, +xs_dict *http_signed_request(snac *snac, const char *method, const char *url, + xs_dict *headers, + const char *body, int b_size, + int *status, xs_str **payload, int *p_size, int timeout) /* does a signed HTTP request */ { - xs *l1; - xs *date; - xs *digest; - xs *s64; - xs *signature; - xs *hdrs; + xs *l1 = NULL; + xs *date = NULL; + xs *digest = NULL; + xs *s64 = NULL; + xs *signature = NULL; + xs *hdrs = NULL; char *host; char *target; char *seckey; diff --git a/snac.c b/snac.c index e8c3a3d..c15a74a 100644 --- a/snac.c +++ b/snac.c @@ -138,8 +138,10 @@ int check_password(const char *uid, const char *passwd, const char *hash) } -void srv_archive(char *direction, char *req, char *payload, int p_size, - int status, char *headers, char *body, int b_size) +void srv_archive(const char *direction, xs_dict *req, + const char *payload, int p_size, + int status, xs_dict *headers, + const char *body, int b_size) /* archives a connection */ { /* obsessive archiving */ diff --git a/snac.h b/snac.h index dc6662e..6185e8b 100644 --- a/snac.h +++ b/snac.h @@ -46,8 +46,10 @@ int validate_uid(const char *uid); d_char *hash_password(const char *uid, const char *passwd, const char *nonce); int check_password(const char *uid, const char *passwd, const char *hash); -void srv_archive(char *direction, char *req, char *payload, int p_size, - int status, char *headers, char *body, int b_size); +void srv_archive(const char *direction, xs_dict *req, + const char *payload, int p_size, + int status, xs_dict *headers, + const char *body, int b_size); double mtime_nl(const char *fn, int *n_link); #define mtime(fn) mtime_nl(fn, NULL) @@ -133,11 +135,11 @@ d_char *dequeue(snac *snac, char *fn); void purge(snac *snac); void purge_all(void); -d_char *http_signed_request(snac *snac, char *method, char *url, - d_char *headers, - d_char *body, int b_size, - int *status, d_char **payload, int *p_size, - int timeout); +xs_dict *http_signed_request(snac *snac, const char *method, const char *url, + xs_dict *headers, + const char *body, int b_size, + int *status, xs_str **payload, int *p_size, + int timeout); int check_signature(snac *snac, char *req); void httpd(void); diff --git a/xs_curl.h b/xs_curl.h index 2637c02..1ac0e13 100644 --- a/xs_curl.h +++ b/xs_curl.h @@ -4,8 +4,9 @@ #define _XS_CURL_H -xs_dict *xs_http_request(char *method, char *url, xs_dict *headers, - xs_str *body, int b_size, int *status, +xs_dict *xs_http_request(const char *method, const char *url, + const xs_dict *headers, + const xs_str *body, int b_size, int *status, xs_str **payload, int *p_size, int timeout); #ifdef XS_IMPLEMENTATION @@ -83,8 +84,9 @@ static int _post_callback(char *buffer, size_t size, } -xs_dict *xs_http_request(char *method, char *url, xs_dict *headers, - xs_str *body, int b_size, int *status, +xs_dict *xs_http_request(const char *method, const char *url, + const xs_dict *headers, + const xs_str *body, int b_size, int *status, xs_str **payload, int *p_size, int timeout) /* does an HTTP request */ { @@ -136,7 +138,7 @@ xs_dict *xs_http_request(char *method, char *url, xs_dict *headers, sprintf(tmp, "content-length: %d", b_size); list = curl_slist_append(list, tmp); - pd.data = body; + pd.data = (char *)body; pd.size = b_size; pd.offset = 0; @@ -146,7 +148,7 @@ xs_dict *xs_http_request(char *method, char *url, xs_dict *headers, } /* fill the request headers */ - p = headers; + p = (xs_dict *)headers; while (xs_dict_iter(&p, &k, &v)) { xs *h = xs_fmt("%s: %s", k, v);