annotate sip-in/sip_ack.c @ 83:3e3fbf44f9d7

sip-in: disconnect and call clearing implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 22:06:37 -0800
parents 8cf85edca543
children 9e9034ef476c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement our handling of SIP ACK, the last step
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in the 3-way INVITE handshake.
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../libsip/parse.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/uas_basic.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "call.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct call *find_call_by_sip_id();
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 handle_sip_ack(req, ess, sin)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct sip_pkt_rx *req;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct uas_parse_hdrs *ess;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct sockaddr_in *sin;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct call *call;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 call = find_call_by_sip_id(ess->call_id);
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (!call)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return; /* ignore spurious ACK */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 /* weed out wrong CSeq */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (ess->cseq_num != call->invite_cseq)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (call->sip_state) {
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case SIP_STATE_INVITE_200:
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
37 switch (call->overall_state) {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
38 case OVERALL_STATE_ANSWERED:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
39 call->sip_state = SIP_STATE_CONNECTED;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
40 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
41 case OVERALL_STATE_TEARDOWN:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
42 initiate_bye(call);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
43 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
44 default:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
45 syslog(LOG_CRIT,
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
46 "FATAL: invalid overall state 0x%x on SIP ACK",
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
47 call->overall_state);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
48 exit(1);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
49 }
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 break;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case SIP_STATE_INVITE_ERR:
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 call->sip_state = SIP_STATE_ENDED;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }