comparison sip-out/bye_in.c @ 163:bfa9f0c0f0ac

sip-out: handle incoming BYE as UAS
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 14:45:31 -0800
parents sip-manual-out/bye_in.c@94b5831c017f
children
comparison
equal deleted inserted replaced
162:83022d408071 163:bfa9f0c0f0ac
1 /*
2 * Here we handle incoming BYE requests in the UAS role.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <sys/time.h>
8 #include <netinet/in.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 "../include/gsm48_const.h"
16 #include "../include/out_routes.h"
17 #include "../libsip/parse.h"
18 #include "../libsip/uas_basic.h"
19 #include "../libsip/out_msg.h"
20 #include "call.h"
21
22 extern struct call *find_call_by_sip_id();
23
24 extern unsigned sip_linger_gotbye;
25 extern unsigned sip_linger_response_err;
26
27 static void
28 bye_found_call(req, ess, sin, call)
29 struct sip_pkt_rx *req;
30 struct uas_parse_hdrs *ess;
31 struct sockaddr_in *sin;
32 struct call *call;
33 {
34 struct sip_msg_out resp;
35 int rc;
36
37 switch (call->sip_state) {
38 case SIP_STATE_INV_SENT:
39 case SIP_STATE_100_RCVD:
40 case SIP_STATE_CONNECTED:
41 call->overall_state = OVERALL_STATE_TEARDOWN;
42 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
43 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
44 disconnect_tmgw(call);
45 call->sip_state = SIP_STATE_ENDED;
46 sip_mark_end_time(call, sip_linger_gotbye);
47 break;
48 case SIP_STATE_CANCEL_SENT:
49 case SIP_STATE_BYE_SENT:
50 call->sip_state = SIP_STATE_ENDED;
51 sip_mark_end_time(call, sip_linger_gotbye);
52 break;
53 case SIP_STATE_ACCEPT_100:
54 case SIP_STATE_ACCEPT_200:
55 case SIP_STATE_ENDED:
56 break;
57 case SIP_STATE_MSG_SIZE_ERR:
58 return;
59 default:
60 syslog(LOG_CRIT,
61 "FATAL: invalid SIP state 0x%x on incoming BYE",
62 call->sip_state);
63 exit(1);
64 }
65 /* send 200 response to BYE */
66 start_response_out_msg(&resp, "200 OK");
67 rc = add_resp_basic_headers(&resp, ess, req->req_method);
68 if (rc < 0) {
69 syslog(LOG_ERR, "msg size error responding to BYE");
70 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
71 sip_mark_end_time(call, sip_linger_response_err);
72 return;
73 }
74 out_msg_finish(&resp);
75 sip_tx_packet(&resp, sin);
76 }
77
78 static void
79 bye_unknown_call(req, ess, sin)
80 struct sip_pkt_rx *req;
81 struct uas_parse_hdrs *ess;
82 struct sockaddr_in *sin;
83 {
84 struct sip_msg_out resp;
85 int rc;
86
87 start_response_out_msg(&resp, "481 Call-ID not found");
88 rc = add_resp_basic_headers(&resp, ess, req->req_method);
89 if (rc < 0)
90 return;
91 out_msg_finish(&resp);
92 sip_tx_packet(&resp, sin);
93 }
94
95 void
96 handle_bye_req(req, ess, sin)
97 struct sip_pkt_rx *req;
98 struct uas_parse_hdrs *ess;
99 struct sockaddr_in *sin;
100 {
101 struct call *call;
102
103 call = find_call_by_sip_id(ess->call_id);
104 if (call)
105 bye_found_call(req, ess, sin, call);
106 else
107 bye_unknown_call(req, ess, sin);
108 }