annotate libnumdb/check_nanp.c @ 219:9ba474e918c0

smpp-test1: try sending some ID strings
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 01 Aug 2023 22:56:52 -0800
parents 960ffce6c542
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The library function implemented in this module consults ThemWi number db
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * to see if a given NANP number is owned by us or not.
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "../include/number_db_file.h"
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern struct numdb_file_hdr numdb_hdr;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern uint64_t *numdb_owned_numbers;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static int
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 compare_owned_num(p1, p2)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 uint64_t *p1, *p2;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (*p1 < *p2)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return(-1);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 else if (*p1 > *p2)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(1);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 else
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(0);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 is_nanp_locally_owned(numstr)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 char *numstr;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 uint64_t key, *res;
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (!numdb_owned_numbers || !numdb_hdr.owned_number_count)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(0);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 key = strtoull(numstr, 0, 10);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 res = bsearch(&key, numdb_owned_numbers, numdb_hdr.owned_number_count,
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 sizeof(uint64_t), compare_owned_num);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (res)
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(1);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 else
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(0);
960ffce6c542 libnumdb: implement NANP lookup
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }