X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fivac.git;a=blobdiff_plain;f=src%2Fivac.c;h=8b8acbc50923ad9b58fd6340546a838479455c72;hp=82b9a7c7c56b9c3364a9d1c108e610bfb0189c34;hb=2fb65b9beceb0945b593e28332507aa1b7c3fd90;hpb=da2c28e700faec39bab322b103fe0298c52fbda7 diff --git a/src/ivac.c b/src/ivac.c index 82b9a7c..8b8acbc 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -21,6 +21,8 @@ * */ +// #define DISPLAY + #include "ivac.h" int main(int argc,char **argv) { @@ -28,10 +30,12 @@ int main(int argc,char **argv) { /* TESTING BY NOW */ t_ivac ivac; + int i; /* set username (futur: read from config or entered later) */ strcpy(ivac.username,"hackbard"); - memset(&ivac.console[0][0],0,IVAC_CONSOLE_LEN*IVAC_CONSOLE_STRING_LEN); + for(i=0;inet)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); +#ifdef DISPLAY display_shutdown(&(ivac->display)); +#endif return SUCCESS; } @@ -182,7 +190,9 @@ int ivac_event_cb(t_event *event,void *ptr) { input_get_event(&(ivac->input),ivac_parse_command,ivac); /* display ivac gui */ +#ifdef DISPLAY ivac_display_content(ivac); +#endif return SUCCESS; } @@ -197,46 +207,143 @@ int ivac_regular_cb(t_event *event,void *ptr) { int ivac_parse_command(t_input *input,void *ptr) { t_ivac *ivac; - int channel,i; + int i,j,k; int len; - char *data,valid=0; + int channel; + char *data,valid; char c_str[IVAC_CONSOLE_STRING_LEN]; + char arg[IVAC_ARG_COUNT][IVAC_ARG_LEN]; ivac=(t_ivac *)ptr; data=input->content; - i=input->c_count-1; - memset(c_str,0,IVAC_CONSOLE_STRING_LEN); + valid=0; + + printf("%c",data[input->c_count-1]); + fflush(NULL); /* parse command routines */ - if((data[i]=='\r') || (data[i]=='\n')) { - - /* parse commands */ - switch(data[0]) { - case '/': - len=strlen(data+1); - if(len==4) { - /* len 4 commands */ - if(!strncmp(data+1,"quit",4)) { - valid=1; - sprintf(c_str,"ivac shutdown\n"); - ivac_add_to_monitor(ivac,c_str); - ivac_shutdown(ivac); + if(data[input->c_count-1]=='\n') { + + /* delete console string + args */ + memset(c_str,0,IVAC_CONSOLE_STRING_LEN); + for(j=0;j='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); + else channel=-1; + if(!(strncmp(arg[1],"name",4))) { + strncpy(ivac->username,arg[2],CHAR_USERNAME); + sprintf(c_str,"changed username to %s",ivac->username); + } + else if((channel>=0)&&(channelnet.connection[channel].status&C_IN_USE) { + sprintf(c_str,"channel %02d: connection in use",channel); + } + else { + strncpy(ivac->net.connection[channel].ip,arg[2],IP_DIGITS); + ivac->net.connection[channel].port=atoi(arg[3]); + sprintf(c_str,"channel %02d: set connection info",channel); + ivac->net.connection[channel].status|=C_INFO_A; + } + } else snprintf(c_str,IVAC_CONSOLE_STRING_LEN,"unknown argument: '%s'", + arg[1]); + } + if(!(strncmp(arg[0],"connect",7))) { + valid=1; + if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); + else channel=-1; + if((channel>=0)&&(channelnet.connection[channel].status&C_INFO_A) + sprintf(c_str,"channel %02d: channel not configured",channel); + else { + if(ivac->net.connection[channel].status&C_IN_USE) + sprintf(c_str,"channel %02d: connection in use",channel); + else { + sprintf(c_str,"channel %02d: trying to connect to %s:%d",channel, + ivac->net.connection[channel].ip, + ivac->net.connection[channel].port); } } - break; - default: - break; + } + else sprintf(c_str,"invalid argument: '%s'",arg[1]); + } + if(!(strncmp(arg[0],"close",5))) { + valid=1; + if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); + else channel=-1; + if((channel>=0)&&(channelnet.connection[channel].status&C_ESTABL) + sprintf(c_str,"channel %02d: no active connection",channel); + else { + ivac->net.connection[channel].status|=C_HANGUP; + sprintf(c_str,"channel %02d: connection closed",channel); + } + } + else sprintf(c_str,"invalid argument: '%s'",arg[1]); } - - if(!valid) { - snprintf(c_str,IVAC_CONSOLE_STRING_LEN-1,"unknown command: '%s...'\n", - data); - ivac_add_to_monitor(ivac,c_str); + if(!(strncmp(arg[0],"select",6))) { + valid=1; + if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); + else channel=-1; + if((channel>=0)&&(channelnet.sendmask|=(1<net.sendmask=0xff; + strcpy(c_str,"selected all channels"); + } + else sprintf(c_str,"invalid argument: '%s'",arg[1]); } + if(!(strncmp(arg[0],"deselect",8))) { + valid=1; + if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); + else channel=-1; + if((channel>=0)&&(channelnet.sendmask&=(~(1<net.sendmask=0; + strcpy(c_str,"deselected all channels"); + } + else sprintf(c_str,"invalid argument: '%s'",arg[1]); + } + + if(!valid) + snprintf(c_str,IVAC_CONSOLE_STRING_LEN,"unknown command: '%s'",arg[0]); + + ivac_add_to_monitor(ivac,c_str); + /* delete content buffer + reset counter */ - memset(input->content,0,input->c_count); + memset(input->content,0,input->c_count-1); input->c_count=0; } @@ -290,11 +397,16 @@ int ivac_display_console(t_display *display) { int ivac_display_console_content(t_ivac *ivac) { - int x,y,len; + int x,y; + int len; + for(y=0;yconsole[y]); move(ivac->display.max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN+y,2); - for(x=0;xconsole[y][x]); + for(x=0;xconsole[y][x]>' ')||(ivac->console[y][x]<='~')) + ?ivac->console[y][x]:' '); + for(x=len;xconsole[i],ivac->console[i+1],IVAC_CONSOLE_STRING_LEN); memcpy(ivac->console[IVAC_CONSOLE_LEN-1],msg,IVAC_CONSOLE_STRING_LEN); + + for(i=0;iconsole[i]); +#ifdef DISPLAY ivac_display_console_content(ivac); +#endif return SUCCESS; }