summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-11-10 20:11:13 -0500
committerJune McEnroe <june@causal.agency>2019-11-10 20:12:25 -0500
commit33a107f82da6e3a3f199a63661b3e31272c3fa71 (patch)
tree45c00d4b1b9f4e89f924c5ed7c29a016c49520a1 /client.c
parentAdd capsicum note to README (diff)
downloadpounce-33a107f82da6e3a3f199a63661b3e31272c3fa71.tar.gz
pounce-33a107f82da6e3a3f199a63661b3e31272c3fa71.zip
Filter invite-notify
Diffstat (limited to '')
-rw-r--r--client.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/client.c b/client.c
index 3ea00c8..22106e3 100644
--- a/client.c
+++ b/client.c
@@ -277,30 +277,31 @@ size_t clientDiff(const struct Client *client) {
 
 typedef const char *Filter(const char *line);
 
-static const char *cmd(const char *line) {
-	static char buf[512];
-	if (*line == ':') {
+static const char *word(size_t i, const char *line) {
+	if (*line != ':') i--;
+	for (; i; --i) {
 		line += strcspn(line, " ");
 		if (*line) line++;
 	}
+	static char buf[512];
 	snprintf(buf, sizeof(buf), "%.*s", (int)strcspn(line, " "), line);
 	return buf;
 }
 
 static const char *filterAccountNotify(const char *line) {
-	return (strcmp(cmd(line), "ACCOUNT") ? line : NULL);
+	return (strcmp(word(1, line), "ACCOUNT") ? line : NULL);
 }
 
 static const char *filterAwayNotify(const char *line) {
-	return (strcmp(cmd(line), "AWAY") ? line : NULL);
+	return (strcmp(word(1, line), "AWAY") ? line : NULL);
 }
 
 static const char *filterChghost(const char *line) {
-	return (strcmp(cmd(line), "CHGHOST") ? line : NULL);
+	return (strcmp(word(1, line), "CHGHOST") ? line : NULL);
 }
 
 static const char *filterExtendedJoin(const char *line) {
-	if (strcmp(cmd(line), "JOIN")) return line;
+	if (strcmp(word(1, line), "JOIN")) return line;
 	size_t len = 0;
 	for (int i = 0; i < 3; ++i) {
 		len += strcspn(&line[len], " ");
@@ -311,11 +312,17 @@ static const char *filterExtendedJoin(const char *line) {
 	return buf;
 }
 
+static const char *filterInviteNotify(const char *line) {
+	if (strcmp(word(1, line), "INVITE")) return line;
+	return (strcmp(word(2, line), stateNick()) ? NULL : line);
+}
+
 static Filter *Filters[] = {
 	[CapAccountNotifyBit] = filterAccountNotify,
 	[CapAwayNotifyBit] = filterAwayNotify,
 	[CapChghostBit] = filterChghost,
 	[CapExtendedJoinBit] = filterExtendedJoin,
+	[CapInviteNotifyBit] = filterInviteNotify,
 };
 
 void clientConsume(struct Client *client) {