diff options
author | June McEnroe <june@causal.agency> | 2019-10-23 17:14:08 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-10-23 17:14:08 -0400 |
commit | 617f3f8b05fa4538c5ef0628196a6e473185fdc5 (patch) | |
tree | 4d03fc97bf939336c835aadad00b0ad9a7aeaa80 /bounce.h | |
parent | Respond to pings (diff) | |
download | pounce-617f3f8b05fa4538c5ef0628196a6e473185fdc5.tar.gz pounce-617f3f8b05fa4538c5ef0628196a6e473185fdc5.zip |
Clean up state.c and factor out parsing
Diffstat (limited to 'bounce.h')
-rw-r--r-- | bounce.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bounce.h b/bounce.h index e81ed8f..491616b 100644 --- a/bounce.h +++ b/bounce.h @@ -16,6 +16,7 @@ #include <stdbool.h> #include <stdlib.h> +#include <string.h> #include <tls.h> #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); |