void process_userinput(char *_line) { static char *line,*line2,*match = "./BitcoinDarkd SuperNET '"; char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int len,timeout,broadcastflag = 0; len = (int32_t)strlen(match); if ( _line[strlen(_line)-1] == '\'' && strncmp(_line,match,len) == 0 ) { _line[strlen(_line)-1] = 0; _line += len; } if ( (json= cJSON_Parse(_line)) != 0 ) { char *process_nn_message(int32_t sock,char *jsonstr); free_json(json); char *SuperNET_JSON(char *jsonstr); retstr = SuperNET_JSON(_line); //retstr = process_nn_message(-1,line); //retstr = nn_loadbalanced((uint8_t *)line,(int32_t)strlen(line)+1); fprintf(stderr,"console.(%s) -> (%s)\n",_line,retstr); return; } else printf("cant parse.(%s)\n",line); printf("[%s]\n",_line); if ( line == 0 ) line = calloc(1,65536), line2 = calloc(1,65536); expand_aliases(line,line2,65536,_line); if ( (line= localcommand(line)) == 0 ) return; if ( line[0] == '!' ) broadcastflag = 1, line++; settoken(ipaddr,line); printf("expands to: %s [%s] %s\n",broadcastflag != 0 ? "broadcast": "",line,ipaddr); if ( is_ipaddr(ipaddr) != 0 ) { line += strlen(ipaddr) + 1; if ( (cmdstr = parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 ) { printf("ipaddr.(%s) (%s)\n",ipaddr,line); //retstr = nn_direct(ipaddr,(uint8_t *)line,(int32_t)strlen(line)+1); printf("deprecated (%s) -> (%s)\n",line,cmdstr); free(cmdstr); } return; } if ( (cmdstr= parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 ) { retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : SUPERNET.PLUGINTIMEOUT); printf("CONSOLE (%s) -> (%s) -> (%s)\n",line,cmdstr,retstr); free(cmdstr); } }
void process_userinput(char *_line) { static char *line,*line2; 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); expand_aliases(line,line2,65536,_line); if ( (line= localcommand(line)) == 0 ) return; if ( line[0] == '!' ) broadcastflag = 1, line++; if ( (json= cJSON_Parse(line)) != 0 ) { char *process_nn_message(int32_t sock,char *jsonstr); free_json(json); retstr = process_nn_message(-1,line); //retstr = nn_loadbalanced((uint8_t *)line,(int32_t)strlen(line)+1); printf("console.(%s) -> (%s)\n",line,retstr); return; } settoken(ipaddr,line); printf("expands to: %s [%s] %s\n",broadcastflag != 0 ? "broadcast": "",line,ipaddr); if ( is_ipaddr(ipaddr) != 0 ) { line += strlen(ipaddr) + 1; if ( (cmdstr = parse_expandedline(plugin,method,&timeout,line,broadcastflag)) != 0 ) { printf("ipaddr.(%s) (%s)\n",ipaddr,line); //retstr = nn_direct(ipaddr,(uint8_t *)line,(int32_t)strlen(line)+1); printf("deprecated (%s) -> (%s)\n",line,cmdstr); free(cmdstr); } return; } if ( (cmdstr= parse_expandedline(plugin,method,&timeout,line,broadcastflag)) != 0 ) { retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : SUPERNET.PLUGINTIMEOUT); printf("CONSOLE (%s) -> (%s) -> (%s)\n",line,cmdstr,retstr); free(cmdstr); } }
void update_alias(char *line) { char retbuf[8192],alias[1024],*value; int32_t i,err; if ( (i= settoken(&alias[1],line)) < 0 ) return; if ( line[i] == 0 ) value = &line[i]; else value = &line[i+1]; line[i] = 0; alias[0] = '#'; printf("i.%d alias.(%s) value.(%s)\n",i,alias,value); if ( value[0] == 0 ) printf("warning value for %s is null\n",alias); kv777_findstr(retbuf,sizeof(retbuf),SUPERNET.alias,alias); if ( strcmp(retbuf,value) == 0 ) printf("UNCHANGED "); else printf("%s ",retbuf[0] == 0 ? "CREATE" : "UPDATE"); printf(" (%s) -> (%s)\n",alias,value); if ( (err= kv777_addstr(SUPERNET.alias,alias,value)) != 0 ) printf("error.%d updating alias database\n",err); }
char *expand_aliases(char *_expanded,char *_expanded2,int32_t max,char *line) { char alias[64],value[8192],*expanded,*otherbuf; int32_t i,j,k,len=0,flag = 1; expanded = _expanded, otherbuf = _expanded2; while ( len < max-8192 && flag != 0 ) { flag = 0; len = (int32_t)strlen(line); for (i=j=0; i<len; i++) { if ( line[i] == '#' ) { if ( (k= settoken(&alias[1],&line[i+1])) <= 0 ) continue; i += k; alias[0] = '#'; if ( kv777_findstr(value,sizeof(value),SUPERNET.alias,alias) != 0 ) { if ( value[0] != 0 ) for (k=0; value[k]!=0; k++) expanded[j++] = value[k]; expanded[j] = 0; //printf("found (%s) -> (%s) [%s]\n",alias,value,expanded); flag++; } } else expanded[j++] = line[i]; } expanded[j] = 0; line = expanded; if ( expanded == _expanded2 ) expanded = _expanded, otherbuf = _expanded2; else expanded = _expanded2, otherbuf = _expanded; } //printf("(%s) -> (%s) len.%d flag.%d\n",line,expanded,len,flag); return(line); }