FreeCalypso > hg > themwi-system-sw
changeset 227:a349ae9d90fa
number db v2: implement themwi-dump-numdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 10:18:50 -0800 |
parents | 28441920fb35 |
children | 7ea6acdb8364 |
files | .hgignore utils/Makefile utils/themwi-dump-numdb2.c |
diffstat | 3 files changed, 97 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Aug 13 22:01:25 2023 -0800 +++ b/.hgignore Mon Aug 14 10:18:50 2023 -0800 @@ -29,6 +29,7 @@ ^utils/tcpserv-dump$ ^utils/themwi-check-own$ ^utils/themwi-dump-numdb$ +^utils/themwi-dump-numdb2$ ^utils/themwi-short-dial$ ^utils/themwi-update-numdb$ ^utils/themwi-update-numdb2$
--- a/utils/Makefile Sun Aug 13 22:01:25 2023 -0800 +++ b/utils/Makefile Mon Aug 14 10:18:50 2023 -0800 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 PROGS= sip-out-test sip-rx-test sip-udp-dump themwi-check-own \ - themwi-dump-numdb themwi-short-dial themwi-update-numdb \ - themwi-update-numdb2 themwi-update-outrt + themwi-dump-numdb themwi-dump-numdb2 themwi-short-dial \ + themwi-update-numdb themwi-update-numdb2 themwi-update-outrt NOINST= rtp-alloc-test smpp-test1 smpp-test2 tcpserv-dump LIBNUMDB=../libnumdb/libnumdb.a LIBRTPA=../librtpalloc/librtpalloc.a @@ -39,6 +39,9 @@ themwi-dump-numdb: themwi-dump-numdb.c ${CC} ${CFLAGS} -o $@ $@.c +themwi-dump-numdb2: themwi-dump-numdb2.c + ${CC} ${CFLAGS} -o $@ $@.c + themwi-short-dial: themwi-short-dial.o ${LIBNUMDB} ${LIBUTIL} ${CC} ${CFLAGS} -o $@ $@.o ${LIBNUMDB} ${LIBUTIL}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/themwi-dump-numdb2.c Mon Aug 14 10:18:50 2023 -0800 @@ -0,0 +1,91 @@ +/* + * This program is a debug utility: it reads and dumps the compiled + * binary form of ThemWi number database version 2. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include "../include/number_db_v2.h" + +static char binfile_default_pathname[] = "/var/gsm/number-db2.bin"; +static char *binfile_pathname; +static FILE *inf; +static struct numdb_file_hdr hdr; + +static void +dump_owned_numbers() +{ + unsigned count; + struct owned_number_rec rec; + + for (count = 0; count < hdr.owned_number_count; count++) { + if (fread(&rec, sizeof rec, 1, inf) != 1) { + fprintf(stderr, "error reading record from %s\n", + binfile_pathname); + exit(1); + } + printf("Owned NANP number: %03u-%03u-%04u\n", + rec.number[0], rec.number[1], rec.number[2]); + printf(" Number flags 0x%02X, usage byte 0x%02X\n", + rec.number_flags, rec.usage); + if ((rec.usage & NUMBER_USAGE_MASK) == NUMBER_USAGE_TYPE_ALIAS) + printf(" Alias maps to: %03u-%03u-%04u\n", + rec.remap[0], rec.remap[1], rec.remap[2]); + if (rec.usage & NUMBER_USAGE_FLAG_E911_VIA) + printf(" E911 route via: %03u-%03u-%04u\n", + rec.remap[0], rec.remap[1], rec.remap[2]); + } +} + +static void +dump_short_numbers() +{ + unsigned count; + struct short_number_rec rec; + + for (count = 0; count < hdr.short_number_count; count++) { + if (fread(&rec, sizeof rec, 1, inf) != 1) { + fprintf(stderr, "error reading record from %s\n", + binfile_pathname); + exit(1); + } + printf("Short number %04u is of type 0x%02X\n", rec.short_num, + rec.short_num_type); + if (rec.short_num_type == SHORT_NUM_TYPE_ABBREV) { + printf(" Abbrev maps to: %03u-%03u-%04u\n", + rec.fullnum_prefix[0], rec.fullnum_prefix[1], + rec.short_num); + printf(" Full number flags: 0x%02X\n", + rec.fullnum_flags); + } + } +} + +main(argc, argv) + char **argv; +{ + if (argc > 2) { + fprintf(stderr, "usage: %s [binfile]\n", argv[0]); + exit(1); + } + if (argv[1]) + binfile_pathname = argv[1]; + else + binfile_pathname = binfile_default_pathname; + inf = fopen(binfile_pathname, "r"); + if (!inf) { + perror(binfile_pathname); + exit(1); + } + if (fread(&hdr, sizeof hdr, 1, inf) != 1) { + fprintf(stderr, "error reading header from %s\n", + binfile_pathname); + exit(1); + } + printf("Count of owned NANP numbers: %u\n", hdr.owned_number_count); + printf("Count of defined short numbers: %u\n", hdr.short_number_count); + dump_owned_numbers(); + dump_short_numbers(); + exit(0); +}