From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/commands.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/commands.c (limited to 'src/commands.c') diff --git a/src/commands.c b/src/commands.c new file mode 100644 index 0000000..8602f7c --- /dev/null +++ b/src/commands.c @@ -0,0 +1,40 @@ +#include "commands.h" +#include "buffer.h" +#include "stralloc.h" +#include "str.h" +#include "case.h" + +static stralloc cmd = {0}; + +int commands(buffer *b,struct commands *c) +{ + int i; + char *arg; + + for (;;) { + if (!stralloc_copys(&cmd,"")) return -1; + + for (;;) { + if (!stralloc_readyplus(&cmd,1)) return -1; + i = buffer_get(b,cmd.s + cmd.len,1); + if (i != 1) return i; + if (cmd.s[cmd.len] == '\n') break; + ++cmd.len; + } + + if (cmd.len > 0) if (cmd.s[cmd.len - 1] == '\r') --cmd.len; + + cmd.s[cmd.len] = 0; + + i = str_chr(cmd.s,' '); + arg = cmd.s + i; + while (*arg == ' ') ++arg; + cmd.s[i] = 0; + + for (i = 0; c[i].text; ++i) + if (case_equals(c[i].text,cmd.s)) break; + + c[i].fun(arg); + if (c[i].flush) c[i].flush(); + } +} -- cgit v1.2.3