annotate mtctest/main.c @ 148:b51247739897

sip-manual-out: attempt to play along with re-INVITEs
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Oct 2022 23:52:08 -0800
parents a065b4a62a8a
children c8e9b295e88f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for ThemWi test MT call generator.
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/errno.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <syslog.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <unistd.h>
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int mtc_socket;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int disconnect_mode;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
37
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
16 static void
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
17 drain_stdin()
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
18 {
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
19 char buf[256];
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
20
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
21 read(0, buf, sizeof buf);
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
22 }
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
23
21
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 main(argc, argv)
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char **argv;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern int optind;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 extern char *optarg;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char *from;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fd_set fds;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int c;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 from = 0;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 while ((c = getopt(argc, argv, "f:")) != EOF) {
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (c) {
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case 'f':
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 from = optarg;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 continue;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 default:
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 usage:
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr,
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 "usage: %s [-f from-number] to-number\n",
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 argv[0]);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (argc != optind + 1)
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 goto usage;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 openlog("themwi-test-mtc", 0, LOG_LOCAL5);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 init_setup_msg(from, argv[optind]);
36
e8e82a4bf12b themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents: 21
diff changeset
51 obtain_dummy_rtp();
21
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 connect_mtc_socket();
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 send_setup_msg();
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 /* main select loop */
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 for (;;) {
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 FD_ZERO(&fds);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 FD_SET(mtc_socket, &fds);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!disconnect_mode)
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 FD_SET(0, &fds);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 c = select(mtc_socket+1, &fds, 0, 0, 0);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (c < 0) {
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (errno == EINTR)
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 continue;
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 perror("select");
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(1);
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (FD_ISSET(mtc_socket, &fds))
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 mtc_socket_select();
37
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
69 if (!disconnect_mode && FD_ISSET(0, &fds)) {
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
70 drain_stdin();
21
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 send_disconnect_req();
37
a065b4a62a8a themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents: 36
diff changeset
72 }
21
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
cc0e1c6e33c3 themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }