summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'http.c')
-rw-r--r--http.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/http.c b/http.c
index 1b3d590..b21f1dc 100644
--- a/http.c
+++ b/http.c
@@ -12,7 +12,7 @@
xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
const char *method, const char *url,
- xs_dict *headers,
+ const xs_dict *headers,
const char *body, int b_size,
int *status, xs_str **payload, int *p_size,
int timeout)
@@ -24,15 +24,16 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
xs *s64 = NULL;
xs *signature = NULL;
xs *hdrs = NULL;
- char *host;
- char *target;
- char *k, *v;
+ const char *host;
+ const char *target;
+ const char *k, *v;
xs_dict *response;
date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT");
{
- xs *s = xs_replace_n(url, "https:/" "/", "", 1);
+ xs *s1 = xs_replace_n(url, "http:/" "/", "", 1);
+ xs *s = xs_replace_n(s1, "https:/" "/", "", 1);
l1 = xs_split_n(s, "/", 1);
}
@@ -105,13 +106,13 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
- xs_dict *headers,
+ const xs_dict *headers,
const char *body, int b_size,
int *status, xs_str **payload, int *p_size,
int timeout)
/* does a signed HTTP request */
{
- char *seckey = xs_dict_get(snac->key, "secret");
+ const char *seckey = xs_dict_get(snac->key, "secret");
xs_dict *response;
response = http_signed_request_raw(snac->actor, seckey, method, url,
@@ -121,17 +122,18 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
}
-int check_signature(xs_dict *req, xs_str **err)
+int check_signature(const xs_dict *req, xs_str **err)
/* check the signature */
{
- char *sig_hdr = xs_dict_get(req, "signature");
+ const char *sig_hdr = xs_dict_get(req, "signature");
xs *keyId = NULL;
xs *headers = NULL;
xs *signature = NULL;
xs *created = NULL;
xs *expires = NULL;
- char *pubkey;
char *p;
+ const char *pubkey;
+ const char *k;
if (xs_is_null(sig_hdr)) {
*err = xs_fmt("missing 'signature' header");
@@ -141,10 +143,10 @@ int check_signature(xs_dict *req, xs_str **err)
{
/* extract the values */
xs *l = xs_split(sig_hdr, ",");
- xs_list *p = l;
- xs_val *v;
+ int c = 0;
+ const xs_val *v;
- while (xs_list_iter(&p, &v)) {
+ while (xs_list_next(l, &v, &c)) {
xs *kv = xs_split_n(v, "=", 1);
if (xs_list_len(kv) != 2)
@@ -191,8 +193,8 @@ int check_signature(xs_dict *req, xs_str **err)
return 0;
}
- if ((p = xs_dict_get(actor, "publicKey")) == NULL ||
- ((pubkey = xs_dict_get(p, "publicKeyPem")) == NULL)) {
+ if ((k = xs_dict_get(actor, "publicKey")) == NULL ||
+ ((pubkey = xs_dict_get(k, "publicKeyPem")) == NULL)) {
*err = xs_fmt("cannot get pubkey from %s", keyId);
return 0;
}
@@ -203,11 +205,11 @@ int check_signature(xs_dict *req, xs_str **err)
{
xs *l = xs_split(headers, " ");
xs_list *p;
- xs_val *v;
+ const xs_val *v;
p = l;
while (xs_list_iter(&p, &v)) {
- char *hc;
+ const char *hc;
xs *ss = NULL;
if (*sig_str != '\0')