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