FreeCalypso > hg > themwi-system-sw
annotate sip-in/bye_out.c @ 93:ff5e96162430
libsip: new function for extracting Call-ID and CSeq from responses
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 24 Sep 2022 15:13:53 -0800 |
parents | a9137bdb6047 |
children | 2c22b40408fb |
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" |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../libsip/out_msg.h" |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "call.h" |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
19 extern char *get_single_header(); |
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 { |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
86 char *call_id_hdr, *cseq_hdr; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
87 struct call *call; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
88 |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
89 call_id_hdr = get_single_header(msg, "Call-ID", "i", (int *) 0); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
90 if (!call_id_hdr) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
91 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
92 call = find_call_by_sip_id(call_id_hdr); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
93 if (!call) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
94 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
95 cseq_hdr = get_single_header(msg, "CSeq", (char *) 0, (int *) 0); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
96 if (!cseq_hdr) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
97 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
98 if (strcmp(cseq_hdr, "1 BYE")) { |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
99 syslog(LOG_ERR, |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
100 "UAC received response with unknown CSeq %.32s", |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
101 cseq_hdr); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
102 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
103 } |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
104 if (msg->status_code < 200) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
105 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
106 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
|
107 call->sip_state = SIP_STATE_ENDED; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
108 } |