From a8c5809efee830102b9d5371b6b63bbbdb8de173 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 May 2015 04:53:26 +0300 Subject: [PATCH] test --- libjl777/SuperNET.c | 11 ++++++++--- libjl777/plugins/console777.c | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/libjl777/SuperNET.c b/libjl777/SuperNET.c index f736fca0..96040113 100644 --- a/libjl777/SuperNET.c +++ b/libjl777/SuperNET.c @@ -585,9 +585,10 @@ int32_t got_newpeer(const char *ip_port) { if ( Debuglevel > 2 ) printf("got_new char *process_jl777_msg(char *previpaddr,char *jsonstr,int32_t duration) { - char plugin[MAX_JSON_FIELD],method[MAX_JSON_FIELD],request[MAX_JSON_FIELD],ipaddr[MAX_JSON_FIELD],path[MAX_JSON_FIELD]; + char *process_user_json(char *plugin,char *method,char *cmdstr,int32_t broadcastflag,int32_t timeout); + char plugin[MAX_JSON_FIELD],method[MAX_JSON_FIELD],request[MAX_JSON_FIELD],ipaddr[MAX_JSON_FIELD],path[MAX_JSON_FIELD],*bstr; uint64_t daemonid,instanceid,tag; - int32_t ind,async,timeout,n = 1; + int32_t ind,async,timeout,broadcastflag = 0,n = 1; uint16_t port,websocket; cJSON *json; if ( (json= cJSON_Parse(jsonstr)) != 0 ) @@ -609,6 +610,9 @@ char *process_jl777_msg(char *previpaddr,char *jsonstr,int32_t duration) daemonid = get_API_nxt64bits(cJSON_GetObjectItem(json,"daemonid")); instanceid = get_API_nxt64bits(cJSON_GetObjectItem(json,"instanceid")); copy_cJSON(method,cJSON_GetObjectItem(json,"method")); + if ( (bstr= cJSON_str(cJSON_GetObjectItem(json,"broadcast"))) != 0 ) + broadcastflag = 1; + else broadcastflag = 0; if ( method[0] == 0 ) { strcpy(method,request); @@ -617,7 +621,8 @@ char *process_jl777_msg(char *previpaddr,char *jsonstr,int32_t duration) } n = get_API_int(cJSON_GetObjectItem(json,"iters"),1); timeout = get_API_int(cJSON_GetObjectItem(json,"timeout"),1000); - return(plugin_method(0,previpaddr==0,plugin,method,daemonid,instanceid,jsonstr,0,timeout)); + return(process_user_json(plugin,method,jsonstr,broadcastflag,timeout)); + //return(plugin_method(0,previpaddr==0,plugin,method,daemonid,instanceid,jsonstr,0,timeout)); } else return(clonestr("{\"error\":\"couldnt parse JSON\"}")); } diff --git a/libjl777/plugins/console777.c b/libjl777/plugins/console777.c index 98396433..8d144412 100644 --- a/libjl777/plugins/console777.c +++ b/libjl777/plugins/console777.c @@ -215,10 +215,24 @@ char *parse_expandedline(char *plugin,char *method,int32_t *timeoutp,char *line, else return(clonestr(pubstr)); } +char *process_user_json(char *plugin,char *method,char *cmdstr,int32_t broadcastflag,int32_t timeout) +{ + struct daemon_info *find_daemoninfo(int32_t *indp,char *name,uint64_t daemonid,uint64_t instanceid); + int32_t tmp; char *retstr; + if ( broadcastflag != 0 || strcmp(plugin,"relay") == 0 ) + retstr = nn_loadbalanced(cmdstr); + else if ( strcmp(plugin,"peers") == 0 ) + retstr = nn_allpeers(cmdstr,timeout,0); + else if ( find_daemoninfo(&tmp,plugin,0,0) != 0 ) + retstr = plugin_method(0,1,plugin,method,0,0,cmdstr,0,timeout != 0 ? timeout : 0); + else retstr = nn_publish(cmdstr,0); + return(retstr); +} + void process_userinput(char *_line) { static char *line,*line2; - char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int j,timeout,broadcastflag = 0; + char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int timeout,broadcastflag = 0; printf("[%s]\n",_line); if ( line == 0 ) line = calloc(1,65536), line2 = calloc(1,65536); @@ -250,14 +264,7 @@ void process_userinput(char *_line) } if ( (cmdstr = parse_expandedline(plugin,method,&timeout,line,broadcastflag)) != 0 ) { - struct daemon_info *find_daemoninfo(int32_t *indp,char *name,uint64_t daemonid,uint64_t instanceid); - if ( broadcastflag != 0 || strcmp(plugin,"relay") == 0 ) - retstr = nn_loadbalanced(cmdstr); - else if ( strcmp(plugin,"peers") == 0 ) - retstr = nn_allpeers(cmdstr,timeout != 0 ? timeout : RELAYS.surveymillis,0); - else if ( find_daemoninfo(&j,plugin,0,0) != 0 ) - retstr = plugin_method(0,1,plugin,method,0,0,cmdstr,0,timeout != 0 ? timeout : 0); - else retstr = nn_publish(cmdstr,0); + retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : RELAYS.surveymillis); printf("(%s) -> (%s) -> (%s)\n",line,cmdstr,retstr); free(cmdstr); }