annotate sip-in/cancel.c @ 240:c7a3ba56c636

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