FreeCalypso > hg > themwi-system-sw
changeset 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 |
files | sip-in/Makefile sip-in/invite_init.c |
diffstat | 2 files changed, 34 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/sip-in/Makefile Mon Aug 14 22:56:20 2023 -0800 +++ b/sip-in/Makefile Mon Aug 14 23:38:24 2023 -0800 @@ -5,7 +5,7 @@ disconnect.o invite_dup.o invite_init.o invite_resp.o main.o mgw_ops.o \ mgw_resp.o mgw_sock.o mncc_handle.o mncc_sig_out.o mncc_sock.o prack.o \ readconf.o retrans.o shutdown.o sip_ack.o sip_log.o sip_uas.o sip_udp.o -LIBS= ../libnumdb/libnumdb.a ../libsip/libsip.a ../libutil/libutil.a +LIBS= ../libnumdb2/libnumdb.a ../libsip/libsip.a ../libutil/libutil.a INSTBIN=/usr/local/bin all: ${PROG}
--- a/sip-in/invite_init.c Mon Aug 14 22:56:20 2023 -0800 +++ b/sip-in/invite_init.c Mon Aug 14 23:38:24 2023 -0800 @@ -12,6 +12,8 @@ #include <string.h> #include <strings.h> #include <syslog.h> +#include "../include/number_db_v2.h" +#include "../libnumdb2/lookup_func.h" #include "../libsip/parse.h" #include "../libsip/uas_basic.h" #include "../libsip/grok_from.h" @@ -35,7 +37,9 @@ struct sockaddr_in *sin; { static unsigned cycle_tag_num, cycle_sdp_addend; - char uri_user[13], *called_nanp; + char uri_user[13], *called_nanp, redir_nanp[11]; + struct owned_number_rec *own; + int is_redir; struct sip_msg_out resp; struct grok_from gfrom; struct supported_ext supp_ext; @@ -85,11 +89,24 @@ goto not_nanp; /* it is valid NANP - but is it one of ours? */ refresh_number_db(); - if (!is_nanp_locally_owned(called_nanp)) { + own = numdb_lookup_nanp(called_nanp); + if (!own) { start_response_out_msg(&resp, "404 Called number does not belong here"); goto error_resp; } + switch (own->usage & NUMBER_USAGE_MASK) { + case NUMBER_USAGE_TYPE_GSM_SUB: + is_redir = 0; + break; + case NUMBER_USAGE_TYPE_ALIAS: + is_redir = 1; + sprintf(redir_nanp, "%03u%03u%04u", + own->remap[0], own->remap[1], own->remap[2]); + break; + default: + is_redir = -1; /* log CDR before rejecting */ + } /* parse and validate From header */ rc = grok_from_header(ess->from, &gfrom); if (rc < 0) { @@ -201,6 +218,16 @@ sprintf(cdr_str, "%.*s", cdr_num_len, gfrom.user); hval = get_single_header(req, "P-Asserted-Identity", (char *) 0, (int *) 0); + /* weed out calls to unassigned numbers */ + if (is_redir < 0) { + syslog(LOG_INFO, "Call from %s to %s: unassigned number", + cdr_str, uri_user); + if (hval) + syslog(LOG_INFO, "Down-call PAI: %.100s", hval); + start_response_out_msg(&resp, + "404 Called number is unassigned"); + goto error_resp; + } /* check if GSM service is up */ rc = connect_gsm_mtcall(); if (rc < 0) { @@ -250,7 +277,7 @@ bcopy(ess->via, dp, copylen); call->invite_cseq = ess->cseq_num; bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in)); - bcopy(called_nanp, call->called_nanp, 11); + bcopy(is_redir ? redir_nanp : called_nanp, call->called_nanp, 11); call->from_uri = call->invite_from + (gfrom.uri - ess->from); call->from_uri_len = gfrom.uri_len; call->from_user = call->invite_from + (gfrom.user - ess->from); @@ -277,6 +304,9 @@ call_list = call; syslog(LOG_INFO, "Call in%06u from %s to %s", call->in_tag_num, cdr_str, uri_user); + if (is_redir) + syslog(LOG_INFO, "Call in%06u redirected to %s", + call->in_tag_num, redir_nanp); if (hval) syslog(LOG_INFO, "Call in%06u PAI: %.100s", call->in_tag_num, hval);