annotate sip-in/invite_init.c @ 261:a375639e4190

smpp-trx-sa: refactor time formatting code
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 11 Oct 2023 17:34:45 -0800
parents 27408ac6e863
children
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 /*
145
4b685a5d9bd4 sip-in code: split invite.c into 3 separate C modules
Mychaela Falconia <falcon@freecalypso.org>
parents: 117
diff changeset
2 * Here we implement our initial processing of SIP INVITE requests.
48
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>
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>
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
15 #include "../include/number_db_v2.h"
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
16 #include "../libnumdb2/lookup_func.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;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
26 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
27 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
28 extern struct call *call_list;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
29
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
30 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
31 extern char *get_single_header();
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
32
145
4b685a5d9bd4 sip-in code: split invite.c into 3 separate C modules
Mychaela Falconia <falcon@freecalypso.org>
parents: 117
diff changeset
33 void
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
34 invite_new_call(req, ess, sin)
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 struct sip_pkt_rx *req;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 struct uas_parse_hdrs *ess;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 struct sockaddr_in *sin;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
39 static unsigned cycle_tag_num, cycle_sdp_addend;
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
40 char uri_user[13], *called_nanp, redir_nanp[11];
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
41 struct owned_number_rec *own;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
42 int is_redir;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 struct sip_msg_out resp;
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
44 struct grok_from gfrom;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
45 struct supported_ext supp_ext;
50
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
46 char *hval, *unsup_ext;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
47 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
48 struct sdp_parse sdp_parse;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
49 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
50 struct call *call;
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
51 char *dp, cdr_str[80];
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
52 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
53 unsigned req_uri_len, to_hdr_len, copylen;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 int rc;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 /* extract called number from Request-URI */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 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
58 if (rc < 0) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 not_nanp: start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 "416 Request-URI is not a NANP number");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 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
62 if (rc < 0) {
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
63 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
64 "INVITE early error response length exceeded");
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 out_msg_finish(&resp);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 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
69 return;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (uri_user[0] == '+') {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (grok_number_string(uri_user+1, 0) != 11 ||
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 uri_user[1] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 called_nanp = uri_user + 2;
248
257da5474e77 sip-in: fix bug in incoming number validation for non-plus
Mychaela Falconia <falcon@freecalypso.org>
parents: 145
diff changeset
76 } else switch (grok_number_string(uri_user, 0)) {
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 case 10:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 called_nanp = uri_user;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 break;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 case 11:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (uri_user[0] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 called_nanp = uri_user + 1;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 break;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 default:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (!is_nanp_valid_prefix(called_nanp))
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 /* 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
91 refresh_number_db();
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
92 own = numdb_lookup_nanp(called_nanp);
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
93 if (!own) {
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 "404 Called number does not belong here");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 goto error_resp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
98 switch (own->usage & NUMBER_USAGE_MASK) {
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
99 case NUMBER_USAGE_TYPE_GSM_SUB:
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
100 is_redir = 0;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
101 break;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
102 case NUMBER_USAGE_TYPE_ALIAS:
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
103 is_redir = 1;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
104 sprintf(redir_nanp, "%03u%03u%04u",
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
105 own->remap[0], own->remap[1], own->remap[2]);
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
106 break;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
107 default:
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
108 is_redir = -1; /* log CDR before rejecting */
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
109 }
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
110 /* parse and validate From header */
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
111 rc = grok_from_header(ess->from, &gfrom);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
112 if (rc < 0) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
113 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
114 goto error_resp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents: 50
diff changeset
115 }
76
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
116 /* 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
117 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
118 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
119 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
120 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
121 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
122 goto error_resp;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
123 }
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
124 } 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
125 if (ess->to[0] != '<')
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
126 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
127 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
128 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
129 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
130 goto bad_to_header;
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
131 } else
21276f045026 sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
132 goto bad_to_header;
49
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
133 /* check 100rel and catch any unsupported requirements */
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
134 supp_ext.name = "100rel";
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
135 supp_ext.req_flag = &ext_100rel_req;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
136 supp_ext.sup_flag = &ext_100rel_sup;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
137 ext_100rel_req = ext_100rel_sup = 0;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
138 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
139 if (rc < 0) {
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
140 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
141 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
142 if (rc < 0)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
143 goto error_resp_toolong;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
144 goto error_resp;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
145 }
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
146 if (ext_100rel_req)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
147 use_100rel = 1;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
148 else if (ext_100rel_sup)
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
149 use_100rel = cfg_use_100rel;
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
150 else
dec31b1a8b96 sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
151 use_100rel = 0;
50
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
152 /* 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
153 if (!req->msg_body_len) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
154 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
155 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
156 if (rc < 0)
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
157 goto error_resp_toolong;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
158 goto error_resp;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
159 }
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
160 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
161 if (!hval) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
162 start_response_out_msg(&resp,
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
163 "415 Missing Content-Type header");
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
164 goto error_415;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
165 }
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
166 if (strcasecmp(hval, "application/sdp")) {
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
167 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
168 goto error_415;
daf1c26d7ae2 sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
169 }
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
170 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
171 if (rc < 0) {
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
172 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
173 goto error_resp;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
174 }
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
175 switch (sdp_parse.codec_mask) {
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
176 case SDP_CODEC_MASK_PCMU:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
177 use_pcma = 0;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
178 break;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
179 case SDP_CODEC_MASK_PCMA:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
180 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
181 use_pcma = 1;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
182 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
183 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
184 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
185 break;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
186 default:
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
187 start_response_out_msg(&resp,
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
188 "488 Unsupported codec selection");
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
189 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
190 if (rc < 0)
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
191 goto error_resp_toolong;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
192 rc = out_msg_add_header(&resp, "Content-Type",
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
193 "application/sdp");
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
194 if (rc < 0)
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
195 goto error_resp_toolong;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
196 bzero(&sdp_gen, sizeof sdp_gen);
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
197 sdp_gen.owner_ip = sip_bind_ip;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
198 sdp_gen.conn_ip = sip_bind_ip;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
199 sdp_gen.codec_mask = SDP_CODEC_MASK_BOTH;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
200 rc = out_msg_finish_sdp(&resp, &sdp_gen);
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
201 if (rc < 0)
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
202 goto error_resp_toolong;
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
203 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
204 return;
55
f1d59210f7b2 sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
205 }
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
206 /* SIP INVITE validation done - gather CDR info */
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
207 cdr_num_len = gfrom.user_len;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
208 if (cdr_num_len > 33)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
209 cdr_num_len = 33;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
210 cdr_cnam_len = gfrom.cnam_len;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
211 if (cdr_cnam_len > 33)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
212 cdr_cnam_len = 33;
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
213 if (cdr_cnam_len)
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
214 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
215 gfrom.cnam_quoted ? "\"" : "", cdr_cnam_len, gfrom.cnam,
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
216 gfrom.cnam_quoted ? "\"" : "");
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
217 else
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
218 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
219 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
220 (int *) 0);
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
221 /* weed out calls to unassigned numbers */
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
222 if (is_redir < 0) {
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
223 syslog(LOG_INFO, "Call from %s to %s: unassigned number",
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
224 cdr_str, uri_user);
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
225 if (hval)
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
226 syslog(LOG_INFO, "Down-call PAI: %.100s", hval);
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
227 start_response_out_msg(&resp,
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
228 "404 Called number is unassigned");
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
229 goto error_resp;
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
230 }
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
231 /* 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
232 rc = connect_gsm_mtcall();
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
233 if (rc < 0) {
250
27408ac6e863 sip-in: consistent CDR logs for statelessly rejected calls
Mychaela Falconia <falcon@freecalypso.org>
parents: 249
diff changeset
234 gsm_offline: syslog(LOG_INFO, "Call from %s to %s: system is down", cdr_str,
27408ac6e863 sip-in: consistent CDR logs for statelessly rejected calls
Mychaela Falconia <falcon@freecalypso.org>
parents: 249
diff changeset
235 uri_user);
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
236 if (hval)
117
c93c339271a7 sip-in CDR syslog: put a safety limit on string length
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
237 syslog(LOG_INFO, "Down-call PAI: %.100s", hval);
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
238 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
239 goto error_resp;
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
240 }
107
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
241 rc = connect_tmgw_socket();
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
242 if (rc < 0)
372209628038 sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
243 goto gsm_offline;
57
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 55
diff changeset
244 /* stateful processing begins */
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
245 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
246 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
247 if (!call) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
248 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
249 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
250 "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
251 goto error_resp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
252 }
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
253 cycle_tag_num++;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
254 if (cycle_tag_num >= 1000000)
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
255 cycle_tag_num = 0;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
256 cycle_sdp_addend++;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
257 if (cycle_sdp_addend >= 0x10000)
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
258 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
259 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
260 dp = (char *)(call + 1);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
261 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
262 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
263 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
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->from) + 1;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
266 call->invite_from = dp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
267 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
268 dp += copylen;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
269 call->invite_to = dp;
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
270 *dp++ = '<';
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
271 bcopy(req->req_uri, dp, req_uri_len);
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
272 dp += req_uri_len;
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
273 *dp++ = '>';
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
274 sprintf(dp, ";tag=in%06u", cycle_tag_num);
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
275 dp += 14;
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
276 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
277 call->invite_via = dp;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
278 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
279 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
280 bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in));
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
281 bcopy(is_redir ? redir_nanp : called_nanp, call->called_nanp, 11);
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 call->use_pcma = use_pcma;
113
bfc97065bf51 sip-in: syslog beginning and clearing of calls
Mychaela Falconia <falcon@freecalypso.org>
parents: 110
diff changeset
291 call->in_tag_num = cycle_tag_num;
77
fe39404092d9 sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents: 76
diff changeset
292 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
293 /* generate 100 response */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
294 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
295 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
296 if (rc < 0) {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
297 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
298 free(call);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
299 return;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
300 }
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
301 out_msg_finish(&resp);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
302 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
303 /* add to call list */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
304 call->next = call_list;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
305 call_list = call;
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
306 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
307 cdr_str, uri_user);
249
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
308 if (is_redir)
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
309 syslog(LOG_INFO, "Call in%06u redirected to %s",
e980fe9c186c sip-in: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents: 248
diff changeset
310 call->in_tag_num, redir_nanp);
114
a30c25fb4c2f sip-in: generate CDR syslog entries
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
311 if (hval)
117
c93c339271a7 sip-in CDR syslog: put a safety limit on string length
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
312 syslog(LOG_INFO, "Call in%06u PAI: %.100s", call->in_tag_num,
c93c339271a7 sip-in CDR syslog: put a safety limit on string length
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
313 hval);
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
314 /* send CRCX to TMGW */
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
315 tmgw_send_crcx(call);
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
316 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
317 call->sip_state = SIP_STATE_INVITE_PROC;
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 }
60
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
319
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
320 void
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
321 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
322 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
323 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
324 struct sockaddr_in *sin;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
325 {
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
326 struct call *call;
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
327
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
328 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
329 if (call)
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
330 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
331 else
02761f1ae5e5 sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
332 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
333 }