FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/main.c @ 113:bfc97065bf51
sip-in: syslog beginning and clearing of calls
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Sep 2022 19:08:13 -0800 |
parents | 51e2f72dc5ab |
children | 056616f7e8ab |
rev | line source |
---|---|
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This is the main module for sip-manual-out test program. |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/time.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/errno.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <netinet/in.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <arpa/inet.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <unistd.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../libsip/out_msg.h" |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/sdp.h" |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern int sip_socket; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern struct in_addr sip_bind_ip, sip_dest_ip; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern unsigned sip_bind_port, sip_dest_port; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern char sip_dest_domain[]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern struct sockaddr_in dummy_rtp_endp; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 struct sockaddr_in sip_dest_sin; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 char from_uri[128], to_uri[128], call_id[128]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct timeval cur_event_time; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 send_invite_req() |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 struct sip_msg_out msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct sdp_gen sdp; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rc = start_request_out_msg(&msg, "INVITE", to_uri); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (rc < 0) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rc = add_req_boilerplate(&msg, "1 INVITE"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 goto msg_size_err; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 rc = add_contact_header(&msg); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 goto msg_size_err; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 goto msg_size_err; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 bzero(&sdp, sizeof sdp); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 sdp.conn_ip = dummy_rtp_endp.sin_addr; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 sdp.conn_port = ntohs(dummy_rtp_endp.sin_port); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 sdp.codec_mask = SDP_CODEC_MASK_BOTH; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 sdp.session_id = sdp.conn_port << 16; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 sdp.owner_ip = sip_bind_ip; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 rc = out_msg_finish_sdp(&msg, &sdp); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 goto msg_size_err; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 sip_tx_packet(&msg, &sip_dest_sin); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 main(argc, argv) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 char **argv; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 fd_set fds; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 int rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (argc < 4 || argc > 5) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 "usage: %s dest-conf from-num to-num [logfile]\n", |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 argv[0]); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 exit(1); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 read_config_file(argv[1]); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 open_sip_udp_socket(); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 obtain_dummy_rtp(); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 sip_dest_sin.sin_family = AF_INET; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 sip_dest_sin.sin_addr = sip_dest_ip; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 sip_dest_sin.sin_port = htons(sip_dest_port); |
74
51e2f72dc5ab
sip-manual-out: generate From tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
79 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[2], |
51e2f72dc5ab
sip-manual-out: generate From tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
80 inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port)); |
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 sprintf(to_uri, "sip:%s@%s", argv[3], sip_dest_domain); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (argv[4]) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 rc = open_sip_log_file(argv[4]); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(1); /* error msg already printed */ |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 gettimeofday(&cur_event_time, 0); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 sprintf(call_id, "%08u_%u@%s", |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 (unsigned)(cur_event_time.tv_sec % 100000000), |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 send_invite_req(); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 /* main select loop */ |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 for (;;) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 FD_ZERO(&fds); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 FD_SET(sip_socket, &fds); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 rc = select(sip_socket+1, &fds, 0, 0, 0); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 if (rc < 0) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (errno == EINTR) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 continue; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 perror("select"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 exit(1); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 gettimeofday(&cur_event_time, 0); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (FD_ISSET(sip_socket, &fds)) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 sip_socket_select(); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |