commit 1c19404

default  ·  2023-12-10 09:17:50 +0000 UTC
parent 95ccff5
Minor reordering code to process_input_message().
1 files changed,  +26, -24
+26, -24
 1@@ -1475,7 +1475,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
 2     int do_notify = 0;
 3 
 4     if (xs_is_null(actor) || *actor == '\0') {
 5-        snac_debug(snac, 0, xs_fmt("malformed message (bad actor)"));
 6+        srv_debug(0, xs_fmt("malformed message (bad actor)"));
 7         return -1;
 8     }
 9 
10@@ -1485,7 +1485,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
11 
12     /* reject uninteresting messages right now */
13     if (strcmp(type, "Add") == 0) {
14-        snac_debug(snac, 0, xs_fmt("Ignored message of type '%s'", type));
15+        srv_debug(0, xs_fmt("Ignored message of type '%s'", type));
16         return -1;
17     }
18 
19@@ -1497,38 +1497,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
20     else
21         utype = "(null)";
22 
23-    /* reject messages that are not for this user */
24-    if (!is_msg_for_me(snac, msg)) {
25-        snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type));
26-
27-        return 1;
28-    }
29-
30-    /* if it's a DM from someone we don't follow, reject the message */
31-    if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
32-        if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
33-            !following_check(snac, actor)) {
34-            snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
35-
36-            return 1;
37-        }
38-    }
39-
40     /* bring the actor */
41     a_status = actor_request(snac, actor, &actor_o);
42 
43     /* do not retry permanent failures */
44     if (a_status == 404 || a_status == 410 || a_status < 0) {
45-        snac_debug(snac, 1,
46-            xs_fmt("dropping message due to actor error %s %d", actor, a_status));
47+        srv_debug(1, xs_fmt("dropping message due to actor error %s %d", actor, a_status));
48 
49         return -1;
50     }
51 
52     if (!valid_status(a_status)) {
53         /* other actor download errors may need a retry */
54-        snac_debug(snac, 1,
55-            xs_fmt("error requesting actor %s %d -- retry later", actor, a_status));
56+        srv_debug(1, xs_fmt("error requesting actor %s %d -- retry later", actor, a_status));
57 
58         return 0;
59     }
60@@ -1537,13 +1518,34 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
61     xs *sig_err = NULL;
62 
63     if (!check_signature(snac, req, &sig_err)) {
64-        snac_log(snac, xs_fmt("bad signature %s (%s)", actor, sig_err));
65+        srv_log(xs_fmt("bad signature %s (%s)", actor, sig_err));
66 
67         srv_archive_error("check_signature", sig_err, req, msg);
68 
69         return -1;
70     }
71 
72+    /* if no user is set, no further checks can be done */
73+    if (snac == NULL)
74+        return 1;
75+
76+    /* reject messages that are not for this user */
77+    if (!is_msg_for_me(snac, msg)) {
78+        snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type));
79+
80+        return 1;
81+    }
82+
83+    /* if it's a DM from someone we don't follow, reject the message */
84+    if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
85+        if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
86+            !following_check(snac, actor)) {
87+            snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
88+
89+            return 1;
90+        }
91+    }
92+
93     if (strcmp(type, "Follow") == 0) { /** **/
94         if (!follower_check(snac, actor)) {
95             xs *f_msg = xs_dup(msg);