comparison sip-in/main.c @ 47:62f39c7cee15

themwi-sip-in skeleton started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 20:33:56 -0800
parents
children 7005d5c535e8
comparison
equal deleted inserted replaced
46:5427b26525cd 47:62f39c7cee15
1 /*
2 * Main module for themwi-sip-in.
3 */
4
5 #include <sys/types.h>
6 #include <sys/time.h>
7 #include <sys/errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <signal.h>
13 #include <syslog.h>
14 #include <unistd.h>
15
16 extern int mgw_socket, sip_socket;
17
18 static int max_fd;
19
20 struct timeval cur_event_time;
21
22 update_max_fd(newfd)
23 {
24 if (newfd > max_fd)
25 max_fd = newfd;
26 }
27
28 main(argc, argv)
29 char **argv;
30 {
31 fd_set fds;
32 int rc;
33
34 openlog("themwi-sip-in", 0, LOG_LOCAL5);
35 read_config_file();
36 if (read_number_db() < 0) {
37 fprintf(stderr, "error reading number database\n");
38 exit(1);
39 }
40 if (open_tmgw_socket() < 0) {
41 fprintf(stderr, "error connecting to themwi-mgw socket\n");
42 exit(1);
43 }
44 if (open_sip_udp_socket() < 0) {
45 fprintf(stderr, "error opening SIP UDP socket\n");
46 exit(1);
47 }
48 if (argv[1]) {
49 rc = open_sip_log_file(argv[1]);
50 if (rc < 0)
51 exit(1); /* error msg already printed */
52 }
53 signal(SIGPIPE, SIG_IGN);
54 /* main select loop */
55 for (;;) {
56 FD_ZERO(&fds);
57 FD_SET(mgw_socket, &fds);
58 FD_SET(sip_socket, &fds);
59 rc = select(max_fd+1, &fds, 0, 0, 0);
60 if (rc < 0) {
61 if (errno == EINTR)
62 continue;
63 syslog(LOG_CRIT, "select: %m");
64 exit(1);
65 }
66 gettimeofday(&cur_event_time, 0);
67 if (FD_ISSET(mgw_socket, &fds))
68 mgw_socket_select();
69 if (FD_ISSET(sip_socket, &fds))
70 sip_socket_select();
71 }
72 }