From 33a107f82da6e3a3f199a63661b3e31272c3fa71 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 10 Nov 2019 20:11:13 -0500 Subject: Filter invite-notify --- client.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'client.c') 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) { -- cgit 1.4.1