summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bounce.h1
-rw-r--r--client.c23
-rw-r--r--pounce.13
3 files changed, 25 insertions, 2 deletions
diff --git a/bounce.h b/bounce.h
index d94eae4..7bf830b 100644
--- a/bounce.h
+++ b/bounce.h
@@ -62,6 +62,7 @@ static inline struct Message parse(char *line) {
 	X("chghost", CapChghost) \
 	X("extended-join", CapExtendedJoin) \
 	X("invite-notify", CapInviteNotify) \
+	X("multi-prefix", CapMultiPrefix) \
 	X("sasl", CapSASL) \
 	X("server-time", CapServerTime) \
 	X("userhost-in-names", CapUserhostInNames) \
diff --git a/client.c b/client.c
index 324c6f0..6653005 100644
--- a/client.c
+++ b/client.c
@@ -302,6 +302,7 @@ static size_t strlcpyn(char *dst, const char *src, size_t cap, size_t len) {
 static char *snip(char *dst, size_t cap, const char *src, const regex_t *regex) {
 	size_t len = 0;
 	regmatch_t match[2];
+	assert(regex->re_nsub);
 	for (; *src; src += match[0].rm_eo) {
 		if (regexec(regex, src, 2, match, 0)) break;
 		len += strlcpyn(&dst[len], src, cap - len, match[0].rm_so);
@@ -353,13 +354,32 @@ static const char *filterInviteNotify(const char *line) {
 	return (wordcmp(line, 2, stateNick()) ? NULL : line);
 }
 
+static const char *filterMultiPrefix(const char *line) {
+	static char buf[512];
+	if (!wordcmp(line, 1, "352")) {
+		static regex_t regex;
+		return snip(
+			buf, sizeof(buf), line,
+			compile(&regex, "([HG][*]?[~!@%&+])[~!@%&+]+")
+		);
+	} else if (!wordcmp(line, 1, "353")) {
+		static regex_t regex;
+		return snip(
+			buf, sizeof(buf), line,
+			compile(&regex, "([ :][~!@%&+])[~!@%&+]+")
+		);
+	} else {
+		return line;
+	}
+}
+
 static const char *filterUserhostInNames(const char *line) {
 	if (wordcmp(line, 1, "353")) return line;
 	static regex_t regex;
 	static char buf[512];
 	return snip(
 		buf, sizeof(buf), line,
-		compile(&regex, "([ :][^!]+)![^ ]+")
+		compile(&regex, "([ :][^!]+)![^@]+@[^ ]+")
 	);
 }
 
@@ -369,6 +389,7 @@ static Filter *Filters[] = {
 	[CapChghostBit] = filterChghost,
 	[CapExtendedJoinBit] = filterExtendedJoin,
 	[CapInviteNotifyBit] = filterInviteNotify,
+	[CapMultiPrefixBit] = filterMultiPrefix,
 	[CapUserhostInNamesBit] = filterUserhostInNames,
 };
 
diff --git a/pounce.1 b/pounce.1
index bc33d23..6b7c5d9 100644
--- a/pounce.1
+++ b/pounce.1
@@ -1,4 +1,4 @@
-.Dd November 11, 2019
+.Dd November 14, 2019
 .Dt POUNCE 1
 .Os
 .
@@ -286,6 +286,7 @@ is supported:
 .Sy chghost ,
 .Sy extended-join ,
 .Sy invite-notify ,
+.Sy multi-prefix ,
 .Sy userhost-in-names .
 .
 .Ss Configuring SASL EXTERNAL