FreeCalypso > hg > themwi-system-sw
annotate sip-in/bye_out.c @ 84:f82157ac7303
sip-in: handle MNCC_RTP_CREATE
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 22:44:44 -0800 |
parents | ff4b76a107a1 |
children | a9137bdb6047 |
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; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 fill_bye_out_msg(msg, call) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct sip_msg_out *msg; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 struct call *call; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 char strbuf[80]; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 int rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 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
|
33 call->from_uri_len); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 sprintf(strbuf, "SIP/2.0/UDP %s:%u", |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 inet_ntoa(sip_bind_ip), sip_bind_port); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 rc = out_msg_add_header(msg, "Via", strbuf); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 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
|
42 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 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
|
45 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 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
|
48 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 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
|
51 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 rc = out_msg_add_header(msg, "Max-Forwards", "70"); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (rc < 0) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 out_msg_finish(msg); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return 0; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 void |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 initiate_bye(call) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 struct call *call; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 struct sip_msg_out msg; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 int rc; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 rc = fill_bye_out_msg(&msg, call); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (rc < 0) { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 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
|
70 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /* TODO: transition from TEARDOWN to DEAD_SIP */ |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 sip_tx_packet(&msg, &call->udp_sin); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 call->sip_state = SIP_STATE_BYE_SENT; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 call->sip_tx_count = 1; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
82
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
78 |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
79 void |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
80 process_sip_response(msg, sin) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
81 struct sip_pkt_rx *msg; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
82 struct sockaddr_in *sin; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
83 { |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
84 char *call_id_hdr, *cseq_hdr; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
85 struct call *call; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
86 |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
87 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
|
88 if (!call_id_hdr) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
89 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
90 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
|
91 if (!call) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
92 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
93 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
|
94 if (!cseq_hdr) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
95 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
96 if (strcmp(cseq_hdr, "1 BYE")) { |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
97 syslog(LOG_ERR, |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
98 "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
|
99 cseq_hdr); |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
100 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
101 } |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
102 if (msg->status_code < 200) |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
103 return; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
104 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
|
105 call->sip_state = SIP_STATE_ENDED; |
ff4b76a107a1
sip-in: process responses as UAC for BYE
Mychaela Falconia <falcon@freecalypso.org>
parents:
81
diff
changeset
|
106 } |