FreeCalypso > hg > themwi-system-sw
annotate sip-in/invite.c @ 76:21276f045026
sip-in: validate To header prior to tag addition
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 16:40:07 -0800 |
parents | 5beb51de1bae |
children | fe39404092d9 |
rev | line source |
---|---|
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement our handling of SIP INVITE method. |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <netinet/in.h> |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
8 #include <arpa/inet.h> |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
10 #include <stdint.h> |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <syslog.h> |
66
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
15 #include "../include/gsm48_const.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../libsip/parse.h" |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/uas_basic.h" |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
18 #include "../libsip/grok_from.h" |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
19 #include "../libsip/req_supp.h" |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
20 #include "../libsip/sdp.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "../libsip/out_msg.h" |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
22 #include "call.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
24 extern struct in_addr sip_bind_ip; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
25 extern unsigned sip_bind_port; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
26 extern int cfg_use_100rel; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
27 extern struct call *call_list; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
28 |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
29 extern struct call *find_call_by_sip_id(); |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
30 extern char *get_single_header(); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
31 |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
32 fill_invite_resp_from_call(msg, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
33 struct sip_msg_out *msg; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
34 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
35 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
36 char cseq_str[32]; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
37 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
38 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
39 rc = out_msg_add_header(msg, "From", call->invite_from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
40 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
41 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
42 rc = out_msg_add_header(msg, "To", call->invite_to); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
43 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
44 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
45 rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
46 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
47 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
48 sprintf(cseq_str, "%u INVITE", call->invite_cseq); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
49 rc = out_msg_add_header(msg, "CSeq", cseq_str); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
50 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
51 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
52 return out_msg_add_header(msg, "Via", call->invite_via); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
53 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
54 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
55 fill_invite_200_resp(msg, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
56 struct sip_msg_out *msg; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
57 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
58 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
59 char contact_str[80]; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
60 struct sdp_gen sdp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
61 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
62 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
63 start_response_out_msg(msg, "200 CONNECT"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
64 rc = fill_invite_resp_from_call(msg, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
65 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
66 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
67 sprintf(contact_str, "<sip:%s:%u;transport=udp>", |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
68 inet_ntoa(sip_bind_ip), sip_bind_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
69 rc = out_msg_add_header(msg, "Contact", contact_str); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
70 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
71 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
72 rc = out_msg_add_header(msg, "Content-Type", "application/sdp"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
73 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
74 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
75 bzero(&sdp, sizeof sdp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
76 sdp.conn_ip = call->pstn_rtp_local.sin_addr; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
77 sdp.conn_port = ntohs(call->pstn_rtp_local.sin_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
78 sdp.codec_mask = call->use_pcma ? SDP_CODEC_MASK_PCMA |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
79 : SDP_CODEC_MASK_PCMU; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
80 sdp.session_id = (sdp.conn_port << 16) | call->sdp_addend; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
81 sdp.owner_ip = sip_bind_ip; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
82 return out_msg_finish_sdp(msg, &sdp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
83 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
84 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
85 static void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
86 invite_new_call(req, ess, sin) |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 struct sip_pkt_rx *req; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 struct uas_parse_hdrs *ess; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 struct sockaddr_in *sin; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 char uri_user[13], *called_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 struct sip_msg_out resp; |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
93 struct grok_from gfrom; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
94 struct supported_ext supp_ext; |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
95 char *hval, *unsup_ext; |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
96 int ext_100rel_req, ext_100rel_sup, use_100rel, use_pcma; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
97 struct sdp_parse sdp_parse; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
98 struct sdp_gen sdp_gen; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
99 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
100 char *dp; |
76
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
101 unsigned req_uri_len, to_hdr_len, copylen; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 int rc; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 /* extract called number from Request-URI */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 rc = user_from_sip_uri(req->req_uri, uri_user, 12); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (rc < 0) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 not_nanp: start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 "416 Request-URI is not a NANP number"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 if (rc < 0) { |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
111 error_resp_toolong: syslog(LOG_ERR, |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
112 "INVITE early error response length exceeded"); |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 return; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 out_msg_finish(&resp); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 sip_tx_packet(&resp, sin); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
117 return; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 if (uri_user[0] == '+') { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if (grok_number_string(uri_user+1, 0) != 11 || |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 uri_user[1] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 called_nanp = uri_user + 2; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } else switch (grok_number_string(uri_user)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 case 10: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 called_nanp = uri_user; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 case 11: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 if (uri_user[0] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 called_nanp = uri_user + 1; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 default: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (!is_nanp_valid_prefix(called_nanp)) |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 /* it is valid NANP - but is it one of ours? */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 refresh_number_db(); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (!is_nanp_locally_owned(called_nanp)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 "404 Called number does not belong here"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 goto error_resp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 } |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
145 /* parse and validate From header */ |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
146 rc = grok_from_header(ess->from, &gfrom); |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
147 if (rc < 0) { |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
148 start_response_out_msg(&resp, "400 Malformed From header"); |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
149 goto error_resp; |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
150 } |
76
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
151 /* validate To header for the purpose of tag addition */ |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
152 req_uri_len = strlen(req->req_uri); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
153 to_hdr_len = strlen(ess->to); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
154 if (to_hdr_len == req_uri_len) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
155 if (strcasecmp(ess->to, req->req_uri)) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
156 bad_to_header: start_response_out_msg(&resp, "400 Bad To header"); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
157 goto error_resp; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
158 } |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
159 } else if (to_hdr_len == req_uri_len + 2) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
160 if (ess->to[0] != '<') |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
161 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
162 if (strncasecmp(ess->to+1, req->req_uri, req_uri_len)) |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
163 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
164 if (ess->to[req_uri_len+1] != '>') |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
165 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
166 } else |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
167 goto bad_to_header; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
168 /* check 100rel and catch any unsupported requirements */ |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
169 supp_ext.name = "100rel"; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
170 supp_ext.req_flag = &ext_100rel_req; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
171 supp_ext.sup_flag = &ext_100rel_sup; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
172 ext_100rel_req = ext_100rel_sup = 0; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
173 rc = parse_require_supported(req, &supp_ext, 1, &unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
174 if (rc < 0) { |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
175 start_response_out_msg(&resp, "420 Extension not supported"); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
176 rc = out_msg_add_header(&resp, "Unsupported", unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
177 if (rc < 0) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
178 goto error_resp_toolong; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
179 goto error_resp; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
180 } |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
181 if (ext_100rel_req) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
182 use_100rel = 1; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
183 else if (ext_100rel_sup) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
184 use_100rel = cfg_use_100rel; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
185 else |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
186 use_100rel = 0; |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
187 /* did the caller send an SDP message body? */ |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
188 if (!req->msg_body_len) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
189 start_response_out_msg(&resp, "415 Missing SDP body"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
190 error_415: rc = out_msg_add_header(&resp, "Accept", "application/sdp"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
191 if (rc < 0) |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
192 goto error_resp_toolong; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
193 goto error_resp; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
194 } |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
195 hval = get_single_header(req, "Content-Type", "c", (int *) 0); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
196 if (!hval) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
197 start_response_out_msg(&resp, |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
198 "415 Missing Content-Type header"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
199 goto error_415; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
200 } |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
201 if (strcasecmp(hval, "application/sdp")) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
202 start_response_out_msg(&resp, "415 Unsupported Content-Type"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
203 goto error_415; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
204 } |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
205 rc = parse_incoming_sdp(req->msg_body, req->msg_body_len, &sdp_parse); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
206 if (rc < 0) { |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
207 start_response_out_msg(&resp, "488 Malformed SDP body"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
208 goto error_resp; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
209 } |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
210 switch (sdp_parse.codec_mask) { |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
211 case SDP_CODEC_MASK_PCMU: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
212 case SDP_CODEC_MASK_BOTH: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
213 use_pcma = 0; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
214 break; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
215 case SDP_CODEC_MASK_PCMA: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
216 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
217 use_pcma = 1; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
218 break; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
219 default: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
220 start_response_out_msg(&resp, |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
221 "488 Unsupported codec selection"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
222 rc = add_resp_basic_headers(&resp, ess, req->req_method); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
223 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
224 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
225 rc = out_msg_add_header(&resp, "Content-Type", |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
226 "application/sdp"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
227 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
228 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
229 bzero(&sdp_gen, sizeof sdp_gen); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
230 sdp_gen.owner_ip = sip_bind_ip; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
231 sdp_gen.conn_ip = sip_bind_ip; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
232 sdp_gen.codec_mask = SDP_CODEC_MASK_BOTH; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
233 rc = out_msg_finish_sdp(&resp, &sdp_gen); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
234 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
235 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
236 sip_tx_packet(&resp, sin); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
237 return; |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
238 } |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
239 /* SIP INVITE validation done - check if GSM service is up */ |
57
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
240 rc = connect_gsm_mtcall(); |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
241 if (rc < 0) { |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
242 start_response_out_msg(&resp, "480 GSM service is offline"); |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
243 goto error_resp; |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
244 } |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
245 /* stateful processing begins */ |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
246 call = malloc(sizeof(struct call) + strlen(ess->call_id) + |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
247 strlen(ess->from) + strlen(ess->to) + strlen(ess->via) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
248 + 4); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
249 if (!call) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
250 syslog(LOG_CRIT, "failed malloc for incoming call!"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
251 start_response_out_msg(&resp, |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
252 "503 Gateway resource allocation failure"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
253 goto error_resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
254 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
255 bzero(call, sizeof(struct call)); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
256 dp = (char *)(call + 1); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
257 copylen = strlen(ess->call_id) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
258 call->sip_call_id = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
259 bcopy(ess->call_id, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
260 dp += copylen; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
261 copylen = strlen(ess->from) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
262 call->invite_from = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
263 bcopy(ess->from, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
264 dp += copylen; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
265 copylen = strlen(ess->to) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
266 call->invite_to = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
267 bcopy(ess->to, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
268 dp += copylen; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
269 copylen = strlen(ess->via) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
270 call->invite_via = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
271 bcopy(ess->via, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
272 call->invite_cseq = ess->cseq_num; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
273 bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in)); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
274 bcopy(called_nanp, call->called_nanp, 11); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
275 call->from_uri = call->invite_from + (gfrom.uri - ess->from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
276 call->from_uri_len = gfrom.uri_len; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
277 call->from_user = call->invite_from + (gfrom.user - ess->from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
278 call->from_user_len = gfrom.user_len; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
279 call->use_100rel = use_100rel; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
280 call->pstn_rtp_remote.sin_family = AF_INET; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
281 call->pstn_rtp_remote.sin_addr = sdp_parse.ip_addr; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
282 call->pstn_rtp_remote.sin_port = htons(sdp_parse.audio_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
283 call->use_pcma = use_pcma; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
284 /* generate 100 response */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
285 start_response_out_msg(&resp, "100 Proceeding"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
286 rc = fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
287 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
288 syslog(LOG_ERR, "INVITE 100 response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
289 free(call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
290 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
291 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
292 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
293 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
294 /* add to call list */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
295 call->next = call_list; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
296 call_list = call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
297 /* send CRCX to TMGW */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
298 tmgw_send_crcx(call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
299 call->overall_state = OVERALL_STATE_CRCX; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
300 call->sip_state = SIP_STATE_INVITE_PROC; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 } |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
302 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
303 static void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
304 invite_existing_call(req, ess, sin, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
305 struct sip_pkt_rx *req; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
306 struct uas_parse_hdrs *ess; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
307 struct sockaddr_in *sin; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
308 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
309 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
310 struct sip_msg_out resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
311 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
312 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
313 if (ess->cseq_num != call->invite_cseq) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
314 start_response_out_msg(&resp, "501 Re-INVITE not supported"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
315 rc = add_resp_basic_headers(&resp, ess, req->req_method); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
316 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
317 syslog(LOG_ERR, |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
318 "sending 501 Re-INVITE error: response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
319 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
320 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
321 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
322 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
323 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
324 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
325 /* it's a retransmission, not a re-INVITE */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
326 switch (call->sip_state) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
327 case SIP_STATE_INVITE_PROC: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
328 start_response_out_msg(&resp, "100 Proceeding"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
329 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
330 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
331 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
332 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
333 case SIP_STATE_RINGING: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
334 case SIP_STATE_RINGING_PRACK: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
335 start_response_out_msg(&resp, "180 Ringing"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
336 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
337 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
338 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
339 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
340 case SIP_STATE_INVITE_200: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
341 case SIP_STATE_CONNECTED: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
342 fill_invite_200_resp(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
343 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
344 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
345 case SIP_STATE_INVITE_ERR: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
346 start_response_out_msg(&resp, call->invite_fail); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
347 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
348 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
349 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
350 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
351 default: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
352 /* silently discard */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
353 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
354 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
355 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
356 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
357 void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
358 handle_sip_invite(req, ess, sin) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
359 struct sip_pkt_rx *req; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
360 struct uas_parse_hdrs *ess; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
361 struct sockaddr_in *sin; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
362 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
363 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
364 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
365 call = find_call_by_sip_id(ess->call_id); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
366 if (call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
367 invite_existing_call(req, ess, sin, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
368 else |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
369 invite_new_call(req, ess, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
370 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
371 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
372 void |
65
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
373 signal_invite_ringing(call) |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
374 struct call *call; |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
375 { |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
376 struct sip_msg_out resp; |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
377 |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
378 start_response_out_msg(&resp, "180 Ringing"); |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
379 fill_invite_resp_from_call(&resp, call); |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
380 out_msg_finish(&resp); |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
381 sip_tx_packet(&resp, &call->udp_sin); |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
382 call->sip_state = SIP_STATE_RINGING; |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
383 } |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
384 |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
385 void |
66
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
386 signal_invite_200(call) |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
387 struct call *call; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
388 { |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
389 struct sip_msg_out resp; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
390 int rc; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
391 |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
392 rc = fill_invite_200_resp(&resp, call); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
393 if (rc < 0) { |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
394 syslog(LOG_ERR, "INVITE 200 response length exceeded"); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
395 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
396 call->overall_state = OVERALL_STATE_TEARDOWN; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
397 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
398 GSM48_CC_CAUSE_INTERWORKING); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
399 disconnect_tmgw(call); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
400 /* TODO: transition from TEARDOWN to DEAD_SIP */ |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
401 return; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
402 } |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
403 sip_tx_packet(&resp, &call->udp_sin); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
404 call->sip_state = SIP_STATE_INVITE_200; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
405 call->sip_tx_count = 1; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
406 } |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
407 |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
408 void |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
409 signal_invite_error(call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
410 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
411 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
412 struct sip_msg_out resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
413 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
414 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
415 start_response_out_msg(&resp, call->invite_fail); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
416 rc = fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
417 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
418 syslog(LOG_ERR, "INVITE late error response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
419 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
420 /* TODO: transition from TEARDOWN to DEAD_SIP */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
421 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
422 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
423 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
424 sip_tx_packet(&resp, &call->udp_sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
425 call->sip_state = SIP_STATE_INVITE_ERR; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
426 call->sip_tx_count = 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
427 } |