FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-check-own.c @ 65:7c0309df59f8
sip-in: handling of ALERTING state
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 18 Sep 2022 15:44:22 -0800 |
parents | 26b98505684e |
children | 697fe2c87fec |
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> |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <syslog.h> |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 main(argc, argv) |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 char **argv; |
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 char nanp[11]; |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 if (argc != 2) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 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
|
17 exit(1); |
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 (grok_number_string(argv[1], 1) != 10) |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 goto usage; |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 dehyphen_number_string(argv[1], nanp); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!is_nanp_valid_prefix(nanp)) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fprintf(stderr, "error: number violates NANP rules\n"); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 openlog("themwi-check-own", 0, LOG_LOCAL5); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (read_number_db() < 0) { |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error reading number database\n"); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 printf("+1-%.3s-%.3s-%s is %s\n", nanp, nanp+3, nanp+6, |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 is_nanp_locally_owned(nanp) ? "locally owned" |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 : "NOT owned by us"); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(0); |
26b98505684e
themwi-check-own utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |