annotate sip-in/bye_out.c @ 81:915f0f397fb6

sip-in: beginning of outgoing BYE support
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 20:11:44 -0800
parents
children ff4b76a107a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct in_addr sip_bind_ip;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern unsigned sip_bind_port;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 fill_bye_out_msg(msg, call)
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct sip_msg_out *msg;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct call *call;
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 char strbuf[80];
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int rc;
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 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
30 call->from_uri_len);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc < 0)
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return rc;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 sprintf(strbuf, "SIP/2.0/UDP %s:%u",
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 inet_ntoa(sip_bind_ip), sip_bind_port);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 rc = out_msg_add_header(msg, "Via", strbuf);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (rc < 0)
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return rc;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 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
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, "To", call->invite_from);
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, "Call-ID", call->sip_call_id);
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, "CSeq", "1 BYE");
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, "Max-Forwards", "70");
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 out_msg_finish(msg);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return 0;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 void
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 initiate_bye(call)
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 struct call *call;
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 struct sip_msg_out msg;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 int rc;
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 rc = fill_bye_out_msg(&msg, call);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (rc < 0) {
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 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
67 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 /* TODO: transition from TEARDOWN to DEAD_SIP */
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 sip_tx_packet(&msg, &call->udp_sin);
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 call->sip_state = SIP_STATE_BYE_SENT;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 call->sip_tx_count = 1;
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }