Network configuration parser is working

This commit is contained in:
Sears Russell 2005-01-02 01:37:05 +00:00
parent 6fa948cd74
commit c45ed9f5d5
3 changed files with 39 additions and 2 deletions

View file

@ -5,3 +5,9 @@ subordinates = {
127.0.0.1:20003, 127.0.0.1:20003,
127.0.0.1:20004 127.0.0.1:20004
} }
group 1 {
members = {1, 3}
}
group 2 {
members = {2, 4}
}

View file

@ -40,10 +40,16 @@ int validate_host_port(cfg_t *cfg, cfg_opt_t *opt) {
return 0; return 0;
} }
cfg_opt_t group_opts[] = {
CFG_INT_LIST("members", "{1,2,3}", CFGF_NONE),
CFG_END()
};
cfg_opt_t opts[] = { cfg_opt_t opts[] = {
CFG_STR("coordinator", "127.0.0.1:10000", CFGF_NONE), CFG_STR("coordinator", "127.0.0.1:10000", CFGF_NONE),
CFG_STR_LIST("subordinates", CFG_STR_LIST("subordinates",
"{127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003}", CFGF_NONE), "{127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003}", CFGF_NONE),
CFG_SEC("group", group_opts, CFGF_TITLE | CFGF_MULTI),
CFG_END() CFG_END()
}; };
NetworkSetup * readNetworkConfig(char * name, int hostnumber) { NetworkSetup * readNetworkConfig(char * name, int hostnumber) {
@ -70,7 +76,32 @@ NetworkSetup * readNetworkConfig(char * name, int hostnumber) {
} else { } else {
printf("I am subordinate # %d\n", hostnumber); printf("I am subordinate # %d\n", hostnumber);
} }
NetworkSetup * ret = calloc(1, sizeof(NetworkSetup));
ret->localport = hostnumber == COORDINATOR
? parse_port(cfg_getstr(cfg, "coordinator"))
: parse_port(cfg_getnstr(cfg, "subordinates", hostnumber));
ret->localhost = hostnumber == COORDINATOR
? parse_addr(cfg_getstr(cfg, "coordinator"))
: parse_addr(cfg_getnstr(cfg, "subordinates", hostnumber));
ret->socket = -1; /// @todo where should the socket field be initialized?
ret->broadcast_lists_count = cfg_size(cfg, "group");
printf("broadcast list count = %d\n", ret->broadcast_lists_count);
ret->broadcast_list_host_count = malloc(sizeof(int *) * ret->broadcast_lists_count);
ret->broadcast_lists = malloc(sizeof(int**) * ret->broadcast_lists_count);
for(i = 0; i < ret->broadcast_lists_count; i++) {
cfg_t * group_cfg = cfg_getnsec(cfg, "group", i);
int j;
ret->broadcast_list_host_count[i] = cfg_size(group_cfg, "members");
ret->broadcast_lists[i] = malloc(sizeof (int *) * ret->broadcast_list_host_count[i]);
printf("Group %d size %d\n", atoi(cfg_title(group_cfg)), ret->broadcast_list_host_count[i]);
for(j = 0; j < ret->broadcast_list_host_count[i]; j++) {
(*ret->broadcast_lists)[i][j] = cfg_getnint(group_cfg, "members", j);
printf("\t->%d\n", (*ret->broadcast_lists)[i][j]);
}
}
cfg_free(cfg); cfg_free(cfg);
return NULL; return ret;
} }

View file

@ -54,7 +54,7 @@ terms specified in this license.
@test @test
*/ */
START_TEST (networksetup_check) { START_TEST (networksetup_check) {
readNetworkConfig("../../libdfa/networksetup.sample", COORDINATOR); assert(readNetworkConfig("../../libdfa/networksetup.sample", COORDINATOR));
} }
END_TEST END_TEST
/** /**