diff options
| author | 2023-08-12 11:23:01 +0200 | |
|---|---|---|
| committer | 2023-08-12 11:23:01 +0200 | |
| commit | cac1c6febd0ce90424831b15a9651026b4bb017c (patch) | |
| tree | ee9e290ef0a51aae2fec42665ef62348e5fc2666 | |
| parent | Rewritten is_msg_public() to not depend on a user. (diff) | |
| download | snac2-cac1c6febd0ce90424831b15a9651026b4bb017c.tar.gz snac2-cac1c6febd0ce90424831b15a9651026b4bb017c.tar.xz snac2-cac1c6febd0ce90424831b15a9651026b4bb017c.zip | |
Rewritten actor_get() to not depend on a user.
| -rw-r--r-- | activitypub.c | 2 | ||||
| -rw-r--r-- | data.c | 10 | ||||
| -rw-r--r-- | html.c | 14 | ||||
| -rw-r--r-- | mastoapi.c | 4 | ||||
| -rw-r--r-- | snac.h | 2 |
5 files changed, 12 insertions, 20 deletions
diff --git a/activitypub.c b/activitypub.c index 2c20e63..6fb6bf5 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -117,7 +117,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data) | |||
| 117 | *data = NULL; | 117 | *data = NULL; |
| 118 | 118 | ||
| 119 | /* get from disk first */ | 119 | /* get from disk first */ |
| 120 | status = actor_get(snac, actor, data); | 120 | status = actor_get(actor, data); |
| 121 | 121 | ||
| 122 | if (status != 200) { | 122 | if (status != 200) { |
| 123 | /* actor data non-existent or stale: get from the net */ | 123 | /* actor data non-existent or stale: get from the net */ |
| @@ -1439,20 +1439,12 @@ int actor_add(const char *actor, xs_dict *msg) | |||
| 1439 | } | 1439 | } |
| 1440 | 1440 | ||
| 1441 | 1441 | ||
| 1442 | int actor_get(snac *snac1, const char *actor, xs_dict **data) | 1442 | int actor_get(const char *actor, xs_dict **data) |
| 1443 | /* returns an already downloaded actor */ | 1443 | /* returns an already downloaded actor */ |
| 1444 | { | 1444 | { |
| 1445 | int status = 200; | 1445 | int status = 200; |
| 1446 | xs_dict *d = NULL; | 1446 | xs_dict *d = NULL; |
| 1447 | 1447 | ||
| 1448 | if (strcmp(actor, snac1->actor) == 0) { | ||
| 1449 | /* this actor */ | ||
| 1450 | if (data) | ||
| 1451 | *data = msg_actor(snac1); | ||
| 1452 | |||
| 1453 | return status; | ||
| 1454 | } | ||
| 1455 | |||
| 1456 | if (xs_startswith(actor, srv_baseurl)) { | 1448 | if (xs_startswith(actor, srv_baseurl)) { |
| 1457 | /* it's a (possible) local user */ | 1449 | /* it's a (possible) local user */ |
| 1458 | xs *l = xs_split(actor, "/"); | 1450 | xs *l = xs_split(actor, "/"); |
| @@ -188,7 +188,7 @@ xs_str *html_actor_icon(xs_str *os, char *actor, | |||
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | 190 | ||
| 191 | xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg) | 191 | xs_str *html_msg_icon(xs_str *os, const xs_dict *msg) |
| 192 | { | 192 | { |
| 193 | char *actor_id; | 193 | char *actor_id; |
| 194 | xs *actor = NULL; | 194 | xs *actor = NULL; |
| @@ -196,7 +196,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg) | |||
| 196 | if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL) | 196 | if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL) |
| 197 | actor_id = xs_dict_get(msg, "actor"); | 197 | actor_id = xs_dict_get(msg, "actor"); |
| 198 | 198 | ||
| 199 | if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) { | 199 | if (actor_id && valid_status(actor_get(actor_id, &actor))) { |
| 200 | char *date = NULL; | 200 | char *date = NULL; |
| 201 | char *udate = NULL; | 201 | char *udate = NULL; |
| 202 | char *url = NULL; | 202 | char *url = NULL; |
| @@ -870,7 +870,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 870 | xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you")); | 870 | xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you")); |
| 871 | s = xs_str_cat(s, s1); | 871 | s = xs_str_cat(s, s1); |
| 872 | 872 | ||
| 873 | s = html_msg_icon(snac, s, msg); | 873 | s = html_msg_icon(s, msg); |
| 874 | 874 | ||
| 875 | s = xs_str_cat(s, "</div>\n</div>\n"); | 875 | s = xs_str_cat(s, "</div>\n</div>\n"); |
| 876 | 876 | ||
| @@ -894,7 +894,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 894 | if (is_muted(snac, actor)) | 894 | if (is_muted(snac, actor)) |
| 895 | return os; | 895 | return os; |
| 896 | 896 | ||
| 897 | if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(snac, actor, NULL))) | 897 | if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(actor, NULL))) |
| 898 | return os; | 898 | return os; |
| 899 | 899 | ||
| 900 | if (level == 0) | 900 | if (level == 0) |
| @@ -990,7 +990,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 990 | } | 990 | } |
| 991 | } | 991 | } |
| 992 | 992 | ||
| 993 | s = html_msg_icon(snac, s, msg); | 993 | s = html_msg_icon(s, msg); |
| 994 | 994 | ||
| 995 | /* add the content */ | 995 | /* add the content */ |
| 996 | s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/ | 996 | s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/ |
| @@ -1450,7 +1450,7 @@ xs_str *html_people_list(snac *snac, xs_str *os, xs_list *list, const char *head | |||
| 1450 | xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); | 1450 | xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); |
| 1451 | xs *actor = NULL; | 1451 | xs *actor = NULL; |
| 1452 | 1452 | ||
| 1453 | if (valid_status(actor_get(snac, actor_id, &actor))) { | 1453 | if (valid_status(actor_get(actor_id, &actor))) { |
| 1454 | s = xs_str_cat(s, "<div class=\"snac-post\">\n<div class=\"snac-post-header\">\n"); | 1454 | s = xs_str_cat(s, "<div class=\"snac-post\">\n<div class=\"snac-post-header\">\n"); |
| 1455 | 1455 | ||
| 1456 | s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0); | 1456 | s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0); |
| @@ -1608,7 +1608,7 @@ xs_str *html_notifications(snac *snac) | |||
| 1608 | const char *actor_id = xs_dict_get(noti, "actor"); | 1608 | const char *actor_id = xs_dict_get(noti, "actor"); |
| 1609 | xs *actor = NULL; | 1609 | xs *actor = NULL; |
| 1610 | 1610 | ||
| 1611 | if (!valid_status(actor_get(snac, actor_id, &actor))) | 1611 | if (!valid_status(actor_get(actor_id, &actor))) |
| 1612 | continue; | 1612 | continue; |
| 1613 | 1613 | ||
| 1614 | xs *a_name = actor_name(actor); | 1614 | xs *a_name = actor_name(actor); |
| @@ -632,7 +632,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 632 | /* converts an ActivityPub note to a Mastodon status */ | 632 | /* converts an ActivityPub note to a Mastodon status */ |
| 633 | { | 633 | { |
| 634 | xs *actor = NULL; | 634 | xs *actor = NULL; |
| 635 | actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor); | 635 | actor_get(xs_dict_get(msg, "attributedTo"), &actor); |
| 636 | 636 | ||
| 637 | /* if the author is not here, discard */ | 637 | /* if the author is not here, discard */ |
| 638 | if (actor == NULL) | 638 | if (actor == NULL) |
| @@ -1310,7 +1310,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1310 | xs *actor = NULL; | 1310 | xs *actor = NULL; |
| 1311 | xs *entry = NULL; | 1311 | xs *entry = NULL; |
| 1312 | 1312 | ||
| 1313 | if (!valid_status(actor_get(&snac1, xs_dict_get(noti, "actor"), &actor))) | 1313 | if (!valid_status(actor_get(xs_dict_get(noti, "actor"), &actor))) |
| 1314 | continue; | 1314 | continue; |
| 1315 | 1315 | ||
| 1316 | if (objid != NULL && !valid_status(object_get(objid, &entry))) | 1316 | if (objid != NULL && !valid_status(object_get(objid, &entry))) |
| @@ -141,7 +141,7 @@ void hide(snac *snac, const char *id); | |||
| 141 | int is_hidden(snac *snac, const char *id); | 141 | int is_hidden(snac *snac, const char *id); |
| 142 | 142 | ||
| 143 | int actor_add(const char *actor, xs_dict *msg); | 143 | int actor_add(const char *actor, xs_dict *msg); |
| 144 | int actor_get(snac *snac, const char *actor, xs_dict **data); | 144 | int actor_get(const char *actor, xs_dict **data); |
| 145 | 145 | ||
| 146 | int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag); | 146 | int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag); |
| 147 | void static_put(snac *snac, const char *id, const char *data, int size); | 147 | void static_put(snac *snac, const char *id, const char *data, int size); |