From dde937cec56b3f6563322d37121308d3f5f5ac39 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Tue, 25 Feb 2020 18:06:41 -0500 Subject: Request server-time from the server and filter tags for clients This doesn't yet, but it will break the "robustness principle" according to which a server "SHOULD NOT" assume that a client capable of parsing one tag is capable of parsing all tags. In future, TagCaps will have all other caps that use tags ORed into it, and only if the client supports none of them will tags be filtered out. --- client.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index 93b1716..8a4e86f 100644 --- a/client.c +++ b/client.c @@ -315,6 +315,10 @@ size_t clientDiff(const struct Client *client) { } static int wordcmp(const char *line, size_t i, const char *word) { + if (line[0] == '@') { + line += strcspn(line, " "); + if (*line) line++; + } while (i--) { line += strcspn(line, " "); if (*line) line++; @@ -421,6 +425,12 @@ static const char *filterUserhostInNames(const char *line) { ); } +static const char *filterTags(const char *line) { + if (line[0] != '@') return line; + const char *sp = strchr(line, ' '); + return (sp ? sp + 1 : NULL); +} + static Filter *Filters[] = { [CapAccountNotifyBit] = filterAccountNotify, [CapAwayNotifyBit] = filterAwayNotify, @@ -441,18 +451,23 @@ void clientConsume(struct Client *client) { if (!Filters[i]) continue; if (diff & (1 << i)) line = Filters[i](line); } + if (stateCaps & TagCaps && !(client->caps & TagCaps)) { + if (line) line = filterTags(line); + } if (!line) { ringConsume(NULL, client->consumer); return; } - if (client->caps & CapServerTime) { + if (client->caps & CapServerTime && !(stateCaps & CapServerTime)) { char ts[sizeof("YYYY-MM-DDThh:mm:ss")]; struct tm *tm = gmtime(&time.tv_sec); strftime(ts, sizeof(ts), "%FT%T", tm); clientFormat( - client, "@time=%s.%03dZ %s\r\n", - ts, (int)(time.tv_usec / 1000), line + client, "@time=%s.%03dZ%c%s\r\n", + ts, (int)(time.tv_usec / 1000), + (line[0] == '@' ? ';' : ' '), + (line[0] == '@' ? &line[1] : line) ); } else { clientFormat(client, "%s\r\n", line); -- cgit 1.4.1