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 event timeout */
36 ivac.event.timeout.tv_sec=IVAC_S_SEC;
37 ivac.event.timeout.tv_usec=IVAC_S_USEC;
39 /* set listen port (futur: read from config or entered later) */
40 network_set_listen_port(&(ivac.net),IVAC_LISTEN_PORT);
43 event_init(&(ivac.event));
46 input_init(&(ivac.input));
49 if(network_init(&(ivac.net))==N_ERROR) {
50 printf("[ivac] use 'fuser -n tcp %d' to kill that process",ivac.net.l_port);
54 /* add listening port + stdin to (read) event system */
55 event_math(ivac.net.l_fd,&(ivac.event),READ,ADD);
56 event_math(0,&(ivac.event),READ,ADD);
58 /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
59 event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
61 network_shutdown(&(ivac.net));
63 input_shutdown(&(ivac.input));
68 int ivac_event_cb(t_event *event,void *ptr) {
75 if(FD_ISSET(ivac->net.l_fd,&(event->rfds))) {
76 /* manage incoming + send info */
77 channel=network_manage_incoming(&(ivac->net));
78 event_math(ivac->net.connection[channel].fd,event,READ,ADD);
79 send_info(channel,&(ivac->net),ivac->username);
83 for(channel=0;channel<MAX_CONNECTIONS;channel++)
84 if(ivac->net.connection[channel].status&C_ESTABL)
85 if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds)))
86 receive_info(channel,&(ivac->net));
88 /* user interaction */
89 if(FD_ISSET(0,&(event->rfds)))
90 input_get_char(&(ivac->input),ivac_display,ivac);
95 int ivac_regular_cb(t_event *event,void *ptr) {
97 /* usual jobs like audio & video transmit ... */
102 int ivac_display(t_input *input,void *ptr) {
108 if(input->content[input->c_count-1]=='q') ivac->event.status=DISABLED;