annotate sip-in/call_list.c @ 123:a36b731bfef9

sip-manual-out: implement sending BYE and CANCEL
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Sep 2022 17:21:11 -0800
parents 6aa63cf4620a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement call list management for themwi-sip-in.
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
7 #include <sys/time.h>
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "call.h"
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct call *call_list;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct call *
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 find_call_by_sip_id(sought_id)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *sought_id;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 for (call = call_list; call; call = call->next)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (!strcmp(call->sip_call_id, sought_id))
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return 0;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
30
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
31 struct call *
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
32 find_call_by_mncc_callref(callref)
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
33 uint32_t callref;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
34 {
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
35 struct call *call;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
36
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
37 for (call = call_list; call; call = call->next)
63
e5aee661e3b2 sip-in: beginning to handle incoming MNCC messages from themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 62
diff changeset
38 if (call->mncc_state && call->mncc_callref == callref)
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
39 return call;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
40 return 0;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
41 }
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
42
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
43 allocate_mncc_callref(call)
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
44 struct call *call;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
45 {
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
46 static uint32_t next_callref;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
47
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
48 for (;;) {
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
49 next_callref++;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
50 if (!find_call_by_mncc_callref(next_callref)) {
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
51 call->mncc_callref = next_callref;
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
52 return(0);
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
53 }
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
54 }
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
55 }
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
56
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
57 void
112
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
58 scan_call_list_for_timeouts(retrans, dead_sip_flag, dead_sip_time)
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
59 int *retrans, *dead_sip_flag;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
60 time_t *dead_sip_time;
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
61 {
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
62 struct call *call;
112
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
63 int got_dead_sip = 0;
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
64
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
65 for (call = call_list; call; call = call->next) {
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
66 switch (call->sip_state) {
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 81
diff changeset
67 case SIP_STATE_RINGING_REL:
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
68 case SIP_STATE_INVITE_200:
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
69 case SIP_STATE_INVITE_ERR:
81
915f0f397fb6 sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
70 case SIP_STATE_BYE_SENT:
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
71 *retrans = 1;
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
72 break;
112
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
73 case SIP_STATE_ENDED:
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
74 case SIP_STATE_MSG_SIZE_ERR:
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
75 if (call->overall_state != OVERALL_STATE_DEAD_SIP)
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
76 continue;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
77 if (got_dead_sip) {
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
78 if (call->sip_clear_time < *dead_sip_time)
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
79 *dead_sip_time = call->sip_clear_time;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
80 } else {
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
81 got_dead_sip = 1;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
82 *dead_sip_flag = 1;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
83 *dead_sip_time = call->sip_clear_time;
6aa63cf4620a sip-in call clearing: select timeout implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
84 }
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
85 }
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
86 }
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
87 }