FreeCalypso > hg > themwi-system-sw
annotate liboutrt/route_e164.c @ 275:def9f6e4f49e default tip
doc/Use-outside-USA: Fake-NANP-numbers article is here
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 27 Nov 2023 21:49:19 -0800 |
parents | e4a93ad611f3 |
children |
rev | line source |
---|---|
135
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement routing of calls to E.164 numbers. |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <netinet/in.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../include/out_routes.h" |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern struct out_routes_header outrt_hdr; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern struct sip_out_dest *outrt_dest_array; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern struct inn_route *outrt_inn_array; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
265
e4a93ad611f3
liboutrt: add prefix length output arg to route_e164_number()
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
19 route_e164_number(target_num, destp, prefix_len_ret) |
135
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *target_num; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct sip_out_dest **destp; |
265
e4a93ad611f3
liboutrt: add prefix length output arg to route_e164_number()
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
22 int *prefix_len_ret; |
135
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned inn_index; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 struct inn_route *rec; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct sip_out_dest *dest; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char *pp, *tp; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 for (inn_index = 0; inn_index < outrt_hdr.num_inn; inn_index++) { |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rec = outrt_inn_array + inn_index; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 pp = rec->prefix; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 tp = target_num; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 while (*pp && *pp == *tp) { |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 pp++; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 tp++; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (*pp) |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 continue; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 dest = outrt_dest_array + rec->sip_dest_id; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 *destp = dest; |
265
e4a93ad611f3
liboutrt: add prefix length output arg to route_e164_number()
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
41 if (prefix_len_ret) |
e4a93ad611f3
liboutrt: add prefix length output arg to route_e164_number()
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
42 *prefix_len_ret = pp - rec->prefix; |
135
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return 1; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return 0; |
333dbb7ce704
liboutrt: implement E.164 routing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |