# HG changeset patch # User Mychaela Falconia # Date 1656279592 28800 # Node ID 960ffce6c5425a0a3020140df12d32a3c1c7631d # Parent 2cc790b6635967faf144107b33e7e40a6e065740 libnumdb: implement NANP lookup diff -r 2cc790b66359 -r 960ffce6c542 libnumdb/Makefile --- a/libnumdb/Makefile Sun Jun 26 13:24:47 2022 -0800 +++ b/libnumdb/Makefile Sun Jun 26 13:39:52 2022 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= readbin.o refresh.o +OBJS= check_nanp.o readbin.o refresh.o LIB= libnumdb.a all: ${LIB} diff -r 2cc790b66359 -r 960ffce6c542 libnumdb/check_nanp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libnumdb/check_nanp.c Sun Jun 26 13:39:52 2022 -0800 @@ -0,0 +1,40 @@ +/* + * The library function implemented in this module consults ThemWi number db + * to see if a given NANP number is owned by us or not. + */ + +#include +#include +#include +#include "../include/number_db_file.h" + +extern struct numdb_file_hdr numdb_hdr; +extern uint64_t *numdb_owned_numbers; + +static int +compare_owned_num(p1, p2) + uint64_t *p1, *p2; +{ + if (*p1 < *p2) + return(-1); + else if (*p1 > *p2) + return(1); + else + return(0); +} + +is_nanp_locally_owned(numstr) + char *numstr; +{ + uint64_t key, *res; + + if (!numdb_owned_numbers || !numdb_hdr.owned_number_count) + return(0); + key = strtoull(numstr, 0, 10); + res = bsearch(&key, numdb_owned_numbers, numdb_hdr.owned_number_count, + sizeof(uint64_t), compare_owned_num); + if (res) + return(1); + else + return(0); +}