From: hackbard Date: Sun, 9 May 2004 16:25:21 +0000 (+0000) Subject: adapted to new network return codes, event/display bugfixes X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d03742fa15c23fa40b8e213cf948e5465508e07b;p=my-code%2Fivac.git adapted to new network return codes, event/display bugfixes --- diff --git a/src/ivac.c b/src/ivac.c index 23d59b1..ca12131 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -172,25 +172,34 @@ int ivac_event_cb(t_event *event,void *ptr) { t_ivac *ivac; int channel; + char c_str[IVAC_CONSOLE_STRING_LEN]; ivac=(t_ivac *)ptr; + /* incoming connection -- first contact => send info */ if(FD_ISSET(ivac->net.l_fd,&(event->rfds))) { - /* manage incoming + send info */ - if((channel=network_manage_incoming(&(ivac->net)))!=N_ERROR) { + channel=network_manage_incoming(&(ivac->net)); + if(channel==N_E_ACCEPT) + sprintf(c_str,"accept failed"); + else if(channel==N_E_MAXC) + sprintf(c_str,"maximum connections reached"); + else { + sprintf(c_str,"established connection from %s port %d on channel %d\n", + ivac->net.connection[channel].ip, + ivac->net.connection[channel].port,channel); + ivac_add_to_monitor(ivac,c_str); event_math(ivac->net.connection[channel].fd,event,READ,ADD); ivac_send_info(channel,ivac); } + ivac_display_content(ivac); } + /* wait for user info */ for(channel=0;channelnet.connection[channel].status&C_ESTABL) { - /* receive info */ + /* remote is sending info */ if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) ivac_receive_info(channel,ivac); - /* sync network/event api */ - if(!(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds_o)))) - event_math(ivac->net.connection[channel].fd,event,READ,ADD); } } @@ -198,9 +207,6 @@ int ivac_event_cb(t_event *event,void *ptr) { if(FD_ISSET(0,&(event->rfds))) input_get_event(&(ivac->input),ivac_parse_command,ivac); - /* display ivac gui */ - // ivac_display_content(ivac); - return SUCCESS; } @@ -267,15 +273,13 @@ int ivac_parse_command(t_input *input,void *ptr) { sprintf(c_str,"changed username to %s",ivac->username); } else if((channel>=0)&&(channelnet.connection[channel].status&C_IN_USE) { + i=network_set_connection_info(&(ivac->net),channel, + ivac->net.connection[channel].ip, + ivac->net.connection[channel].port); + if(i==N_E_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]); + if(i==N_SUCCESS) 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]); } @@ -284,17 +288,17 @@ int ivac_parse_command(t_input *input,void *ptr) { 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)) + i=network_connect(&(ivac->net),channel); + if(i==N_E_IN_USE) + sprintf(c_str,"channel %02d: connection in use",channel); + else if(i==N_E_NO_INFO) 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); - ivac->net.connection[channel].status|=C_IN_USE; - } + sprintf(c_str,"channel %02d: connected to %s:%d",channel, + ivac->net.connection[channel].ip, + ivac->net.connection[channel].port); + event_math(ivac->net.connection[channel].fd,&(ivac->event),READ,ADD); + ivac_send_info(channel,ivac); } } else sprintf(c_str,"invalid argument: '%s'",arg[1]); @@ -304,12 +308,11 @@ int ivac_parse_command(t_input *input,void *ptr) { 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)) + i=network_close(&(ivac->net),channel); + if(i==N_E_NC) sprintf(c_str,"channel %02d: no active connection",channel); - else { - ivac->net.connection[channel].status|=C_HANGUP; + else sprintf(c_str,"channel %02d: connection closed",channel); - } } else sprintf(c_str,"invalid argument: '%s'",arg[1]); } @@ -318,11 +321,11 @@ int ivac_parse_command(t_input *input,void *ptr) { if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); else channel=-1; if((channel>=0)&&(channelnet.sendmask|=(1<net),channel); sprintf(c_str,"selected channel %d",channel); } else if(arg[1][0]='*') { - ivac->net.sendmask=0xff; + network_select(&(ivac->net),MAX_CONNECTIONS); strcpy(c_str,"selected all channels"); } else sprintf(c_str,"invalid argument: '%s'",arg[1]); @@ -332,11 +335,11 @@ int ivac_parse_command(t_input *input,void *ptr) { if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); else channel=-1; if((channel>=0)&&(channelnet.sendmask&=(~(1<net),channel); sprintf(c_str,"deselected channel %d",channel); } else if(arg[1][0]='*') { - ivac->net.sendmask=0; + network_deselect(&(ivac->net),MAX_CONNECTIONS); strcpy(c_str,"deselected all channels"); } else sprintf(c_str,"invalid argument: '%s'",arg[1]);