Changeset - e736dd843da3
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 16 years ago 2009-05-24 22:36:28
ohnobinki@ohnopublishing.net
moved some options code from distren.c to libdistren
4 files changed with 39 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/client/Makefile.am
Show inline comments
 
bin_PROGRAMS = distren
 
distren_SOURCES = distren.c
 
distren_LDADD = @DISTLIBS_LIBS@ @top_builddir@/src/common/libdistrencommon.la libdistren.la @XML_LIBS@
 
distren_CFLAGS = @DISTLIBS_CFLAGS@ -I@top_srcdir@/src/common @XML_CPPFLAGS@
 
distren_LDADD = @DISTLIBS_LIBS@libdistren.la
 
distren_CFLAGS = @DISTLIBS_CFLAGS@
 

	
 

	
 
include_HEADERS = distren.h
 

	
 
#see http://sources.redhat.com/autobook/autobook/autobook_106.html#SEC106
 
#libdistren:
 

	
 
lib_LTLIBRARIES = libdistren.la
 

	
 
libdistren_la_SOURCES = distren.h libdistren.h libdistren.c libdistren_job.c libdistren_unbias.c libdistren_config.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
 
libdistren_la_LIBADD = @DISTLIBS_LIBS@
 
libdistren_la_CXXFLAGS = @DISTLIBS_CFLAGS@
 
libdistren_la_LIBADD = @DISTLIBS_LIBS@ @top_builddir@/src/common/libdistrencommon.la @XML_LIBS@
 
libdistren_la_CFLAGS = @DISTLIBS_CFLAGS@ -I@top_srcdir@/src/common @XML_CPPFLAGS@
 

	
 
#see http://sources.redhat.com/autobook/autobook/autobook_91.html
 
# either increase the revision number or the interface number each release!
 
libdistren_la_LDFLAGS = -version-info 0:0:0
src/client/distren.c
Show inline comments
 
@@ -5,130 +5,110 @@
 

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

	
 

	
 
/* Ideas for php-side stuff:
 
 *
 
 * PHP adds the users... has captcha and email confirmation wth a pseudo-random number that
 
 * the user must enter on the site. Apache should be running mod_peruser for safety, and I'm
 
 * thinking zserver2 for web serving for convenience...
 
 */
 

	
 

	
 
#include "options.h"
 
#include "execio.h"
 

	
 
#include <distren.h>
 

	
 
#include <stdio.h> /* sprintf, printf */
 
#include <stdlib.h> /* malloc, free */
 
#include <unistd.h> /* getopt */
 
#include <libxml/tree.h> /* Happy fun XML time */
 
#include <libxml/xmlwriter.h>
 
#include <confuse.h>
 
#include <string.h> // for strcat
 

	
 

	
 
int main(int argc, char *argv[])
 
{
 
  char *input;
 
  char *output;
 
  char *jobid;
 
  
 
  char curopt;
 

	
 
  distren_t distren;
 
  distren_job_t distren_job;
 

	
 
  struct options_common *options;
 

	
 
  cfg_t *cfg;
 

	
 
  cfg_opt_t cfg_opts[] =
 
    {
 
      CFG_STR_LIST("render_types", NULL, 0),
 
      CFG_STR("username", NULL, 0),
 
      CFG_STR("name", NULL, 0),
 
      CFG_STR("email", NULL, 0),
 
      CFG_END()
 
    };
 

	
 
  input = NULL;
 
  output = NULL;
 

	
 
  while(-1 != (curopt = getopt(argc, argv, "i:o:h")))
 
    {
 
      if(curopt == ':')
 
	{
 
	  fprintf(stderr, "-%c: is missing an argument\n", optopt);
 
	  return 1;
 
	}
 
      else if(curopt == '?')
 
	{
 
	  fprintf(stderr, "-%c: invalid option specified\n", optopt);
 
	  return 1;
 
	}
 
      else if(curopt == 'h')
 
	{
 
	  fprintf(stderr, "Usage: %s -i <inputfile> -o <outputfile>\n", argv[0]);
 
	  fprintf(stderr, "\t-i\tSpecifies the input file\n\
 
\t-o\tSpecifies the output file\n\
 
\t-h\tShows this help message\n");
 
	  /*
 
	    don't return here because options_init will have an overall
 
	    options help page
 
	  */
 
	}
 
      else if(curopt == 'i')
 
	/* 
 
	   TODO: is strdup good or bad? what about 
 
	   the idea that all libs should allow plugging different
 
	   malloc/free implementations in?
 
	 */
 
	input = strdup(optarg);
 
      else if(curopt == 'o')
 
	output = strdup(optarg);
 
    } 
 
  /*
 
    parse the config file after the arguments so we can intercept -h for help
 
  */  
 
  if(options_init(argc, argv, &cfg, cfg_opts, "client", &options))
 
    {
 
      fprintf(stderr, "error getting configuration\n");
 
      //return 1;
 
    }
 

	
 
  /* 
 
     give this error after the general arguments parsing so that
 
     the general help from options_init can have effect 
 
  */
 
  if(!input
 
     || !output)
 
    {
 
      fprintf(stderr, "Input and output files must be specified\n");
 
      return 1;
 
    }
 

	
 
  fprintf(stderr, "reading from %s\nwriting to %s\n", input, output);
 
  
 
  distren_init_mf(&distren, &malloc, &free);
 
  
 
  distren_submit_file(distren, &distren_job, input);
 
  
 
  distren_job_getid(distren_job, &jobid);
 
  fprintf(stdout, "jobid: %s\n", jobid);
 

	
 
  distren_job_retrieve_file(distren_job, output);
 

	
 
  distren_job_free(distren_job);
 
@@ -155,32 +135,32 @@ int main(int argc, char *argv[])
 
	"-c",
 
	"\"echo hello from ${HOSTNAME}\"", // "\"useradd -M -c" strcat( cfg_getstr(cfg, "name") cfg_getstr(cfg, "email")) "-d /home/distren --gid 537" cfg_getstr(cfg, "username") "\"",
 
	(char *)NULL
 
      };
 

	
 
    size_t readlen;
 
    fprintf(stderr, "execio madness is occuring!");
 
    fprintf(stderr, "execio_open returns %d\n", execio_open(&testrem, "ssh", execargv));
 
    buf[9] = '\0';
 
    while(!execio_read(testrem, buf, 9, &readlen))
 
      {
 
	if(readlen > 9 )
 
	  {
 
	    fprintf(stderr, "execio_read doesn't set readlen correctly or read() is messed up\n");
 
	    return 1;
 
	  }
 
	buf[readlen] = '\0';
 
	fprintf(stderr, "read \"%s\"\n", buf);
 
      }
 
    execio_close(testrem);
 
  // Can we prune off some of this code up here^? I'm not exactly sure how execio returns output, but it seems like more could be happening in execio itself, and less happening where it is actually called.
 
  // We need some code to ssh, and if the SSH fails, tell the user to register.
 
  // Killed the user reg code, as the php interface will take care of this. Although it should check for users...
 

	
 
  options_free(options);
 
  
 
  return 0;
 
};
 

	
 

	
 

	
 

	
 

	
src/client/libdistren.h
Show inline comments
 
@@ -6,59 +6,65 @@
 
  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/>.
 
*/
 

	
 
/*
 
  Private definitions for libdistren.
 
 */
 

	
 
#include <distren.h>
 

	
 
struct distren
 
{
 
  distren_malloc_t malloc;
 
  distren_free_t free;
 
  struct options_common *options; /*< use a pointer just to avoid #include "options.h"? */
 
};
 

	
 
struct distren_job
 
{
 
  char *jobid;
 
};
 

	
 
/*
 
  functions
 
*/
 

	
 
/**
 
   Avoid poluting the public namespace until we fix visibility.
 
 */
 
#define _malloc _distren_malloc
 
/**
 
   All of libdistren should use this rather than malloc.h's malloc.
 
 */
 
void *_malloc(distren_t distren, size_t size);
 

	
 
/**
 
   Avoid poluting the public namespace until we fix visibility.
 
 */
 
#define _free _distren_free
 
/**
 
   All of libdisren should use this instead of malloc.h's free()
 
*/
 
void _free(distren_t distren, void *tofree);
 

	
 
/**
 
   Sets up the distren handle with information garnered from
 
   configuration files, etc. Uses the environment variable
 
   DISTREN_CONFIG or the built-in default config file location.
 
 */
 
int _distren_getoptions(distren_t handle);
 

	
 
/**
 
   Unsets-up the distren handle with options loadable from a config file.
 
 */
 
int _distren_loseoptions(distren_t handle);
src/client/libdistren_config.c
Show inline comments
 
/*
 
  Copyright 2008 Nathan Phillip Brink, Ethan Zonca, Matt Orlando
 

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

	
 
/*
 
  Functions and code for retrieving the client's configuration information.
 
 */
 

	
 
#include <libdistren.h>
 
#include "options.h"
 

	
 
/**
 
@todo Stub
 
 */
 
int _distren_getoptions(distren_t handle)
 
{
 
  cfg_t *cfg;
 

	
 
  cfg_opt_t cfg_opts[] =
 
    {
 
      CFG_STR_LIST("render_types", NULL, 0),
 
      CFG_STR("username", NULL, 0),
 
      CFG_STR("name", NULL, 0),
 
      CFG_STR("email", NULL, 0),
 
      CFG_END()
 
    };
 
  
 
  if(options_init(0, NULL, &cfg, cfg_opts, "client", &handle->options))
 
    {
 
      fprintf(stderr, "error getting configuration\n");
 
      return 1;
 
    }
 
  
 
  return 1;
 
}
 

	
 
/**
 
@todo stubish
 
 */
 
int _distren_loseoptions(distren_t handle)
 
{
 
  options_free(handle->options);
 
  
 
  return 0;
 
}
0 comments (0 inline, 0 general)