コード例 #1
0
/* int segs2name (poptContext  *optCon, char **filename, int *seg_list); */
int main (int argc, char **argv)
{
    int i, ret;
    LorsExnode *exnode;
    char        *s;
    char        *output_filename = "-";
    char        *filename;
    int          same_name=0;
    int         v;
    int         file_cnt = 0;
    int         opts = LORS_MANAGE_CAP;
    XndRc       xndrc;

    poptContext optCon;   /* context for parsing command-line options */
    struct poptOption optionsTable[] = {
  { "samename",   'f', POPT_ARG_NONE,   0,                  SAME_OUTPUTNAME, 
        "Save the modified exNode to the original exNode filename.", NULL },
  { "outputfile", 'o', POPT_ARG_STRING, &output_filename,   OUTPUTNAME, 
        "Specify the name for the output exNode file.", NULL},
  { "read-cap",   'r', POPT_ARG_NONE,   0,                  LORS_READ_CAP, 
        "Delete the read capabilities from the exNode.", NULL},
  { "write-cap",  'w', POPT_ARG_NONE,   0,                  LORS_WRITE_CAP, 
        "Delete the write capabilities from the exNode.", NULL},
  { "manage-cap", 'm', POPT_ARG_NONE,   0,                  LORS_MANAGE_CAP, 
        "Delete the manage capabilities from the exNode.", NULL},
  { "version",    'v', POPT_ARG_NONE,   0,                  LORS_VERSION, 
        "Display Version information about this package.", NULL},
  { "verbose",    'V', POPT_ARG_INT,    &xndrc.verbose,        VERBOSE, 
        "Modify the level or mode of Verbosity in output messages.", "0"},
  /* { "demo",  'D', POPT_ARG_NONE, 0, LORS_ARG_DEMO, 
        "Add the messages understood by the LoRS View visualization.", NULL}, */
        POPT_AUTOHELP
        { NULL, 0, 0, NULL, 0 }
    };

    parse_xndrc_files(&xndrc);
    g_lors_demo = xndrc.demo;

    optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0);
    poptSetOtherOptionHelp(optCon, "<filename>");

    if ( argc < 2 )
    {
        poptPrintUsage(optCon, stderr, 0);
        poptPrintHelp(optCon, stderr, 0);
                                 exit(EXIT_FAILURE);
    }
    while ( (v=poptGetNextOpt(optCon)) >= 0)
    {
        switch(v)
        {
            case LORS_READ_CAP:
            case LORS_WRITE_CAP:
            case LORS_MANAGE_CAP:
                opts |= v;
                break;
            case SAME_OUTPUTNAME:
                same_name = 1;
                break;
            case LORS_ARG_DEMO:
                g_lors_demo = (!g_lors_demo);
                break;
            case LORS_VERSION:
            {
                const char *package;
                double version;
                lorsGetLibraryVersion(&package, &version);
                fprintf(stderr, "Version: %s %f\n", package, version);
                exit(EXIT_FAILURE);
                break;
            }
            default:
                /*fprintf(stderr, "Unsupported option: %d\n", v);*/
                break;
        }

    }

    g_db_level = xndrc.verbose;
    if ( v < -1 )
    {
        fprintf(stderr, "error: %d\n", v);
        fprintf(stderr, "%s: %s\n",
                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
                 poptStrerror(v));
    }
    while ( (filename = (char *)poptGetArg(optCon)) != NULL )
    {
        file_cnt++;
        /* output_filename= NULL;*/
	if (same_name == 1) output_filename = filename;
        ret = lorsModifyFile(filename, output_filename, opts);
        if ( ret != LORS_SUCCESS )
        {
            fprintf(stderr, "An error occured during modify: %d\n", ret);
        }
    }
    if ( file_cnt == 0 )
    {
        fprintf(stderr, "Error. You must also provide a filename on "
                "which lors_modify operates.\n");
        poptPrintHelp(optCon, stderr, 0);
        exit(EXIT_FAILURE);
    }
    free_xndrc(&xndrc);
    poptFreeContext(optCon);
    return 0;
}
コード例 #2
0
ファイル: lors_refresh.c プロジェクト: datalogistics/dlt-lors
int main (int argc, char **argv)
{
    int i, ret;
    LorsExnode *exnode;
    struct ibp_depot   lbone_server = {"dsj.sinrg.cs.utk.edu", 6767};
    char        *s;
    char        *lbonehost = NULL;
    char        *output_filename = NULL;
    const char        *filename;
    int          same_name=0;
    char        *location = "state= tn";
    int         storage_type = IBP_SOFT;
    int         maxdepots = 6;
    time_t      duration = 0;
    ulong_t     data_blocksize = 1024*1024*5;
    char        *s_data_blocksize = NULL;
    ulong_t     max_buffersize = 1024*1024*5;
    char        *s_max_buffersize = NULL;
    ulong_t     offset=0, length=-1;
    int         copies = 1;
    int         threads = 10;
    int         timeout = 600;
    char        *s_timeout = "600s";
    int         encryption = 0;
    int         v;
    int         file_cnt = 0;
    double      days = 0;
    int         opts =0;
    XndRc       xndrc;

    poptContext optCon;   /* context for parsing command-line options */
    struct poptOption optionsTable[] = {
  { "version",    'v', POPT_ARG_NONE,   0,                       LORS_VERSION, 
        "Display Version information about this package.", NULL},
  { "verbose",    'V', POPT_ARG_INT,    &xndrc.verbose,          VERBOSE, 
        "Modify the level or mode of Verbosity in output messages.", "0"},
  { "threads",    't', POPT_ARG_INT,    &xndrc.threads,          THREADS, 
        "Specify the maximum number of threads to use to perform Listing.", NULL},
  { "timeout",    'T', POPT_ARG_STRING,    &s_timeout,           TIMEOUT, 
        "Specify the maximum time to allow for all operations.", "'3m'"},
  { "maximum",    'm', POPT_ARG_NONE,               0,           LORS_REFRESH_MAX, 
        "Set expiration time of mappings to the maximum time allowed by Depot.", NULL},
  { "add",        'd', POPT_ARG_STRING,    &s_timeout,           LORS_REFRESH_EXTEND_BY, 
        "Extend the expiration by the specified amount of time. The available modifiers "
        "are 'm' 'h' 'd' for 'minute' 'hour' and 'days' respectively.  Default is seconds.", NULL},
  { "set",        's', POPT_ARG_STRING,    &s_timeout,           LORS_REFRESH_EXTEND_TO, 
        "Set expiration to be specified amount of time from the present.  The available"
        " modifiers are 'm' 'h' 'd'.  Default is seconds.", NULL},
  { "absolute",   'a', POPT_ARG_INT,        &duration,           LORS_REFRESH_ABSOLUTE, 
        "Set expiration to an absolute time.", "<abs time>"},
  { "demo",  'D', POPT_ARG_NONE, 0, LORS_ARG_DEMO, 
        "Add the messages understood by the LoRS View visualization.", NULL},
        POPT_AUTOHELP
        { NULL, 0, 0, NULL, 0 }
    };

    parse_xndrc_files(&xndrc);
    g_lors_demo = xndrc.demo;
    optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0);
    poptSetOtherOptionHelp(optCon, "<filename>");

    if ( argc < 2 )
    {
        poptPrintUsage(optCon, stderr, 0);
        poptPrintHelp(optCon, stderr, 0);
        free_xndrc(&xndrc);
        poptFreeContext(optCon);
        exit(EXIT_FAILURE);
    }
    while ( (v=poptGetNextOpt(optCon)) >= 0)
    {
        switch(v)
        {
            case TIMEOUT:
                if ( strtotimeout(s_timeout, &xndrc.timeout) != 0 )
                {
                    fprintf(stderr, "Value too large for type.\n");
                    free_xndrc(&xndrc);
                    poptFreeContext(optCon);
                    exit(EXIT_FAILURE);
                }
                break;
            case LORS_REFRESH_MAX:
                opts |= v;
                break;
            case LORS_REFRESH_EXTEND_BY:
            case LORS_REFRESH_EXTEND_TO:
                if ( strtotimeout(s_timeout, &duration) != 0 )
                {
                    fprintf(stderr, "Value too large for type.\n");
                    free_xndrc(&xndrc);
                    poptFreeContext(optCon);
                    exit(EXIT_FAILURE);
                }
            case LORS_REFRESH_ABSOLUTE:
                opts |= v;
                break;
            case LORS_ARG_DEMO:
                g_lors_demo = (!g_lors_demo);
                break;
            case LORS_VERSION:
            {
                const char *package;
                double version;
                lorsGetLibraryVersion(&package, &version);
                fprintf(stderr, "Version: %s %f\n", package, version);
                free_xndrc(&xndrc);
                poptFreeContext(optCon);
                exit(EXIT_FAILURE);
            }
                break;
            default:
                break;
                /*fprintf(stderr, "Unsupported option: %d\n", v);*/
        }

    }
    g_db_level = xndrc.verbose;
    if ( v < -1 )
    {
        fprintf(stderr, "error: %d\n", v);
        fprintf(stderr, "%s: %s\n",
                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
                 poptStrerror(v));
    }


    while ( (filename = poptGetArg(optCon)) != NULL )
    {
        file_cnt++;

        /* translate days into seconds. */

        /*fprintf(stderr, "days:%f\n", days);*/
        /*duration = (time_t)(days*24.0*60.0*60.0);*/
        /*fprintf(stderr, "duration:%d\n", duration);*/
        ret = lorsRefreshFile(filename, duration, xndrc.threads, xndrc.timeout, opts); 
        if ( ret != LORS_SUCCESS )
        {
            fprintf(stderr, "LORS_ERROR: %d\n", ret);
            continue;
        }
    }
    if ( file_cnt == 0 )
    {
        fprintf(stderr, "Error. You must also provide a filename on "
                "which lors_upload operates.\n");
        poptPrintHelp(optCon, stderr, 0);
        free_xndrc(&xndrc);
        poptFreeContext(optCon);
        exit(EXIT_FAILURE);
    }
    
    free_xndrc(&xndrc);
    poptFreeContext(optCon);
    return 0;
}
コード例 #3
0
int main (int argc, char **argv)
{
    int  ret;
    LorsExnode *exnode;
    struct ibp_depot   lbone_server = {"dsj.sinrg.cs.utk.edu", 6767};
	socket_io_handler handle;
    IBP_depot   lbs;
    char        *s;
    char        *lbonehost = NULL;
    char        *output_filename = "-";
    int         same_output = 0;
    const char  *filename;
    char        *location = "state= tn";
    int         storage_type = IBP_SOFT;
    int         maxdepots = 6;
    double      duration = 2;
    ulong_t     data_blocksize = 1024*1024*5;
    char        *s_data_blocksize = NULL;
    ulong_t     max_buffersize = 1024*1024*45;
    char        *s_max_buffersize = NULL;
    ulong_t     prebuffer = 1;
    char        *s_prebuffer = NULL;
    int         cache = 2;
    ulong_t     offset=0, length=0;
    int         copies = 1;
    int         threads = 10;
    int         timeout = 600;
    char        *s_timeout = "600s";
    int         encryption = 0;
    int         v;
    int         try1 = 0;
    int         file_cnt = 0;
    int         dp_threads = -1;
    int         job_threads = 2;
    int         progress = 5;
    XndRc       xndrc;
    int         opts = 0;
	char       *report_host = NULL;
	uuid_t      out;
	char       session_id[33];
	int        i;
	int        inner_loop_flag = 0;
	
	// init status
	handle.status = CONN_WAITING;

    poptContext optCon;   /* context for parsing command-line options */
    struct poptOption optionsTable[] = {
  { "samename",   'f', POPT_ARG_NONE,   0,                  SAME_OUTPUTNAME, 
        "Specify the exNode filename by appending .xnd to the original filename.", NULL },
  { "outputfile", 'o', POPT_ARG_STRING, &output_filename,   OUTPUTNAME, 
        "Specify a specific name for the output exNode file.", NULL},
  { "version",    'v', POPT_ARG_NONE,   0,                  LORS_VERSION, 
        "Display Version information about this package.", NULL},
  { "verbose",    'V', POPT_ARG_INT,    &xndrc.verbose,        VERBOSE, 
        "Modify the level or mode of Verbosity in output messages.", "0"},
  { "thread-depot", 'a', POPT_ARG_INT,    &dp_threads, THREADDEPOT, 
        "Specify the maxmium connection to any single IBP depot.", 
        "-1"},
  { "redundancy", 'r', POPT_ARG_INT,    &job_threads, REDUNDANCY , 
        "Specify the maxmium number of threads working on a single download job.", 
        "1"},
  { "resume", 'R', POPT_ARG_NONE,    0, LORS_RECOVER, 
       "Download will resume working on a partially downloaded file if one is detected.", 
        NULL},
  { "progress", 'p', POPT_ARG_INT,    &progress, PROGRESS, 
        "The progress number specifies how many completed blocks are allowed before "
        "a download of a pending block is duplicated.", 
        "0"},
  /*{ "location",   'l', POPT_ARG_STRING, &xndrc.location,          LOCATION_HINT, 
        "Specify a location hint to pass the LBone Query.", "'x'"},*/
  { "bs", 'b', POPT_ARG_STRING|POPT_ARGFLAG_ONEDASH, &s_data_blocksize,  DATA_BLOCKSIZE, 
        "Specify the logical blocksize of transfers.", "'5M'"},
  { "threads",    't', POPT_ARG_INT,    &xndrc.threads,           THREADS, 
        "Specify the maximum number of threads to use to perform Download.", NULL},
  { "timeout",    'T', POPT_ARG_STRING,    &s_timeout,           TIMEOUT, 
        "Specify the maximum time to allow for all operations.", "'3m'"},
  { "prebuffer", 'q', POPT_ARG_INT, &prebuffer,  PREBUFFER_SIZE, 
        "Specify the number of blocks to prebuffer before outputting to file.", NULL},
  { "cache", 'C', POPT_ARG_INT, &cache,  CACHE_SIZE, 
        "Specify the number of block-sized memory buffers to use during download.", NULL},
  { "buffersize", 'M', POPT_ARG_STRING, &s_max_buffersize,  MAX_BUFFSIZE, 
        "Specify the maximum internal buffer size to use on operations.", NULL},
  { "offset",     'O', POPT_ARG_LONG,    &offset,           FILE_OFFSET, 
        "Specify an offset relative to the exNode from which download will begin",NULL},
  { "length",     'L', POPT_ARG_LONG,    &length,           FILE_LENGTH, 
        "Specify a length other than the logical extent of the exNode.", NULL},
  { "demo",  'D', POPT_ARG_NONE, 0, LORS_ARG_DEMO, 
        "Add the messages understood by the LoRS View visualization.", NULL},
  { "visualize-progress",  'X', POPT_ARG_STRING, &report_host, VISUALIZE_PROGRESS, 
        "Http link to visualizer with port e.g. http://dlt.incntre.iu.edu:8000 .", NULL},
        POPT_AUTOHELP
        { NULL, 0, 0, NULL, 0 }
    };


    optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0);
    poptSetOtherOptionHelp(optCon, "<filename>");
#ifndef _MINGW
    signal(SIGPIPE, sigpipe_handle);
#endif

    if ( argc < 2 )
    {
        poptPrintUsage(optCon, stderr, 0);
        poptPrintHelp(optCon, stderr, 0);
        exit(EXIT_FAILURE);
    }
    lbs = &lbone_server;
    parse_xndrc_files(&xndrc);
    g_lors_demo = xndrc.demo;

    while ( (v=poptGetNextOpt(optCon)) >= 0)
    {
        switch(v)
        {
            case DATA_BLOCKSIZE:
                if ( strtobytes(s_data_blocksize, &xndrc.data_blocksize) != 0 )
                {
                    fprintf(stderr, "The blocksize specified is too large for internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case MAX_BUFFSIZE:
                if ( strtobytes(s_max_buffersize, &xndrc.max_buffersize) != 0 )
                {
                    fprintf(stderr, "The blocksize specified is too large for internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case TIMEOUT:
                if ( strtotimeout(s_timeout, &xndrc.timeout) != 0 )
                {
                    fprintf(stderr, "Value too large for type.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case LBONESERVER:
                strncpy(lbone_server.host, lbonehost, 255);
                break;
            case STORAGE_TYPE_HARD:
                xndrc.storage_type = IBP_HARD;
                break;
            case STORAGE_TYPE_SOFT:
                xndrc.storage_type = IBP_SOFT;
                break;
            case LORS_RECOVER:
                opts |= LORS_RECOVER;
                break;
            case PREBUFFER_SIZE:
                if ( prebuffer <= 0 ){
                    fprintf(stderr,"Invalid pre-buffer number !\n");
                    exit(-1);
                };
                break;
            case CACHE_SIZE:
                if ( cache < 0 ) { cache = 0 ; };
                break;
            case LORS_VERSION:
            {
                const char *package;
                double version;
                lorsGetLibraryVersion(&package, &version);
                fprintf(stderr, "Version: %s %f\n", package, version);
                exit(EXIT_FAILURE);
                break;
            }
            case LORS_ARG_DEMO:
                g_lors_demo = (!g_lors_demo);
                break;
            case SAME_OUTPUTNAME:
                same_output = 1;
                break;
            default:
                /* TODO: be more specific: */
                /*fprintf(stderr, "Unsupported option: %d\n", v);*/
                break;
        }

    }
    g_db_level = xndrc.verbose;
    if ( v < -1 )
    {
        fprintf(stderr, "error: %d\n", v);
        fprintf(stderr, "%s: %s\n",
                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
                 poptStrerror(v));
    }


    while ( (filename = poptGetArg(optCon)) != NULL )
    {
        longlong x = 0;
        longlong y = 0;
        file_cnt++;
        if ( same_output == 1 ) { output_filename = NULL; }

        lorsDebugPrint(D_LORS_VERBOSE, "%s %s %d %d %ld %d %d\n",
                      filename, output_filename, offset, length, 
                      xndrc.max_buffersize, xndrc.threads, xndrc.timeout);

        lorsDebugPrint(D_LORS_VERBOSE, "offset: %d, length: %d\n", offset, length);
        lorsDebugPrint(D_LORS_VERBOSE, "File: %s--------------------------------------------\n", filename);
        
        x = length;
        y = offset;
		
		// generate session id
		if(report_host != NULL){
			uuid_generate(out);
			for(i = 0; i < 16; i++)
				sprintf(session_id + (i*2),"%02x", out[i]);
			handle.server_add = report_host;
			handle.session_id = session_id;
			//fprintf(stderr, "Init .. \n");	
			if(socket_io_init(&handle) != SOCK_SUCCESS){
				fprintf(stderr, "socket io Init failed \n");
			}
		}

        if ( lbonehost == NULL )
        {
            lbs = xndrc.lboneList[0]; 
            try1 = 1;
        } else 
        {
            lbs = &lbone_server;
            try1 = 0;
        }
        do 
        {
            ret = lorsDownloadFile(filename, output_filename, y, x,
                               xndrc.data_blocksize,
                               xndrc.max_buffersize,
                               prebuffer,
                               dp_threads,
                               job_threads,
                               progress,
                               cache,
                               lbs->host,
                               lbs->port,
                               xndrc.location,xndrc.resolution_file,
                               xndrc.threads, xndrc.timeout, 
							   &handle, opts); 
         
            if ( ret != LORS_SUCCESS )
            {
                if ( ret == LORS_LBONE_FAILED && xndrc.lboneList[try1] != NULL )
                {
                    fprintf(stderr, "%s: %d\n", xndrc.lboneList[try1]->host, 
                            xndrc.lboneList[try1]->port);
                    fprintf(stderr, "LBone failure: trying next server\n");
                    lbs = xndrc.lboneList[try1];
                    try1++;
                } else 
                {
                    fprintf(stderr, "LORS_ERROR: %d\n", ret);
					inner_loop_flag = 1;
                    break;
                }
            }
        } while ( ret != LORS_SUCCESS );
		
		if(report_host != NULL){
			if(handle.status == CONN_CONNECTED){
				socket_io_send_clear(&handle);
			}
	
			if(handle.status != CONN_WAITING){
				socket_io_close(&handle);
			}
		}
		
		if(inner_loop_flag){
			exit(EXIT_FAILURE);
		}

    }


    if ( file_cnt == 0 )
    {
        fprintf(stderr, "Error. You must also provide a filename on "
                "which lors_upload operates.\n");
        poptPrintHelp(optCon, stderr, 0);
        exit(EXIT_FAILURE);
    }
    free_xndrc(&xndrc);
    poptFreeContext(optCon);
    return 0;
}
コード例 #4
0
ファイル: lors_upload.c プロジェクト: datalogistics/dlt-lors
int main (int argc, char **argv)
{
    int ret;
    LorsExnode *exnode;
    struct ibp_depot   lbone_server = {"dsj.sinrg.cs.utk.edu", 6767};
	socket_io_handler handle;
    IBP_depot          lbs = NULL,*dp_list = NULL;
    char        *s;
    char        *lbonehost = NULL;
    char        *output_filename = NULL;
	char        *upload_dir_path = NULL;
	char        *upload_dir_id = NULL;
    const char  *filename = NULL;
    int          same_name=0;
    char        *s_data_blocksize = NULL;
    char        *s_e2e_blocksize = NULL;
    char        *s_max_buffersize = NULL;
    ulong_t     offset=0;
    long        length=-1;
    char *      s_offset=NULL;
    char *      s_length=NULL;
    char        *s_timeout = "600s";
    char        *s_duration = "1d";
    int         encryption = 0;
    int         v;
    int         none=0;
    int         depot_list = 0;
    int         file_cnt = 0;
    XndRc       xndrc;
    XndRc       drc;
    int         *e2e_order_tmp = NULL;
    int         e2e_cnt = 0;
    int         try1 = 0;
    int         type_set = 0;
    int         fragments=0;
    char        *rcfile=NULL;
	char       *report_host = NULL;
	uuid_t      out;
	char       session_id[33];
	int        i;
	unis_config config;
    poptContext optCon;   /* context for parsing command-line options */

	handle.status = CONN_WAITING;

    struct poptOption optionsTable[] = {
  { "samename",   'f', POPT_ARG_NONE,   0,                  SAME_OUTPUTNAME, 
        "Specify the exNode filename by appending .xnd to the original filename.", NULL },
  { "stdin",   'i', POPT_ARG_NONE,   0,                  READ_STDIN, 
        "Read from standard input rather than a specified filename.", NULL },
  { "outputfile", 'o', POPT_ARG_STRING, &output_filename,   OUTPUTNAME, 
	    "Specify a specific name for the output exNode file. "
	    "Default output format is Exnode. 1) If file extension is \".uef\" "
	    "then output file format will be Unis Exnode Format (.uef) "
	    "2) if ouputfile contain  link then exnodes will posted"
	    " to that link", NULL},
  { "upload_dir", 'u', POPT_ARG_STRING, &upload_dir_path,   UPLOAD_DIR, 
	    "Specifiy the upload directory path in Unis File System e.g. /user23/LSAT8/2015/1/15", NULL},
  { "version",    'v', POPT_ARG_NONE,   0,                  LORS_VERSION, 
        "Display Version information about this package.", NULL},
  { "verbose",    'V', POPT_ARG_INT,    &xndrc.verbose,        VERBOSE, 
        "Modify the level or mode of Verbosity in output messages.", "0"},
  { "lbone-host", 'H', POPT_ARG_STRING, &lbonehost,         LBONESERVER, 
        "Specify an L-Bone Server for resource discover and proxmity resolution.", NULL},
  { "lbone-port", 'P', POPT_ARG_INT,    &lbone_server.port, LBONEPORT, 
	    "Specify the port number when using an L-Bone Server on a non standard port.", 
	    "6767"},
  { "location",   'l', POPT_ARG_STRING, &xndrc.location,          LOCATION_HINT, 
        "Specify a location hint to pass the L-Bone Query.", "\"state= TN\""},
  { "duration",   'd', POPT_ARG_STRING,     &s_duration,          DURATION, 
        "Specify the amount of time to allocate storage. The available modifiers are "
        "'m' 'h' 'd' for 'minute' 'hour' and 'days' respectively. Default is seconds. "
        "(e.g. -d 1d or -d 1h)", NULL},
  { "soft",       's', POPT_ARG_NONE,   0,                  STORAGE_TYPE_SOFT, 
        "Specify SOFT storage for storage allocations.", NULL},
  { "hard",       'h', POPT_ARG_NONE,   0,                  STORAGE_TYPE_HARD, 
        "Specify HARD storage for storage allocations.", NULL},
  { "maxdepots",  'm', POPT_ARG_INT,   &xndrc.maxdepots,          MAX_DEPOTS, 
        "Specify the maximum number of depots returned by the 'location' hint.", "6"},
  { "bs", 'b', POPT_ARG_STRING|POPT_ARGFLAG_ONEDASH, &s_data_blocksize,  DATA_BLOCKSIZE, 
        "Specify the logical data blocksize of input file.", "'5M'"},
  { "copies",     'c', POPT_ARG_INT,    &xndrc.copies,            COPIES, 
        "Specify the number of copies.", "1"},
  { "fragments",  'F', POPT_ARG_INT,     &fragments,      NUM_FRAGMENTS, 
        "Rather than specifying the logical data blocksize, specify the number of "
        "blocks into which the file should be divided.", "4" },
  { "depot-list",        0, POPT_ARG_NONE,   0,        DEPOT_LIST, 
        "Only use depots specified in .xndrc file", NULL},
  { "threads",    't', POPT_ARG_INT,    &xndrc.threads,           THREADS, 
        "Specify the maximum number of threads to use to perform Upload.", NULL},
  { "timeout",    'T', POPT_ARG_STRING,    &s_timeout,           TIMEOUT, 
        "Specify the maximum time to allow for all operations.", "'3m'"},
  { "buffersize", 'M', POPT_ARG_STRING, &s_max_buffersize,  MAX_BUFFSIZE, 
        "Specify the maximum internal buffer to use on operations.", NULL},
  { "offset",     'O', POPT_ARG_STRING,    &s_offset,           FILE_OFFSET, 
        "Specify an offset relative to the exNode from which download will begin",NULL},
  { "length",     'L', POPT_ARG_STRING,    &s_length,           FILE_LENGTH, 
        "Specify a length other than the logical extent of the exNode.", NULL},
  { "none",        'n', POPT_ARG_NONE,   0,   LORS_NO_E2E, 
        "Turn off all e2e services.", NULL},
  { "des",        'e', POPT_ARG_NONE|POPT_ARGFLAG_OR,   &encryption,   DES_ENCRYPTION, 
        "Turn on des encryption.", NULL},
  { "aes",        'a', POPT_ARG_NONE|POPT_ARGFLAG_OR,   &encryption,   AES_ENCRYPTION, 
        "Turn on aes encryption.", NULL},
  { "compress",   'z', POPT_ARG_NONE|POPT_ARGFLAG_OR,   &encryption,   ZLIB_COMPRESS, 
        "Turn on zlib compression.", NULL},
  { "xor",        'x', POPT_ARG_NONE|POPT_ARGFLAG_OR,   &encryption,   XOR_ENCRYPTION, 
        "Turn on xor encryption.", NULL},
  { "checksum",   'k', POPT_ARG_NONE|POPT_ARGFLAG_OR,   &encryption,   ADD_CHECKSUM, 
        "Turn on checksum.", NULL},
  { "e2e-blocksize", 'E', POPT_ARG_STRING,   &s_e2e_blocksize,     E2E_BLOCKSIZE, 
        "When specifying e2e conditioning, select an e2e bocksize "
        "which will evenly fit into your chosen Mapping Blocksize.", NULL},
  { "xndrc", 'x', POPT_ARG_STRING, &rcfile, RCFILE, 
        "You may specify an alternate source for the upload DepotList.", "<filename>"},
  { "demo",  'D', POPT_ARG_NONE, 0, LORS_ARG_DEMO, 
        "Add the messages understood by the LoRS View visualization.", NULL},
  { "visualize-progress",  'X', POPT_ARG_STRING, &report_host, VISUALIZE_PROGRESS, 
     	"Http link to visualizer with port e.g. http://dlt.incntre.iu.edu:8000 .", NULL},
        POPT_AUTOHELP
        { NULL, 0, 0, NULL, 0 }
  };

    memset(&drc, 0, sizeof(XndRc));
    memset(&xndrc, 0, sizeof(XndRc));

    parse_xndrc_files(&xndrc);
    lbs = &lbone_server;
    g_lors_demo = xndrc.demo;

    optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0);
    poptSetOtherOptionHelp(optCon, "<filename>");
#ifndef _MINGW
    signal(SIGPIPE, sigpipe_handle);
#endif
    /*signal(SIGINT, sigint_handle);*/


    if ( argc < 2 )
    {
        poptPrintUsage(optCon, stderr, 0);
        poptPrintHelp(optCon, stderr, 0);
                                 exit(EXIT_FAILURE);
    }

    while ( (v=poptGetNextOpt(optCon)) >= 0)
    {
        switch(v)
        {
            case DATA_BLOCKSIZE:
                if ( strtobytes(s_data_blocksize, &xndrc.data_blocksize) != 0 )
                {
                    fprintf(stderr, "The blocksize specified is too large for internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                if ( fragments != 0 )
                {
                    fprintf(stderr, "Specify either Fragments or Blocksize, not both.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case NUM_FRAGMENTS:
                if ( s_data_blocksize != NULL )
                {
                    fprintf(stderr, "Specify either Fragments or Blocksize, not both.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case MAX_BUFFSIZE:
                if ( strtobytes(s_max_buffersize, &xndrc.max_buffersize) != 0 )
                {
                    fprintf(stderr, "The blocksize specified is too large for "
                            "internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case AES_ENCRYPTION:
                fprintf(stderr, "AES: encryption\n");
                xndrc.e2e_order[e2e_cnt] = AES_ENCRYPTION;
                e2e_cnt++;
                break;
            case DES_ENCRYPTION:
                xndrc.e2e_order[e2e_cnt] = DES_ENCRYPTION;
                e2e_cnt++;
                break;
            case XOR_ENCRYPTION:
                xndrc.e2e_order[e2e_cnt] = XOR_ENCRYPTION;
                e2e_cnt++;
                break;
            case ADD_CHECKSUM:
                xndrc.e2e_order[e2e_cnt] = ADD_CHECKSUM;
                e2e_cnt++;
                break;
            case ZLIB_COMPRESS:
                xndrc.e2e_order[e2e_cnt] = ZLIB_COMPRESS;
                e2e_cnt++;
                break;
            case LORS_NO_E2E:
                none = 1;
                break;
            case FILE_OFFSET:
                if ( strtobytes(s_offset, &offset) != 0 )
                {
                    fprintf(stderr, "The offset specified is too large for "
                            "internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case FILE_LENGTH:
                if ( strtobytes(s_length, &length) != 0 )
                {
                    fprintf(stderr, "The length specified is too large for "
                            "internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case E2E_BLOCKSIZE:
                if ( strtobytes(s_e2e_blocksize, &xndrc.e2e_blocksize) != 0 )
                {
                    fprintf(stderr, "The e2e blocksize specified is too large for "
                            "internal datatype.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case DEPOT_LIST:
                depot_list = 1;
                break;
            case TIMEOUT:
                if ( strtotimeout(s_timeout, &xndrc.timeout) != 0 )
                {
                    fprintf(stderr, "Value too large for type.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case LBONESERVER:
                strncpy(lbone_server.host, lbonehost, 255);
                break;
            case STORAGE_TYPE_HARD:
                if ( type_set > 0 )
                {
                    fprintf(stderr, "Set one of either Hard or Soft storage.\n");
                    exit(EXIT_FAILURE);
                }
                xndrc.storage_type = IBP_HARD;
                type_set++;
                break;
            case STORAGE_TYPE_SOFT:
                if ( type_set > 0 )
                {
                    fprintf(stderr, "Set one of either Hard or Soft storage.\n");
                    exit(EXIT_FAILURE);
                }
                xndrc.storage_type = IBP_SOFT;
                type_set++;
                break;
            case DURATION:
                if ( strtotimeout(s_duration, &xndrc.duration) != 0 )
                {
                    fprintf(stderr, "Value too large for type.\n");
                    exit(EXIT_FAILURE);
                }
                break;
            case LORS_VERSION:
            {
                const char *package;
                double version;
                lorsGetLibraryVersion(&package, &version);
                fprintf(stderr, "Version: %s %f\n", package, version);
                exit(EXIT_FAILURE);
                break;
            }
            case LORS_ARG_DEMO:
                g_lors_demo = (!g_lors_demo);
                break;
            case READ_STDIN:
                filename = "-";
                break;
            case SAME_OUTPUTNAME:
                same_name = 1;
                break;
#if 0
            default:
                fprintf(stderr, "Unsupported option: %d\n", v);
#endif
        }

    }
    if ( rcfile != NULL )
    {
        if ( read_xndrc_file(&drc, rcfile) != 0 )
        {
            fprintf(stderr, "Unable to open specified rcfile\n");
            exit(EXIT_FAILURE);
        }
        xndrc.depotList = drc.depotList;
    }

    
    g_db_level = xndrc.verbose;
    if ( v < -1 )
    {
        fprintf(stderr, "error: %d\n", v);
        fprintf(stderr, "%s: %s\n",
                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
                 poptStrerror(v));
    }

    /*g_db_level = D_LORS_TERSE | D_LORS_VERBOSE | D_LORS_ERR_MSG ;*/

    if ( depot_list == 1 ){
        dp_list = xndrc.depotList;
    }else {
        dp_list = NULL;
    };
    /* setup default e2e conditioning for upload */
    if ( none > 0 )
    {
        xndrc.e2e_order[0] = -1;
        e2e_cnt = 0;
    } else if ( e2e_cnt == 0 )
    {
        for(; xndrc.e2e_order[e2e_cnt] != -1; e2e_cnt++);
    }
	/*check the upload directory */
	if(output_filename != NULL && strstr(output_filename, "http://") != NULL )
	{
		
        if(upload_dir_path == NULL){
			fprintf(stderr, "Missing UNIS upload directory absolute path \n");
			exit(EXIT_FAILURE);
		}else{
			memset (&config, 0, sizeof(unis_config));
			config.endpoint = output_filename;
			config.persistent = 1;
			ret = unis_create_directory(&config, upload_dir_path, &upload_dir_id);
			if(ret == 0){
				fprintf(stderr, "Failed to get the upload directory id from UNIS \n");
				exit(EXIT_FAILURE);
			}
		}
	}
	/*Generate session UUID*/
	if(report_host != NULL)
	{
		uuid_generate(out);
		for(i = 0; i < 16; i++)
			sprintf(session_id + (i*2),"%02x", out[i]);

		handle.server_add = report_host;
		handle.session_id = session_id;
	
		if(socket_io_init(&handle) != SOCK_SUCCESS)
		{
			fprintf(stderr, "Socket IO Init failed \n");
		}
	}

    if ( filename != NULL )
    {
        goto in_while;
    }
    while ( (filename = poptGetArg(optCon)) != NULL )
    {
in_while:
        file_cnt++;
        if ( same_name == 1 )
        {
            int len;
            char *s;
            s = strrchr (filename, '/');
            if ( s == NULL ) s = filename;
            else s++;
            len = strlen(s) + strlen(".xnd") + 1;
            output_filename = malloc(sizeof(char)*len);
            snprintf(output_filename, len, "%s.xnd", s);
        }
        lorsDebugPrint(D_LORS_VERBOSE, "%s %ld %ld %ld %d %s %d %s %d %d %d %ld %d %d\n",
                      filename, offset, length, xndrc.data_blocksize, xndrc.copies, 
                      lbone_server.host, lbone_server.port, xndrc.location, 
                      xndrc.maxdepots, xndrc.storage_type, xndrc.duration, 
                      xndrc.max_buffersize, xndrc.threads, xndrc.timeout);
        if ( e2e_cnt > 0 )
        {
            xndrc.e2e_order[e2e_cnt] = -1;
            e2e_order_tmp = xndrc.e2e_order;
        }
        /* start from first lbone server in xndrc file */
        if ( lbonehost == NULL )
        {
            lbs = xndrc.lboneList[try1];
            try1 = 1;
        } else {
            lbs = &lbone_server;
            try1 = 0;
        }
        do 
        {
            /*fprintf(stderr, "e2e_blocksize: %ld\n", xndrc.e2e_blocksize);*/
            ret = lorsUploadFile(filename, output_filename, offset, (longlong)length, 
                             xndrc.data_blocksize, xndrc.copies, fragments, 
                             xndrc.e2e_blocksize, e2e_order_tmp, lbs, dp_list, 
                             xndrc.location, xndrc.maxdepots, xndrc.storage_type, 
                             xndrc.duration, xndrc.max_buffersize, 
                             xndrc.resolution_file, xndrc.threads, 
							 xndrc.timeout, &handle, upload_dir_id,  0); 
            if ( ret != LORS_SUCCESS && ret != LORS_PARTIAL )
            {
                if ( ret == LORS_LBONE_FAILED && xndrc.lboneList[try1] != NULL )
                {
                    fprintf(stderr, "%s: %d\n", xndrc.lboneList[try1]->host, 
                            xndrc.lboneList[try1]->port);
                    fprintf(stderr, "L-Bone failure: trying next server\n");
                    lbs = xndrc.lboneList[try1];
                    try1++;
                } else 
                {
                    fprintf(stderr, "LORS_ERROR: %d\n", ret);
                    exit(EXIT_FAILURE);
                }
            }
        } while ( ret != LORS_SUCCESS && ret != LORS_PARTIAL );
        free(output_filename);
    }

	if(report_host != NULL){
		if(handle.status == CONN_CONNECTED){
			socket_io_send_clear(&handle);
		}
	
		if(handle.status != CONN_WAITING){
			socket_io_close(&handle);
		}
	}

    if ( file_cnt == 0 )
    {
        fprintf(stderr, "Error. You must also provide a filename on "
                "which lors_upload operates.\n");
        poptPrintHelp(optCon, stderr, 0);
        exit(EXIT_FAILURE);
    }
    free_xndrc(&xndrc);
    poptFreeContext(optCon);
    if ( ret == LORS_PARTIAL ) return 1;
    return 0;
}