comparison libnumdb/check_nanp.c @ 10:960ffce6c542

libnumdb: implement NANP lookup
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Jun 2022 13:39:52 -0800
parents
children
comparison
equal deleted inserted replaced
9:2cc790b66359 10:960ffce6c542
1 /*
2 * The library function implemented in this module consults ThemWi number db
3 * to see if a given NANP number is owned by us or not.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include "../include/number_db_file.h"
10
11 extern struct numdb_file_hdr numdb_hdr;
12 extern uint64_t *numdb_owned_numbers;
13
14 static int
15 compare_owned_num(p1, p2)
16 uint64_t *p1, *p2;
17 {
18 if (*p1 < *p2)
19 return(-1);
20 else if (*p1 > *p2)
21 return(1);
22 else
23 return(0);
24 }
25
26 is_nanp_locally_owned(numstr)
27 char *numstr;
28 {
29 uint64_t key, *res;
30
31 if (!numdb_owned_numbers || !numdb_hdr.owned_number_count)
32 return(0);
33 key = strtoull(numstr, 0, 10);
34 res = bsearch(&key, numdb_owned_numbers, numdb_hdr.owned_number_count,
35 sizeof(uint64_t), compare_owned_num);
36 if (res)
37 return(1);
38 else
39 return(0);
40 }