FreeCalypso > hg > themwi-system-sw
changeset 134:2b03d2584f88
liboutrt: implement refresh
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 06 Oct 2022 23:31:37 -0800 |
parents | 765991f42d86 |
children | 333dbb7ce704 |
files | liboutrt/Makefile liboutrt/refresh.c |
diffstat | 2 files changed, 58 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liboutrt/Makefile Thu Oct 06 23:15:26 2022 -0800 +++ b/liboutrt/Makefile Thu Oct 06 23:31:37 2022 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= readbin.o +OBJS= readbin.o refresh.o LIB= liboutrt.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboutrt/refresh.c Thu Oct 06 23:31:37 2022 -0800 @@ -0,0 +1,57 @@ +/* + * themwi-sip-out and possibly other similar long-running processes in + * the future need to be able to pick up updates to the outbound call + * routing database without being restarted. Whenever they need to + * consult the route db when handling a new call setup, they will call + * refresh_out_routes_db(), which does a stat on the file, followed by + * a re-read if the file has changed. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <syslog.h> +#include "../include/out_routes.h" + +extern char outrt_pathname[]; +extern struct stat outrt_file_stat; +extern struct sip_out_dest *outrt_dest_array; +extern struct inn_route *outrt_inn_array; +extern struct special_num_route *outrt_spec_array; + +refresh_out_routes_db() +{ + int rc; + struct stat st; + + rc = stat(outrt_pathname, &st); + if (rc < 0) { + syslog(LOG_CRIT, "unable to stat %s for refresh: %m", + outrt_pathname); + return(-1); + } + if (st.st_mtime == outrt_file_stat.st_mtime && + st.st_ctime == outrt_file_stat.st_ctime && + st.st_size == outrt_file_stat.st_size) + return(0); + free(outrt_dest_array); + if (outrt_inn_array) { + free(outrt_inn_array); + outrt_inn_array = 0; + } + if (outrt_spec_array) { + free(outrt_spec_array); + outrt_spec_array = 0; + } + rc = read_out_routes_db(); + if (rc < 0) { + syslog(LOG_CRIT, "error reading %s on refresh!", + outrt_pathname); + exit(1); + } + return(1); +}