annotate sip-out/bye_in.c @ 231:abb3f415b9dd

themwi-update-numdb2: check secondary numbers
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 11:45:41 -0800
parents bfa9f0c0f0ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
147
94b5831c017f sip-manual-out code: split bye_in.c from uas.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
2 * Here we handle incoming BYE requests in the UAS role.
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
7 #include <sys/time.h>
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
10 #include <stdint.h>
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
14 #include <syslog.h>
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
15 #include "../include/gsm48_const.h"
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
16 #include "../include/out_routes.h"
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/parse.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../libsip/uas_basic.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "../libsip/out_msg.h"
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
20 #include "call.h"
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
22 extern struct call *find_call_by_sip_id();
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
23
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
24 extern unsigned sip_linger_gotbye;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
25 extern unsigned sip_linger_response_err;
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
26
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static void
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
28 bye_found_call(req, ess, sin, call)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct sip_pkt_rx *req;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct uas_parse_hdrs *ess;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct sockaddr_in *sin;
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
32 struct call *call;
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
34 struct sip_msg_out resp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
35 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
36
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
37 switch (call->sip_state) {
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
38 case SIP_STATE_INV_SENT:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
39 case SIP_STATE_100_RCVD:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
40 case SIP_STATE_CONNECTED:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
41 call->overall_state = OVERALL_STATE_TEARDOWN;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
42 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
43 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
44 disconnect_tmgw(call);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
45 call->sip_state = SIP_STATE_ENDED;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
46 sip_mark_end_time(call, sip_linger_gotbye);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
47 break;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
48 case SIP_STATE_CANCEL_SENT:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
49 case SIP_STATE_BYE_SENT:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
50 call->sip_state = SIP_STATE_ENDED;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
51 sip_mark_end_time(call, sip_linger_gotbye);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
52 break;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
53 case SIP_STATE_ACCEPT_100:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
54 case SIP_STATE_ACCEPT_200:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
55 case SIP_STATE_ENDED:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
56 break;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
57 case SIP_STATE_MSG_SIZE_ERR:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
58 return;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
59 default:
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
60 syslog(LOG_CRIT,
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
61 "FATAL: invalid SIP state 0x%x on incoming BYE",
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
62 call->sip_state);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
63 exit(1);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
64 }
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
65 /* send 200 response to BYE */
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
66 start_response_out_msg(&resp, "200 OK");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
67 rc = add_resp_basic_headers(&resp, ess, req->req_method);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
68 if (rc < 0) {
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
69 syslog(LOG_ERR, "msg size error responding to BYE");
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
70 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
71 sip_mark_end_time(call, sip_linger_response_err);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
72 return;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
73 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
74 out_msg_finish(&resp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
75 sip_tx_packet(&resp, sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
76 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
77
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
78 static void
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
79 bye_unknown_call(req, ess, sin)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
80 struct sip_pkt_rx *req;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
81 struct uas_parse_hdrs *ess;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
82 struct sockaddr_in *sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
83 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
84 struct sip_msg_out resp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
85 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
86
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
87 start_response_out_msg(&resp, "481 Call-ID not found");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
88 rc = add_resp_basic_headers(&resp, ess, req->req_method);
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
89 if (rc < 0)
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
90 return;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
91 out_msg_finish(&resp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
92 sip_tx_packet(&resp, sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
93 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
94
147
94b5831c017f sip-manual-out code: split bye_in.c from uas.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
95 void
94b5831c017f sip-manual-out code: split bye_in.c from uas.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
96 handle_bye_req(req, ess, sin)
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
97 struct sip_pkt_rx *req;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
98 struct uas_parse_hdrs *ess;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
99 struct sockaddr_in *sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
100 {
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
101 struct call *call;
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
102
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
103 call = find_call_by_sip_id(ess->call_id);
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
104 if (call)
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
105 bye_found_call(req, ess, sin, call);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
106 else
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
107 bye_unknown_call(req, ess, sin);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }