diff options
| author | 2023-03-06 14:28:53 +0100 | |
|---|---|---|
| committer | 2023-03-06 14:28:53 +0100 | |
| commit | e3e45b7c98ecae9b5e0b1d417b29fda073505134 (patch) | |
| tree | d070cc62b7a6f524980e80afc7c04fce38cd5031 | |
| parent | Changed the way invalid codes in strings are stripped. (diff) | |
| download | snac2-e3e45b7c98ecae9b5e0b1d417b29fda073505134.tar.gz snac2-e3e45b7c98ecae9b5e0b1d417b29fda073505134.tar.xz snac2-e3e45b7c98ecae9b5e0b1d417b29fda073505134.zip | |
New function is_msg_for_me().
| -rw-r--r-- | activitypub.c | 35 | ||||
| -rw-r--r-- | snac.h | 1 |
2 files changed, 35 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index e5713fa..ee790c7 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -289,6 +289,34 @@ int is_msg_public(snac *snac, xs_dict *msg) | |||
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | 291 | ||
| 292 | int is_msg_for_me(snac *snac, xs_dict *msg) | ||
| 293 | /* checks if this message is for me */ | ||
| 294 | { | ||
| 295 | int ret = 1; | ||
| 296 | char *type = xs_dict_get(msg, "type"); | ||
| 297 | |||
| 298 | if (!xs_is_null(type) && strcmp(type, "Note") == 0) { | ||
| 299 | xs *rcpts = recipient_list(snac, msg, 0); | ||
| 300 | xs_list *p = rcpts; | ||
| 301 | xs_str *v; | ||
| 302 | |||
| 303 | while(xs_list_iter(&p, &v)) { | ||
| 304 | /* explicitly for me? we're done */ | ||
| 305 | if (strcmp(v, snac->actor) == 0) | ||
| 306 | goto done; | ||
| 307 | } | ||
| 308 | |||
| 309 | /* if we're not following this fellow, then the answer is NO */ | ||
| 310 | char *atto = xs_dict_get(msg, "attributedTo"); | ||
| 311 | if (xs_is_null(atto) || !following_check(snac, atto)) | ||
| 312 | ret = 0; | ||
| 313 | } | ||
| 314 | |||
| 315 | done: | ||
| 316 | return ret; | ||
| 317 | } | ||
| 318 | |||
| 319 | |||
| 292 | void process_tags(snac *snac, const char *content, d_char **n_content, d_char **tag) | 320 | void process_tags(snac *snac, const char *content, d_char **n_content, d_char **tag) |
| 293 | /* parses mentions and tags from content */ | 321 | /* parses mentions and tags from content */ |
| 294 | { | 322 | { |
| @@ -874,7 +902,7 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg | |||
| 874 | 902 | ||
| 875 | /** queues **/ | 903 | /** queues **/ |
| 876 | 904 | ||
| 877 | int process_input_message(snac *snac, char *msg, char *req) | 905 | int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) |
| 878 | /* processes an ActivityPub message from the input queue */ | 906 | /* processes an ActivityPub message from the input queue */ |
| 879 | { | 907 | { |
| 880 | /* actor and type exist, were checked previously */ | 908 | /* actor and type exist, were checked previously */ |
| @@ -892,6 +920,11 @@ int process_input_message(snac *snac, char *msg, char *req) | |||
| 892 | else | 920 | else |
| 893 | utype = "(null)"; | 921 | utype = "(null)"; |
| 894 | 922 | ||
| 923 | /* reject messages that are not for this user */ | ||
| 924 | if (!is_msg_for_me(snac, msg)) { | ||
| 925 | snac_debug(snac, 0, xs_fmt("message from %s not for us", actor)); | ||
| 926 | } | ||
| 927 | |||
| 895 | /* bring the actor */ | 928 | /* bring the actor */ |
| 896 | a_status = actor_request(snac, actor, &actor_o); | 929 | a_status = actor_request(snac, actor, &actor_o); |
| 897 | 930 | ||
| @@ -195,6 +195,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, | |||
| 195 | d_char *get_actor_inbox(snac *snac, char *actor); | 195 | d_char *get_actor_inbox(snac *snac, char *actor); |
| 196 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); | 196 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); |
| 197 | int is_msg_public(snac *snac, xs_dict *msg); | 197 | int is_msg_public(snac *snac, xs_dict *msg); |
| 198 | int is_msg_for_me(snac *snac, xs_dict *msg); | ||
| 198 | 199 | ||
| 199 | int process_user_queue(snac *snac); | 200 | int process_user_queue(snac *snac); |
| 200 | void process_queue_item(xs_dict *q_item); | 201 | void process_queue_item(xs_dict *q_item); |