annotate sip-in/invite.c @ 114:a30c25fb4c2f

sip-in: generate CDR syslog entries
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 22:41:16 -0800
parents bfc97065bf51
children c93c339271a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
7 #include <sys/time.h>
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #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
9 #include <arpa/inet.h>
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
11 #include <stdint.h>
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #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
16 #include "../include/gsm48_const.h"
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/parse.h"
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../libsip/uas_basic.h"
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
19 #include "../libsip/grok_from.h"
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
20 #include "../libsip/req_supp.h"
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
21 #include "../libsip/sdp.h"
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #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
23 #include "call.h"
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
25 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
26 extern unsigned sip_bind_port;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
27 extern int cfg_use_100rel;
104
ce3b1db7d1d7 sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
28 extern int cfg_force_pcma;
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 *call_list;
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
30 extern unsigned sip_linger_error;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
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 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
33 extern char *get_single_header();
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
34
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
35 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
36 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
37 struct call *call;
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 char cseq_str[32];
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
40 int rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
41
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, "From", call->invite_from);
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, "To", call->invite_to);
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 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
49 if (rc < 0)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
50 return rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
51 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
52 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
53 if (rc < 0)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
54 return rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
55 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
56 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
57
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
58 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
59 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
60 struct call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
61 {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
62 char contact_str[80];
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
63 struct sdp_gen sdp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
64 int rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
65
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
66 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
67 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
68 if (rc < 0)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
69 return rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
70 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
71 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
72 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
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 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
76 if (rc < 0)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
77 return rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
78 bzero(&sdp, sizeof sdp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
79 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
80 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
81 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
82 : SDP_CODEC_MASK_PCMU;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
83 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
84 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
85 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
86 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
87
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
88 static void
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
89 invite_new_call(req, ess, sin)
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 struct sip_pkt_rx *req;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 struct uas_parse_hdrs *ess;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 struct sockaddr_in *sin;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
94 static unsigned cycle_tag_num, cycle_sdp_addend;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 char uri_user[13], *called_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 struct sip_msg_out resp;
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
97 struct grok_from gfrom;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
98 struct supported_ext supp_ext;
50
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
99 char *hval, *unsup_ext;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
100 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
101 struct sdp_parse sdp_parse;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
102 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
103 struct call *call;
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
104 char *dp, cdr_str[80];
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
105 unsigned cdr_num_len, cdr_cnam_len;
76
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
106 unsigned req_uri_len, to_hdr_len, copylen;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 int rc;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 /* extract called number from Request-URI */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 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
111 if (rc < 0) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 not_nanp: start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 "416 Request-URI is not a NANP number");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 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
115 if (rc < 0) {
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
116 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
117 "INVITE early error response length exceeded");
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 out_msg_finish(&resp);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 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
122 return;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (uri_user[0] == '+') {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (grok_number_string(uri_user+1, 0) != 11 ||
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 uri_user[1] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 called_nanp = uri_user + 2;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 } else switch (grok_number_string(uri_user)) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 case 10:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 called_nanp = uri_user;
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 case 11:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (uri_user[0] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 called_nanp = uri_user + 1;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 break;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 default:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (!is_nanp_valid_prefix(called_nanp))
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 /* 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
144 refresh_number_db();
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (!is_nanp_locally_owned(called_nanp)) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 "404 Called number does not belong here");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 goto error_resp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
150 /* parse and validate From header */
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
151 rc = grok_from_header(ess->from, &gfrom);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
152 if (rc < 0) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
153 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
154 goto error_resp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
155 }
76
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
156 /* 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
157 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
158 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
159 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
160 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
161 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
162 goto error_resp;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
163 }
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
164 } 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
165 if (ess->to[0] != '<')
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
166 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
167 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
168 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
169 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
170 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
171 } else
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
172 goto bad_to_header;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
173 /* check 100rel and catch any unsupported requirements */
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
174 supp_ext.name = "100rel";
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
175 supp_ext.req_flag = &ext_100rel_req;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
176 supp_ext.sup_flag = &ext_100rel_sup;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
177 ext_100rel_req = ext_100rel_sup = 0;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
178 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
179 if (rc < 0) {
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
180 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
181 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
182 if (rc < 0)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
183 goto error_resp_toolong;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
184 goto error_resp;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
185 }
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
186 if (ext_100rel_req)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
187 use_100rel = 1;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
188 else if (ext_100rel_sup)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
189 use_100rel = cfg_use_100rel;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
190 else
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
191 use_100rel = 0;
50
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
192 /* 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
193 if (!req->msg_body_len) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
194 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
195 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
196 if (rc < 0)
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
197 goto error_resp_toolong;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
198 goto error_resp;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
199 }
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
200 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
201 if (!hval) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
202 start_response_out_msg(&resp,
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
203 "415 Missing Content-Type header");
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
204 goto error_415;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
205 }
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
206 if (strcasecmp(hval, "application/sdp")) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
207 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
208 goto error_415;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
209 }
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
210 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
211 if (rc < 0) {
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
212 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
213 goto error_resp;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
214 }
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
215 switch (sdp_parse.codec_mask) {
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
216 case SDP_CODEC_MASK_PCMU:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
217 use_pcma = 0;
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 case SDP_CODEC_MASK_PCMA:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
220 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
221 use_pcma = 1;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
222 break;
104
ce3b1db7d1d7 sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
223 case SDP_CODEC_MASK_BOTH:
ce3b1db7d1d7 sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
224 use_pcma = cfg_force_pcma;
ce3b1db7d1d7 sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
225 break;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
226 default:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
227 start_response_out_msg(&resp,
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
228 "488 Unsupported codec selection");
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
229 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
230 if (rc < 0)
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
231 goto error_resp_toolong;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
232 rc = out_msg_add_header(&resp, "Content-Type",
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
233 "application/sdp");
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 bzero(&sdp_gen, sizeof sdp_gen);
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
237 sdp_gen.owner_ip = sip_bind_ip;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
238 sdp_gen.conn_ip = sip_bind_ip;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
239 sdp_gen.codec_mask = SDP_CODEC_MASK_BOTH;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
240 rc = out_msg_finish_sdp(&resp, &sdp_gen);
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
241 if (rc < 0)
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
242 goto error_resp_toolong;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
243 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
244 return;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
245 }
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
246 /* SIP INVITE validation done - gather CDR info */
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
247 cdr_num_len = gfrom.user_len;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
248 if (cdr_num_len > 33)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
249 cdr_num_len = 33;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
250 cdr_cnam_len = gfrom.cnam_len;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
251 if (cdr_cnam_len > 33)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
252 cdr_cnam_len = 33;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
253 if (cdr_cnam_len)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
254 sprintf(cdr_str, "%.*s (%s%.*s%s)", cdr_num_len, gfrom.user,
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
255 gfrom.cnam_quoted ? "\"" : "", cdr_cnam_len, gfrom.cnam,
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
256 gfrom.cnam_quoted ? "\"" : "");
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
257 else
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
258 sprintf(cdr_str, "%.*s", cdr_num_len, gfrom.user);
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
259 hval = get_single_header(req, "P-Asserted-Identity", (char *) 0,
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
260 (int *) 0);
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
261 /* 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
262 rc = connect_gsm_mtcall();
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
263 if (rc < 0) {
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
264 gsm_offline: syslog(LOG_INFO, "Down-call from %s to %s", cdr_str, uri_user);
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
265 if (hval)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
266 syslog(LOG_INFO, "Down-call PAI: %s", hval);
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
267 start_response_out_msg(&resp, "480 GSM service is offline");
57
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
268 goto error_resp;
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
269 }
107
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
270 rc = connect_tmgw_socket();
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
271 if (rc < 0)
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
272 goto gsm_offline;
57
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
273 /* stateful processing begins */
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
274 call = malloc(sizeof(struct call) + strlen(ess->call_id) +
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
275 strlen(ess->from) + req_uri_len + strlen(ess->via) + 19);
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
276 if (!call) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
277 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
278 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
279 "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
280 goto error_resp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
281 }
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
282 cycle_tag_num++;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
283 if (cycle_tag_num >= 1000000)
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
284 cycle_tag_num = 0;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
285 cycle_sdp_addend++;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
286 if (cycle_sdp_addend >= 0x10000)
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
287 cycle_sdp_addend = 0;
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
288 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
289 dp = (char *)(call + 1);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
290 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
291 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
292 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
293 dp += copylen;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
294 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
295 call->invite_from = dp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
296 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
297 dp += copylen;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
298 call->invite_to = dp;
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
299 *dp++ = '<';
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
300 bcopy(req->req_uri, dp, req_uri_len);
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
301 dp += req_uri_len;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
302 *dp++ = '>';
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
303 sprintf(dp, ";tag=in%06u", cycle_tag_num);
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
304 dp += 14;
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
305 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
306 call->invite_via = dp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 call->use_pcma = use_pcma;
113
bfc97065bf51 sip-in: syslog beginning and clearing of calls
Mychaela Falconia <falcon@freecalypso.org>
parents: 110
diff changeset
320 call->in_tag_num = cycle_tag_num;
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
321 call->sdp_addend = cycle_sdp_addend;
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
322 /* generate 100 response */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
323 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
324 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
325 if (rc < 0) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
326 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
327 free(call);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
328 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
329 }
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 /* add to call list */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
333 call->next = call_list;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
334 call_list = call;
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
335 syslog(LOG_INFO, "Call in%06u from %s to %s", call->in_tag_num,
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
336 cdr_str, uri_user);
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
337 if (hval)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
338 syslog(LOG_INFO, "Call in%06u PAI: %s", call->in_tag_num, hval);
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
339 /* send CRCX to TMGW */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
340 tmgw_send_crcx(call);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
341 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
342 call->sip_state = SIP_STATE_INVITE_PROC;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 }
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
344
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
345 static void
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
346 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
347 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
348 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
349 struct sockaddr_in *sin;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
350 struct call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
351 {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
352 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
353 int rc;
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 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
356 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
357 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
358 if (rc < 0) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
359 syslog(LOG_ERR,
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
360 "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
361 return;
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 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
364 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
365 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
366 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
367 /* 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
368 switch (call->sip_state) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
369 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
370 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
371 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
372 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
373 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
374 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
375 case SIP_STATE_RINGING:
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
376 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
377 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
378 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
379 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
380 return;
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
381 case SIP_STATE_RINGING_REL:
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
382 start_response_out_msg(&resp, "180 Ringing");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
383 fill_invite_resp_from_call(&resp, call);
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
384 out_msg_add_header(&resp, "Require", "100rel");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
385 out_msg_add_header(&resp, "RSeq", "1");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
386 out_msg_finish(&resp);
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
387 sip_tx_packet(&resp, sin);
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
388 return;
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
389 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
390 case SIP_STATE_CONNECTED:
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
391 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
392 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
393 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
394 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
395 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
396 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
397 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
398 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
399 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
400 default:
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
401 /* silently discard */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
402 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
403 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
404 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
405
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
406 void
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
407 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
408 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
409 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
410 struct sockaddr_in *sin;
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 call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
413
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
414 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
415 if (call)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
416 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
417 else
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
418 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
419 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
420
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
421 void
65
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
422 signal_invite_ringing(call)
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
423 struct call *call;
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
424 {
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
425 struct sip_msg_out resp;
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
426 int rc;
65
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
427
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
428 start_response_out_msg(&resp, "180 Ringing");
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
429 rc = fill_invite_resp_from_call(&resp, call);
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
430 if (rc < 0) {
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
431 msg_size_err: syslog(LOG_ERR, "INVITE 180 response length exceeded");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
432 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
433 call->overall_state = OVERALL_STATE_TEARDOWN;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
434 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
435 GSM48_CC_CAUSE_INTERWORKING);
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
436 disconnect_tmgw(call);
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
437 sip_mark_end_time(call, sip_linger_error);
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
438 return;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
439 }
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
440 if (call->use_100rel) {
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
441 rc = out_msg_add_header(&resp, "Require", "100rel");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
442 if (rc < 0)
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
443 goto msg_size_err;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
444 rc = out_msg_add_header(&resp, "RSeq", "1");
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
445 if (rc < 0)
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
446 goto msg_size_err;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
447 }
65
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
448 out_msg_finish(&resp);
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
449 sip_tx_packet(&resp, &call->udp_sin);
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
450 if (call->use_100rel) {
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
451 call->sip_state = SIP_STATE_RINGING_REL;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
452 call->sip_tx_count = 1;
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
453 } else
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
454 call->sip_state = SIP_STATE_RINGING;
65
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
455 }
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
456
7c0309df59f8 sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents: 60
diff changeset
457 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
458 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
459 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
460 {
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
461 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
462 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
463
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 disconnect_tmgw(call);
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
472 sip_mark_end_time(call, sip_linger_error);
66
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
473 return;
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
474 }
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
475 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
476 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
477 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
478 }
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
479
5beb51de1bae sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
480 void
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
481 signal_invite_error(call)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
482 struct call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
483 {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
484 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
485 int rc;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
486
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
487 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
488 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
489 if (rc < 0) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
490 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
491 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
492 sip_mark_end_time(call, sip_linger_error);
110
c1c94b7fc2e2 sip-in call clearing: DEAD_SIP transition implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
493 transition_dead_sip(call);
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
494 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
495 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
496 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
497 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
498 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
499 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
500 }