From e7e54068aa06e882bebf0750707e4b8c1af56bf5 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 9 Nov 2019 12:42:39 -0500 Subject: Parse capabilities The list that I've defined are the ones that I expect to be able to enable probably without any clients breaking... And of course server-time which pounce implements itself. --- bounce.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'bounce.h') diff --git a/bounce.h b/bounce.h index aa7fda1..5dd2536 100644 --- a/bounce.h +++ b/bounce.h @@ -35,8 +35,6 @@ typedef unsigned char byte; -bool verbose; - enum { ParamCap = 15 }; struct Message { char *origin; @@ -58,6 +56,59 @@ static inline struct Message parse(char *line) { return msg; } +#define ENUM_CAP \ + X("account-notify", CapAccountNotify) \ + X("away-notify", CapAwayNotify) \ + X("chghost", CapChghost) \ + X("extended-join", CapExtendedJoin) \ + X("invite-notify", CapInviteNotify) \ + X("server-time", CapServerTime) \ + X("", CapUnsupported) + +enum Cap { +#define X(name, id) BIT(id), + ENUM_CAP +#undef X +}; + +static const char *CapNames[] = { +#define X(name, id) [id##Bit] = name, + ENUM_CAP +#undef X +}; + +static inline enum Cap capParse(const char *list) { + enum Cap caps = 0; + while (*list) { + enum Cap cap = CapUnsupported; + size_t len = strcspn(list, " "); + for (size_t i = 0; i < ARRAY_LEN(CapNames); ++i) { + if (len != strlen(CapNames[i])) continue; + if (strncmp(list, CapNames[i], len)) continue; + cap = 1 << i; + break; + } + caps |= cap; + list += len; + if (*list) list++; + } + return caps; +} + +static inline const char *capList(enum Cap caps) { + static char buf[1024]; + buf[0] = '\0'; + for (size_t i = 0; i < ARRAY_LEN(CapNames); ++i) { + if (caps & (1 << i)) { + if (buf[0]) strlcat(buf, " ", sizeof(buf)); + strlcat(buf, CapNames[i], sizeof(buf)); + } + } + return buf; +} + +bool verbose; + void ringAlloc(size_t len); void ringProduce(const char *line); size_t ringConsumer(const char *name); -- cgit 1.4.1