FreeCalypso > hg > themwi-system-sw
annotate sip-in/bye_out.c @ 108:0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Sep 2022 14:29:10 -0800 |
parents | 2c22b40408fb |
children | 9b87894704eb |
rev | line source |
---|---|
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement our UAC functionality of sending BYE. |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <netinet/in.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <arpa/inet.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <syslog.h> |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "../libsip/parse.h" |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
16 #include "../libsip/resp_ident.h" |
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/out_msg.h" |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "call.h" |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
20 extern struct call *find_call_by_sip_id(); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
21 |
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern struct in_addr sip_bind_ip; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern unsigned sip_bind_port; |
92
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
24 extern unsigned max_forwards; |
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fill_bye_out_msg(msg, call) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct sip_msg_out *msg; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct call *call; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 char strbuf[80]; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 int rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 rc = start_request_out_msg_urilen(msg, "BYE", call->from_uri, |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 call->from_uri_len); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 sprintf(strbuf, "SIP/2.0/UDP %s:%u", |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 inet_ntoa(sip_bind_ip), sip_bind_port); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 rc = out_msg_add_header(msg, "Via", strbuf); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = out_msg_add_header(msg, "From", call->invite_to); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 rc = out_msg_add_header(msg, "To", call->invite_from); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 rc = out_msg_add_header(msg, "CSeq", "1 BYE"); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return rc; |
92
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
54 sprintf(strbuf, "%u", max_forwards); |
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
55 rc = out_msg_add_header(msg, "Max-Forwards", strbuf); |
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 out_msg_finish(msg); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return 0; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 void |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 initiate_bye(call) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 struct call *call; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 struct sip_msg_out msg; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 int rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 rc = fill_bye_out_msg(&msg, call); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (rc < 0) { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 syslog(LOG_ERR, "outgoing BYE request msg length exceeded"); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 /* TODO: transition from TEARDOWN to DEAD_SIP */ |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 return; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 sip_tx_packet(&msg, &call->udp_sin); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 call->sip_state = SIP_STATE_BYE_SENT; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 call->sip_tx_count = 1; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
80 |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
81 void |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
82 process_sip_response(msg, sin) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
83 struct sip_pkt_rx *msg; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
84 struct sockaddr_in *sin; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
85 { |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
86 struct sip_resp_ident rid; |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
87 struct call *call; |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
88 int rc; |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
89 |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
90 rc = sip_resp_extract_ident(msg, &rid); |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
91 if (rc < 0) { |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
92 syslog(LOG_ERR, "SIP %03u response: bad or missing %s header", |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
93 msg->status_code, rid.error_field); |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
94 return; |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
95 } |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
96 call = find_call_by_sip_id(rid.call_id); |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
97 if (!call) { |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
98 syslog(LOG_ERR, "SIP %03u response: unmatched Call-ID", |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
99 msg->status_code); |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
100 return; |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
101 } |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
102 if (rid.cseq_num != 1 || strcmp(rid.cseq_method, "BYE")) { |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
103 syslog(LOG_ERR, |
94
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
104 "UAC received %03u response with unknown CSeq %u %.32s", |
2c22b40408fb
sip-in BYE UAC: use new libsip function for response ident
Mychaela Falconia <falcon@freecalypso.org>
parents:
92
diff
changeset
|
105 msg->status_code, rid.cseq_num, rid.cseq_method); |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
106 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
107 } |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
108 if (msg->status_code < 200) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
109 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
110 if (call->sip_state == SIP_STATE_BYE_SENT) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
111 call->sip_state = SIP_STATE_ENDED; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
112 } |