Changeset - 4b9e91831d84
[Not reviewed]
default
0 4 1
Nathan Brink (binki) - 16 years ago 2009-07-25 00:28:54
ohnobinki@ohnopublishing.net
added remoteio info to options.c
5 files changed with 56 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/common/Makefile.am
Show inline comments
 
pkglib_LTLIBRARIES = libdistrencommon.la
 

	
 
libdistrencommon_la_SOURCES = options.c options.h execio.h execio.c remoteio.h remoteio.c
 
libdistrencommon_la_SOURCES = options.c options.h execio.h execio.c remoteio.h libremoteio.h remoteio.c
 
#evidently the following should not be LDADD, but LDFLAGS because automake doesn't like the idea of LDADD for libraries for some reason... or I am very confused
 
libdistrencommon_la_LIBADD = @DISTLIBS_LIBS@
 
libdistrencommon_la_CXXFLAGS = @DISTLIBS_CFLAGS@
 

	
 
#see http://sources.redhat.com/autobook/autobook/autobook_91.html
 
# either increase the revision number or the interface number each release!
 
libdistrencommon_la_LDFLAGS = -version-info 0:0:0
src/common/libremoteio.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  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/>.
 
*/
 

	
 
#ifndef _DISTREN_LIBREMOTEIO_H
 
#define _DISTREN_LIBREMOTEIO_H
 

	
 
#include "remoteio.h"
 

	
 
/**
 
  private declarations for remoteio, to be included by options.c and remoteio.c
 
 */
 

	
 
struct remoteio_opts {
 
  char *ssh_command;
 
};
 

	
 

	
 
#endif
src/common/options.c
Show inline comments
 
/*
 
  Copyright 2008 Nathan Phillip Brink, Ethan Zonca
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  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 <confuse.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 

	
 
struct options_common_data 
 
{
 
  cfg_t *cfg;
 
};
 

	
 

	
 
int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, char *myname, struct options_common **allopts)
 
{
 
  char *configfile;
 

	
 
  size_t i;
 

	
 
  /* For those of you who don't know, the following is an example of concatenation of constant strings by the C compiler. Now, that doesn't mean you can do run-time string concatenation ;-) 
 
   strdup is because someday configfile will be customizable via argv[]
 
   */
 

	
 
  i = strlen(SYSCONFDIR "/distren.conf") + strlen(myname) + 1;
 
  configfile = malloc(i);
 
  if(!configfile)
 
@@ -51,51 +54,63 @@ int options_init(int argc, char *argv[],
 
    }
 
  strncpy(configfile, SYSCONFDIR "/distren", strlen(SYSCONFDIR "/distren") + 1);
 
  strcat(configfile, myname);
 
  strcat(configfile, ".conf");
 
  
 
  *allopts = malloc(sizeof(struct options_common));
 
  if(!*allopts)
 
    {
 
      perror("malloc");
 
      free(configfile);
 
      return 1;
 
    }
 
  memset(*allopts, '\0', sizeof(struct options_common));
 
  
 
  (*allopts)->data = malloc(sizeof(struct options_common_data));
 
  if(!(*allopts)->data)
 
    {
 
      perror("malloc");
 
      free(configfile);
 
      free(*allopts);
 
      return 1;
 
    }
 
  memset((*allopts)->data, '\0', sizeof(struct options_common_data));
 
  
 
  /* Conf File Parser */
 
  (*allopts)->remoteio = malloc(sizeof(struct remoteio_opts));
 
  if(!(*allopts)->data)
 
    {
 
      perror("malloc");
 
      free(configfile);
 
      free((*allopts)->data);
 
      free(*allopts);
 
      return 1;
 
    }
 
  memset((*allopts)->remoteio, '\0', sizeof(struct remoteio_opts));
 
  
 
  
 
  cfg_opt_t common_opts[] =
 
    {
 
      CFG_SIMPLE_STR("ssh-command", &(*allopts)->remoteio->ssh_command),
 
      CFG_END()
 
    };
 
  
 
  /*
 
    In these arrays, I should replace NULL with a pointer to a string in the struct which should hold the result of confuse processing an option. This is partially because confuse will not free the values it parses.
 
   */
 
  cfg_opt_t server_opts[] = 
 
    {
 
      CFG_STR("username", NULL, CFGF_NONE),
 
      CFG_STR("hostname", NULL, CFGF_NONE),
 
      CFG_STR("method", "ssh", CFGF_NONE),
 
      CFG_STR_LIST("types", NULL, CFGF_NONE),
 
      CFG_END()
 
    };
 

	
 
  cfg_opt_t opts[] =
 
    {
 
      CFG_SEC("common",
 
	      common_opts,
 
	      CFGF_NONE),
 
      CFG_SEC("server",
 
	      server_opts,
 
	      CFGF_MULTI | CFGF_TITLE),
 
      CFG_SEC(myname,
 
@@ -121,29 +136,30 @@ int options_init(int argc, char *argv[],
 
      
 
      free((*allopts)->data);
 
      free(*allopts);
 
      free(configfile);
 
      
 
      return 1;
 
      
 
    case CFG_SUCCESS:
 
      break;
 
    }
 
  
 
  free(configfile);
 
  
 
  *mycfg = cfg_getsec((*allopts)->data->cfg, myname);
 

	
 
  return 0;
 
}
 

	
 
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;
 
}
src/common/remoteio.c
Show inline comments
 
@@ -3,52 +3,49 @@
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  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/>.
 

	
 
*/
 

	
 
#include "remoteio.h"
 
#include "execio.h"
 

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

	
 
/**
 
   @todo there must be passage of a configuratoin struct to allow configuration of different ssh clients.
 
 */
 
int remoteio_open(struct remoteio **rem, char *servername)
 
int remoteio_open(struct remoteio **rem, struct remoteio_opts *opts, char *servername)
 
{
 
  char *sshargs[] = {"ssh", servername, "distrend", "-d", (char *)NULL};
 
  int rtn;
 

	
 
  *rem = malloc(sizeof(struct remoteio));
 
  rtn = execio_open( &(*rem)->execio, "ssh", sshargs);
 
  if(rtn)
 
    {
 
      fprintf(stderr, "error opening remoteio channel to server ``%s''" , servername);
 
      free(*rem);
 
      return 1;
 
    }
 
  
 
  return 0;
 
}
 

	
 

	
 
int remoteio_read(struct remoteio *rem, void *buf, size_t len, size_t *bytesread)
 
{
 
  return execio_read(rem->execio, buf, len, bytesread);
 
}
 

	
 
int remoteio_write(struct remoteio *rem, void *buf, size_t len, size_t *byteswritten)
 
{
src/common/remoteio.h
Show inline comments
 
@@ -5,49 +5,51 @@
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  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/>.
 
*/
 

	
 
#ifndef _DISTREN_REMOTEIO_H
 
#define _DISTREN_REMOTEIO_H
 

	
 
#include <stdlib.h>
 

	
 
/*
 
  RemoteIO provides an abstraction to the method of talking to a remote distrend. It is a layer on top of execio that should provide an equivalent interface.
 
 */
 

	
 
struct remoteio_opts;
 

	
 
struct remoteio {
 
  struct execio *execio;
 
};
 

	
 
/**
 
   Opens connection with remote distrend. Returns 1 on error.
 

	
 
   @todo should this be asynchronous?
 
 */
 
int remoteio_open(struct remoteio **rem, char *servername);
 
int remoteio_open(struct remoteio **rem, struct remoteio_opts *opts, char *servername);
 

	
 
/**
 
   non-blocking I/O.
 
   @return 0 on success, 1 on failure
 
 */
 
int remoteio_read(struct remoteio *rem, void *buf, size_t len, size_t *bytesread);
 
int remoteio_write(struct remoteio *rem, void *buf, size_t len, size_t *byteswritten);
 

	
 
/**
 
   Closes a remoteio session.
 
   @return nonzero on error
 
*/
 
int remoteio_close(struct remoteio *rem);
 

	
 
#endif
0 comments (0 inline, 0 general)