# HG changeset patch # User Mychaela Falconia # Date 1656280272 28800 # Node ID 1d590563e64bc41898ddcb9a3329ed9c29cf486c # Parent 960ffce6c5425a0a3020140df12d32a3c1c7631d libnumdb: implement short number lookup diff -r 960ffce6c542 -r 1d590563e64b libnumdb/Makefile --- a/libnumdb/Makefile Sun Jun 26 13:39:52 2022 -0800 +++ b/libnumdb/Makefile Sun Jun 26 13:51:12 2022 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= check_nanp.o readbin.o refresh.o +OBJS= check_nanp.o check_short.o readbin.o refresh.o LIB= libnumdb.a all: ${LIB} diff -r 960ffce6c542 -r 1d590563e64b libnumdb/check_short.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libnumdb/check_short.c Sun Jun 26 13:51:12 2022 -0800 @@ -0,0 +1,45 @@ +/* + * The library function implemented in this module looks up 4-digit short + * dialing numbers in ThemWi number db to determine their disposition. + */ + +#include +#include +#include +#include "../include/number_db_file.h" + +extern struct numdb_file_hdr numdb_hdr; +extern struct short_number_map *numdb_short_numbers; + +static int +compare_short_num(p1, p2) + struct short_number_map *p1, *p2; +{ + if (p1->short_code < p2->short_code) + return(-1); + else if (p1->short_code > p2->short_code) + return(1); + else + return(0); +} + +lookup_short_dial_number(numstr, nanp_buf) + char *numstr, *nanp_buf; +{ + struct short_number_map key, *res; + + if (!numdb_short_numbers || !numdb_hdr.short_number_count) + return(0); + key.short_code = strtoul(numstr, 0, 10); + res = bsearch(&key, numdb_short_numbers, numdb_hdr.short_number_count, + sizeof(struct short_number_map), compare_short_num); + if (!res) + return(0); + if (res->prefix < 200000 || res->prefix > 999999) { + /* either ITN or an invalid record, also treated as an ITN */ + nanp_buf[0] = '\0'; + return(1); + } + sprintf(nanp_buf, "%06u%04u", res->prefix, res->short_code); + return(1); +}