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