annotate sip-out/uac_resp.c @ 161:c0a391f28e91

sip-out: handle responses to UAC BYE
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 13:38:40 -0800
parents 0bacca1f2f7b
children 83022d408071
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
161
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
23 extern unsigned sip_linger_bye_out_ok;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
24 extern unsigned sip_linger_bye_out_err;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
25
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
26 void
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
27 handle_bye_response(call, msg, sin)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
28 struct call *call;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
29 struct sip_pkt_rx *msg;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
30 struct sockaddr_in *sin;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
31 {
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
32 if (msg->status_code != 200)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
33 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
34 msg->status_str);
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
35 if (msg->status_code < 200)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
36 return;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
37 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
38 call->sip_state = SIP_STATE_ENDED;
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
39 if (msg->status_code <= 299)
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
40 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
41 else
c0a391f28e91 sip-out: handle responses to UAC BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
42 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
43 }
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
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
46 void
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
47 process_sip_response(msg, sin)
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
48 struct sip_pkt_rx *msg;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
49 struct sockaddr_in *sin;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
51 struct sip_resp_ident rid;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
55 rc = sip_resp_extract_ident(msg, &rid);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
56 if (rc < 0) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
57 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
58 msg->status_code, rid.error_field);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
59 return;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
60 }
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
61 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
62 if (!call) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
63 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
64 msg->status_code);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
67 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
68 handle_invite_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
69 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
70 handle_cancel_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
71 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
72 handle_bye_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
73 else
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
74 syslog(LOG_ERR,
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
75 "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
76 msg->status_code, rid.cseq_num, rid.cseq_method);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }