summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/parameters/handle_remote_client_commands.c199
-rw-r--r--src/config/parameters/parameters.c22
2 files changed, 212 insertions, 9 deletions
diff --git a/src/config/parameters/handle_remote_client_commands.c b/src/config/parameters/handle_remote_client_commands.c
new file mode 100644
index 0000000..5523e37
--- /dev/null
+++ b/src/config/parameters/handle_remote_client_commands.c
@@ -0,0 +1,199 @@
+/**** 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 <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**** RELABSD *****************************************************************/
+#include <relabsd/debug.h>
+#include <relabsd/server.h>
+
+#include <relabsd/util/string.h>
+
+#include <relabsd/config/parameters.h>
+
+/******************************************************************************/
+/**** TYPES *******************************************************************/
+/******************************************************************************/
+struct relabsd_parameters_client_input
+{
+ FILE * socket_as_file;
+ ssize_t size;
+ char * buffer;
+ size_t buffer_size;
+};
+
+/******************************************************************************/
+/**** LOCAL FUNCTIONS *********************************************************/
+/******************************************************************************/
+static int get_next_argument
+(
+ struct relabsd_parameters_client_input input [const restrict static 1]
+)
+{
+ errno = 0;
+ input->size =
+ getline
+ (
+ &(input->buffer),
+ &(input->buffer_size),
+ input->socket_as_file
+ );
+
+ if (input->size < 1)
+ {
+ RELABSD_ERROR
+ (
+ "Unable to read line from client socket: %s.",
+ strerror(errno)
+ );
+
+ return -1;
+ }
+
+ input->buffer[(input->size - 1)] = '\0';
+
+ return 0;
+}
+
+static void initialize_client_input
+(
+ FILE socket_as_file [const static 1],
+ struct relabsd_parameters_client_input input [const restrict static 1]
+)
+{
+ input->socket_as_file = socket_as_file;
+ input->size = 0;
+ input->buffer = (char *) NULL;
+ input->buffer_size = 0;
+}
+
+static void finalize_client_input
+(
+ struct relabsd_parameters_client_input input [const restrict static 1]
+)
+{
+ free((void *) input->buffer);
+
+ input->buffer = (char *) NULL;
+ input->buffer_size = 0;
+}
+
+static int handle_timeout_change
+(
+ struct relabsd_parameters_client_input input [const restrict static 1],
+ struct relabsd_parameters parameters [const static 1]
+)
+{
+ int timeout_msec;
+
+ if (get_next_argument(input) < 0)
+ {
+ RELABSD_S_ERROR("Could not get timeout value from client.");
+
+ return -1;
+ }
+
+ if (relabsd_util_parse_int(input->buffer, 0, INT_MAX, &timeout_msec) < 0)
+ {
+ RELABSD_S_ERROR("Invalid timeout value from client.");
+
+ return -1;
+ }
+
+ relabsd_parameters_set_timeout(timeout_msec, parameters);
+
+ return 0;
+}
+
+static int handle_inputs
+(
+ struct relabsd_parameters_client_input input [const restrict static 1],
+ struct relabsd_parameters parameters [const static 1]
+)
+{
+ for (;;)
+ {
+ if (get_next_argument(input) < 0)
+ {
+ RELABSD_S_ERROR("Could not get next client command.");
+
+ return -1;
+ }
+
+ if ((input->buffer[0] == '\n') || (input->buffer[0] == '\0'))
+ {
+ return 0;
+ }
+ else if
+ (
+ RELABSD_STRING_EQUALS("-q", input->buffer)
+ || RELABSD_STRING_EQUALS("--quit", input->buffer)
+ )
+ {
+ relabsd_server_interrupt();
+ }
+ else if
+ (
+ RELABSD_STRING_EQUALS("-t", input->buffer)
+ || RELABSD_STRING_EQUALS("--timeout", input->buffer)
+ )
+ {
+ if (handle_timeout_change(input, parameters) < 0)
+ {
+ return 0;
+ }
+ }
+ else if
+ (
+ RELABSD_STRING_EQUALS("-n", input->buffer)
+ || RELABSD_STRING_EQUALS("--name", input->buffer)
+ )
+ {
+ /* TODO: implement */
+ RELABSD_PROG_ERROR("Unimplemented command \"%s\".", input->buffer);
+ }
+ else if
+ (
+ RELABSD_STRING_EQUALS("-m", input->buffer)
+ || RELABSD_STRING_EQUALS("--mod-axis", input->buffer)
+ )
+ {
+ /* TODO: implement */
+ RELABSD_PROG_ERROR("Unimplemented command \"%s\".", input->buffer);
+ }
+ else
+ {
+ RELABSD_ERROR("Unknown client command \"%s\"", input->buffer);
+
+ return -1;
+ }
+ }
+}
+
+/******************************************************************************/
+/**** EXPORTED FUNCTIONS ******************************************************/
+/******************************************************************************/
+int relabsd_parameters_handle_remote_client
+(
+ FILE socket_as_file [const static 1],
+ struct relabsd_parameters parameters [const restrict static 1]
+)
+{
+ struct relabsd_parameters_client_input input;
+
+ initialize_client_input(socket_as_file, &input);
+
+ (void) handle_inputs(&input, parameters);
+
+ finalize_client_input(&input);
+
+ return 0;
+}
diff --git a/src/config/parameters/parameters.c b/src/config/parameters/parameters.c
index 0e98016..84b348c 100644
--- a/src/config/parameters/parameters.c
+++ b/src/config/parameters/parameters.c
@@ -337,8 +337,8 @@ int relabsd_parameters_argument_count_for
{
if
(
- RELABSD_STRING_EQUALS("-n", option)
- || RELABSD_STRING_EQUALS("--name", option)
+ RELABSD_STRING_EQUALS("-q", option)
+ || RELABSD_STRING_EQUALS("--quit", option)
)
{
*result = 0;
@@ -373,7 +373,7 @@ int relabsd_parameters_argument_count_for
|| RELABSD_STRING_EQUALS("--mod-axis", option)
)
{
- *result = 7;
+ *result = 3;
}
else if
(
@@ -411,7 +411,8 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])
"\t%s [-? | --compatible] <physical_device_file> [<CONF_OPTION>+]\n"
"\t\tDevice & configuration compatibility test.\n\n"
- "\t%s [-c | --client] <server_file> [(<CLIENT_OPTION>|<CONF_OPTION>)+]"
+ "\t%s [-c | --client] <server_file> "
+ "[(<CLIENT_OPTION>|<GLOBAL_CONF_OPTION>)+]"
"\n"
"\t\tSends the commands to a given server instance.\n\n"
@@ -423,21 +424,24 @@ void relabsd_parameters_print_usage (const char exec [const restrict static 1])
" [(<SERVER_OPTION>|<CONF_OPTION>)+]:\n"
"\t\tCreates an unnamed server instance.\n\n"
- "<CONF_OPTION>:\n"
+ "<GLOBAL_CONF_OPTION>:\n"
"\t[-n | --name] <relabsd_device_name>:\n"
"\t\tNames the virtual device.\n\n"
"\t[-t | --timeout] <timeout_in_ms>:\n"
"\t\tSets a zeroing timeout (0 to disable).\n\n"
+ "\t[-m | --mod-axis] <name> [min|max|fuzz|flat|resolution|enable]"
+ " [+|-|=]<value>:\n"
+ "\t\tModifies an axis.\n\n"
+
+ "<CONF_OPTION>:\n"
+ "\t<GLOBAL_CONF_OPTION>\n\n"
+
"\t[-a | --axis] <name> <min> <max> <fuzz> <flat> <resolution> "
"<options>:\n"
"\t\t(Re)defines an axis.\n\n"
- "\t[-m | --mod-axis] <name> [min|max|fuzz|flat|resolution]"
- " [+|-|=]<value>:\n"
- "\t\tModifies an axis.\n\n"
-
"\t[-f | --config] <config_file>"
"\t\tUse the options defined in <config_file>.\n\n"