view liboutrt/refresh.c @ 267:81958b35f74d

NANP validation: allow made-up area codes of N9X form
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 15:28:09 -0800
parents 2b03d2584f88
children
line wrap: on
line source

/*
 * 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);
}