diff options
| author | 2024-01-18 23:04:37 +0100 | |
|---|---|---|
| committer | 2024-01-18 23:04:37 +0100 | |
| commit | 65040b65a35e36423e7154e643d9c69401ec5b2c (patch) | |
| tree | f6e0c65299925e342920586f183c1fff4d3b8c2a | |
| parent | Deleted breakpoint. (diff) | |
| download | snac2-65040b65a35e36423e7154e643d9c69401ec5b2c.tar.gz snac2-65040b65a35e36423e7154e643d9c69401ec5b2c.tar.xz snac2-65040b65a35e36423e7154e643d9c69401ec5b2c.zip | |
New function get_atto(), to get the attributedTo field.
| -rw-r--r-- | activitypub.c | 44 | ||||
| -rw-r--r-- | data.c | 3 | ||||
| -rw-r--r-- | html.c | 31 | ||||
| -rw-r--r-- | mastoapi.c | 12 | ||||
| -rw-r--r-- | snac.h | 2 |
5 files changed, 49 insertions, 43 deletions
diff --git a/activitypub.c b/activitypub.c index 2306eb5..33ddd0f 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -156,6 +156,34 @@ int actor_request(snac *user, const char *actor, xs_dict **data) | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | 158 | ||
| 159 | char *get_atto(const xs_dict *msg) | ||
| 160 | /* gets the attributedTo field (an actor) */ | ||
| 161 | { | ||
| 162 | char *actor = xs_dict_get(msg, "attributedTo"); | ||
| 163 | |||
| 164 | /* if the actor is a list of objects (like on Peertube videos), pick the Person */ | ||
| 165 | if (xs_type(actor) == XSTYPE_LIST) { | ||
| 166 | xs_list *p = actor; | ||
| 167 | xs_dict *v; | ||
| 168 | actor = NULL; | ||
| 169 | |||
| 170 | while (actor == NULL && xs_list_iter(&p, &v)) { | ||
| 171 | if (xs_type(v) == XSTYPE_DICT) { | ||
| 172 | char *type = xs_dict_get(v, "type"); | ||
| 173 | if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) { | ||
| 174 | actor = xs_dict_get(v, "id"); | ||
| 175 | |||
| 176 | if (xs_type(actor) != XSTYPE_STRING) | ||
| 177 | actor = NULL; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | return actor; | ||
| 184 | } | ||
| 185 | |||
| 186 | |||
| 159 | int timeline_request(snac *snac, char **id, xs_str **wrk, int level) | 187 | int timeline_request(snac *snac, char **id, xs_str **wrk, int level) |
| 160 | /* ensures that an entry and its ancestors are in the timeline */ | 188 | /* ensures that an entry and its ancestors are in the timeline */ |
| 161 | { | 189 | { |
| @@ -203,7 +231,7 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level) | |||
| 203 | } | 231 | } |
| 204 | 232 | ||
| 205 | if (xs_match(type, "Note|Page|Article")) { | 233 | if (xs_match(type, "Note|Page|Article")) { |
| 206 | const char *actor = xs_dict_get(object, "attributedTo"); | 234 | const char *actor = get_atto(object); |
| 207 | 235 | ||
| 208 | /* request (and drop) the actor for this entry */ | 236 | /* request (and drop) the actor for this entry */ |
| 209 | if (!xs_is_null(actor)) | 237 | if (!xs_is_null(actor)) |
| @@ -531,7 +559,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg) | |||
| 531 | } | 559 | } |
| 532 | 560 | ||
| 533 | /* accept if it's by someone we follow */ | 561 | /* accept if it's by someone we follow */ |
| 534 | char *atto = xs_dict_get(msg, "attributedTo"); | 562 | char *atto = get_atto(msg); |
| 535 | 563 | ||
| 536 | if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) | 564 | if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) |
| 537 | return 3; | 565 | return 3; |
| @@ -543,7 +571,7 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg) | |||
| 543 | 571 | ||
| 544 | /* try to get the replied message */ | 572 | /* try to get the replied message */ |
| 545 | if (valid_status(object_get(irt, &r_msg))) { | 573 | if (valid_status(object_get(irt, &r_msg))) { |
| 546 | atto = xs_dict_get(r_msg, "attributedTo"); | 574 | atto = get_atto(r_msg); |
| 547 | 575 | ||
| 548 | /* accept if the replied message is from someone we follow */ | 576 | /* accept if the replied message is from someone we follow */ |
| 549 | if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) | 577 | if (pub_msg && !xs_is_null(atto) && following_check(snac, atto)) |
| @@ -958,7 +986,7 @@ xs_dict *msg_admiration(snac *snac, char *object, char *type) | |||
| 958 | if (is_msg_public(a_msg)) | 986 | if (is_msg_public(a_msg)) |
| 959 | rcpts = xs_list_append(rcpts, public_address); | 987 | rcpts = xs_list_append(rcpts, public_address); |
| 960 | 988 | ||
| 961 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); | 989 | rcpts = xs_list_append(rcpts, get_atto(a_msg)); |
| 962 | 990 | ||
| 963 | msg = xs_dict_append(msg, "to", rcpts); | 991 | msg = xs_dict_append(msg, "to", rcpts); |
| 964 | } | 992 | } |
| @@ -1085,7 +1113,7 @@ xs_dict *msg_create(snac *snac, const xs_dict *object) | |||
| 1085 | xs_dict *msg = msg_base(snac, "Create", "@wrapper", snac->actor, NULL, object); | 1113 | xs_dict *msg = msg_base(snac, "Create", "@wrapper", snac->actor, NULL, object); |
| 1086 | xs_val *v; | 1114 | xs_val *v; |
| 1087 | 1115 | ||
| 1088 | if ((v = xs_dict_get(object, "attributedTo"))) | 1116 | if ((v = get_atto(object))) |
| 1089 | msg = xs_dict_append(msg, "attributedTo", v); | 1117 | msg = xs_dict_append(msg, "attributedTo", v); |
| 1090 | 1118 | ||
| 1091 | if ((v = xs_dict_get(object, "cc"))) | 1119 | if ((v = xs_dict_get(object, "cc"))) |
| @@ -1213,7 +1241,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 1213 | /* add this author as recipient */ | 1241 | /* add this author as recipient */ |
| 1214 | char *a, *v; | 1242 | char *a, *v; |
| 1215 | 1243 | ||
| 1216 | if ((a = xs_dict_get(p_msg, "attributedTo")) && xs_list_in(to, a) == -1) | 1244 | if ((a = get_atto(p_msg)) && xs_list_in(to, a) == -1) |
| 1217 | to = xs_list_append(to, a); | 1245 | to = xs_list_append(to, a); |
| 1218 | 1246 | ||
| 1219 | /* add this author to the tag list as a mention */ | 1247 | /* add this author to the tag list as a mention */ |
| @@ -1447,7 +1475,7 @@ int update_question(snac *user, const char *id) | |||
| 1447 | continue; | 1475 | continue; |
| 1448 | 1476 | ||
| 1449 | const char *name = xs_dict_get(obj, "name"); | 1477 | const char *name = xs_dict_get(obj, "name"); |
| 1450 | const char *atto = xs_dict_get(obj, "attributedTo"); | 1478 | const char *atto = get_atto(obj); |
| 1451 | 1479 | ||
| 1452 | if (name && atto) { | 1480 | if (name && atto) { |
| 1453 | /* get the current count */ | 1481 | /* get the current count */ |
| @@ -1799,7 +1827,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) | |||
| 1799 | timeline_request(snac, &object, &wrk, 0); | 1827 | timeline_request(snac, &object, &wrk, 0); |
| 1800 | 1828 | ||
| 1801 | if (valid_status(object_get(object, &a_msg))) { | 1829 | if (valid_status(object_get(object, &a_msg))) { |
| 1802 | const char *who = xs_dict_get(a_msg, "attributedTo"); | 1830 | const char *who = get_atto(a_msg); |
| 1803 | 1831 | ||
| 1804 | if (who && !is_muted(snac, who)) { | 1832 | if (who && !is_muted(snac, who)) { |
| 1805 | /* bring the actor */ | 1833 | /* bring the actor */ |
| @@ -2345,7 +2345,8 @@ int was_question_voted(snac *user, const char *id) | |||
| 2345 | xs *obj = NULL; | 2345 | xs *obj = NULL; |
| 2346 | 2346 | ||
| 2347 | if (valid_status(object_get_by_md5(md5, &obj))) { | 2347 | if (valid_status(object_get_by_md5(md5, &obj))) { |
| 2348 | if (strcmp(xs_dict_get(obj, "attributedTo"), user->actor) == 0 && | 2348 | char *atto = get_atto(obj); |
| 2349 | if (atto && strcmp(atto, user->actor) == 0 && | ||
| 2349 | !xs_is_null(xs_dict_get(obj, "name"))) { | 2350 | !xs_is_null(xs_dict_get(obj, "name"))) { |
| 2350 | voted = 1; | 2351 | voted = 1; |
| 2351 | break; | 2352 | break; |
| @@ -1275,35 +1275,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int local, | |||
| 1275 | if (strcmp(type, "Note") == 0 && !xs_is_null(xs_dict_get(msg, "name"))) | 1275 | if (strcmp(type, "Note") == 0 && !xs_is_null(xs_dict_get(msg, "name"))) |
| 1276 | return NULL; | 1276 | return NULL; |
| 1277 | 1277 | ||
| 1278 | /* bring the main actor */ | 1278 | /* get the attributedTo */ |
| 1279 | if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) | 1279 | if ((actor = get_atto(msg)) == NULL) |
| 1280 | return NULL; | 1280 | return NULL; |
| 1281 | 1281 | ||
| 1282 | /* if the actor is a list (like on Peertube videos), pick the Person */ | ||
| 1283 | if (xs_type(actor) == XSTYPE_LIST) { | ||
| 1284 | char *e_actor = NULL; | ||
| 1285 | xs_list *p = actor; | ||
| 1286 | |||
| 1287 | while (xs_list_iter(&p, &v)) { | ||
| 1288 | if (xs_type(v) == XSTYPE_DICT) { | ||
| 1289 | char *type = xs_dict_get(v, "type"); | ||
| 1290 | if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Person") == 0) { | ||
| 1291 | e_actor = xs_dict_get(v, "id"); | ||
| 1292 | |||
| 1293 | if (xs_type(e_actor) == XSTYPE_STRING) | ||
| 1294 | break; | ||
| 1295 | else | ||
| 1296 | e_actor = NULL; | ||
| 1297 | } | ||
| 1298 | } | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | if (e_actor != NULL) | ||
| 1302 | actor = e_actor; | ||
| 1303 | else | ||
| 1304 | return NULL; | ||
| 1305 | } | ||
| 1306 | |||
| 1307 | /* ignore muted morons immediately */ | 1282 | /* ignore muted morons immediately */ |
| 1308 | if (user && is_muted(user, actor)) | 1283 | if (user && is_muted(user, actor)) |
| 1309 | return NULL; | 1284 | return NULL; |
| @@ -1979,7 +1954,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, | |||
| 1979 | 1954 | ||
| 1980 | /* if it's an instance page, discard private users */ | 1955 | /* if it's an instance page, discard private users */ |
| 1981 | if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { | 1956 | if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { |
| 1982 | const char *atto = xs_dict_get(msg, "attributedTo"); | 1957 | const char *atto = get_atto(msg); |
| 1983 | xs *l = xs_split(atto, "/"); | 1958 | xs *l = xs_split(atto, "/"); |
| 1984 | const char *uid = xs_list_get(l, -1); | 1959 | const char *uid = xs_list_get(l, -1); |
| 1985 | snac user; | 1960 | snac user; |
| @@ -701,7 +701,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 701 | /* converts an ActivityPub note to a Mastodon status */ | 701 | /* converts an ActivityPub note to a Mastodon status */ |
| 702 | { | 702 | { |
| 703 | xs *actor = NULL; | 703 | xs *actor = NULL; |
| 704 | actor_get(xs_dict_get(msg, "attributedTo"), &actor); | 704 | actor_get(get_atto(msg), &actor); |
| 705 | 705 | ||
| 706 | /* if the author is not here, discard */ | 706 | /* if the author is not here, discard */ |
| 707 | if (actor == NULL) | 707 | if (actor == NULL) |
| @@ -967,7 +967,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 967 | st = xs_dict_set(st, "in_reply_to_id", irt_mid); | 967 | st = xs_dict_set(st, "in_reply_to_id", irt_mid); |
| 968 | 968 | ||
| 969 | char *at = NULL; | 969 | char *at = NULL; |
| 970 | if (!xs_is_null(at = xs_dict_get(irto, "attributedTo"))) { | 970 | if (!xs_is_null(at = get_atto(irto))) { |
| 971 | xs *at_md5 = xs_md5_hex(at, strlen(at)); | 971 | xs *at_md5 = xs_md5_hex(at, strlen(at)); |
| 972 | st = xs_dict_set(st, "in_reply_to_account_id", at_md5); | 972 | st = xs_dict_set(st, "in_reply_to_account_id", at_md5); |
| 973 | } | 973 | } |
| @@ -1443,7 +1443,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1443 | from = xs_dict_get(msg, "audience"); | 1443 | from = xs_dict_get(msg, "audience"); |
| 1444 | 1444 | ||
| 1445 | if (from == NULL) | 1445 | if (from == NULL) |
| 1446 | from = xs_dict_get(msg, "attributedTo"); | 1446 | from = get_atto(msg); |
| 1447 | 1447 | ||
| 1448 | if (from == NULL) | 1448 | if (from == NULL) |
| 1449 | continue; | 1449 | continue; |
| @@ -1525,7 +1525,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1525 | 1525 | ||
| 1526 | /* discard private users */ | 1526 | /* discard private users */ |
| 1527 | { | 1527 | { |
| 1528 | const char *atto = xs_dict_get(msg, "attributedTo"); | 1528 | const char *atto = get_atto(msg); |
| 1529 | xs *l = xs_split(atto, "/"); | 1529 | xs *l = xs_split(atto, "/"); |
| 1530 | const char *uid = xs_list_get(l, -1); | 1530 | const char *uid = xs_list_get(l, -1); |
| 1531 | snac p_user; | 1531 | snac p_user; |
| @@ -1825,7 +1825,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1825 | 1825 | ||
| 1826 | if (valid_status(object_get_by_md5(id, &msg))) { | 1826 | if (valid_status(object_get_by_md5(id, &msg))) { |
| 1827 | if (op == NULL) { | 1827 | if (op == NULL) { |
| 1828 | if (!is_muted(&snac1, xs_dict_get(msg, "attributedTo"))) { | 1828 | if (!is_muted(&snac1, get_atto(msg))) { |
| 1829 | /* return the status itself */ | 1829 | /* return the status itself */ |
| 1830 | out = mastoapi_status(&snac1, msg); | 1830 | out = mastoapi_status(&snac1, msg); |
| 1831 | } | 1831 | } |
| @@ -2435,7 +2435,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2435 | 2435 | ||
| 2436 | if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { | 2436 | if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { |
| 2437 | const char *id = xs_dict_get(msg, "id"); | 2437 | const char *id = xs_dict_get(msg, "id"); |
| 2438 | const char *atto = xs_dict_get(msg, "attributedTo"); | 2438 | const char *atto = get_atto(msg); |
| 2439 | 2439 | ||
| 2440 | xs_list *opts = xs_dict_get(msg, "oneOf"); | 2440 | xs_list *opts = xs_dict_get(msg, "oneOf"); |
| 2441 | if (opts == NULL) | 2441 | if (opts == NULL) |
| @@ -245,6 +245,8 @@ const char *default_avatar_base64(void); | |||
| 245 | 245 | ||
| 246 | xs_str *process_tags(snac *snac, const char *content, xs_list **tag); | 246 | xs_str *process_tags(snac *snac, const char *content, xs_list **tag); |
| 247 | 247 | ||
| 248 | char *get_atto(const xs_dict *msg); | ||
| 249 | |||
| 248 | xs_dict *msg_admiration(snac *snac, char *object, char *type); | 250 | xs_dict *msg_admiration(snac *snac, char *object, char *type); |
| 249 | xs_dict *msg_create(snac *snac, const xs_dict *object); | 251 | xs_dict *msg_create(snac *snac, const xs_dict *object); |
| 250 | xs_dict *msg_follow(snac *snac, const char *actor); | 252 | xs_dict *msg_follow(snac *snac, const char *actor); |