From 1c194042580249fae3b54ea00517c399d8bc7b77 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 10 Dec 2023 10:17:50 +0100 Subject: [PATCH] Minor reordering code to process_input_message(). --- activitypub.c | 66 ++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) 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,6 +1497,38 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) else utype = "(null)"; + /* 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) { + 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 */ + srv_debug(1, xs_fmt("error requesting actor %s %d -- retry later", actor, a_status)); + + return 0; + } + + /* check the signature */ + xs *sig_err = NULL; + + if (!check_signature(snac, req, &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)); @@ -1514,36 +1546,6 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) } } - /* 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)); - - 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)); - - return 0; - } - - /* check the signature */ - xs *sig_err = NULL; - - if (!check_signature(snac, req, &sig_err)) { - snac_log(snac, xs_fmt("bad signature %s (%s)", actor, sig_err)); - - srv_archive_error("check_signature", sig_err, req, msg); - - return -1; - } - if (strcmp(type, "Follow") == 0) { /** **/ if (!follower_check(snac, actor)) { xs *f_msg = xs_dup(msg);