From 617f3f8b05fa4538c5ef0628196a6e473185fdc5 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 23 Oct 2019 17:14:08 -0400 Subject: Clean up state.c and factor out parsing --- bounce.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'bounce.h') diff --git a/bounce.h b/bounce.h index e81ed8f..491616b 100644 --- a/bounce.h +++ b/bounce.h @@ -16,6 +16,7 @@ #include #include +#include #include #ifndef DEFAULT_CERT_PATH @@ -30,6 +31,29 @@ struct Client { struct tls *tls; }; +#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0])) + +enum { ParamCap = 15 }; +struct Command { + const char *origin; + const char *name; + const char *params[ParamCap]; +}; + +static inline struct Command parse(char *line) { + struct Command cmd = {0}; + if (line[0] == ':') cmd.origin = 1 + strsep(&line, " "); + cmd.name = strsep(&line, " "); + for (size_t i = 0; line && i < ParamCap; ++i) { + if (line[0] == ':') { + cmd.params[i] = &line[1]; + break; + } + cmd.params[i] = strsep(&line, " "); + } + return cmd; +} + bool verbose; void listenConfig(const char *cert, const char *priv); -- cgit 1.4.1