summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-12-10 10:27:45 +0100
committerdefault <nobody@localhost>2023-12-10 10:27:45 +0100
commit90179f84596e7885fade4552cbeac0beb5c53303 (patch)
treeecae50149124ee87fbe91fc6131176bcc28baeb0
parent1c194042580249fae3b54ea00517c399d8bc7b77 (diff)
activitypub_request() may have a NULL user.
In the NULL user case, only non-signed requests will be done, but it's probably enough for actor requests in most cases.
-rw-r--r--activitypub.c21
-rw-r--r--http.c4
2 files changed, 13 insertions, 12 deletions
diff --git a/activitypub.c b/activitypub.c
index 0764fa2..a852256 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -60,18 +60,22 @@ const char *default_avatar_base64(void)
}
-int activitypub_request(snac *snac, const char *url, xs_dict **data)
+int activitypub_request(snac *user, const char *url, xs_dict **data)
/* request an object */
{
- int status;
+ int status = 0;
xs *response = NULL;
xs *payload = NULL;
int p_size;
char *ctype;
- /* get from the net */
- response = http_signed_request(snac, "GET", url,
- NULL, NULL, 0, &status, &payload, &p_size, 0);
+ *data = NULL;
+
+ if (user != NULL) {
+ /* get from the net */
+ response = http_signed_request(user, "GET", url,
+ NULL, NULL, 0, &status, &payload, &p_size, 0);
+ }
if (status == 0 || (status >= 500 && status <= 599)) {
/* I found an instance running Misskey that returned
@@ -107,14 +111,11 @@ int activitypub_request(snac *snac, const char *url, xs_dict **data)
status = 500;
}
- if (!valid_status(status))
- *data = NULL;
-
return status;
}
-int actor_request(snac *snac, const char *actor, xs_dict **data)
+int actor_request(snac *user, const char *actor, xs_dict **data)
/* request an actor */
{
int status, status2;
@@ -128,7 +129,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data)
if (status != 200) {
/* actor data non-existent or stale: get from the net */
- status2 = activitypub_request(snac, actor, &payload);
+ status2 = activitypub_request(user, actor, &payload);
if (valid_status(status2)) {
/* renew data */
diff --git a/http.c b/http.c
index 28947ad..d7f1629 100644
--- a/http.c
+++ b/http.c
@@ -120,7 +120,7 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
}
-int check_signature(snac *snac, xs_dict *req, xs_str **err)
+int check_signature(snac *user, xs_dict *req, xs_str **err)
/* check the signature */
{
char *sig_hdr = xs_dict_get(req, "signature");
@@ -173,7 +173,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err)
xs *actor = NULL;
- if (!valid_status(actor_request(snac, keyId, &actor))) {
+ if (!valid_status(actor_request(user, keyId, &actor))) {
*err = xs_fmt("unknown actor %s", keyId);
return 0;
}