comparison liboutrt/refresh.c @ 134:2b03d2584f88

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