commit 90179f8
default
·
2023-12-10 09:27:45 +0000 UTC
parent 1c19404
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.
2 files changed,
+13,
-12
M
http.c
+11,
-10
1@@ -60,18 +60,22 @@ const char *default_avatar_base64(void)
2 }
3
4
5-int activitypub_request(snac *snac, const char *url, xs_dict **data)
6+int activitypub_request(snac *user, const char *url, xs_dict **data)
7 /* request an object */
8 {
9- int status;
10+ int status = 0;
11 xs *response = NULL;
12 xs *payload = NULL;
13 int p_size;
14 char *ctype;
15
16- /* get from the net */
17- response = http_signed_request(snac, "GET", url,
18- NULL, NULL, 0, &status, &payload, &p_size, 0);
19+ *data = NULL;
20+
21+ if (user != NULL) {
22+ /* get from the net */
23+ response = http_signed_request(user, "GET", url,
24+ NULL, NULL, 0, &status, &payload, &p_size, 0);
25+ }
26
27 if (status == 0 || (status >= 500 && status <= 599)) {
28 /* I found an instance running Misskey that returned
29@@ -107,14 +111,11 @@ int activitypub_request(snac *snac, const char *url, xs_dict **data)
30 status = 500;
31 }
32
33- if (!valid_status(status))
34- *data = NULL;
35-
36 return status;
37 }
38
39
40-int actor_request(snac *snac, const char *actor, xs_dict **data)
41+int actor_request(snac *user, const char *actor, xs_dict **data)
42 /* request an actor */
43 {
44 int status, status2;
45@@ -128,7 +129,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data)
46
47 if (status != 200) {
48 /* actor data non-existent or stale: get from the net */
49- status2 = activitypub_request(snac, actor, &payload);
50+ status2 = activitypub_request(user, actor, &payload);
51
52 if (valid_status(status2)) {
53 /* renew data */
M
http.c
+2,
-2
1@@ -120,7 +120,7 @@ xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
2 }
3
4
5-int check_signature(snac *snac, xs_dict *req, xs_str **err)
6+int check_signature(snac *user, xs_dict *req, xs_str **err)
7 /* check the signature */
8 {
9 char *sig_hdr = xs_dict_get(req, "signature");
10@@ -173,7 +173,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err)
11
12 xs *actor = NULL;
13
14- if (!valid_status(actor_request(snac, keyId, &actor))) {
15+ if (!valid_status(actor_request(user, keyId, &actor))) {
16 *err = xs_fmt("unknown actor %s", keyId);
17 return 0;
18 }