From 1c194042580249fae3b54ea00517c399d8bc7b77 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 10 Dec 2023 10:17:50 +0100 Subject: Minor reordering code to process_input_message(). --- activitypub.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index 517b942..0764fa2 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1475,7 +1475,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) int do_notify = 0; if (xs_is_null(actor) || *actor == '\0') { - snac_debug(snac, 0, xs_fmt("malformed message (bad actor)")); + srv_debug(0, xs_fmt("malformed message (bad actor)")); return -1; } @@ -1485,7 +1485,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) /* reject uninteresting messages right now */ if (strcmp(type, "Add") == 0) { - snac_debug(snac, 0, xs_fmt("Ignored message of type '%s'", type)); + srv_debug(0, xs_fmt("Ignored message of type '%s'", type)); return -1; } @@ -1497,38 +1497,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) else utype = "(null)"; - /* reject messages that are not for this user */ - if (!is_msg_for_me(snac, msg)) { - snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type)); - - return 1; - } - - /* if it's a DM from someone we don't follow, reject the message */ - if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) { - if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) && - !following_check(snac, actor)) { - snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor)); - - return 1; - } - } - /* bring the actor */ a_status = actor_request(snac, actor, &actor_o); /* do not retry permanent failures */ if (a_status == 404 || a_status == 410 || a_status < 0) { - snac_debug(snac, 1, - xs_fmt("dropping message due to actor error %s %d", actor, a_status)); + srv_debug(1, xs_fmt("dropping message due to actor error %s %d", actor, a_status)); return -1; } if (!valid_status(a_status)) { /* other actor download errors may need a retry */ - snac_debug(snac, 1, - xs_fmt("error requesting actor %s %d -- retry later", actor, a_status)); + srv_debug(1, xs_fmt("error requesting actor %s %d -- retry later", actor, a_status)); return 0; } @@ -1537,13 +1518,34 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) xs *sig_err = NULL; if (!check_signature(snac, req, &sig_err)) { - snac_log(snac, xs_fmt("bad signature %s (%s)", actor, sig_err)); + srv_log(xs_fmt("bad signature %s (%s)", actor, sig_err)); srv_archive_error("check_signature", sig_err, req, msg); return -1; } + /* if no user is set, no further checks can be done */ + if (snac == NULL) + return 1; + + /* reject messages that are not for this user */ + if (!is_msg_for_me(snac, msg)) { + snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type)); + + return 1; + } + + /* if it's a DM from someone we don't follow, reject the message */ + if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) { + if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) && + !following_check(snac, actor)) { + snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor)); + + return 1; + } + } + if (strcmp(type, "Follow") == 0) { /** **/ if (!follower_check(snac, actor)) { xs *f_msg = xs_dup(msg); -- cgit v1.2.3