Files @ feebc1df83c1
Branch filter:

Location: DistRen/src/client/distren.c - annotation

binki
Exit if -h is passed.
7f09dcee58f4
abcf8952747b
7f09dcee58f4
aaedffb71a83
aaedffb71a83
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
7f09dcee58f4
aaedffb71a83
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
7f09dcee58f4
aaedffb71a83
7f09dcee58f4
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
2aa1075cee71
d6e050f635ca
d6e050f635ca
d6e050f635ca
2aa1075cee71
2aa1075cee71
2aa1075cee71
2aa1075cee71
2e10900d91d9
2aa1075cee71
2aa1075cee71
2aa1075cee71
92659c5651ef
92659c5651ef
2c0ae3006fa0
3b998819751e
d643c8d1d8a8
d643c8d1d8a8
2b98f7dd04fc
eee9474aa604
0a8f68f3d17f
32011f71cbbb
257ea2fc6baf
257ea2fc6baf
627c64f1fd14
627c64f1fd14
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
d6e050f635ca
2b98f7dd04fc
2b98f7dd04fc
257ea2fc6baf
03937b2315eb
9c7a6746bc2a
9c7a6746bc2a
9c7a6746bc2a
2b98f7dd04fc
2b98f7dd04fc
60d3bb17d7d3
60d3bb17d7d3
60d3bb17d7d3
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
2b98f7dd04fc
2b98f7dd04fc
257ea2fc6baf
72489034987c
257ea2fc6baf
2b98f7dd04fc
257ea2fc6baf
2b98f7dd04fc
257ea2fc6baf
2b98f7dd04fc
2b98f7dd04fc
257ea2fc6baf
257ea2fc6baf
2b98f7dd04fc
2b98f7dd04fc
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
d6e050f635ca
feebc1df83c1
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
2b98f7dd04fc
03937b2315eb
2b98f7dd04fc
d6e050f635ca
d6e050f635ca
d6e050f635ca
257ea2fc6baf
2b98f7dd04fc
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
ad5012647934
ad5012647934
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
03937b2315eb
da79b5082151
815127c2345a
257ea2fc6baf
815127c2345a
815127c2345a
03937b2315eb
257ea2fc6baf
815127c2345a
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
03937b2315eb
03937b2315eb
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
815127c2345a
257ea2fc6baf
257ea2fc6baf
815127c2345a
3fcf567f92be
257ea2fc6baf
257ea2fc6baf
257ea2fc6baf
3f7a5dbb61b6
03937b2315eb
03937b2315eb
/*
  Copyright 2010 Nathan Phillip Brink, Ethan Zonca, Matthew 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/>.
*/


/* This code is meant to submit files to the distren server(s). Let's say server for now. And let's state file purpose in each file just so we don't get screwed up! */


/* 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 "common/config.h"

#include "distren.h"

#include <stdio.h> /* sprintf, printf */
#include <stdlib.h> /* malloc, free */
#include <unistd.h> /* getopt */
#include <confuse.h>
#include <string.h> // for strcat

int main_opt_set(const char *name, char **dst, const char *src);

int main(int argc, char *argv[])
{
  short dologin;
  short printinfo;
  short lazy;

  char *input;
  char *output;
  char *joburi;

  char *username;
  char *password;

  char curopt;

  distren_t distren;
  distren_job_t distren_job;

  dologin = 0;
  printinfo = 0;
  lazy = 1;

  input = NULL;
  output = NULL;
  joburi = NULL;

  while(-1 != (curopt = getopt(argc, argv, "di:j:o:u:p:h")))
    {
      switch(curopt)
	{
	case ':':
	  fprintf(stderr, "-%c: is missing an argument\n", optopt);
	  return 1;

	case '?':
	  fprintf(stderr, "-%c: invalid option specified\n", optopt);
	  return 1;

	case 'h':
	  fprintf(stderr, "Usage: %s [-u <username>] [-p <password>] ...\n", argv[0]);
	  fprintf(stderr, "\t-i\tSpecifies an input file to submit to the server.\n\
\t-o\tSpecifies the name that should be given to a job retrieved from the server.\n\
\t-j\tSpecifies the job handle of a job to view information about or retrieve.\n\
\t-d\tDisplays information about the job specified with -j or uploaded by -i.\n\
\t-h\tShows this help message.\n");
	  
	  return 0;
	  break;

	case 'u':
	  main_opt_set("-u", &username, optarg);
	  dologin = 1;
	  break;

	case 'p':
	  main_opt_set("-p", &password, optarg);
	  dologin = 1;
	  break;

	case 'i':
	  if(joburi)
	    {
	      fprintf(stderr, "You may not specify both -i and -j; -j must refer to an existing job URL and -i will create a new job and thus retrieve its URL.\n");
	      return 1;
	    }
	  main_opt_set("-i", &input, optarg);
	  break;

	case 'o':
	  main_opt_set("-o", &output, optarg);
	  break;

	case 'j':
	  if(input)
	    {
	      fprintf(stderr, "You may not specify both -j and -i; -i is submitting a new jobs whose URL cannot be known before it is submitted\n");
	      return 1;
	    }
	  main_opt_set("-j", &joburi, optarg);
	  break;

	case 'd':
	  printinfo = 1;
	  break;
	}
    }

  
     // give this error after the general arguments parsing so that
     // the general help from options_init can have effect
  if(!username || !password)
    {
      fprintf(stderr, "Username and password must be specified:\n");
      if(!username)
	fprintf(stderr, "\tyou did not specify a username\n");
      if(!password)
	fprintf(stderr, "\tyou did not specify a password\n");
      return 1;
    }
  if(dologin)
    {
      fprintf(stderr, "Trying username and password on server...");
      fprintf(stderr, "STUB\n");
      lazy = 0;
    }

  if(distren_init(&distren))
    {
      fprintf(stderr, "error initializing the distren handle\n");
      return 1;
    }

  if(input)
    {
      if(distren_submit_file(distren, &distren_job, input))
	{
	  fprintf(stderr, "error submitting file\n");
	  return 1;
	}

      if(distren_job_geturi(distren_job, &joburi))
	{
	  fprintf(stderr, "error retrieving joburi\n");
	  return 1;
	}

      lazy = 0;
      fprintf(stdout, "joburi: %s\n", joburi);
    }

  if(output)
    {
      if(distren_job_retrieve_file(distren_job, output))
	{
	  fprintf(stderr, "error retrieving output file\n");
	  return 1;
	}

      lazy = 0;
    }

  /*
   * if these following lines fail, it'll be reported as a core dump
   * ;-)
   */
  if(distren_job)
    distren_job_free(distren_job);

  distren_free(distren);

  if(lazy)
    fprintf(stderr, "Performed no action\n");

  return 0;
};

  /**
   * A helper for main() that will print a warning about overriding
   * specifying an argument multiple times and properly handle options
   * overriding eachother.
   *
   * Before calling main_opt_set() for the first time, the caller must
   * preset *dst to NULL.
   *
   * @param name something to identify the particular option to the user.
   * @param dst the poiner to where a newly allocated string's pointer should be stored.
   * @param src the value specified by the user.
   */
int main_opt_set(const char *name, char **dst, const char *src)
{
  if(*dst)
    {
      fprintf(stderr, "warning: You have specified %s before, setting it to %s\n", name, src);
      free(*dst);
    }

  *dst = strdup(src);
  return 0;
}