aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-06-07 19:20:42 +0200
committercbdev <cb@cbcdn.com>2019-06-07 19:20:42 +0200
commitc9062e7d1a1d917f618b71ac3810b4f3e396ab0d (patch)
treec5cccc090f4f46b4253a3ba1a6cbc35a167d109b /config.c
parentedcec9fa9086599d56bffe7fdb2c1f05ae7a3ad8 (diff)
downloadwebsocksy-c9062e7d1a1d917f618b71ac3810b4f3e396ab0d.tar.gz
websocksy-c9062e7d1a1d917f618b71ac3810b4f3e396ab0d.tar.bz2
websocksy-c9062e7d1a1d917f618b71ac3810b4f3e396ab0d.zip
Main readme and config module
Diffstat (limited to 'config.c')
-rw-r--r--config.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/config.c b/config.c
new file mode 100644
index 0000000..7da08eb
--- /dev/null
+++ b/config.c
@@ -0,0 +1,74 @@
+#include <string.h>
+#include <stdio.h>
+
+#include "websocksy.h"
+#include "config.h"
+#include "plugin.h"
+
+static enum /*_config_file_section*/ {
+ cfg_main,
+ cfg_backend
+} config_section = cfg_main;
+
+int config_parse_file(ws_config* config, char* filename){
+ return 1;
+}
+
+int config_parse_arguments(ws_config* config, int argc, char** argv){
+ size_t u;
+ char* option = NULL, *value = NULL;
+
+ //if exactly one argument, treat it as config file
+ if(argc == 1){
+ return config_parse_file(config, argv[0]);
+ }
+
+ if(argc % 2){
+ return 1;
+ }
+
+ for(u = 0; u < argc; u += 2){
+ if(argv[u][0] != '-'){
+ return 1;
+ }
+ switch(argv[u][1]){
+ case 'p':
+ config->port = argv[u + 1];
+ break;
+ case 'l':
+ config->host = argv[u + 1];
+ break;
+ case 'b':
+ //clean up the previously registered backend
+ if(config->backend.cleanup){
+ config->backend.cleanup();
+ }
+ //load the backend plugin
+ if(plugin_backend_load(PLUGINS, argv[u + 1], &(config->backend))){
+ return 1;
+ }
+ if(config->backend.init() != WEBSOCKSY_API_VERSION){
+ fprintf(stderr, "Loaded backend %s was built for a different API version\n", argv[u + 1]);
+ return 1;
+ }
+ break;
+ case 'c':
+ if(!strchr(argv[u + 1], '=')){
+ return 1;
+ }
+ if(!config->backend.config){
+ continue;
+ }
+ option = strdup(argv[u + 1]);
+ value = strchr(option, '=');
+ *value = 0;
+ value++;
+ config->backend.config(option, value);
+ free(option);
+ option = NULL;
+ value = NULL;
+ break;
+ }
+ }
+ return 0;
+}