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
 
@@ -34,18 +34,20 @@ enum remoteio_method
 
  };
 

	
 
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 */
 
};
 

	
 
struct remoteio_opts
 
{
 
  char *ssh_command;
 
  struct remoteio_server *servers;
 
};
 

	
 

	
 
#endif
src/common/options.c
Show inline comments
 
@@ -20,12 +20,13 @@
 
/* The purpose of this file is to... */
 

	
 
#include "options.h"
 

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

	
 
#include <confuse.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <unistd.h>
 
@@ -35,23 +36,26 @@ struct options_common_data
 
  cfg_t *cfg;
 
};
 

	
 

	
 
/**
 
   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)
 
      {
 
      case 'h':
 
	fprintf(stderr, "libdistren common options\n\
 
@@ -201,15 +205,58 @@ int options_init(int argc, char *argv[],
 
    }
 

	
 
  free(configfile);
 

	
 
  *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 */
 

	
 
  cfg_free(opts->data->cfg);
 

	
0 comments (0 inline, 0 general)