diff options
| author | 2022-09-23 17:33:33 +0200 | |
|---|---|---|
| committer | 2022-09-23 17:33:33 +0200 | |
| commit | bdc166111df38377e0fdcffe386715d1c33c7ef2 (patch) | |
| tree | b13a3ec860b38abe4b599e4f6a8f65f5031c8e60 /activitypub.c | |
| parent | Reworked timeline_add(). (diff) | |
| download | snac2-bdc166111df38377e0fdcffe386715d1c33c7ef2.tar.gz snac2-bdc166111df38377e0fdcffe386715d1c33c7ef2.tar.xz snac2-bdc166111df38377e0fdcffe386715d1c33c7ef2.zip | |
[activitypub.c] New file.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c new file mode 100644 index 0000000..de99b75 --- /dev/null +++ b/activitypub.c | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | ||
| 2 | /* copyright (c) 2022 grunfink - MIT license */ | ||
| 3 | |||
| 4 | #include "xs.h" | ||
| 5 | #include "xs_encdec.h" | ||
| 6 | #include "xs_json.h" | ||
| 7 | #include "xs_curl.h" | ||
| 8 | |||
| 9 | #include "snac.h" | ||
| 10 | |||
| 11 | const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public"; | ||
| 12 | |||
| 13 | int activitypub_request(snac *snac, char *url, d_char **data) | ||
| 14 | /* request an object */ | ||
| 15 | { | ||
| 16 | int status; | ||
| 17 | xs *response = NULL; | ||
| 18 | xs *payload; | ||
| 19 | int p_size; | ||
| 20 | |||
| 21 | /* check if it's an url for this same site */ | ||
| 22 | /* ... */ | ||
| 23 | |||
| 24 | /* get from the net */ | ||
| 25 | response = http_signed_request(snac, "GET", url, | ||
| 26 | NULL, NULL, 0, &status, &payload, &p_size); | ||
| 27 | |||
| 28 | { | ||
| 29 | xs *j = xs_json_loads(response); | ||
| 30 | printf("%s\n", j); | ||
| 31 | } | ||
| 32 | |||
| 33 | if (valid_status(status)) { | ||
| 34 | *data = xs_json_loads(payload); | ||
| 35 | } | ||
| 36 | |||
| 37 | return status; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | #if 0 | ||
| 42 | int actor_request(snac *snac, char *actor, d_char **data) | ||
| 43 | /* request an actor */ | ||
| 44 | { | ||
| 45 | int status; | ||
| 46 | xs *response = NULL; | ||
| 47 | xs *payload; | ||
| 48 | int p_size; | ||
| 49 | |||
| 50 | /* get from disk first */ | ||
| 51 | status = actor_get(snac, actor, data); | ||
| 52 | |||
| 53 | if (status == 200) | ||
| 54 | return; | ||
| 55 | |||
| 56 | /* get from the net */ | ||
| 57 | response = http_signed_request(snac, "GET", actor, | ||
| 58 | NULL, NULL, 0, &status, &payload, &p_size); | ||
| 59 | |||
| 60 | // response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral", | ||
| 61 | // headers, NULL, 0, &status, &payload, &p_size); | ||
| 62 | |||
| 63 | return status; | ||
| 64 | } | ||
| 65 | #endif | ||