aboutsummaryrefslogtreecommitdiff
path: root/server-cli.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2023-12-08 17:55:57 +0200
committerSyndamia <kamen@syndamia.com>2023-12-08 17:55:57 +0200
commit7ad507e3ec8efb0cdbc32474ea7c1ccbf031b960 (patch)
tree712dd3f5acf72ba621bd3eeed282467e2e258636 /server-cli.c
parentde1e66d00a5469f02eb7323553b3b087e6255980 (diff)
downloadpico-web-7ad507e3ec8efb0cdbc32474ea7c1ccbf031b960.tar
pico-web-7ad507e3ec8efb0cdbc32474ea7c1ccbf031b960.tar.gz
pico-web-7ad507e3ec8efb0cdbc32474ea7c1ccbf031b960.zip
[server] Moved server-cli to it's own file and reorganized server and server-cli
Diffstat (limited to 'server-cli.c')
-rw-r--r--server-cli.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/server-cli.c b/server-cli.c
new file mode 100644
index 0000000..82c9501
--- /dev/null
+++ b/server-cli.c
@@ -0,0 +1,46 @@
+#include <util.h>
+#include <server-connection.h>
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+
+#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 (name[0] != 'q' && name[0] != '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")) {
+ printf("help\tPrints this message\nvhosts\tPrints all registered virtual hosts\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);
+}