FreeCalypso > hg > themwi-system-sw
comparison sip-in/cancel.c @ 79:b0df2b200d77
sip-in: implement SIP CANCEL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 18:58:11 -0800 |
parents | |
children | 0d6435808bcd |
comparison
equal
deleted
inserted
replaced
78:72b7d85d6354 | 79:b0df2b200d77 |
---|---|
1 /* | |
2 * Here we implement our handling of SIP CANCEL method. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/socket.h> | |
7 #include <netinet/in.h> | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <strings.h> | |
13 #include <syslog.h> | |
14 #include "../include/gsm48_const.h" | |
15 #include "../libsip/parse.h" | |
16 #include "../libsip/uas_basic.h" | |
17 #include "../libsip/out_msg.h" | |
18 #include "call.h" | |
19 | |
20 extern struct call *find_call_by_sip_id(); | |
21 | |
22 static void | |
23 cancel_200_response(req, ess, sin, call) | |
24 struct sip_pkt_rx *req; | |
25 struct uas_parse_hdrs *ess; | |
26 struct sockaddr_in *sin; | |
27 struct call *call; | |
28 { | |
29 struct sip_msg_out resp; | |
30 char cseq_str[32]; | |
31 int rc; | |
32 | |
33 start_response_out_msg(&resp, "200 OK"); | |
34 rc = out_msg_add_header(&resp, "From", call->invite_from); | |
35 if (rc < 0) { | |
36 msg_size_err: syslog(LOG_ERR, "CANCEL 200 response length exceeded"); | |
37 return; | |
38 } | |
39 rc = out_msg_add_header(&resp, "To", call->invite_to); | |
40 if (rc < 0) | |
41 goto msg_size_err; | |
42 rc = out_msg_add_header(&resp, "Call-ID", call->sip_call_id); | |
43 if (rc < 0) | |
44 goto msg_size_err; | |
45 sprintf(cseq_str, "%u CANCEL", call->invite_cseq); | |
46 rc = out_msg_add_header(&resp, "CSeq", cseq_str); | |
47 if (rc < 0) | |
48 goto msg_size_err; | |
49 rc = out_msg_add_header(&resp, "Via", ess->via); | |
50 if (rc < 0) | |
51 goto msg_size_err; | |
52 out_msg_finish(&resp); | |
53 sip_tx_packet(&resp, sin); | |
54 } | |
55 | |
56 static void | |
57 cancel_481_response(req, ess, sin) | |
58 struct sip_pkt_rx *req; | |
59 struct uas_parse_hdrs *ess; | |
60 struct sockaddr_in *sin; | |
61 { | |
62 struct sip_msg_out resp; | |
63 int rc; | |
64 | |
65 start_response_out_msg(&resp, "481 Call-ID/CSeq not found"); | |
66 rc = add_resp_basic_headers(&resp, ess, req->req_method); | |
67 if (rc < 0) | |
68 return; | |
69 out_msg_finish(&resp); | |
70 sip_tx_packet(&resp, sin); | |
71 } | |
72 | |
73 void | |
74 handle_sip_cancel(req, ess, sin) | |
75 struct sip_pkt_rx *req; | |
76 struct uas_parse_hdrs *ess; | |
77 struct sockaddr_in *sin; | |
78 { | |
79 struct call *call; | |
80 | |
81 call = find_call_by_sip_id(ess->call_id); | |
82 if (!call) { | |
83 cancel_481_response(req, ess, sin); | |
84 return; | |
85 } | |
86 /* weed out wrong CSeq */ | |
87 if (ess->cseq_num != call->invite_cseq) { | |
88 cancel_481_response(req, ess, sin); | |
89 return; | |
90 } | |
91 /* it is for us - act on it */ | |
92 switch (call->sip_state) { | |
93 case SIP_STATE_INVITE_PROC: | |
94 case SIP_STATE_RINGING: | |
95 case SIP_STATE_RINGING_PRACK: | |
96 call->overall_state = OVERALL_STATE_TEARDOWN; | |
97 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND, | |
98 GSM48_CC_CAUSE_NORM_CALL_CLEAR); | |
99 disconnect_tmgw(call); | |
100 strcpy(call->invite_fail, "487 Call attempt terminated"); | |
101 signal_invite_error(call); | |
102 break; | |
103 case SIP_STATE_MSG_SIZE_ERR: | |
104 return; | |
105 } | |
106 cancel_200_response(req, ess, sin, call); | |
107 } |