summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c50
1 files changed, 26 insertions, 24 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)
1475 int do_notify = 0; 1475 int do_notify = 0;
1476 1476
1477 if (xs_is_null(actor) || *actor == '\0') { 1477 if (xs_is_null(actor) || *actor == '\0') {
1478 snac_debug(snac, 0, xs_fmt("malformed message (bad actor)")); 1478 srv_debug(0, xs_fmt("malformed message (bad actor)"));
1479 return -1; 1479 return -1;
1480 } 1480 }
1481 1481
@@ -1485,7 +1485,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1485 1485
1486 /* reject uninteresting messages right now */ 1486 /* reject uninteresting messages right now */
1487 if (strcmp(type, "Add") == 0) { 1487 if (strcmp(type, "Add") == 0) {
1488 snac_debug(snac, 0, xs_fmt("Ignored message of type '%s'", type)); 1488 srv_debug(0, xs_fmt("Ignored message of type '%s'", type));
1489 return -1; 1489 return -1;
1490 } 1490 }
1491 1491
@@ -1497,38 +1497,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1497 else 1497 else
1498 utype = "(null)"; 1498 utype = "(null)";
1499 1499
1500 /* reject messages that are not for this user */
1501 if (!is_msg_for_me(snac, msg)) {
1502 snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type));
1503
1504 return 1;
1505 }
1506
1507 /* if it's a DM from someone we don't follow, reject the message */
1508 if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
1509 if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
1510 !following_check(snac, actor)) {
1511 snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
1512
1513 return 1;
1514 }
1515 }
1516
1517 /* bring the actor */ 1500 /* bring the actor */
1518 a_status = actor_request(snac, actor, &actor_o); 1501 a_status = actor_request(snac, actor, &actor_o);
1519 1502
1520 /* do not retry permanent failures */ 1503 /* do not retry permanent failures */
1521 if (a_status == 404 || a_status == 410 || a_status < 0) { 1504 if (a_status == 404 || a_status == 410 || a_status < 0) {
1522 snac_debug(snac, 1, 1505 srv_debug(1, xs_fmt("dropping message due to actor error %s %d", actor, a_status));
1523 xs_fmt("dropping message due to actor error %s %d", actor, a_status));
1524 1506
1525 return -1; 1507 return -1;
1526 } 1508 }
1527 1509
1528 if (!valid_status(a_status)) { 1510 if (!valid_status(a_status)) {
1529 /* other actor download errors may need a retry */ 1511 /* other actor download errors may need a retry */
1530 snac_debug(snac, 1, 1512 srv_debug(1, xs_fmt("error requesting actor %s %d -- retry later", actor, a_status));
1531 xs_fmt("error requesting actor %s %d -- retry later", actor, a_status));
1532 1513
1533 return 0; 1514 return 0;
1534 } 1515 }
@@ -1537,13 +1518,34 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1537 xs *sig_err = NULL; 1518 xs *sig_err = NULL;
1538 1519
1539 if (!check_signature(snac, req, &sig_err)) { 1520 if (!check_signature(snac, req, &sig_err)) {
1540 snac_log(snac, xs_fmt("bad signature %s (%s)", actor, sig_err)); 1521 srv_log(xs_fmt("bad signature %s (%s)", actor, sig_err));
1541 1522
1542 srv_archive_error("check_signature", sig_err, req, msg); 1523 srv_archive_error("check_signature", sig_err, req, msg);
1543 1524
1544 return -1; 1525 return -1;
1545 } 1526 }
1546 1527
1528 /* if no user is set, no further checks can be done */
1529 if (snac == NULL)
1530 return 1;
1531
1532 /* reject messages that are not for this user */
1533 if (!is_msg_for_me(snac, msg)) {
1534 snac_debug(snac, 1, xs_fmt("message from %s of type '%s' not for us", actor, type));
1535
1536 return 1;
1537 }
1538
1539 /* if it's a DM from someone we don't follow, reject the message */
1540 if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
1541 if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
1542 !following_check(snac, actor)) {
1543 snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
1544
1545 return 1;
1546 }
1547 }
1548
1547 if (strcmp(type, "Follow") == 0) { /** **/ 1549 if (strcmp(type, "Follow") == 0) { /** **/
1548 if (!follower_check(snac, actor)) { 1550 if (!follower_check(snac, actor)) {
1549 xs *f_msg = xs_dup(msg); 1551 xs *f_msg = xs_dup(msg);