# HG changeset patch # User Mychaela Falconia # Date 1665126926 28800 # Node ID 765991f42d86ffe97f29a7b6cd2baf1a8c951f79 # Parent aa278d75d757343e33bd7453016f39b14fa536a2 liboutrt started with binary file reading diff -r aa278d75d757 -r 765991f42d86 liboutrt/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboutrt/Makefile Thu Oct 06 23:15:26 2022 -0800 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= readbin.o +LIB= liboutrt.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r aa278d75d757 -r 765991f42d86 liboutrt/readbin.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboutrt/readbin.c Thu Oct 06 23:15:26 2022 -0800 @@ -0,0 +1,85 @@ +/* + * This library module contains the code that reads /var/gsm/out-routes.bin, + * as well as definitions of global variables into which the booty is read. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../include/out_routes.h" + +char outrt_pathname[] = "/var/gsm/out-routes.bin"; +struct stat outrt_file_stat; +struct out_routes_header outrt_hdr; +struct sip_out_dest *outrt_dest_array; +struct inn_route *outrt_inn_array; +struct special_num_route *outrt_spec_array; + +read_out_routes_db() +{ + FILE *inf; + + inf = fopen(outrt_pathname, "r"); + if (!inf) { + syslog(LOG_CRIT, "open %s: %m", outrt_pathname); + return(-1); + } + fstat(fileno(inf), &outrt_file_stat); + if (!S_ISREG(outrt_file_stat.st_mode)) { + syslog(LOG_CRIT, "invalid %s: not a regular file", + outrt_pathname); + fclose(inf); + return(-1); + } + if (fread(&outrt_hdr, sizeof outrt_hdr, 1, inf) != 1) { +read_err: syslog(LOG_CRIT, "error reading from %s: %m", outrt_pathname); + fclose(inf); + return(-1); + } + if (!outrt_hdr.num_dest) { + syslog(LOG_CRIT, "%s contains invalid data", outrt_pathname); + fclose(inf); + return(-1); + } + outrt_dest_array = + malloc(outrt_hdr.num_dest * sizeof(struct sip_out_dest)); + if (!outrt_dest_array) { + syslog(LOG_CRIT, "malloc for SIP dest array: %m"); + fclose(inf); + return(-1); + } + if (fread(outrt_dest_array, sizeof(struct sip_out_dest), + outrt_hdr.num_dest, inf) != outrt_hdr.num_dest) + goto read_err; + if (outrt_hdr.num_inn) { + outrt_inn_array = + malloc(outrt_hdr.num_inn * sizeof(struct inn_route)); + if (!outrt_inn_array) { + syslog(LOG_CRIT, "malloc for E.164 route array: %m"); + fclose(inf); + return(-1); + } + if (fread(outrt_inn_array, sizeof(struct inn_route), + outrt_hdr.num_inn, inf) != outrt_hdr.num_inn) + goto read_err; + } + if (outrt_hdr.num_special) { + outrt_spec_array = malloc(outrt_hdr.num_special * + sizeof(struct special_num_route)); + if (!outrt_spec_array) { + syslog(LOG_CRIT, "malloc for special route array: %m"); + fclose(inf); + return(-1); + } + if (fread(outrt_spec_array, sizeof(struct special_num_route), + outrt_hdr.num_special, inf) != outrt_hdr.num_special) + goto read_err; + } + fclose(inf); + return(0); +}