annotate mncc/main.c @ 147:94b5831c017f

sip-manual-out code: split bye_in.c from uas.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Oct 2022 23:01:32 -0800
parents ccc5ab6d8388
children 2ebad02adbe5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for ThemWi MNCC daemon.
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/errno.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <signal.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "struct.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int mncc_socket;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int mtcall_listener;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct socket_conn *mtcall_socket_head;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static int max_fd;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 update_max_fd(newfd)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (newfd > max_fd)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 max_fd = newfd;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 main(argc, argv)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char **argv;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fd_set fds;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 struct socket_conn *conn, **connp;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 int c;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 openlog("themwi-mncc", 0, LOG_LOCAL5);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (read_number_db() < 0) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fprintf(stderr, "error reading number database\n");
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (open_mncc_socket() < 0) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr, "error connecting to GSM MNCC socket\n");
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (create_mtcall_socket() < 0) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr, "error creating MT call socket\n");
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 signal(SIGPIPE, SIG_IGN);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 /* main select loop */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 for (;;) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 FD_ZERO(&fds);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 FD_SET(mncc_socket, &fds);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 FD_SET(mtcall_listener, &fds);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 for (connp = &mtcall_socket_head; conn = *connp; ) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (conn->fd < 0) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *connp = conn->next;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 free(conn);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 continue;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 FD_SET(conn->fd, &fds);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 connp = &conn->next;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 c = select(max_fd+1, &fds, 0, 0, 0);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (c < 0) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (errno == EINTR)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 continue;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 syslog(LOG_CRIT, "select: %m");
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 exit(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (FD_ISSET(mncc_socket, &fds))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 mncc_socket_select();
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (FD_ISSET(mtcall_listener, &fds))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 mtsock_accept_handler();
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 for (conn = mtcall_socket_head; conn; conn = conn->next)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (FD_ISSET(conn->fd, &fds))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 extsock_read_select(conn);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 gc_call_list();
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }