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 determine the process to kill!\n",
61 /* add listening port + stdin to (read) event system */
62 event_math(ivac.net.l_fd,&(ivac.event),READ,ADD);
63 event_math(0,&(ivac.event),READ,ADD);
66 ivac_display(&(ivac));
68 /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
69 event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
76 int ivac_shutdown(t_ivac *ivac) {
78 network_shutdown(&(ivac->net));
79 input_shutdown(&(ivac->input));
80 event_stop(&(ivac->event));
85 int ivac_send_info(int channel,t_ivac *ivac) {
87 char data[SEND_N_MAX];
90 size=strlen(ivac->username);
92 data[0]=IVAC_SEND_NAME;
94 strncpy(data+2,ivac->username,size);
97 data[size]=IVAC_SEND_G_CAP;
99 data[size+2]=ivac->g_cap;
102 data[size]=IVAC_SEND_AV_CAP;
104 data[size+2]=(ivac->av_cap)>>8;
105 data[size+3]=(ivac->av_cap)&0xff;
108 if(network_send(ivac->net.connection[channel].fd,data,size)==N_ERROR) {
109 puts("[ivac] ivac_send_info failed");
116 int ivac_receive_info(int channel,t_ivac *ivac) {
118 char data[SEND_N_MAX];
123 if((length=network_receive(ivac->net.connection[channel].fd,
124 data,SEND_N_MAX))==N_ERROR) {
125 puts("[ivac] ivac_receive_info failed");
129 while(length-count) {
130 switch(data[count]) {
132 strncpy(ivac->challenger[channel].name,data+count+2,data[count+1]);
133 ivac->challenger[channel].name[data[count+1]]='\0';
134 count+=(data[count+1]+2);
136 case IVAC_SEND_G_CAP:
137 ivac->challenger[channel].g_cap=data[count+2];
140 case IVAC_SEND_AV_CAP:
141 ivac->challenger[channel].av_cap=data[count+2]<<8;
142 ivac->challenger[channel].av_cap|=data[count+3];
146 puts("[ivac] ivac_receive_info, unknown character");
155 int ivac_event_cb(t_event *event,void *ptr) {
162 if(FD_ISSET(ivac->net.l_fd,&(event->rfds))) {
163 /* manage incoming + send info */
164 channel=network_manage_incoming(&(ivac->net));
165 event_math(ivac->net.connection[channel].fd,event,READ,ADD);
166 ivac_send_info(channel,ivac);
170 for(channel=0;channel<MAX_CONNECTIONS;channel++)
171 if(ivac->net.connection[channel].status&C_ESTABL)
172 if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds)))
173 ivac_receive_info(channel,ivac);
175 /* user interaction */
176 if(FD_ISSET(0,&(event->rfds)))
177 input_get_event(&(ivac->input),ivac_parse_command,ivac);
179 /* display ivac gui */
185 int ivac_regular_cb(t_event *event,void *ptr) {
187 /* usual jobs like audio & video transmit ... */
192 int ivac_parse_command(t_input *input,void *ptr) {
199 /* parse command routines */
201 if(input->content[input->c_count-1]=='\n') {
202 /* delete content buffer + reset counter */
203 memset(input->content,0,input->c_count);
210 int ivac_display_head(void) {
215 for(column=0;column<COLUMN;column++) printf("#");
219 for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
221 for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
224 for(column=0;column<COLUMN;column++) printf("#");
230 int ivac_display_prompt(t_ivac *ivac) {
234 for(column=0;column<COLUMN;column++) printf("#");
236 printf("## command: ");
237 for(column=12;column<12+ivac->input.c_count;column++)
238 printf("%c",ivac->input.content[column-12]);
239 for(column=12+ivac->input.c_count;column<COLUMN-2;column++) printf(" ");
242 for(column=0;column<COLUMN;column++) printf("#");
247 int ivac_display(t_ivac *ivac) {
254 /* build content of middle part + display */
255 for(line=3;line<LINE-3;line++) {
257 for(column=1;column<COLUMN-1;column++) printf(" ");
261 /* display command prompt */
262 ivac_display_prompt(ivac);