comparison 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
comparison
equal deleted inserted replaced
80:a9944b66dcc5 81:915f0f397fb6
1 /*
2 * In this module we implement our UAC functionality of sending BYE.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <syslog.h>
15 #include "../libsip/parse.h"
16 #include "../libsip/out_msg.h"
17 #include "call.h"
18
19 extern struct in_addr sip_bind_ip;
20 extern unsigned sip_bind_port;
21
22 fill_bye_out_msg(msg, call)
23 struct sip_msg_out *msg;
24 struct call *call;
25 {
26 char strbuf[80];
27 int rc;
28
29 rc = start_request_out_msg_urilen(msg, "BYE", call->from_uri,
30 call->from_uri_len);
31 if (rc < 0)
32 return rc;
33 sprintf(strbuf, "SIP/2.0/UDP %s:%u",
34 inet_ntoa(sip_bind_ip), sip_bind_port);
35 rc = out_msg_add_header(msg, "Via", strbuf);
36 if (rc < 0)
37 return rc;
38 rc = out_msg_add_header(msg, "From", call->invite_to);
39 if (rc < 0)
40 return rc;
41 rc = out_msg_add_header(msg, "To", call->invite_from);
42 if (rc < 0)
43 return rc;
44 rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id);
45 if (rc < 0)
46 return rc;
47 rc = out_msg_add_header(msg, "CSeq", "1 BYE");
48 if (rc < 0)
49 return rc;
50 rc = out_msg_add_header(msg, "Max-Forwards", "70");
51 if (rc < 0)
52 return rc;
53 out_msg_finish(msg);
54 return 0;
55 }
56
57 void
58 initiate_bye(call)
59 struct call *call;
60 {
61 struct sip_msg_out msg;
62 int rc;
63
64 rc = fill_bye_out_msg(&msg, call);
65 if (rc < 0) {
66 syslog(LOG_ERR, "outgoing BYE request msg length exceeded");
67 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
68 /* TODO: transition from TEARDOWN to DEAD_SIP */
69 return;
70 }
71 sip_tx_packet(&msg, &call->udp_sin);
72 call->sip_state = SIP_STATE_BYE_SENT;
73 call->sip_tx_count = 1;
74 }