annotate sip-out/reinvite.c @ 243:59a166c50d0e

themwi-mncc: convert to libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 19:13:26 -0800
parents 9419fe55824f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
148
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
2 * Here we handle incoming INVITE requests in the UAS role: even though
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
3 * we are strictly outbound, BulkVS servers will send us periodic
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
4 * re-INVITEs as keepalives, and we have to play along.
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/socket.h>
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
9 #include <sys/time.h>
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <netinet/in.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
12 #include <stdint.h>
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
16 #include <syslog.h>
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
17 #include "../include/out_routes.h"
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../libsip/parse.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "../libsip/uas_basic.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "../libsip/out_msg.h"
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
21 #include "call.h"
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
23 extern struct call *find_call_by_sip_id();
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
24
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static void
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
26 invite_found_call(req, ess, sin, call)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct sip_pkt_rx *req;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct uas_parse_hdrs *ess;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct sockaddr_in *sin;
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
30 struct call *call;
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
32 struct sip_msg_out resp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
33 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
34
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
35 switch (call->sip_state) {
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
36 case SIP_STATE_INV_SENT:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
37 case SIP_STATE_100_RCVD:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
38 start_response_out_msg(&resp, "491 Outbound INVITE pending");
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
39 break;
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
40 case SIP_STATE_CONNECTED:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
41 start_response_out_msg(&resp, "200 OK");
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
42 break;
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
43 case SIP_STATE_CANCEL_SENT:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
44 case SIP_STATE_BYE_SENT:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
45 case SIP_STATE_ACCEPT_100:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
46 case SIP_STATE_ACCEPT_200:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
47 case SIP_STATE_ENDED:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
48 start_response_out_msg(&resp, "488 Call terminated");
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
49 break;
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
50 case SIP_STATE_MSG_SIZE_ERR:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
51 return;
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
52 default:
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
53 syslog(LOG_CRIT,
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
54 "FATAL: invalid SIP state 0x%x on incoming re-INVITE",
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
55 call->sip_state);
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
56 exit(1);
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
57 }
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
58 rc = add_resp_basic_headers(&resp, ess, req->req_method);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
59 if (rc < 0) {
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
60 syslog(LOG_ERR, "Re-INVITE response message size error");
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
61 return;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
62 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
63 out_msg_finish(&resp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
64 sip_tx_packet(&resp, sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
65 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
66
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
67 static void
148
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
68 invite_unknown_call(req, ess, sin)
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
69 struct sip_pkt_rx *req;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
70 struct uas_parse_hdrs *ess;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
71 struct sockaddr_in *sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
72 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
73 struct sip_msg_out resp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
74 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
75
148
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
76 start_response_out_msg(&resp, "405 This gateway is outbound only");
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
77 rc = add_resp_basic_headers(&resp, ess, req->req_method);
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
78 if (rc < 0)
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
79 return;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
80 out_msg_finish(&resp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
81 sip_tx_packet(&resp, sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
82 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
83
147
94b5831c017f sip-manual-out code: split bye_in.c from uas.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
84 void
148
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
85 handle_invite_req(req, ess, sin)
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
86 struct sip_pkt_rx *req;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
87 struct uas_parse_hdrs *ess;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
88 struct sockaddr_in *sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
89 {
165
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
90 struct call *call;
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
91
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
92 call = find_call_by_sip_id(ess->call_id);
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
93 if (call)
9419fe55824f themwi-sip-out complete to the point of compiling and linking
Mychaela Falconia <falcon@freecalypso.org>
parents: 148
diff changeset
94 invite_found_call(req, ess, sin, call);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
95 else
148
b51247739897 sip-manual-out: attempt to play along with re-INVITEs
Mychaela Falconia <falcon@freecalypso.org>
parents: 147
diff changeset
96 invite_unknown_call(req, ess, sin);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }