annotate utils/themwi-check-own.c @ 6:1e548c7a24a1

themwi-check-own: old source as starting point
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Dec 2023 03:14:35 +0000
parents
children dc1554b7dfb8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "../include/number_db_v2.h"
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libnumdb2/lookup_func.h"
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 main(argc, argv)
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char nanp[11];
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct owned_number_rec *rec;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (argc != 2) {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 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
21 exit(1);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 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
24 goto usage;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 dehyphen_number_string(argv[1], nanp);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (!is_nanp_valid_prefix(nanp)) {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 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
28 exit(1);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 openlog("themwi-check-own", 0, LOG_LOCAL5);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (read_number_db() < 0) {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fprintf(stderr, "error reading number database\n");
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 rec = numdb_lookup_nanp(nanp);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 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
37 if (!rec) {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 puts("NOT owned by us");
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fputs("locally owned, ", stdout);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 switch (rec->usage & NUMBER_USAGE_MASK) {
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 case NUMBER_USAGE_TYPE_RSVD:
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 puts("reserved");
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 break;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case NUMBER_USAGE_TYPE_GSM_SUB:
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 puts("assigned to a GSM subscriber");
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 break;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 case NUMBER_USAGE_TYPE_ALIAS:
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 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
51 rec->remap[1], rec->remap[2]);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 break;
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 default:
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 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
55 }
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 exit(0);
1e548c7a24a1 themwi-check-own: old source as starting point
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }