summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-03-06 20:07:44 +0100
committerGravatar default2023-03-06 20:07:44 +0100
commit946c29773a1277f37ef41cd869170371d55783bd (patch)
treed8ea10be6b8afdf4cb929a867cd218d6bf9dbce1
parentFixed is_msg_for_me(). (diff)
downloadsnac2-946c29773a1277f37ef41cd869170371d55783bd.tar.gz
snac2-946c29773a1277f37ef41cd869170371d55783bd.tar.xz
snac2-946c29773a1277f37ef41cd869170371d55783bd.zip
Some improvements to is_msg_for_me().
-rw-r--r--activitypub.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/activitypub.c b/activitypub.c
index 75cbecf..4e8abf1 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -289,31 +289,48 @@ int is_msg_public(snac *snac, xs_dict *msg)
289} 289}
290 290
291 291
292int is_msg_for_me(snac *snac, xs_dict *msg) 292int is_msg_for_me(snac *snac, xs_dict *c_msg)
293/* checks if this message is for me */ 293/* checks if this message is for me */
294{ 294{
295 int ret = 1; 295 char *type = xs_dict_get(c_msg, "type");
296 char *type = xs_dict_get(msg, "type");
297 296
298 if (!xs_is_null(type) && strcmp(type, "Create") == 0) { 297 /* if it's not a Create, allow */
299 xs *rcpts = recipient_list(snac, msg, 0); 298 if (xs_is_null(type) || strcmp(type, "Create") != 0)
300 xs_list *p = rcpts; 299 return 1;
301 xs_str *v;
302 300
303 while(xs_list_iter(&p, &v)) { 301 xs_dict *msg = xs_dict_get(c_msg, "object");
304 /* explicitly for me? we're done */ 302 xs *rcpts = recipient_list(snac, msg, 0);
305 if (strcmp(v, snac->actor) == 0) 303 xs_list *p = rcpts;
306 goto done; 304 xs_str *v;
307 } 305
306 while(xs_list_iter(&p, &v)) {
307 /* explicitly for me? we're done */
308 if (strcmp(v, snac->actor) == 0)
309 return 2;
310 }
308 311
309 /* if we're not following this fellow, then the answer is NO */ 312 /* accept if it's from someone we follow */
310 char *actor = xs_dict_get(msg, "actor"); 313 char *atto = xs_dict_get(msg, "attributedTo");
311 if (xs_is_null(actor) || !following_check(snac, actor)) 314
312 ret = 0; 315 if (!xs_is_null(atto) && following_check(snac, atto))
316 return 3;
317
318 /* is this message a reply to another? */
319 char *irt = xs_dict_get(msg, "inReplyTo");
320 if (!xs_is_null(irt)) {
321 xs *r_msg = NULL;
322
323 /* try to get it */
324 if (valid_status(object_get(irt, &r_msg))) {
325 atto = xs_dict_get(r_msg, "attributedTo");
326
327 /* accept if the replied message is from someone we follow */
328 if (!xs_is_null(atto) && following_check(snac, atto))
329 return 4;
330 }
313 } 331 }
314 332
315done: 333 return 0;
316 return ret;
317} 334}
318 335
319 336
@@ -921,7 +938,10 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
921 utype = "(null)"; 938 utype = "(null)";
922 939
923 /* reject messages that are not for this user */ 940 /* reject messages that are not for this user */
924 if (!is_msg_for_me(snac, msg)) { 941 int d = is_msg_for_me(snac, msg);
942 snac_debug(snac, 0, xs_fmt("---> %s %d", xs_dict_get(msg, "id"), d));
943
944 if (!d) {
925 snac_debug(snac, 0, xs_fmt("message from %s not for us", actor)); 945 snac_debug(snac, 0, xs_fmt("message from %s not for us", actor));
926 } 946 }
927 947