Changeset - 1665faff5bfd
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 16 years ago 2009-08-03 21:24:35
ohnobinki@ohnopublishing.net
moved remoteio options parsing to remoteio.c
3 files changed with 54 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/common/libremoteio.h
Show inline comments
 
@@ -21,6 +21,7 @@
 
#define _DISTREN_LIBREMOTEIO_H
 

	
 
#include "remoteio.h"
 
#include <confuse.h>
 

	
 
/**
 
  private declarations for remoteio, to be included by options.c and remoteio.c
 
@@ -49,5 +50,6 @@ struct remoteio_opts
 
  struct remoteio_server *servers;
 
};
 

	
 
int remoteio_config(cfg_t *cfg, struct remoteio_opts *opts);
 

	
 
#endif
src/common/options.c
Show inline comments
 
@@ -46,13 +46,11 @@ int options_init(int argc, char *argv[],
 
  char *configfileprefix;
 
  char *configfile;
 

	
 
  size_t i, j;
 
  size_t i;
 

	
 
  char *optstring = "hc:";
 
  char curopt;
 

	
 
  struct remoteio_server *aserver;
 

	
 
  configfileprefix = NULL;
 
  while((curopt = getopt(argc, argv, optstring)) != -1)
 
    switch(curopt)
 
@@ -214,39 +212,13 @@ int options_init(int argc, char *argv[],
 
   */
 

	
 
  /* remoteio -- iterate through servers */
 
  aserver = malloc(sizeof(struct remoteio_server));
 
  if(!aserver)
 
  i = remoteio_config((*allopts)->data->cfg, (*allopts)->remoteio);
 
  if(i)
 
    {
 
      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 */
 
      fprintf(stderr, "cleanup\n");
 
	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 1;
 
    };
 

	
 
  return 0;
 
}
src/common/remoteio.c
Show inline comments
 
@@ -23,6 +23,52 @@
 

	
 
#include <stdlib.h>
 
#include <stdio.h>
 
#include <string.h>
 

	
 
int remoteio_config(cfg_t *cfg, struct remoteio_opts *opts)
 
{
 
  size_t numservers;
 
  size_t counter;
 
  
 
  struct remoteio_server *aserver;
 

	
 
  opts->servers = malloc(sizeof(struct remoteio_server));
 
  if(!opts->servers)
 
    {
 
      fprintf(stderr, "@todo cleanup!\n");
 
      abort();
 
    }
 
  
 
  aserver = opts->servers;
 
  
 
  numservers = cfg_size(cfg, "server"); 
 
  for(counter = 0; counter < numservers; counter ++)
 
    {
 
      cfg_t *cfg_aserver;
 
      
 
      cfg_aserver = cfg_getnsec(cfg, "server", counter);
 
      
 
      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(counter < numservers - 1)
 
	{
 
	  aserver->next = malloc(sizeof(struct remoteio_server));
 
	  aserver = aserver->next;
 
	}
 
    }
 
  aserver->next = NULL;
 
  
 
  return 0;
 
}
 

	
 
int remoteio_open(struct remoteio **rem, struct remoteio_opts *opts, char *servername)
 
{
0 comments (0 inline, 0 general)