summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-20 19:46:07 -0400
committerJune McEnroe <june@causal.agency>2021-06-20 19:46:07 -0400
commit06c5342cfe158e2dbce8dd3bbbb07e757d6c219e (patch)
treed78a423682d0ae65cdcc1c6f3c5ab5dcc789958f
parentFix MOTD buffer reallocation (diff)
downloadlitterbox-06c5342cfe158e2dbce8dd3bbbb07e757d6c219e.tar.gz
litterbox-06c5342cfe158e2dbce8dd3bbbb07e757d6c219e.zip
Tighten action handling
Don't match actions in notices. Match empty "\1ACTION\1" actions.
Don't truncate at the first '\1'.
-rw-r--r--litterbox.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/litterbox.c b/litterbox.c
index 48e5b60..707a0a0 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -432,6 +432,23 @@ static void insertEvent(
 	dbRun(stmt);
 }
 
+static enum Type messageType(struct Message *msg) {
+	if (msg->cmd[0] == 'N') return Notice;
+	if (strncmp(msg->params[1], "\1ACTION", 7)) return Privmsg;
+	if (msg->params[1][7] == ' ') {
+		msg->params[1] += 8;
+	} else if (msg->params[1][7] == '\1') {
+		msg->params[1] += 7;
+	} else {
+		return Privmsg;
+	}
+	size_t len = strlen(msg->params[1]);
+	if (msg->params[1][len - 1] == '\1') {
+		msg->params[1][len - 1] = '\0';
+	}
+	return Action;
+}
+
 static void handlePrivmsg(struct Message *msg) {
 	require(msg, true, 2);
 
@@ -440,14 +457,7 @@ static void handlePrivmsg(struct Message *msg) {
 	if (statusmsg) context += strspn(context, statusmsg);
 	if (strchr(chanTypes, context[0])) query = false;
 	if (!strcmp(context, self)) context = msg->nick;
-
-	enum Type type = (!strcmp(msg->cmd, "NOTICE") ? Notice : Privmsg);
-	char *message = msg->params[1];
-	if (!strncmp(message, "\1ACTION ", 8)) {
-		message += 8;
-		message[strcspn(message, "\1")] = '\0';
-		type = Action;
-	}
+	enum Type type = messageType(msg);
 
 	bool selfMessage = !strcmp(msg->nick, msg->params[0]);
 	if (query && searchQuery && type == Privmsg) {
@@ -460,7 +470,7 @@ static void handlePrivmsg(struct Message *msg) {
 
 	insertContext(context, query);
 	insertName(msg);
-	insertEvent(msg, type, context, NULL, message);
+	insertEvent(msg, type, context, NULL, msg->params[1]);
 }
 
 static void insertTopic(
5-08-13 15:37:42 +0200'>2015-08-13cache.c: fix header orderJohn Keeping 2015-08-13configfile.c: don't include system headers directlyJohn Keeping 2015-08-13Remove redundant includesJohn Keeping 2015-08-13Makefile: include Git's config.mak.unameJohn Keeping 2015-08-13tests: allow shell to be overriddenJohn Keeping 2015-08-13redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping 2015-08-12log: allow users to follow a fileJohn Keeping 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld 2015-08-12filters: apply HTML escapingLazaros Koromilas 2015-08-12git: update to v2.5.0Christian Hesse 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt