summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2022-09-23 18:15:59 +0200
committerGravatar default2022-09-23 18:15:59 +0200
commita0bcc4e6c022fc55956920fd49303abc6ca9b4db (patch)
treebbf2da67a9632f0515d73577337dc4c3091c47fb /activitypub.c
parentserver_get_handler() returns the status. (diff)
downloadsnac2-a0bcc4e6c022fc55956920fd49303abc6ca9b4db.tar.gz
snac2-a0bcc4e6c022fc55956920fd49303abc6ca9b4db.tar.xz
snac2-a0bcc4e6c022fc55956920fd49303abc6ca9b4db.zip
Improved activitypub_request().
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/activitypub.c b/activitypub.c
index de99b75..7cbf4db 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -15,8 +15,9 @@ int activitypub_request(snac *snac, char *url, d_char **data)
15{ 15{
16 int status; 16 int status;
17 xs *response = NULL; 17 xs *response = NULL;
18 xs *payload; 18 xs *payload = NULL;
19 int p_size; 19 int p_size;
20 char *ctype;
20 21
21 /* check if it's an url for this same site */ 22 /* check if it's an url for this same site */
22 /* ... */ 23 /* ... */
@@ -25,41 +26,51 @@ int activitypub_request(snac *snac, char *url, d_char **data)
25 response = http_signed_request(snac, "GET", url, 26 response = http_signed_request(snac, "GET", url,
26 NULL, NULL, 0, &status, &payload, &p_size); 27 NULL, NULL, 0, &status, &payload, &p_size);
27 28
28 {
29 xs *j = xs_json_loads(response);
30 printf("%s\n", j);
31 }
32
33 if (valid_status(status)) { 29 if (valid_status(status)) {
34 *data = xs_json_loads(payload); 30 if (dbglevel >= 3) {
31 xs *j = xs_json_dumps_pp(response, 4);
32 fprintf(stderr, "%s\n", j);
33 }
34
35 /* ensure it's ActivityPub data */
36 ctype = xs_dict_get(response, "content-type");
37
38 if (xs_str_in(ctype, "application/activity+json") != -1)
39 *data = xs_json_loads(payload);
40 else
41 status = 500;
35 } 42 }
36 43
44 if (!valid_status(status))
45 *data = NULL;
46
37 return status; 47 return status;
38} 48}
39 49
40 50
41#if 0
42int actor_request(snac *snac, char *actor, d_char **data) 51int actor_request(snac *snac, char *actor, d_char **data)
43/* request an actor */ 52/* request an actor */
44{ 53{
45 int status; 54 int status, status2;
46 xs *response = NULL; 55 xs *payload = NULL;
47 xs *payload;
48 int p_size;
49 56
50 /* get from disk first */ 57 /* get from disk first */
51 status = actor_get(snac, actor, data); 58 status = actor_get(snac, actor, data);
52 59
53 if (status == 200) 60 if (status == 200)
54 return; 61 return status;
55 62
56 /* get from the net */ 63 /* actor data non-existent or stale: get from the net */
57 response = http_signed_request(snac, "GET", actor, 64 status2 = activitypub_request(snac, actor, &payload);
58 NULL, NULL, 0, &status, &payload, &p_size);
59 65
60// response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral", 66 if (valid_status(status2)) {
61// headers, NULL, 0, &status, &payload, &p_size); 67 /* renew data */
68 xs *j = xs_json_dumps_pp(payload, 4);
69 status = actor_add(snac, actor, j);
70
71 *data = payload;
72 payload = NULL;
73 }
62 74
63 return status; 75 return status;
64} 76}
65#endif