annotate liboutrt/refresh.c @ 241:d7c2a2c0b922

utils/Makefile: only using libnumdb2 now
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:42:49 -0800
parents 2b03d2584f88
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
2 * themwi-sip-out and possibly other similar long-running processes in
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
3 * the future need to be able to pick up updates to the outbound call
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
4 * routing database without being restarted. Whenever they need to
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
5 * consult the route db when handling a new call setup, they will call
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
6 * refresh_out_routes_db(), which does a stat on the file, followed by
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
7 * a re-read if the file has changed.
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/stat.h>
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
12 #include <sys/socket.h>
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
13 #include <netinet/in.h>
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdint.h>
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <stdlib.h>
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <syslog.h>
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
18 #include "../include/out_routes.h"
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
20 extern char outrt_pathname[];
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
21 extern struct stat outrt_file_stat;
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
22 extern struct sip_out_dest *outrt_dest_array;
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
23 extern struct inn_route *outrt_inn_array;
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
24 extern struct special_num_route *outrt_spec_array;
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
26 refresh_out_routes_db()
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 int rc;
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct stat st;
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
31 rc = stat(outrt_pathname, &st);
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (rc < 0) {
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 syslog(LOG_CRIT, "unable to stat %s for refresh: %m",
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
34 outrt_pathname);
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
37 if (st.st_mtime == outrt_file_stat.st_mtime &&
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
38 st.st_ctime == outrt_file_stat.st_ctime &&
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
39 st.st_size == outrt_file_stat.st_size)
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(0);
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
41 free(outrt_dest_array);
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
42 if (outrt_inn_array) {
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
43 free(outrt_inn_array);
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
44 outrt_inn_array = 0;
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
46 if (outrt_spec_array) {
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
47 free(outrt_spec_array);
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
48 outrt_spec_array = 0;
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
50 rc = read_out_routes_db();
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (rc < 0) {
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 syslog(LOG_CRIT, "error reading %s on refresh!",
134
2b03d2584f88 liboutrt: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
53 outrt_pathname);
9
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(1);
2cc790b66359 libnumdb: implement refresh
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }