From cb86d3213519727a7fecd05b18b6a8adff230976 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 6 Jan 2024 11:15:57 +0200 Subject: (src) Moved source files to a src folder --- src/server-cli.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/server-cli.c (limited to 'src/server-cli.c') diff --git a/src/server-cli.c b/src/server-cli.c new file mode 100644 index 0000000..58e5ea4 --- /dev/null +++ b/src/server-cli.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#define MAX_LEN_COMMAND 16 +#define COMMAND_FORMAT ": %16s" + +void handleCLI(sds **vhosts, int vhostsc) { + // Get a line + char line[256]; + fgets(line, 256, stdin); + + // Get command name and it's arguments + // Currently no command takes arguments + char name[MAX_LEN_COMMAND+1]; + int argsAssigned = sscanf(line, COMMAND_FORMAT, name); + + while (!streq(name, "q") && !streq(name, "e") && !streq(name, "quit") && !streq(name, "exit")) { + if (argsAssigned < 1) { + printf("Bad command syntax!\n"); + } + else if (streq(name, "vhosts")) { + for (int i = 0; i < vhostsc; i++) { + printf("Name: \"%s\" Root dir: \"%s\" Error file: \"%s\"\n", + vhosts[i][vh_user], + vhosts[i][vh_path], + vhosts[i][vh_error]); + } + } + else if (streq(name, "help") || streq(name, "h") || streq(name, "?")) { + printf("help,h,?\tPrints this message\nvhosts\t\tPrints all registered virtual hosts\nquit,exit,q,e\tExits the program\n"); + } + else { + printf("Unknown command %s!\n", name); + } + + // Get line and divided it into command name and arguments + fgets(line, 256, stdin); + argsAssigned = sscanf(line, COMMAND_FORMAT, name); + } + + printf("Exiting...\n"); + kill(getppid(), SIGTERM); +} -- cgit v1.2.3