aboutsummaryrefslogtreecommitdiffhomepage
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/config.c b/config.c
index f425fe4..d3605e2 100644
--- a/config.c
+++ b/config.c
@@ -4,15 +4,15 @@
#include "config.h"
#include "backend.h"
-enum {
+static enum {
none,
backend_cfg,
instance_cfg,
map
} parser_state = none;
-backend* current_backend = NULL;
-instance* current_instance = NULL;
+static backend* current_backend = NULL;
+static instance* current_instance = NULL;
static char* config_trim_line(char* in){
ssize_t u;
@@ -28,6 +28,48 @@ static char* config_trim_line(char* in){
return in;
}
+static int config_map(char* to, char* from){
+ char* chanspec_to = to, *chanspec_from = from;
+ instance* instance_to = NULL, *instance_from = NULL;
+ channel* channel_from = NULL, *channel_to = NULL;
+
+ //separate channel spec from instance
+ for(; *chanspec_to && *chanspec_to != '.'; chanspec_to++){
+ }
+
+ for(; *chanspec_from && *chanspec_from != '.'; chanspec_from++){
+ }
+
+ if(!*chanspec_to || !*chanspec_from){
+ fprintf(stderr, "Mapping does not contain a proper instance specification\n");
+ return 1;
+ }
+
+ //terminate
+ *chanspec_to = *chanspec_from = 0;
+ chanspec_to++;
+ chanspec_from++;
+
+ //find matching instances
+ instance_to = instance_match(to);
+ instance_from = instance_match(from);
+
+ if(!instance_to || !instance_from){
+ fprintf(stderr, "No such instance %s\n", instance_from ? to : from);
+ return 1;
+ }
+
+ channel_from = instance_from->backend->channel(instance_from, chanspec_from);
+ channel_to = instance_to->backend->channel(instance_to, chanspec_to);
+
+ if(!channel_from || !channel_to){
+ fprintf(stderr, "Failed to parse channel specifications\n");
+ return 1;
+ }
+
+ return mm_map_channel(channel_from, channel_to);
+}
+
int config_read(char* cfg_file){
int rv = 1;
size_t line_alloc = 0;
@@ -114,17 +156,22 @@ int config_read(char* cfg_file){
*separator = 0;
separator++;
+ line = config_trim_line(line);
+ separator = config_trim_line(separator);
- if(parser_state == backend_cfg && current_backend->conf(config_trim_line(line), config_trim_line(separator))){
+ if(parser_state == backend_cfg && current_backend->conf(line, separator)){
fprintf(stderr, "Failed to configure backend %s\n", current_backend->name);
goto bail;
}
- else if(parser_state == instance_cfg && current_backend->conf_instance(current_instance, config_trim_line(line), config_trim_line(separator))){
+ else if(parser_state == instance_cfg && current_backend->conf_instance(current_instance, line, separator)){
fprintf(stderr, "Failed to configure instance %s\n", current_instance->name);
goto bail;
}
else if(parser_state == map){
- //TODO map two channels
+ if(config_map(line, separator)){
+ fprintf(stderr, "Failed to map channel\n");
+ goto bail;
+ }
}
}
}