annotate sip-out/uac_resp.c @ 156:0bacca1f2f7b

sip-out: handle all INVITE responses, except errors
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 07:13:55 -0800
parents 2730ccb44549
children c0a391f28e91
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
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
23 void
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
24 process_sip_response(msg, sin)
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
25 struct sip_pkt_rx *msg;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
26 struct sockaddr_in *sin;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
28 struct sip_resp_ident rid;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
32 rc = sip_resp_extract_ident(msg, &rid);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
33 if (rc < 0) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
34 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
35 msg->status_code, rid.error_field);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
36 return;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
37 }
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
38 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
39 if (!call) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
40 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
41 msg->status_code);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
44 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
45 handle_invite_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
46 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
47 handle_cancel_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
48 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
49 handle_bye_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
50 else
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
51 syslog(LOG_ERR,
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
52 "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
53 msg->status_code, rid.cseq_num, rid.cseq_method);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }