FreeCalypso > hg > themwi-system-sw
annotate sip-in/bye_in.c @ 116:3a1f0e13a3ac
sip-in call clearing: time comparison was reversed
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Sep 2022 23:05:38 -0800 |
parents | c1c94b7fc2e2 |
children |
rev | line source |
---|---|
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
2 * Here we implement our handling of incoming SIP BYE requests. |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
7 #include <sys/time.h> |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <netinet/in.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <syslog.h> |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "../include/gsm48_const.h" |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../libsip/parse.h" |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/uas_basic.h" |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "../libsip/out_msg.h" |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "call.h" |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern struct call *find_call_by_sip_id(); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
23 extern unsigned sip_linger_gotbye; |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
24 extern unsigned sip_linger_error; |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
25 |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 void |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
27 handle_sip_bye(req, ess, sin) |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct sip_pkt_rx *req; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct uas_parse_hdrs *ess; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 struct sockaddr_in *sin; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct call *call; |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
33 struct sip_msg_out resp; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
34 char cseq_str[32]; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
35 int rc; |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 call = find_call_by_sip_id(ess->call_id); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (!call) { |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
39 start_response_out_msg(&resp, "481 Call-ID not found"); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
40 rc = add_resp_basic_headers(&resp, ess, req->req_method); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
41 if (rc < 0) |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
42 return; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
43 out_msg_finish(&resp); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
44 sip_tx_packet(&resp, sin); |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 switch (call->sip_state) { |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 case SIP_STATE_INVITE_PROC: |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 case SIP_STATE_RINGING: |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
80
diff
changeset
|
50 case SIP_STATE_RINGING_REL: |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 call->overall_state = OVERALL_STATE_TEARDOWN; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND, |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 disconnect_tmgw(call); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 strcpy(call->invite_fail, "487 Call attempt terminated"); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 signal_invite_error(call); |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 break; |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
58 case SIP_STATE_INVITE_200: |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
59 case SIP_STATE_CONNECTED: |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
60 call->overall_state = OVERALL_STATE_TEARDOWN; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
61 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND, |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
62 GSM48_CC_CAUSE_NORM_CALL_CLEAR); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
63 disconnect_tmgw(call); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
64 call->sip_state = SIP_STATE_ENDED; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
65 sip_mark_end_time(call, sip_linger_gotbye); |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
66 break; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
67 case SIP_STATE_BYE_SENT: |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
68 call->sip_state = SIP_STATE_ENDED; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
69 sip_mark_end_time(call, sip_linger_gotbye); |
110
c1c94b7fc2e2
sip-in call clearing: DEAD_SIP transition implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
109
diff
changeset
|
70 transition_dead_sip(call); |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
71 break; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
72 case SIP_STATE_INVITE_ERR: |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
73 case SIP_STATE_ENDED: |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
74 break; |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 case SIP_STATE_MSG_SIZE_ERR: |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return; |
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
78 /* send 200 response to BYE */ |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
79 start_response_out_msg(&resp, "200 OK"); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
80 rc = out_msg_add_header(&resp, "From", call->invite_from); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
81 if (rc < 0) { |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
82 msg_size_err: syslog(LOG_ERR, "BYE 200 response length exceeded"); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
83 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
84 sip_mark_end_time(call, sip_linger_error); |
80
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
85 return; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
86 } |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
87 rc = out_msg_add_header(&resp, "To", call->invite_to); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
88 if (rc < 0) |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
89 goto msg_size_err; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
90 rc = out_msg_add_header(&resp, "Call-ID", call->sip_call_id); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
91 if (rc < 0) |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
92 goto msg_size_err; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
93 sprintf(cseq_str, "%u BYE", ess->cseq_num); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
94 rc = out_msg_add_header(&resp, "CSeq", cseq_str); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
95 if (rc < 0) |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
96 goto msg_size_err; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
97 rc = out_msg_add_header(&resp, "Via", ess->via); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
98 if (rc < 0) |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
99 goto msg_size_err; |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
100 out_msg_finish(&resp); |
a9944b66dcc5
sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
79
diff
changeset
|
101 sip_tx_packet(&resp, sin); |
79
b0df2b200d77
sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |