1 /* ivac.c -- main ivac file
3 * author: hackbard@hackdaworld.dyndns.org
4 * frank.zirkelbach@physik.uni-augsburg.de
6 * Copyright (C) 2004 Frank Zirkelbach
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 int main(int argc,char **argv) {
32 /* set username (futur: read from config or entered later) */
33 strcpy(ivac.username,"hackbard");
35 /* set capabilities (futur: set by check routines) */
37 ivac.av_cap=AUDIO|VIDEO|DUPLEX;
39 /* set event timeout */
40 ivac.event.timeout.tv_sec=IVAC_S_SEC;
41 ivac.event.timeout.tv_usec=IVAC_S_USEC;
43 /* set listen port (futur: read from config or entered later) */
44 network_set_listen_port(&(ivac.net),IVAC_LISTEN_PORT);
47 event_init(&(ivac.event));
50 ivac.input.mode=CONTENT_BUFFER;
51 input_init(&(ivac.input));
54 if(network_init(&(ivac.net))==N_ERROR) {
55 printf("[ivac] use 'fuser -n tcp %d' to kill that process",ivac.net.l_port);
59 /* add listening port + stdin to (read) event system */
60 event_math(ivac.net.l_fd,&(ivac.event),READ,ADD);
61 event_math(0,&(ivac.event),READ,ADD);
64 ivac_display(&(ivac));
66 /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
67 event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
69 network_shutdown(&(ivac.net));
71 input_shutdown(&(ivac.input));
76 int ivac_send_info(int channel,t_ivac *ivac) {
78 char data[SEND_N_MAX];
81 size=strlen(ivac->username);
83 data[0]=IVAC_SEND_NAME;
85 strncpy(data+2,ivac->username,size);
88 data[size]=IVAC_SEND_G_CAP;
90 data[size+2]=ivac->g_cap;
93 data[size]=IVAC_SEND_AV_CAP;
95 data[size+2]=(ivac->av_cap)>>8;
96 data[size+3]=(ivac->av_cap)&0xff;
99 if(network_send(ivac->net.connection[channel].fd,data,size)==N_ERROR) {
100 puts("[ivac] ivac_send_info failed");
107 int ivac_receive_info(int channel,t_ivac *ivac) {
109 char data[SEND_N_MAX];
114 if((length=network_receive(ivac->net.connection[channel].fd,
115 data,SEND_N_MAX))==N_ERROR) {
116 puts("[ivac] ivac_receive_info failed");
120 while(length-count) {
121 switch(data[count]) {
123 strncpy(ivac->challenger[channel].name,data+count+2,data[count+1]);
124 ivac->challenger[channel].name[data[count+1]]='\0';
125 count+=(data[count+1]+2);
127 case IVAC_SEND_G_CAP:
128 ivac->challenger[channel].g_cap=data[count+2];
131 case IVAC_SEND_AV_CAP:
132 ivac->challenger[channel].av_cap=data[count+2]<<8;
133 ivac->challenger[channel].av_cap|=data[count+3];
137 puts("[ivac] ivac_receive_info, unknown character");
146 int ivac_event_cb(t_event *event,void *ptr) {
153 if(FD_ISSET(ivac->net.l_fd,&(event->rfds))) {
154 /* manage incoming + send info */
155 channel=network_manage_incoming(&(ivac->net));
156 event_math(ivac->net.connection[channel].fd,event,READ,ADD);
157 ivac_send_info(channel,ivac);
161 for(channel=0;channel<MAX_CONNECTIONS;channel++)
162 if(ivac->net.connection[channel].status&C_ESTABL)
163 if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds)))
164 ivac_receive_info(channel,ivac);
166 /* user interaction */
167 if(FD_ISSET(0,&(event->rfds)))
168 input_get_event(&(ivac->input),ivac_parse_command,ivac);
170 /* display ivac gui */
176 int ivac_regular_cb(t_event *event,void *ptr) {
178 /* usual jobs like audio & video transmit ... */
183 int ivac_parse_command(t_input *input,void *ptr) {
190 /* parse command routines */
192 if(input->content[input->c_count-1]=='\n') {
193 /* delete content buffer + reset counter */
194 memset(input->content,0,input->c_count);
201 int ivac_display_head(void) {
206 for(column=0;column<COLUMN;column++) printf("#");
210 for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
212 for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
215 for(column=0;column<COLUMN;column++) printf("#");
221 int ivac_display_prompt(t_ivac *ivac) {
225 for(column=0;column<COLUMN;column++) printf("#");
227 printf("## command: ");
228 for(column=12;column<12+ivac->input.c_count;column++)
229 printf("%c",ivac->input.content[column-12]);
230 for(column=12+ivac->input.c_count;column<COLUMN-2;column++) printf(" ");
233 for(column=0;column<COLUMN;column++) printf("#");
238 int ivac_display(t_ivac *ivac) {
245 /* build content of middle part + display */
246 for(line=3;line<LINE-3;line++) {
248 for(column=1;column<COLUMN-1;column++) printf(" ");
252 /* display command prompt */
253 ivac_display_prompt(ivac);