aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-01-06 08:13:16 +0100
committernsensfel <SpamShield0@noot-noot.org>2020-01-06 08:13:16 +0100
commit11138ae4e8e3ed2f01156189923f7904c8f21591 (patch)
tree72b724c397a685140a9dc37b6314b88f798be8da
parentf9a06303ce72aa6697c17447dfef545db72c2407 (diff)
downloadrelabsd-11138ae4e8e3ed2f01156189923f7904c8f21591.zip
relabsd-11138ae4e8e3ed2f01156189923f7904c8f21591.tar.bz2
...
-rw-r--r--include/relabsd/server.h6
-rw-r--r--src/client.c2
-rw-r--r--src/config/parameters/parameters.c12
-rw-r--r--src/server/communication_thread.c3
-rw-r--r--src/server/handle_client.c87
5 files changed, 103 insertions, 7 deletions
diff --git a/include/relabsd/server.h b/include/relabsd/server.h
index 2bc0447..d5d36a6 100644
--- a/include/relabsd/server.h
+++ b/include/relabsd/server.h
@@ -37,3 +37,9 @@ int relabsd_server_join_communication_thread
(
struct relabsd_server server [const static 1]
);
+
+int relabsd_server_handle_client
+(
+ const int socket,
+ struct relabsd_server server [const static 1]
+);
diff --git a/src/client.c b/src/client.c
index 4d1f659..c4c1148 100644
--- a/src/client.c
+++ b/src/client.c
@@ -144,7 +144,7 @@ static int send_commands
}
}
- if (fputc('\0', socket) == EOF)
+ if (fputc('\n', socket) == EOF)
{
}
diff --git a/src/config/parameters/parameters.c b/src/config/parameters/parameters.c
index fa53b6a..e3328ca 100644
--- a/src/config/parameters/parameters.c
+++ b/src/config/parameters/parameters.c
@@ -394,13 +394,17 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])
"<options>:\n"
"\t\t(Re)defines an axis.\n\n"
- "\t[-m | --mod-axis] <name> <min> <max> <fuzz> <flat> <resolution> "
- "<signed_options>:\n"
- "\t\tModifies an axis (use + and - signs for the options).\n\n"
+ "\t[-m | --mod-axis] <name> <MOD_PARAM> [+|-|=]<value>:\n"
+ "\t\tModifies an axis.\n\n"
"\t[-f | --config] <config_file>"
"<options>:\n"
- "\t\t(Re)defines an axis.\n",
+ "\t\t(Re)defines an axis.\n\n"
+
+ "\t[-q | --quit]:\n"
+ "\t\tTerminates the targeted server instance.\n\n"
+
+ "<MOD_PARAM>: [min|max|fuzz|flat|resolution]\n",
exec
);
}
diff --git a/src/server/communication_thread.c b/src/server/communication_thread.c
index 0f367da..cc91065 100644
--- a/src/server/communication_thread.c
+++ b/src/server/communication_thread.c
@@ -9,7 +9,6 @@
/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/
-
static void main_loop (struct relabsd_server server [const static 1])
{
int communication_socket, current_client_socket;
@@ -87,7 +86,7 @@ static void main_loop (struct relabsd_server server [const static 1])
return -1;
}
- (void) handle_client(current_client_socket, server);
+ (void) relabsd_server_handle_client(current_client_socket, server);
}
}
diff --git a/src/server/handle_client.c b/src/server/handle_client.c
new file mode 100644
index 0000000..696725b
--- /dev/null
+++ b/src/server/handle_client.c
@@ -0,0 +1,87 @@
+/**** POSIX *******************************************************************/
+/*
+ * To get the POSIX 'getline' function.
+ * We don't know what POSIX version is set by default.
+ */
+#define _POSIX_C_SOURCE 200809L
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**** RELABSD *****************************************************************/
+#include <relabsd/debug.h>
+#include <relabsd/server.h>
+
+/******************************************************************************/
+/**** LOCAL FUNCTIONS *********************************************************/
+/******************************************************************************/
+static void handle_input
+(
+ const ssize_t input_size,
+ const char input [const static 1],
+ struct relabsd_server server [const static 1]
+)
+{
+}
+
+/******************************************************************************/
+/**** EXPORTED FUNCTIONS ******************************************************/
+/******************************************************************************/
+int relabsd_server_handle_client
+(
+ const int socket,
+ struct relabsd_server server [const static 1]
+)
+{
+ FILE * socket_as_file;
+ /* FIXME: reallocating at every new connection is kind of wasteful. */
+ char * input;
+ ssize_t input_size;
+
+ errno = 0;
+ socket_as_file = fdopen(socket, "r");
+
+ if (socket_as_file == ((FILE *) NULL))
+ {
+ RELABSD_ERROR
+ (
+ "Unable to open client socket as a FILE: %s.",
+ strerror(errno)
+ );
+
+ (void) close(socket);
+
+ return -1;
+ }
+
+ errno = 0;
+
+ input_size = getline(&input, (size_t *) NULL, socket_as_file);
+
+ if (input_size < 1)
+ {
+ RELABSD_ERROR
+ (
+ "Unable to read line from client socket: %s.",
+ strerror(errno)
+ );
+
+ (void) free((void *) input);
+
+ /* This also closes 'socket' */
+ (void) fclose(socket_as_file);
+
+ return -1;
+ }
+
+ handle_input(input_size, input, server);
+
+ (void) free((void *) input);
+
+ /* This also closes 'socket' */
+ (void) fclose(socket_as_file);
+
+ return 0;
+}