# HG changeset patch # User Binki # Date 2009-08-02 23:25:37 # Node ID 75a599984bd29392318286072c2af70681de7f15 # Parent b61b21152b06c8d488d8a74bc1938250ee38d60f partial parsing of server config section diff --git a/src/common/libremoteio.h b/src/common/libremoteio.h --- a/src/common/libremoteio.h +++ b/src/common/libremoteio.h @@ -37,6 +37,7 @@ struct remoteio_server { struct remoteio_server *next; char *name; + char *hostname; char *username; enum remoteio_method method; unsigned int types; /*< See ``Server types'' in protocol.h */ @@ -45,6 +46,7 @@ struct remoteio_server struct remoteio_opts { char *ssh_command; + struct remoteio_server *servers; }; diff --git a/src/common/options.c b/src/common/options.c --- a/src/common/options.c +++ b/src/common/options.c @@ -23,6 +23,7 @@ /* privat-ish files for components we need to config */ #include "libremoteio.h" +#include "protocol.h" /*< for DISTREN_SERVERTYPE_* */ #include #include @@ -38,17 +39,20 @@ struct options_common_data /** Not reentrant because of call to getenv() + @todo replace abort()s with something useful */ int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, char *myname, struct options_common **allopts) { char *configfileprefix; char *configfile; - size_t i; + size_t i, j; char *optstring = "hc:"; char curopt; + struct remoteio_server *aserver; + configfileprefix = NULL; while((curopt = getopt(argc, argv, optstring)) != -1) switch(curopt) @@ -204,9 +208,52 @@ int options_init(int argc, char *argv[], *mycfg = cfg_getsec((*allopts)->data->cfg, myname); + + /* + * libdistrencommon's config options: + */ + + /* remoteio -- iterate through servers */ + aserver = malloc(sizeof(struct remoteio_server)); + if(!aserver) + { + fprintf(stderr, "@todo cleanup!\n"); + abort(); + } + (*allopts)->remoteio->servers = aserver; + + j = cfg_size((*allopts)->data->cfg, "server"); + for(i = 0; i < j; i ++) + { + cfg_t *cfg_aserver; + + cfg_aserver = cfg_getnsec((*allopts)->data->cfg, "server", i); + + if(!aserver) /*< if the malloc in the previous loop failed */ + abort(); + + aserver->name = strdup(cfg_title(cfg_aserver)); + aserver->hostname = strdup(cfg_getstr(cfg_aserver, "hostname")); + aserver->username = strdup(cfg_getstr(cfg_aserver, "username")); + if(strcmp(cfg_getstr(cfg_aserver, "method"), "ssh") == 0) + aserver->method = REMOTEIO_METHOD_SSH; + else + abort(); + + if(i < j - 1) + { + aserver->next = malloc(sizeof(struct remoteio_server)); + aserver = aserver->next; + } + } + aserver->next = NULL; + return 0; } +/** + @todo free remoteio_servers +*/ int options_free(struct options_common *opts) { /* free the other common_options struct's members */