aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-14 17:59:20 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-14 17:59:20 +0200
commit9ef9f01ce425ff82b6e5f87643dfe624dc56a4a2 (patch)
tree95cd63129b2cf4fc8ba92a2611bbd88c25ce93bb
parent08dca7c0f612864513354288fc676968cddfbd96 (diff)
downloadstorage-9ef9f01ce425ff82b6e5f87643dfe624dc56a4a2.zip
storage-9ef9f01ce425ff82b6e5f87643dfe624dc56a4a2.tar.bz2
Sets up proper parameters.
-rw-r--r--src/main.c9
-rw-r--r--src/parameters/parameters.c64
-rw-r--r--src/parameters/parameters_types.h2
3 files changed, 71 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 9216104..4b4f959 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,16 +17,19 @@ static void print_help (const char runnable [const restrict static 1])
{
printf
(
- "JabberHive - Limiter\n"
+ "JabberHive - Storage\n"
"Software Version %d\n"
"Protocol Version %d\n"
"\nUsages:\n"
- " JH GATEWAY:\t%s SOCKET_NAME DESTINATION REPLY_RATE\n"
+ " JH GATEWAY:\t%s SOCKET_NAME DESTINATION\n"
" SHOW HELP:\tAnything else.\n"
"\nParameters:\n"
" SOCKET_NAME:\tValid UNIX socket.\n"
" DESTINATION:\tValid UNIX socket.\n"
- " REPLY_RATE:\tInteger [0,100].\n",
+ "\nOptions:\n"
+ " -m, --main-storage:\tMain storage file (data is appended).\n"
+ " -t, --temporary-storage-prefix:\tPrefix for temporary files"
+ " (e.g. \"/tmp/jh_storage_\").\n",
JH_PROGRAM_VERSION,
JH_PROTOCOL_VERSION,
runnable
diff --git a/src/parameters/parameters.c b/src/parameters/parameters.c
index 80cb01b..d3a373f 100644
--- a/src/parameters/parameters.c
+++ b/src/parameters/parameters.c
@@ -78,6 +78,65 @@ static void set_parameters
}
param->dest_socket_name = argv[2];
+
+}
+
+static int set_options
+(
+ struct JH_parameters param [const restrict static 1],
+ int const argc,
+ const char * argv [const static argc]
+)
+{
+ int i;
+
+ for (i = (JH_PARAMETERS_COUNT + 1); i < argc; ++i)
+ {
+
+ if
+ (
+ JH_STRING_EQUALS("-m", argv[i])
+ || JH_STRING_EQUALS("--main-storage", argv[i])
+ )
+ {
+ if (i == (argc - 1))
+ {
+ JH_FATAL(stderr, "Missing value for option \"%s\".", argv[i]);
+
+ return -1;
+ }
+
+ i += 1;
+
+ param->main_storage_filename = argv[i];
+ }
+ else if
+ (
+ JH_STRING_EQUALS("-t", argv[i])
+ || JH_STRING_EQUALS("--temporary-storage-prefix", argv[i])
+ )
+ {
+ if (i == (argc - 1))
+ {
+ JH_FATAL(stderr, "Missing value for option \"%s\".", argv[i]);
+
+ return -1;
+ }
+
+ i += 1;
+
+ param->temp_storage_prefix = argv[i];
+ param->temp_storage_prefix_length = strlen(argv[i]);
+ }
+ else
+ {
+ JH_FATAL(stderr, "Unrecognized option \"%s\".", argv[i]);
+
+ return -1;
+ }
+ }
+
+ return 0;
}
int JH_parameters_initialize
@@ -91,6 +150,11 @@ int JH_parameters_initialize
set_parameters(param, argc, argv);
+ if (set_options(param, argc, argv) < 0)
+ {
+ return -1;
+ }
+
if (!is_valid(param))
{
return -1;
diff --git a/src/parameters/parameters_types.h b/src/parameters/parameters_types.h
index c21d14b..f70301b 100644
--- a/src/parameters/parameters_types.h
+++ b/src/parameters/parameters_types.h
@@ -3,7 +3,7 @@
#include <stdlib.h>
-#define JH_PARAMETERS_COUNT 3
+#define JH_PARAMETERS_COUNT 2
#define JH_PARAMETERS_DEFAULT_MAIN_STORAGE_FILENAME "storage.txt"
#define JH_PARAMETERS_DEFAULT_TEMP_STORAGE_PREFIX "/tmp/jabberhive-storage/storage_thread_"