annotate sip-out/uac_resp.c @ 198:cf1ba5d65188

mgw: start using project-global rtp_defs.h
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 29 Mar 2023 20:06:40 -0800
parents 83022d408071
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
2 * In this module we implement our handling of SIP responses in the UAC role.
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/time.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/gsm48_const.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/out_routes.h"
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
17 #include "../libsip/parse.h"
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
18 #include "../libsip/resp_ident.h"
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "call.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern struct call *find_call_by_sip_id();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
162
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
23 extern unsigned sip_linger_timeout;
161
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
24 extern unsigned sip_linger_bye_out_ok;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
25 extern unsigned sip_linger_bye_out_err;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
26
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
27 void
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
28 handle_bye_response(call, msg, sin)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
29 struct call *call;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
30 struct sip_pkt_rx *msg;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
31 struct sockaddr_in *sin;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
32 {
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
33 if (msg->status_code != 200)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
34 syslog(LOG_ERR, "non-200 response to BYE: %.64s",
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
35 msg->status_str);
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
36 if (msg->status_code < 200)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
37 return;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
38 if (call->sip_state == SIP_STATE_BYE_SENT) {
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
39 call->sip_state = SIP_STATE_ENDED;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
40 if (msg->status_code <= 299)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
41 sip_mark_end_time(call, sip_linger_bye_out_ok);
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
42 else
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
43 sip_mark_end_time(call, sip_linger_bye_out_err);
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
44 }
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
45 }
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
46
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
47 void
162
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
48 handle_cancel_response(call, msg, sin)
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
49 struct call *call;
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
50 struct sip_pkt_rx *msg;
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
51 struct sockaddr_in *sin;
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
52 {
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
53 if (msg->status_code != 200)
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
54 syslog(LOG_ERR, "non-200 response to CANCEL: %.64s",
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
55 msg->status_str);
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
56 if (msg->status_code < 200)
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
57 return;
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
58 if (call->sip_state == SIP_STATE_CANCEL_SENT) {
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
59 call->sip_state = SIP_STATE_ACCEPT_200;
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
60 if (msg->status_code <= 299)
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
61 sip_mark_end_time(call, sip_linger_timeout);
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
62 else
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
63 sip_mark_end_time(call, sip_linger_bye_out_err);
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
64 }
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
65 }
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
66
83022d408071 sip-out: handle responses to UAC CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 161
diff changeset
67 void
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
68 process_sip_response(msg, sin)
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
69 struct sip_pkt_rx *msg;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
70 struct sockaddr_in *sin;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
72 struct sip_resp_ident rid;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
76 rc = sip_resp_extract_ident(msg, &rid);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
77 if (rc < 0) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
78 syslog(LOG_ERR, "SIP %03u response: bad or missing %s header",
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
79 msg->status_code, rid.error_field);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
80 return;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
81 }
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
82 call = find_call_by_sip_id(rid.call_id);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
83 if (!call) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
84 syslog(LOG_ERR, "SIP %03u response: unmatched Call-ID",
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
85 msg->status_code);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
88 if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "INVITE"))
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
89 handle_invite_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
90 else if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "CANCEL"))
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
91 handle_cancel_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
92 else if (rid.cseq_num == 2 && !strcmp(rid.cseq_method, "BYE"))
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
93 handle_bye_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
94 else
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
95 syslog(LOG_ERR,
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
96 "UAC received %03u response with unknown CSeq %u %.32s",
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
97 msg->status_code, rid.cseq_num, rid.cseq_method);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }