comparison sip-in/invite_init.c @ 249:e980fe9c186c

sip-in: convert to libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 23:38:24 -0800
parents 257da5474e77
children 27408ac6e863
comparison
equal deleted inserted replaced
248:257da5474e77 249:e980fe9c186c
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <string.h> 12 #include <string.h>
13 #include <strings.h> 13 #include <strings.h>
14 #include <syslog.h> 14 #include <syslog.h>
15 #include "../include/number_db_v2.h"
16 #include "../libnumdb2/lookup_func.h"
15 #include "../libsip/parse.h" 17 #include "../libsip/parse.h"
16 #include "../libsip/uas_basic.h" 18 #include "../libsip/uas_basic.h"
17 #include "../libsip/grok_from.h" 19 #include "../libsip/grok_from.h"
18 #include "../libsip/req_supp.h" 20 #include "../libsip/req_supp.h"
19 #include "../libsip/sdp.h" 21 #include "../libsip/sdp.h"
33 struct sip_pkt_rx *req; 35 struct sip_pkt_rx *req;
34 struct uas_parse_hdrs *ess; 36 struct uas_parse_hdrs *ess;
35 struct sockaddr_in *sin; 37 struct sockaddr_in *sin;
36 { 38 {
37 static unsigned cycle_tag_num, cycle_sdp_addend; 39 static unsigned cycle_tag_num, cycle_sdp_addend;
38 char uri_user[13], *called_nanp; 40 char uri_user[13], *called_nanp, redir_nanp[11];
41 struct owned_number_rec *own;
42 int is_redir;
39 struct sip_msg_out resp; 43 struct sip_msg_out resp;
40 struct grok_from gfrom; 44 struct grok_from gfrom;
41 struct supported_ext supp_ext; 45 struct supported_ext supp_ext;
42 char *hval, *unsup_ext; 46 char *hval, *unsup_ext;
43 int ext_100rel_req, ext_100rel_sup, use_100rel, use_pcma; 47 int ext_100rel_req, ext_100rel_sup, use_100rel, use_pcma;
83 } 87 }
84 if (!is_nanp_valid_prefix(called_nanp)) 88 if (!is_nanp_valid_prefix(called_nanp))
85 goto not_nanp; 89 goto not_nanp;
86 /* it is valid NANP - but is it one of ours? */ 90 /* it is valid NANP - but is it one of ours? */
87 refresh_number_db(); 91 refresh_number_db();
88 if (!is_nanp_locally_owned(called_nanp)) { 92 own = numdb_lookup_nanp(called_nanp);
93 if (!own) {
89 start_response_out_msg(&resp, 94 start_response_out_msg(&resp,
90 "404 Called number does not belong here"); 95 "404 Called number does not belong here");
91 goto error_resp; 96 goto error_resp;
97 }
98 switch (own->usage & NUMBER_USAGE_MASK) {
99 case NUMBER_USAGE_TYPE_GSM_SUB:
100 is_redir = 0;
101 break;
102 case NUMBER_USAGE_TYPE_ALIAS:
103 is_redir = 1;
104 sprintf(redir_nanp, "%03u%03u%04u",
105 own->remap[0], own->remap[1], own->remap[2]);
106 break;
107 default:
108 is_redir = -1; /* log CDR before rejecting */
92 } 109 }
93 /* parse and validate From header */ 110 /* parse and validate From header */
94 rc = grok_from_header(ess->from, &gfrom); 111 rc = grok_from_header(ess->from, &gfrom);
95 if (rc < 0) { 112 if (rc < 0) {
96 start_response_out_msg(&resp, "400 Malformed From header"); 113 start_response_out_msg(&resp, "400 Malformed From header");
199 gfrom.cnam_quoted ? "\"" : ""); 216 gfrom.cnam_quoted ? "\"" : "");
200 else 217 else
201 sprintf(cdr_str, "%.*s", cdr_num_len, gfrom.user); 218 sprintf(cdr_str, "%.*s", cdr_num_len, gfrom.user);
202 hval = get_single_header(req, "P-Asserted-Identity", (char *) 0, 219 hval = get_single_header(req, "P-Asserted-Identity", (char *) 0,
203 (int *) 0); 220 (int *) 0);
221 /* weed out calls to unassigned numbers */
222 if (is_redir < 0) {
223 syslog(LOG_INFO, "Call from %s to %s: unassigned number",
224 cdr_str, uri_user);
225 if (hval)
226 syslog(LOG_INFO, "Down-call PAI: %.100s", hval);
227 start_response_out_msg(&resp,
228 "404 Called number is unassigned");
229 goto error_resp;
230 }
204 /* check if GSM service is up */ 231 /* check if GSM service is up */
205 rc = connect_gsm_mtcall(); 232 rc = connect_gsm_mtcall();
206 if (rc < 0) { 233 if (rc < 0) {
207 gsm_offline: syslog(LOG_INFO, "Down-call from %s to %s", cdr_str, uri_user); 234 gsm_offline: syslog(LOG_INFO, "Down-call from %s to %s", cdr_str, uri_user);
208 if (hval) 235 if (hval)
248 copylen = strlen(ess->via) + 1; 275 copylen = strlen(ess->via) + 1;
249 call->invite_via = dp; 276 call->invite_via = dp;
250 bcopy(ess->via, dp, copylen); 277 bcopy(ess->via, dp, copylen);
251 call->invite_cseq = ess->cseq_num; 278 call->invite_cseq = ess->cseq_num;
252 bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in)); 279 bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in));
253 bcopy(called_nanp, call->called_nanp, 11); 280 bcopy(is_redir ? redir_nanp : called_nanp, call->called_nanp, 11);
254 call->from_uri = call->invite_from + (gfrom.uri - ess->from); 281 call->from_uri = call->invite_from + (gfrom.uri - ess->from);
255 call->from_uri_len = gfrom.uri_len; 282 call->from_uri_len = gfrom.uri_len;
256 call->from_user = call->invite_from + (gfrom.user - ess->from); 283 call->from_user = call->invite_from + (gfrom.user - ess->from);
257 call->from_user_len = gfrom.user_len; 284 call->from_user_len = gfrom.user_len;
258 call->use_100rel = use_100rel; 285 call->use_100rel = use_100rel;
275 /* add to call list */ 302 /* add to call list */
276 call->next = call_list; 303 call->next = call_list;
277 call_list = call; 304 call_list = call;
278 syslog(LOG_INFO, "Call in%06u from %s to %s", call->in_tag_num, 305 syslog(LOG_INFO, "Call in%06u from %s to %s", call->in_tag_num,
279 cdr_str, uri_user); 306 cdr_str, uri_user);
307 if (is_redir)
308 syslog(LOG_INFO, "Call in%06u redirected to %s",
309 call->in_tag_num, redir_nanp);
280 if (hval) 310 if (hval)
281 syslog(LOG_INFO, "Call in%06u PAI: %.100s", call->in_tag_num, 311 syslog(LOG_INFO, "Call in%06u PAI: %.100s", call->in_tag_num,
282 hval); 312 hval);
283 /* send CRCX to TMGW */ 313 /* send CRCX to TMGW */
284 tmgw_send_crcx(call); 314 tmgw_send_crcx(call);