Changeset - 75a599984bd2
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 16 years ago 2009-08-02 23:25:37
ohnobinki@ohnopublishing.net
partial parsing of server config section
2 files changed with 50 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/common/libremoteio.h
Show inline comments
 
@@ -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;
 
};
 

	
 

	
src/common/options.c
Show inline comments
 
@@ -23,6 +23,7 @@
 

	
 
/* privat-ish files for components we need to config */
 
#include "libremoteio.h"
 
#include "protocol.h" /*< for DISTREN_SERVERTYPE_* */
 

	
 
#include <confuse.h>
 
#include <string.h>
 
@@ -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 */
0 comments (0 inline, 0 general)