summary refs log tree commit diff
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
parentAdd capsicum note to README (diff)
downloadpounce-33a107f82da6e3a3f199a63661b3e31272c3fa71.tar.gz
pounce-33a107f82da6e3a3f199a63661b3e31272c3fa71.zip
Filter invite-notify
-rw-r--r--bounce.h2
-rw-r--r--client.c21
-rw-r--r--pounce.13
-rw-r--r--state.c8
4 files changed, 23 insertions, 11 deletions
diff --git a/bounce.h b/bounce.h
index 8480d75..dd26bc3 100644
--- a/bounce.h
+++ b/bounce.h
@@ -61,6 +61,7 @@ static inline struct Message parse(char *line) {
 	X("away-notify", CapAwayNotify) \
 	X("chghost", CapChghost) \
 	X("extended-join", CapExtendedJoin) \
+	X("invite-notify", CapInviteNotify) \
 	X("sasl", CapSASL) \
 	X("server-time", CapServerTime) \
 	X("", CapUnsupported)
@@ -152,6 +153,7 @@ void stateLogin(
 bool stateReady(void);
 void stateParse(char *line);
 void stateSync(struct Client *client);
+const char *stateNick(void);
 const char *stateEcho(void);
 
 struct option;
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) {
diff --git a/pounce.1 b/pounce.1
index 9477bbe..bf4f60a 100644
--- a/pounce.1
+++ b/pounce.1
@@ -284,7 +284,8 @@ is supported:
 .Sy account-notify ,
 .Sy away-notify ,
 .Sy chghost ,
-.Sy extended-join .
+.Sy extended-join ,
+.Sy invite-notify .
 .
 .Ss Configuring SASL EXTERNAL
 .Bl -enum
diff --git a/state.c b/state.c
index b786adb..4103fff 100644
--- a/state.c
+++ b/state.c
@@ -119,10 +119,12 @@ static struct {
 	char *myInfo[5];
 } intro;
 
+const char *stateNick(void) {
+	return (self.nick ? self.nick : "*");
+}
+
 const char *stateEcho(void) {
-	if (self.origin) return self.origin;
-	if (self.nick) return self.nick;
-	return "*";
+	return (self.origin ? self.origin : stateNick());
 }
 
 bool stateReady(void) {