annotate sip-out/uac_resp.c @ 155:2730ccb44549

sip-out: initial UAC response handling
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2022 23:30:00 -0800
parents sip-out/uac_out.c@e54b0a9e322f
children 0bacca1f2f7b
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"
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
19 #include "../libsip/sdp.h"
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "../libsip/out_msg.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "call.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern struct call *find_call_by_sip_id();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
25 void
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
26 process_sip_response(msg, sin)
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
27 struct sip_pkt_rx *msg;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
28 struct sockaddr_in *sin;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
30 struct sip_resp_ident rid;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
34 rc = sip_resp_extract_ident(msg, &rid);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
35 if (rc < 0) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
36 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
37 msg->status_code, rid.error_field);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
38 return;
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
39 }
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
40 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
41 if (!call) {
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
42 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
43 msg->status_code);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
155
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
46 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
47 handle_invite_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 == 1 && !strcmp(rid.cseq_method, "CANCEL"))
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
49 handle_cancel_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
50 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
51 handle_bye_response(call, msg, sin);
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
52 else
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
53 syslog(LOG_ERR,
2730ccb44549 sip-out: initial UAC response handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 154
diff changeset
54 "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
55 msg->status_code, rid.cseq_num, rid.cseq_method);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }