commit 4634392

default  ·  2023-02-02 02:49:38 +0000 UTC
parent ec07b0c
Minor header tweaks.
4 files changed,  +31, -25
M http.c
M snac.c
M snac.h
M http.c
+10, -10
 1@@ -11,19 +11,19 @@
 2 
 3 #include "snac.h"
 4 
 5-d_char *http_signed_request(snac *snac, char *method, char *url,
 6-                            d_char *headers,
 7-                            d_char *body, int b_size,
 8-                            int *status, d_char **payload, int *p_size,
 9+xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
10+                            xs_dict *headers,
11+                            const char *body, int b_size,
12+                            int *status, xs_str **payload, int *p_size,
13                             int timeout)
14 /* does a signed HTTP request */
15 {
16-    xs *l1;
17-    xs *date;
18-    xs *digest;
19-    xs *s64;
20-    xs *signature;
21-    xs *hdrs;
22+    xs *l1 = NULL;
23+    xs *date = NULL;
24+    xs *digest = NULL;
25+    xs *s64 = NULL;
26+    xs *signature = NULL;
27+    xs *hdrs = NULL;
28     char *host;
29     char *target;
30     char *seckey;
M snac.c
+4, -2
 1@@ -138,8 +138,10 @@ int check_password(const char *uid, const char *passwd, const char *hash)
 2 }
 3 
 4 
 5-void srv_archive(char *direction, char *req, char *payload, int p_size,
 6-                 int status, char *headers, char *body, int b_size)
 7+void srv_archive(const char *direction, xs_dict *req,
 8+                 const char *payload, int p_size,
 9+                 int status, xs_dict *headers,
10+                 const char *body, int b_size)
11 /* archives a connection */
12 {
13     /* obsessive archiving */
M snac.h
+9, -7
 1@@ -46,8 +46,10 @@ int validate_uid(const char *uid);
 2 d_char *hash_password(const char *uid, const char *passwd, const char *nonce);
 3 int check_password(const char *uid, const char *passwd, const char *hash);
 4 
 5-void srv_archive(char *direction, char *req, char *payload, int p_size,
 6-                 int status, char *headers, char *body, int b_size);
 7+void srv_archive(const char *direction, xs_dict *req,
 8+                 const char *payload, int p_size,
 9+                 int status, xs_dict *headers,
10+                 const char *body, int b_size);
11 
12 double mtime_nl(const char *fn, int *n_link);
13 #define mtime(fn) mtime_nl(fn, NULL)
14@@ -133,11 +135,11 @@ d_char *dequeue(snac *snac, char *fn);
15 void purge(snac *snac);
16 void purge_all(void);
17 
18-d_char *http_signed_request(snac *snac, char *method, char *url,
19-                        d_char *headers,
20-                        d_char *body, int b_size,
21-                        int *status, d_char **payload, int *p_size,
22-                        int timeout);
23+xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
24+                            xs_dict *headers,
25+                            const char *body, int b_size,
26+                            int *status, xs_str **payload, int *p_size,
27+                            int timeout);
28 int check_signature(snac *snac, char *req);
29 
30 void httpd(void);
+8, -6
 1@@ -4,8 +4,9 @@
 2 
 3 #define _XS_CURL_H
 4 
 5-xs_dict *xs_http_request(char *method, char *url, xs_dict *headers,
 6-                        xs_str *body, int b_size, int *status,
 7+xs_dict *xs_http_request(const char *method, const char *url,
 8+                        const xs_dict *headers,
 9+                        const xs_str *body, int b_size, int *status,
10                         xs_str **payload, int *p_size, int timeout);
11 
12 #ifdef XS_IMPLEMENTATION
13@@ -83,8 +84,9 @@ static int _post_callback(char *buffer, size_t size,
14 }
15 
16 
17-xs_dict *xs_http_request(char *method, char *url, xs_dict *headers,
18-                        xs_str *body, int b_size, int *status,
19+xs_dict *xs_http_request(const char *method, const char *url,
20+                        const xs_dict *headers,
21+                        const xs_str *body, int b_size, int *status,
22                         xs_str **payload, int *p_size, int timeout)
23 /* does an HTTP request */
24 {
25@@ -136,7 +138,7 @@ xs_dict *xs_http_request(char *method, char *url, xs_dict *headers,
26             sprintf(tmp, "content-length: %d", b_size);
27             list = curl_slist_append(list, tmp);
28 
29-            pd.data = body;
30+            pd.data = (char *)body;
31             pd.size = b_size;
32             pd.offset = 0;
33 
34@@ -146,7 +148,7 @@ xs_dict *xs_http_request(char *method, char *url, xs_dict *headers,
35     }
36 
37     /* fill the request headers */
38-    p = headers;
39+    p = (xs_dict *)headers;
40     while (xs_dict_iter(&p, &k, &v)) {
41         xs *h = xs_fmt("%s: %s", k, v);
42