annotate utils/themwi-dump-numdb.c @ 112:6aa63cf4620a

sip-in call clearing: select timeout implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 18:59:55 -0800
parents 7749ae8b6414
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program is a debug utility: it reads and dumps the compiled
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * binary form of ThemWi number database.
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "../include/number_db_file.h"
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 static char binfile_default_pathname[] = "/var/gsm/number-db.bin";
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char *binfile_pathname;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static FILE *inf;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static struct numdb_file_hdr hdr;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static void
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 dump_owned_numbers()
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned count;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 uint64_t rec;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 for (count = 0; count < hdr.owned_number_count; count++) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (fread(&rec, sizeof rec, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "error reading record from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rec < 2000000000ULL || rec > 9999999999ULL) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fprintf(stderr,
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 "owned number record #%u: uint64_t value out of valid range\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
7
7749ae8b6414 themwi-dump-numdb: NANP output looks better without the '-' after +1
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
34 printf("Owned NANP number: +1%llu\n", rec);
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 static void
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 dump_short_numbers()
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 unsigned count;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 struct short_number_map rec;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (count = 0; count < hdr.short_number_count; count++) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (fread(&rec, sizeof rec, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr, "error reading record from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rec.short_code > 9999) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 fprintf(stderr,
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 "short number record #%u: short_code field out of valid range\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (!rec.prefix) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 printf("Short number %04u is an ITN\n", rec.short_code);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 continue;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rec.prefix < 200000 || rec.prefix > 999999) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr,
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 "short number record #%u: prefix field out of valid range\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
7
7749ae8b6414 themwi-dump-numdb: NANP output looks better without the '-' after +1
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
66 printf("Short number %04u maps to +1%06u%04u\n",
6
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 rec.short_code, rec.prefix, rec.short_code);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 main(argc, argv)
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 char **argv;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (argc > 2) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr, "usage: %s [binfile]\n", argv[0]);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (argv[1])
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 binfile_pathname = argv[1];
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 else
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 binfile_pathname = binfile_default_pathname;
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 inf = fopen(binfile_pathname, "r");
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (!inf) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 perror(binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (fread(&hdr, sizeof hdr, 1, inf) != 1) {
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 fprintf(stderr, "error reading header from %s\n",
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 binfile_pathname);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exit(1);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 printf("Count of owned NANP numbers: %u\n", hdr.owned_number_count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 printf("Count of defined short numbers: %u\n", hdr.short_number_count);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 dump_owned_numbers();
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 dump_short_numbers();
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 exit(0);
030143a95fb5 themwi-dump-numdb utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }