From 4b8f4da10c28323b52c2ddb4d5dffca8a23dbe07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 26 Aug 2016 00:32:40 -0300 Subject: [PATCH] test --- iguana/main.c | 61 +++++++++++++++++++++++++++++---------- includes/iguana_globals.h | 2 ++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/iguana/main.c b/iguana/main.c index abfe3c210..70be31c3c 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -168,6 +168,19 @@ char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remotead int32_t iguana_jsonQ() { struct iguana_jsonitem *ptr; char *str; + if ( COMMANDLINE_ARGFILE != 0 ) + { + ptr = calloc(1,sizeof(*ptr) + strlen(COMMANDLINE_ARGFILE) + 1); + ptr->myinfo = SuperNET_MYINFO(0); + strcpy(ptr->jsonstr,COMMANDLINE_ARGFILE); + free(COMMANDLINE_ARGFILE); + COMMANDLINE_ARGFILE = 0; + if ( (ptr->retjsonstr= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr,ptr->port)) == 0 ) + ptr->retjsonstr = clonestr("{\"error\":\"null return from iguana_jsonstr\"}"); + printf("COMMANDLINE_ARGFILE.(%s) -> (%s) %.0f\n",ptr->jsonstr,ptr->retjsonstr!=0?ptr->retjsonstr:"null return",OS_milliseconds()); + queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0); + return(1); + } if ( (ptr= queue_dequeue(&finishedQ,0)) != 0 ) { if ( ptr->expired != 0 ) @@ -521,17 +534,31 @@ void iguana_appletests(struct supernet_info *myinfo) } } -void iguana_commandline(struct supernet_info *myinfo,char *arg) +int32_t iguana_commandline(struct supernet_info *myinfo,char *arg) { - cJSON *argjson,*array; char *coinargs,*argstr,*str; int32_t i,n; long filesize = 0; + cJSON *argjson,*array; char *coinargs,*argstr=0,*str; int32_t i,n; long filesize = 0; if ( arg == 0 ) arg = "iguana.conf"; - if ( arg != 0 ) + else if ( (COMMANDLINE_ARGFILE= OS_filestr(&filesize,arg)) != 0 ) + { + if ( (argjson= cJSON_Parse(COMMANDLINE_ARGFILE)) == 0 ) + { + printf("couldnt parse %s: (%s) after initialized\n",arg,COMMANDLINE_ARGFILE); + free(COMMANDLINE_ARGFILE); + COMMANDLINE_ARGFILE = 0; + } + else + { + free_json(argjson); + printf("Will run (%s) after initialized\n",COMMANDLINE_ARGFILE); + } + } + else if ( arg != 0 ) { if ( arg[0] == '{' || arg[0] == '[' ) argstr = arg; - else argstr = OS_filestr(&filesize,arg); - if ( (argjson= cJSON_Parse(argstr)) != 0 ) + //else argstr = OS_filestr(&filesize,arg); + if ( argstr != 0 && (argjson= cJSON_Parse(argstr)) != 0 ) { IGUANA_NUMHELPERS = juint(argjson,"numhelpers"); if ( (myinfo->rpcport= juint(argjson,"port")) == 0 ) @@ -572,10 +599,11 @@ void iguana_commandline(struct supernet_info *myinfo,char *arg) } printf(") <- IOTA random passphrase\n"); } - } else printf("error parsing.(%s)\n",(char *)argstr); - if ( argstr != arg ) - free(argstr); + } //else printf("error parsing.(%s)\n",(char *)argstr); + //if ( argstr != arg ) + // free(argstr); } + return(COMMANDLINE_ARGFILE != 0); } void iguana_ensuredirs() @@ -646,7 +674,7 @@ void iguana_urlinit(struct supernet_info *myinfo,int32_t ismainnet,int32_t usess void iguana_launchdaemons(struct supernet_info *myinfo) { int32_t i; char *helperargs,helperstr[512]; - if ( IGUANA_NUMHELPERS == 0 ) + if ( IGUANA_NUMHELPERS == 0 || COMMANDLINE_ARGFILE != 0 ) IGUANA_NUMHELPERS = 1; for (i=0; itradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("btce"),0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitstamp"),0); #endif - iguana_helpinit(myinfo); - iguana_relays_init(myinfo); - basilisks_init(myinfo); - iguana_commandline(myinfo,arg); + if ( iguana_commandline(myinfo,arg) == 0 ) + { + iguana_helpinit(myinfo); + iguana_relays_init(myinfo); + basilisks_init(myinfo); #ifdef __APPLE__ - iguana_appletests(myinfo); + iguana_appletests(myinfo); #endif + } iguana_launchdaemons(myinfo); } diff --git a/includes/iguana_globals.h b/includes/iguana_globals.h index da160e9dc..aa7eba976 100755 --- a/includes/iguana_globals.h +++ b/includes/iguana_globals.h @@ -52,7 +52,9 @@ int32_t IGUANA_NUMHELPERS = 1; #define CONDEXTERN extern #endif + // ALL globals must be here! +CONDEXTERN char *COMMANDLINE_ARGFILE; CONDEXTERN char *Iguana_validcommands[]; CONDEXTERN int32_t Showmode,Autofold,PANGEA_MAXTHREADS;