FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-check-own.c @ 246:74dae755f85a
themwi-test-mtc: convert to libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 22:37:11 -0800 |
parents | 697fe2c87fec |
children |
rev | line source |
---|---|
13
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility performs a lookup in ThemWi number database to see |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * if a given NANP number is owned by us. |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
238
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
7 #include <stdint.h> |
13
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <syslog.h> |
238
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
10 #include "../include/number_db_v2.h" |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
11 #include "../libnumdb2/lookup_func.h" |
13
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char nanp[11]; |
238
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
17 struct owned_number_rec *rec; |
13
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (argc != 2) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 usage: fprintf(stderr, "usage: %s 10-digit-number\n", argv[0]); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 exit(1); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (grok_number_string(argv[1], 1) != 10) |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 goto usage; |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 dehyphen_number_string(argv[1], nanp); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!is_nanp_valid_prefix(nanp)) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(stderr, "error: number violates NANP rules\n"); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 openlog("themwi-check-own", 0, LOG_LOCAL5); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (read_number_db() < 0) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, "error reading number database\n"); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
238
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
35 rec = numdb_lookup_nanp(nanp); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
36 printf("+1-%.3s-%.3s-%s is ", nanp, nanp+3, nanp+6); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
37 if (!rec) { |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
38 puts("NOT owned by us"); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
39 exit(1); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
40 } |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
41 fputs("locally owned, ", stdout); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
42 switch (rec->usage & NUMBER_USAGE_MASK) { |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
43 case NUMBER_USAGE_TYPE_RSVD: |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
44 puts("reserved"); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
45 break; |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
46 case NUMBER_USAGE_TYPE_GSM_SUB: |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
47 puts("assigned to a GSM subscriber"); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
48 break; |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
49 case NUMBER_USAGE_TYPE_ALIAS: |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
50 printf("mapped to +1-%03u-%03u-%04u\n", rec->remap[0], |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
51 rec->remap[1], rec->remap[2]); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
52 break; |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
53 default: |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
54 printf("unknown usage byte 0x%02X\n", rec->usage); |
697fe2c87fec
themwi-check-own: convert to libnumdb2
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
55 } |
13
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(0); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |