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
 
@@ -28,24 +28,26 @@
 

	
 
enum remoteio_method
 
  {
 
    REMOTEIO_METHOD_SSH,
 
    /*    REMOTEIO_METHOD_TCP */ /*< someday, maybe */
 
    /*    REMOETIO_METHOD_XMLRPC */ /*< again, maybe someday */
 
  };
 

	
 
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
 
@@ -14,50 +14,54 @@
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

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

	
 
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\
 
\n\
 
\t-h\tShow this help.\n\
 
\t-c <path>\tBasename for configuration files. For instance, if distrencommon.conf is located at /etc/distren/distrencommon.conf, set this option /etc/distren/distren . Default value: %s\n\
 
\n", SYSCONFDIR "/distren");
 
	return 2;
 
	break;
 
@@ -195,27 +199,70 @@ int options_init(int argc, char *argv[],
 
      free(configfile);
 

	
 
      return 1;
 

	
 
    case CFG_SUCCESS:
 
      break;
 
    }
 

	
 
  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);
 

	
 
  free(opts->remoteio);
 
  free(opts->data);
 
  free(opts);
 

	
 
  return 0;
 
}
0 comments (0 inline, 0 general)