[asterisk-commits] tilghman: trunk r44595 - /trunk/apps/app_rpt.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Oct 6 10:27:31 MST 2006


Author: tilghman
Date: Fri Oct  6 12:27:30 2006
New Revision: 44595

URL: http://svn.digium.com/view/asterisk?rev=44595&view=rev
Log:
Massive cleanup of the rpt code, updating to current coding guidelines

Modified:
    trunk/apps/app_rpt.c

Modified: trunk/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_rpt.c?rev=44595&r1=44594&r2=44595&view=diff
==============================================================================
--- trunk/apps/app_rpt.c (original)
+++ trunk/apps/app_rpt.c Fri Oct  6 12:27:30 2006
@@ -178,16 +178,16 @@
 #define REM_SCANTIME 100
 
 
-enum {REM_OFF,REM_MONITOR,REM_TX};
-
-enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
-	CONNECTED,CONNFAIL,STATUS,TIMEOUT,ID1, STATS_TIME,
+enum {REM_OFF, REM_MONITOR, REM_TX};
+
+enum {ID, PROC, TERM, COMPLETE, UNKEY, REMDISC, REMALREADY, REMNOTFOUND, REMGO,
+	CONNECTED, CONNFAIL, STATUS, TIMEOUT, ID1, STATS_TIME,
 	STATS_VERSION, IDTALKOVER, ARB_ALPHA, TEST_TONE, REV_PATCH,
 	TAILMSG, MACRO_NOTFOUND, MACRO_BUSY, LASTNODEKEY};
 
-enum {REM_SIMPLEX,REM_MINUS,REM_PLUS};
-
-enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
+enum {REM_SIMPLEX, REM_MINUS, REM_PLUS};
+
+enum {REM_LOWPWR, REM_MEDPWR, REM_HIPWR};
 
 enum {DC_INDETERMINATE, DC_REQ_FLUSH, DC_ERROR, DC_COMPLETE, DC_DOKEY};
 
@@ -195,10 +195,10 @@
 
 enum {DLY_TELEM, DLY_ID, DLY_UNKEY, DLY_CALLTERM};
 
-enum {REM_MODE_FM,REM_MODE_USB,REM_MODE_LSB,REM_MODE_AM};
-
-enum {HF_SCAN_OFF,HF_SCAN_DOWN_SLOW,HF_SCAN_DOWN_QUICK,
-      HF_SCAN_DOWN_FAST,HF_SCAN_UP_SLOW,HF_SCAN_UP_QUICK,HF_SCAN_UP_FAST};
+enum {REM_MODE_FM, REM_MODE_USB, REM_MODE_LSB, REM_MODE_AM};
+
+enum {HF_SCAN_OFF, HF_SCAN_DOWN_SLOW, HF_SCAN_DOWN_QUICK,
+      HF_SCAN_DOWN_FAST, HF_SCAN_UP_SLOW, HF_SCAN_UP_QUICK, HF_SCAN_UP_FAST};
 
 #include "asterisk.h"
 
@@ -241,6 +241,7 @@
 #include "asterisk/config.h"
 #include "asterisk/say.h"
 #include "asterisk/localtime.h"
+#include "asterisk/app.h"
 
 static char *app = "Rpt";
 
@@ -288,8 +289,8 @@
 static int nrpts = 0;
 
 char *discstr = "!!DISCONNECT!!";
-static char *remote_rig_ft897="ft897";
-static char *remote_rig_rbi="rbi";
+static char *remote_rig_ft897 = "ft897";
+static char *remote_rig_rbi = "rbi";
 
 #ifdef	OLD_ASTERISK
 STANDARD_LOCAL_USER;
@@ -393,18 +394,17 @@
 	char *remote;
 
 	struct {
-
-		const char *ourcontext;
-		const char *ourcallerid;
-		const char *acctcode;
-		const char *ident;
-		char *tonezone;
+		char ourcontext[80];
+		char ourcallerid[80];
+		char acctcode[21];
+		char ident[80];
+		char tonezone[80];
 		char simple;
-		const char *functions;
-		const char *link_functions;
-		const char *phone_functions;
-		const char *dphone_functions;
-		const char *nodes;
+		char functions[80];
+		char link_functions[80];
+		char phone_functions[80];
+		char dphone_functions[80];
+		char nodes[80];
 		int hangtime;
 		int totime;
 		int idtime;
@@ -412,15 +412,17 @@
 		int tailsquashedtime;
 		int duplex;
 		int politeid;
-		char *tailmessages[500];
-		int tailmessagemax;
-		const char	*memory;
-		const char	*macro;
-		const char	*startupmacro;
+		char *tailmsgbuf;
+		AST_DECLARE_APP_ARGS(tailmsg,
+			AST_APP_ARG(msgs)[100];
+		);
+		char memory[80];
+		char macro[80];
+		char startupmacro[80];
 		int iobase;
 		char funcchar;
 		char endchar;
-		char	nobusyout;
+		char nobusyout;
 	} p;
 	struct rpt_link links;
 	int unkeytocttimer;
@@ -438,24 +440,24 @@
 	char rem_dtmfbuf[MAXDTMF];
 	char lastdtmfcommand[MAXDTMF];
 	char cmdnode[50];
-	struct ast_channel *rxchannel,*txchannel;
-	struct ast_channel *pchannel,*txpchannel, *remchannel;
+	struct ast_channel *rxchannel, *txchannel;
+	struct ast_channel *pchannel, *txpchannel, *remchannel;
 	struct rpt_tele tele;
-	struct timeval lasttv,curtv;
-	pthread_t rpt_call_thread,rpt_thread;
-	time_t dtmf_time,rem_dtmf_time,dtmf_time_rem;
-	int tailtimer,totimer,idtimer,txconf,conf,callmode,cidx,scantimer,tmsgtimer,skedtimer;
-	int mustid,tailid;
+	struct timeval lasttv, curtv;
+	pthread_t rpt_call_thread, rpt_thread;
+	time_t dtmf_time, rem_dtmf_time, dtmf_time_rem;
+	int tailtimer, totimer, idtimer, txconf, conf, callmode, cidx, scantimer, tmsgtimer, skedtimer;
+	int mustid, tailid;
 	int tailevent;
 	int telemrefcount;
-	int dtmfidx,rem_dtmfidx;
-	int dailytxtime,dailykerchunks,totalkerchunks,dailykeyups,totalkeyups,timeouts;
+	int dtmfidx, rem_dtmfidx;
+	int dailytxtime, dailykerchunks, totalkerchunks, dailykeyups, totalkeyups, timeouts;
 	int totalexecdcommands, dailyexecdcommands;
-	long	retxtimer;
+	long retxtimer;
 	long long totaltxtime;
 	char mydtmf;
 	char exten[AST_MAX_EXTENSION];
-	char freq[MAXREMSTR],rxpl[MAXREMSTR],txpl[MAXREMSTR];
+	char freq[MAXREMSTR], rxpl[MAXREMSTR], txpl[MAXREMSTR];
 	char offset;
 	char powerlevel;
 	char txplon;
@@ -481,22 +483,22 @@
 	int tailmessagen;
 	time_t disgorgetime;
 	time_t lastthreadrestarttime;
-	long	macrotimer;
-	char	lastnodewhichkeyedusup[MAXNODESTR];
+	long macrotimer;
+	char lastnodewhichkeyedusup[MAXNODESTR];
 #ifdef	__RPT_NOTCH
 	struct rptfilter
 	{
-		char	desc[100];
-		float	x0;
-		float	x1;
-		float	x2;
-		float	y0;
-		float	y1;
-		float	y2;
-		float	gain;
-		float	const0;
-		float	const1;
-		float	const2;
+		char desc[100];
+		float x0;
+		float x1;
+		float x2;
+		float y0;
+		float y1;
+		float y2;
+		float gain;
+		float const0;
+		float const1;
+		float const2;
 	} filters[MAXFILTERS];
 #endif
 #ifdef	_MDC_DECODE_H_
@@ -512,8 +514,8 @@
 
 #define	MAXLOCKTHREAD 100
 
-#define rpt_mutex_lock(x) _rpt_mutex_lock(x,myrpt,__LINE__)
-#define rpt_mutex_unlock(x) _rpt_mutex_unlock(x,myrpt,__LINE__)
+#define	rpt_mutex_lock(x)	_rpt_mutex_lock(x, myrpt, __LINE__)
+#define	rpt_mutex_unlock(x)	_rpt_mutex_unlock(x, myrpt, __LINE__)
 
 struct lockthread
 {
@@ -539,36 +541,33 @@
 
 static struct lockthread *get_lockthread(pthread_t id)
 {
-int	i;
-
-	for(i = 0; i < MAXLOCKTHREAD; i++)
-	{
-		if (lockthreads[i].id == id) return(&lockthreads[i]);
-	}
-	return(NULL);
-}
-
-static struct lockthread *put_lockthread(pthread_t id)
-{
-int	i;
-
-	for(i = 0; i < MAXLOCKTHREAD; i++)
-	{
+	int	i;
+
+	for (i = 0; i < MAXLOCKTHREAD; i++) {
 		if (lockthreads[i].id == id)
 			return(&lockthreads[i]);
 	}
-	for(i = 0; i < MAXLOCKTHREAD; i++)
-	{
-		if (!lockthreads[i].id)
-		{
+	return NULL;
+}
+
+static struct lockthread *put_lockthread(pthread_t id)
+{
+	int	i;
+
+	for (i = 0; i < MAXLOCKTHREAD; i++) {
+		if (lockthreads[i].id == id)
+			return(&lockthreads[i]);
+	}
+	for (i = 0; i < MAXLOCKTHREAD; i++) {
+		if (!lockthreads[i].id) {
 			lockthreads[i].lockcount = 0;
 			lockthreads[i].lastlock = 0;
 			lockthreads[i].lastunlock = 0;
 			lockthreads[i].id = id;
-			return(&lockthreads[i]);
-		}
-	}
-	return(NULL);
+			return &lockthreads[i];
+		}
+	}
+	return NULL;
 }
 
 
@@ -576,9 +575,9 @@
 {
 	struct by_lightning lock_ring_copy[32];
 	int lock_ring_index_copy;
-	int i,j;
+	int i, j;
 	long long diff;
-	char a[100];
+	char a[100] = "";
 	struct timeval lasttv;
 
 	ast_mutex_lock(&locklock);
@@ -587,30 +586,27 @@
 	ast_mutex_unlock(&locklock);
 
 	lasttv.tv_sec = lasttv.tv_usec = 0;
-	for(i = 0 ; i < 32 ; i++)
-	{
+	for (i = 0; i < 32; i++) {
 		j = (i + lock_ring_index_copy) % 32;
-		strftime(a,sizeof(a) - 1,"%m/%d/%Y %H:%M:%S",
+		strftime(a, sizeof(a) - 1, "%m/%d/%Y %H:%M:%S",
 			localtime(&lock_ring_copy[j].tv.tv_sec));
 		diff = 0;
-		if(lasttv.tv_sec)
-		{
-			diff = (lock_ring_copy[j].tv.tv_sec - lasttv.tv_sec)
-				* 1000000;
+		if (lasttv.tv_sec) {
+			diff = (lock_ring_copy[j].tv.tv_sec - lasttv.tv_sec) * 1000000;
 			diff += (lock_ring_copy[j].tv.tv_usec - lasttv.tv_usec);
 		}
 		lasttv.tv_sec = lock_ring_copy[j].tv.tv_sec;
 		lasttv.tv_usec = lock_ring_copy[j].tv.tv_usec;
-		if (!lock_ring_copy[j].tv.tv_sec) continue;
-		if (lock_ring_copy[j].line < 0)
-		{
-			ast_log(LOG_NOTICE,"LOCKDEBUG [#%d] UNLOCK app_rpt.c:%d node %s pid %x diff %lld us at %s.%06d\n",
-				i - 31,-lock_ring_copy[j].line,lock_ring_copy[j].rpt->name,(int) lock_ring_copy[j].lockthread.id,diff,a,(int)lock_ring_copy[j].tv.tv_usec);
-		}
-		else
-		{
-			ast_log(LOG_NOTICE,"LOCKDEBUG [#%d] LOCK app_rpt.c:%d node %s pid %x diff %lld us at %s.%06d\n",
-				i - 31,lock_ring_copy[j].line,lock_ring_copy[j].rpt->name,(int) lock_ring_copy[j].lockthread.id,diff,a,(int)lock_ring_copy[j].tv.tv_usec);
+		if (!lock_ring_copy[j].tv.tv_sec)
+			continue;
+		if (lock_ring_copy[j].line < 0) {
+			ast_log(LOG_NOTICE, "LOCKDEBUG [#%d] UNLOCK app_rpt.c:%d node %s pid %x diff %lld us at %s.%06d\n",
+				i - 31, -lock_ring_copy[j].line, lock_ring_copy[j].rpt->name,
+				(int) lock_ring_copy[j].lockthread.id, diff, a, (int)lock_ring_copy[j].tv.tv_usec);
+		} else {
+			ast_log(LOG_NOTICE, "LOCKDEBUG [#%d] LOCK app_rpt.c:%d node %s pid %x diff %lld us at %s.%06d\n",
+				i - 31, lock_ring_copy[j].line, lock_ring_copy[j].rpt->name,
+				(int) lock_ring_copy[j].lockthread.id, diff, a, (int)lock_ring_copy[j].tv.tv_usec);
 		}
 	}
 }
@@ -618,22 +614,21 @@
 
 static void _rpt_mutex_lock(ast_mutex_t *lockp, struct rpt *myrpt, int line)
 {
-struct lockthread *t;
-pthread_t id;
+	struct lockthread *t;
+	pthread_t id;
 
 	id = pthread_self();
 	ast_mutex_lock(&locklock);
 	t = put_lockthread(id);
-	if (!t)
-	{
+	if (!t) {
 		ast_mutex_unlock(&locklock);
 		return;
 	}
-	if (t->lockcount)
-	{
+	if (t->lockcount) {
 		int lastline = t->lastlock;
 		ast_mutex_unlock(&locklock);
-		ast_log(LOG_NOTICE,"rpt_mutex_lock: Double lock request line %d node %s pid %x, last lock was line %d\n",line,myrpt->name,(int) t->id,lastline);
+		ast_log(LOG_NOTICE, "rpt_mutex_lock: Double lock request line %d node %s pid %x, last lock was line %d\n",
+				line, myrpt->name, (int) t->id, lastline);
 		rpt_mutex_spew();
 		return;
 	}
@@ -641,9 +636,9 @@
 	t->lockcount = 1;
 	gettimeofday(&lock_ring[lock_ring_index].tv, NULL);
 	lock_ring[lock_ring_index].rpt = myrpt;
-	memcpy(&lock_ring[lock_ring_index].lockthread,t,sizeof(struct lockthread));
+	memcpy(&lock_ring[lock_ring_index].lockthread, t, sizeof(struct lockthread));
 	lock_ring[lock_ring_index++].line = line;
-	if(lock_ring_index == 32)
+	if (lock_ring_index == 32)
 		lock_ring_index = 0;
 	ast_mutex_unlock(&locklock);
 	ast_mutex_lock(lockp);
@@ -652,22 +647,21 @@
 
 static void _rpt_mutex_unlock(ast_mutex_t *lockp, struct rpt *myrpt, int line)
 {
-struct lockthread *t;
-pthread_t id;
+	struct lockthread *t;
+	pthread_t id;
 
 	id = pthread_self();
 	ast_mutex_lock(&locklock);
 	t = put_lockthread(id);
-	if (!t)
-	{
+	if (!t) {
 		ast_mutex_unlock(&locklock);
 		return;
 	}
-	if (!t->lockcount)
-	{
+	if (!t->lockcount) {
 		int lastline = t->lastunlock;
 		ast_mutex_unlock(&locklock);
-		ast_log(LOG_NOTICE,"rpt_mutex_lock: Double un-lock request line %d node %s pid %x, last un-lock was line %d\n",line,myrpt->name,(int) t->id,lastline);
+		ast_log(LOG_NOTICE, "rpt_mutex_lock: Double un-lock request line %d node %s pid %x, last un-lock was line %d\n",
+				line, myrpt->name, (int) t->id, lastline);
 		rpt_mutex_spew();
 		return;
 	}
@@ -675,9 +669,9 @@
 	t->lockcount = 0;
 	gettimeofday(&lock_ring[lock_ring_index].tv, NULL);
 	lock_ring[lock_ring_index].rpt = myrpt;
-	memcpy(&lock_ring[lock_ring_index].lockthread,t,sizeof(struct lockthread));
+	memcpy(&lock_ring[lock_ring_index].lockthread, t, sizeof(struct lockthread));
 	lock_ring[lock_ring_index++].line = -line;
-	if(lock_ring_index == 32)
+	if (lock_ring_index == 32)
 		lock_ring_index = 0;
 	ast_mutex_unlock(&locklock);
 	ast_mutex_unlock(lockp);
@@ -728,27 +722,27 @@
 
 static struct ast_cli_entry cli_rpt[] = {
 	{ { "rpt", "debug", "level" },
-	rpt_do_debug, "Enable app_rpt debugging",
-	debug_usage },
-
-        { { "rpt", "dump" },
-	rpt_do_dump, "Dump app_rpt structs for debugging",
-	dump_usage },
-
-        { { "rpt", "stats" },
-	rpt_do_stats, "Dump node statistics",
-	dump_stats },
-        { { "rpt", "lstats" },
-	rpt_do_lstats, "Dump link statistics",
-	dump_lstats },
-
-        { { "rpt", "reload" },
-	rpt_do_reload, "Reload app_rpt config",
-	reload_usage },
-
-        { { "rpt", "restart" },
-	rpt_do_restart, "Restart app_rpt",
-	restart_usage },
+		rpt_do_debug, "Enable app_rpt debugging",
+		debug_usage },
+
+	{ { "rpt", "dump" },
+		rpt_do_dump, "Dump app_rpt structs for debugging",
+		dump_usage },
+
+	{ { "rpt", "stats" },
+		rpt_do_stats, "Dump node statistics",
+		dump_stats },
+	{ { "rpt", "lstats" },
+		rpt_do_lstats, "Dump link statistics",
+		dump_lstats },
+
+	{ { "rpt", "reload" },
+		rpt_do_reload, "Reload app_rpt config",
+		reload_usage },
+
+	{ { "rpt", "restart" },
+		rpt_do_restart, "Restart app_rpt",
+		restart_usage },
 };
 
 /*
@@ -757,18 +751,18 @@
 
 
 static struct telem_defaults tele_defs[] = {
-	{"ct1","|t(350,0,100,3072)(500,0,100,3072)(660,0,100,3072)"},
-	{"ct2","|t(660,880,150,3072)"},
-	{"ct3","|t(440,0,150,3072)"},
-	{"ct4","|t(550,0,150,3072)"},
-	{"ct5","|t(660,0,150,3072)"},
-	{"ct6","|t(880,0,150,3072)"},
-	{"ct7","|t(660,440,150,3072)"},
-	{"ct8","|t(700,1100,150,3072)"},
-	{"remotemon","|t(1600,0,75,2048)"},
-	{"remotetx","|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048)"},
-	{"cmdmode","|t(900,904,200,2048)"},
-	{"functcomplete","|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)"}
+	{"ct1", "|t(350,0,100,3072)(500,0,100,3072)(660,0,100,3072)"},
+	{"ct2", "|t(660,880,150,3072)"},
+	{"ct3", "|t(440,0,150,3072)"},
+	{"ct4", "|t(550,0,150,3072)"},
+	{"ct5", "|t(660,0,150,3072)"},
+	{"ct6", "|t(880,0,150,3072)"},
+	{"ct7", "|t(660,440,150,3072)"},
+	{"ct8", "|t(700,1100,150,3072)"},
+	{"remotemon", "|t(1600,0,75,2048)"},
+	{"remotetx", "|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048)"},
+	{"cmdmode", "|t(900,904,200,2048)"},
+	{"functcomplete", "|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)"}
 } ;
 
 /*
@@ -805,70 +799,21 @@
 } ;
 
 /*
-* Break up a delimited string into a table of substrings
-*
-* str - delimited string ( will be modified )
-* strp- list of pointers to substrings (this is built by this function), NULL will be placed at end of list
-* limit- maximum number of substrings to process
-*/
-	
-
-
-static int finddelim(char *str, char *strp[], int limit)
-{
-int     i,l,inquo;
-
-        inquo = 0;
-        i = 0;
-        strp[i++] = str;
-        if (!*str)
-           {
-                strp[0] = 0;
-                return(0);
-           }
-        for(l = 0; *str && (l < limit) ; str++)
-           {
-                if (*str == QUOTECHR)
-                   {
-                        if (inquo)
-                           {
-                                *str = 0;
-                                inquo = 0;
-                           }
-                        else
-                           {
-                                strp[i - 1] = str + 1;
-                                inquo = 1;
-                           }
-		}
-                if ((*str == DELIMCHR) && (!inquo))
-                {
-                        *str = 0;
-			l++;
-                        strp[i++] = str + 1;
-                }
-           }
-        strp[i] = 0;
-        return(i);
-
-}
-
-/*
 * Match a keyword in a list, and return index of string plus 1 if there was a match,
 * else return 0. If param is passed in non-null, then it will be set to the first character past the match
 */
 
 static int matchkeyword(char *string, char **param, char *keywords[])
 {
-int	i,ls;
-	for( i = 0 ; keywords[i] ; i++){
+	int	i, ls;
+	for (i = 0; keywords[i]; i++) {
 		ls = strlen(keywords[i]);
-		if(!ls){
+		if (!ls) {
 			*param = NULL;
 			return 0;
 		}
-		if(!strncmp(string, keywords[i], ls)){
-			if(param)
+		if (!strncmp(string, keywords[i], ls)) {
+			if (param)
 				*param = string + ls;
 			return i + 1; 
 		}
@@ -884,15 +829,15 @@
 
 static char *skipchars(char *string, char *charlist)
 {
-int i;	
-	while(*string){
-		for(i = 0; charlist[i] ; i++){
-			if(*string == charlist[i]){
+	int i;	
+	while (*string) {
+		for (i = 0; charlist[i] ; i++) {
+			if (*string == charlist[i]) {
 				string++;
 				break;
 			}
 		}
-		if(!charlist[i])
+		if (!charlist[i])
 			return string;
 	}
 	return string;
@@ -902,11 +847,13 @@
 
 static int myatoi(const char *str)
 {
-int	ret;
-
-	if (str == NULL) return -1;
+	int	ret;
+
+	if (str == NULL)
+		return -1;
 	/* leave this %i alone, non-base-10 input is useful here */
-	if (sscanf(str,"%i",&ret) != 1) return -1;
+	if (sscanf(str, "%i", &ret) != 1)
+		return -1;
 	return ret;
 }
 
@@ -916,20 +863,19 @@
 /* rpt filter routine */
 static void rpt_filter(struct rpt *myrpt, volatile short *buf, int len)
 {
-int	i,j;
-struct	rptfilter *f;
-
-	for(i = 0; i < len; i++)
-	{
-		for(j = 0; j < MAXFILTERS; j++)
-		{
+	int	i, j;
+	struct rptfilter *f;
+
+	for (i = 0; i < len; i++) {
+		for (j = 0; j < MAXFILTERS; j++) {
 			f = &myrpt->filters[j];
-			if (!*f->desc) continue;
+			if (!*f->desc)
+				continue;
 			f->x0 = f->x1; f->x1 = f->x2;
-		        f->x2 = ((float)buf[i]) / f->gain;
-		        f->y0 = f->y1; f->y1 = f->y2;
-		        f->y2 =   (f->x0 + f->x2) +   f->const0 * f->x1
-		                     + (f->const1 * f->y0) + (f->const2 * f->y1);
+			f->x2 = ((float)buf[i]) / f->gain;
+			f->y0 = f->y1; f->y1 = f->y2;
+			f->y2 =   (f->x0 + f->x2)     +  f->const0 * f->x1
+			        + (f->const1 * f->y0) + (f->const2 * f->y1);
 			buf[i] = (short)f->y2;
 		}
 	}
@@ -938,54 +884,52 @@
 #endif
 
 /* Retrieve an int from a config file */
-                                                                                
-static int retrieve_astcfgint(struct rpt *myrpt,char *category, char *name, int min, int max, int defl)
-{
-        const char *var;
-        int ret;
-                                                                                
-        var = ast_variable_retrieve(myrpt->cfg, category, name);
-        if(var){
-                ret = myatoi(var);
-                if(ret < min)
-                        ret = min;
-                if(ret > max)
-                        ret = max;
-        }
-        else
-                ret = defl;
-        return ret;
-}
-
-
-static void load_rpt_vars(int n,int init)
-{
-char *this;
-	const char *val;
-int	j,longestnode;
-struct ast_variable *vp;
-struct ast_config *cfg;
+static int retrieve_astcfgint(struct rpt *myrpt, const char *category, const char *name, int min, int max, int defl)
+{
+	const char *var = ast_variable_retrieve(myrpt->cfg, category, name);
+	int ret;
+
+	if (var) {
+		ret = myatoi(var);
+		if (ret < min)
+			ret = min;
+		else if (ret > max)
+			ret = max;
+	} else
+		ret = defl;
+	return ret;
+}
+
+
+static void load_rpt_vars(int n, int init)
+{
+	int	j;
+	struct ast_variable *vp, *var;
+	struct ast_config *cfg;
 #ifdef	__RPT_NOTCH
-int	i;
-char *strs[100];
+	AST_DECLARE_APP_ARGS(strs,
+		AST_APP_ARG(str)[100];
+	);
 #endif
 
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "%s config for repeater %s\n",
-			(init) ? "Loading initial" : "Re-Loading",rpt_vars[n].name);
+			(init) ? "Loading initial" : "Re-Loading", rpt_vars[n].name);
 	ast_mutex_lock(&rpt_vars[n].lock);
-	if (rpt_vars[n].cfg) ast_config_destroy(rpt_vars[n].cfg);
+	if (rpt_vars[n].cfg)
+		ast_config_destroy(rpt_vars[n].cfg);
 	cfg = ast_config_load("rpt.conf");
 	if (!cfg) {
 		ast_mutex_unlock(&rpt_vars[n].lock);
- 		ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf.  Radio Repeater disabled.\n");
+		ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf.  Radio Repeater disabled.\n");
 		pthread_exit(NULL);
 	}
-	rpt_vars[n].cfg = cfg; 
-	this = rpt_vars[n].name;
- 	memset(&rpt_vars[n].p,0,sizeof(rpt_vars[n].p));
-	if (init)
-	{
+	rpt_vars[n].cfg = cfg;
+	/* Free previously malloc'ed buffer */
+	if (!init && rpt_vars[n].p.tailmsgbuf)
+		ast_free(rpt_vars[n].p.tailmsgbuf);
+	memset(&rpt_vars[n].p, 0, sizeof(rpt_vars[n].p));
+	if (init) {
 		char *cp;
 		int savearea = (char *)&rpt_vars[n].p - (char *)&rpt_vars[n];
 
@@ -999,156 +943,163 @@
 	}
 #ifdef	__RPT_NOTCH
 	/* zot out filters stuff */
-	memset(&rpt_vars[n].filters,0,sizeof(rpt_vars[n].filters));
+	memset(&rpt_vars[n].filters, 0, sizeof(rpt_vars[n].filters));
 #endif
-	val = ast_variable_retrieve(cfg,this,"context");
-	if (val) rpt_vars[n].p.ourcontext = val;
-	else rpt_vars[n].p.ourcontext = this;
-	val = ast_variable_retrieve(cfg,this,"callerid");
-	if (val) rpt_vars[n].p.ourcallerid = val;
-	val = ast_variable_retrieve(cfg,this,"accountcode");
-	if (val) rpt_vars[n].p.acctcode = val;
-	val = ast_variable_retrieve(cfg,this,"idrecording");
-	if (val) rpt_vars[n].p.ident = val;
-	val = ast_variable_retrieve(cfg,this,"hangtime");
-	if (val) rpt_vars[n].p.hangtime = atoi(val);
-		else rpt_vars[n].p.hangtime = HANGTIME;
-	val = ast_variable_retrieve(cfg,this,"totime");
-	if (val) rpt_vars[n].p.totime = atoi(val);
-		else rpt_vars[n].p.totime = TOTIME;
-	rpt_vars[n].p.tailmessagetime = retrieve_astcfgint(&rpt_vars[n],this, "tailmessagetime", 0, 2400000, 0);		
-	rpt_vars[n].p.tailsquashedtime = retrieve_astcfgint(&rpt_vars[n],this, "tailsquashedtime", 0, 2400000, 0);		
-	rpt_vars[n].p.duplex = retrieve_astcfgint(&rpt_vars[n],this,"duplex",0,4,2);
-	rpt_vars[n].p.idtime = retrieve_astcfgint(&rpt_vars[n],this, "idtime", 60000, 2400000, IDTIME);	/* Enforce a min max */
-	rpt_vars[n].p.politeid = retrieve_astcfgint(&rpt_vars[n],this, "politeid", 30000, 300000, POLITEID); /* Enforce a min max */
-	val = ast_variable_retrieve(cfg,this,"tonezone");
-	if (val) rpt_vars[n].p.tonezone = ast_strdupa(val);
-	rpt_vars[n].p.tailmessages[0] = 0;
-	rpt_vars[n].p.tailmessagemax = 0;
-	val = ast_variable_retrieve(cfg,this,"tailmessagelist");
-	if (val) rpt_vars[n].p.tailmessagemax = finddelim(ast_strdupa(val), rpt_vars[n].p.tailmessages, 500);
-	val = ast_variable_retrieve(cfg,this,"memory");
-	if (!val) val = MEMORY;
-	rpt_vars[n].p.memory = val;
-	val = ast_variable_retrieve(cfg,this,"macro");
-	if (!val) val = MACRO;
-	rpt_vars[n].p.macro = val;
-	val = ast_variable_retrieve(cfg,this,"startup_macro");
-	if (val) rpt_vars[n].p.startupmacro = val;
-	val = ast_variable_retrieve(cfg,this,"iobase");
-	/* do not use atoi() here, we need to be able to have
-		the input specified in hex or decimal so we use
-		sscanf with a %i */
-	if ((!val) || (sscanf(val,"%i",&rpt_vars[n].p.iobase) != 1))
+
+	/* Defaults */
+	ast_copy_string(rpt_vars[n].p.ourcontext, rpt_vars[n].name, sizeof(rpt_vars[n].p.ourcontext));
+	rpt_vars[n].p.hangtime = HANGTIME;
+	rpt_vars[n].p.totime = TOTIME;
+	rpt_vars[n].p.duplex = 2;
+	rpt_vars[n].p.idtime = IDTIME;
+	rpt_vars[n].p.politeid = POLITEID;
+	ast_copy_string(rpt_vars[n].p.memory, MEMORY, sizeof(rpt_vars[n].p.memory));
+	ast_copy_string(rpt_vars[n].p.macro, MACRO, sizeof(rpt_vars[n].p.macro));
 	rpt_vars[n].p.iobase = DEFAULT_IOBASE;
-	val = ast_variable_retrieve(cfg,this,"functions");
-	if (!val)
-		{
-			val = FUNCTIONS;
-			rpt_vars[n].p.simple = 1;
-		} 
-	rpt_vars[n].p.functions = val;
-	val =  ast_variable_retrieve(cfg,this,"link_functions");
-	if (val) rpt_vars[n].p.link_functions = val;
-	else 
-		rpt_vars[n].p.link_functions = rpt_vars[n].p.functions;
-	val = ast_variable_retrieve(cfg,this,"phone_functions");
-	if (val) rpt_vars[n].p.phone_functions = val;
-	val = ast_variable_retrieve(cfg,this,"dphone_functions");
-	if (val) rpt_vars[n].p.dphone_functions = val;
-	val = ast_variable_retrieve(cfg,this,"funcchar");
-	if (!val) rpt_vars[n].p.funcchar = FUNCCHAR; else 
-		rpt_vars[n].p.funcchar = *val;		
-	val = ast_variable_retrieve(cfg,this,"endchar");
-	if (!val) rpt_vars[n].p.endchar = ENDCHAR; else 
-		rpt_vars[n].p.endchar = *val;		
-	val = ast_variable_retrieve(cfg,this,"nobusyout");
-	if (val) rpt_vars[n].p.nobusyout = ast_true(val);
-	val = ast_variable_retrieve(cfg,this,"nodes");
-	if (!val) val = NODES;
-	rpt_vars[n].p.nodes = val;
+	ast_copy_string(rpt_vars[n].p.functions, FUNCTIONS, sizeof(rpt_vars[n].p.functions));
+	rpt_vars[n].p.simple = 1;
+	rpt_vars[n].p.funcchar = FUNCCHAR;
+	rpt_vars[n].p.endchar = ENDCHAR;
+	ast_copy_string(rpt_vars[n].p.nodes, NODES, sizeof(rpt_vars[n].p.nodes));
+
+	for (var = ast_variable_browse(cfg, rpt_vars[n].name); var; var = var->next) {
+		if (!strcmp(var->name, "context")) {
+			ast_copy_string(rpt_vars[n].p.ourcontext, var->value, sizeof(rpt_vars[n].p.ourcontext));
+		} else if (!strcmp(var->name, "callerid")) {
+			ast_copy_string(rpt_vars[n].p.ourcallerid, var->value, sizeof(rpt_vars[n].p.ourcallerid));
+		} else if (!strcmp(var->name, "accountcode")) {
+			ast_copy_string(rpt_vars[n].p.acctcode, var->value, sizeof(rpt_vars[n].p.acctcode));
+		} else if (!strcmp(var->name, "idrecording")) {
+			ast_copy_string(rpt_vars[n].p.ident, var->value, sizeof(rpt_vars[n].p.ident));
+		} else if (!strcmp(var->name, "hangtime")) {
+			rpt_vars[n].p.hangtime = atoi(var->value);
+		} else if (!strcmp(var->name, "totime")) {
+			rpt_vars[n].p.totime = atoi(var->value);
+		} else if (!strcmp(var->name, "tailmessagetime")) {
+			rpt_vars[n].p.tailmessagetime = atoi(var->value);
+			if (rpt_vars[n].p.tailmessagetime < 0)
+				rpt_vars[n].p.tailmessagetime = 0;
+			else if (rpt_vars[n].p.tailmessagetime > 2400000)
+				rpt_vars[n].p.tailmessagetime = 2400000;
+		} else if (!strcmp(var->name, "tailsquashedtime")) {
+			rpt_vars[n].p.tailsquashedtime = atoi(var->value);
+			if (rpt_vars[n].p.tailsquashedtime < 0)
+				rpt_vars[n].p.tailsquashedtime = 0;
+			else if (rpt_vars[n].p.tailsquashedtime > 2400000)
+				rpt_vars[n].p.tailsquashedtime = 2400000;
+		} else if (!strcmp(var->name, "duplex")) {
+			rpt_vars[n].p.duplex = atoi(var->value);
+			if (rpt_vars[n].p.duplex < 0)
+				rpt_vars[n].p.duplex = 0;
+			else if (rpt_vars[n].p.duplex > 4)
+				rpt_vars[n].p.duplex = 4;
+		} else if (!strcmp(var->name, "idtime")) {
+			rpt_vars[n].p.idtime = atoi(var->value);
+			if (rpt_vars[n].p.idtime < 60000)
+				rpt_vars[n].p.idtime = 60000;
+			else if (rpt_vars[n].p.idtime > 2400000)
+				rpt_vars[n].p.idtime = 2400000;
+		} else if (!strcmp(var->name, "politeid")) {
+			rpt_vars[n].p.politeid = atoi(var->value);
+			if (rpt_vars[n].p.politeid < 30000)
+				rpt_vars[n].p.politeid = 30000;
+			else if (rpt_vars[n].p.politeid > 300000)
+				rpt_vars[n].p.politeid = 300000;
+		} else if (!strcmp(var->name, "tonezone")) {
+			ast_copy_string(rpt_vars[n].p.tonezone, var->value, sizeof(rpt_vars[n].p.tonezone));
+		} else if (!strcmp(var->name, "tailmessagelist")) {
+			rpt_vars[n].p.tailmsgbuf = ast_strdup(var->value);
+			AST_NONSTANDARD_APP_ARGS(rpt_vars[n].p.tailmsg, rpt_vars[n].p.tailmsgbuf, ',');
+		} else if (!strcmp(var->name, "memory")) {
+			ast_copy_string(rpt_vars[n].p.memory, var->value, sizeof(rpt_vars[n].p.memory));
+		} else if (!strcmp(var->name, "macro")) {
+			ast_copy_string(rpt_vars[n].p.macro, var->value, sizeof(rpt_vars[n].p.macro));
+		} else if (!strcmp(var->name, "startup_macro")) {
+			ast_copy_string(rpt_vars[n].p.startupmacro, var->value, sizeof(rpt_vars[n].p.startupmacro));
+		} else if (!strcmp(var->name, "iobase")) {
+			/* do not use atoi() here, we need to be able to have
+			   the input specified in hex or decimal so we use
+			   sscanf with a %i */
+			if (sscanf(var->value, "%i", &rpt_vars[n].p.iobase) != 1)
+				rpt_vars[n].p.iobase = DEFAULT_IOBASE;
+		} else if (!strcmp(var->name, "functions")) {
+			rpt_vars[n].p.simple = 0;
+			ast_copy_string(rpt_vars[n].p.functions, var->value, sizeof(rpt_vars[n].p.functions));
+		} else if (!strcmp(var->name, "link_functions")) {
+			ast_copy_string(rpt_vars[n].p.link_functions, var->value, sizeof(rpt_vars[n].p.link_functions));
+		} else if (!strcmp(var->name, "phone_functions")) {
+			ast_copy_string(rpt_vars[n].p.phone_functions, var->value, sizeof(rpt_vars[n].p.phone_functions));
+		} else if (!strcmp(var->name, "dphone_functions")) {
+			ast_copy_string(rpt_vars[n].p.dphone_functions, var->value, sizeof(rpt_vars[n].p.dphone_functions));
+		} else if (!strcmp(var->name, "funcchar")) {
+			rpt_vars[n].p.funcchar = *var->value;
+		} else if (!strcmp(var->name, "endchar")) {
+			rpt_vars[n].p.endchar = *var->value;
+		} else if (!strcmp(var->name, "nobusyout")) {
+			rpt_vars[n].p.nobusyout = ast_true(var->value);
+		} else if (!strcmp(var->name, "nodes")) {
+			ast_copy_string(rpt_vars[n].p.nodes, var->value, sizeof(rpt_vars[n].p.nodes));
 #ifdef	__RPT_NOTCH
-	val = ast_variable_retrieve(cfg,this,"rxnotch");
-	if (val) {
-		i = finddelim(ast_strdupa(val),strs,MAXFILTERS * 2);
-		i &= ~1; /* force an even number, rounded down */
-		if (i >= 2) for(j = 0; j < i; j += 2)
-		{
-			rpt_mknotch(atof(strs[j]),atof(strs[j + 1]),
-			  &rpt_vars[n].filters[j >> 1].gain,
-			    &rpt_vars[n].filters[j >> 1].const0,
-				&rpt_vars[n].filters[j >> 1].const1,
-				    &rpt_vars[n].filters[j >> 1].const2);
-			sprintf(rpt_vars[n].filters[j >> 1].desc,"%s Hz, BW = %s",
-				strs[j],strs[j + 1]);
-		}
-
-	}
+		} else if (!strcmp(var->name, "rxnotch")) {
+			char *tmp = ast_strdupa(val);
+			AST_NONSTANDARD_APP_ARGS(strs, tmp, ',');
+			strs.argc &= ~1; /* force an even number, rounded down */
+			if (strs.argc >= 2) {
+				for (j = 0; j < strs.argc; j += 2) {
+					rpt_mknotch(atof(strs.str[j]),atof(strs.str[j + 1]),
+						&rpt_vars[n].filters[j >> 1].gain,
+						&rpt_vars[n].filters[j >> 1].const0,
+						&rpt_vars[n].filters[j >> 1].const1,
+						&rpt_vars[n].filters[j >> 1].const2);
+					sprintf(rpt_vars[n].filters[j >> 1].desc, "%s Hz, BW = %s",
+						strs.str[j], strs.str[j + 1]);
+				}
+			}
 #endif
-	longestnode = 0;
-
-	vp = ast_variable_browse(cfg, rpt_vars[n].p.nodes);
-		
-	while(vp){
-		j = strlen(vp->name);
-		if (j > longestnode)
-			longestnode = j;
-		vp = vp->next;
-	}
-
-	rpt_vars[n].longestnode = longestnode;
-		
+		}
+	}
+
+	/* If these aren't specified, copy them from the functions property. */
+	if (ast_strlen_zero(rpt_vars[n].p.link_functions))
+		ast_copy_string(rpt_vars[n].p.link_functions, rpt_vars[n].p.functions, sizeof(rpt_vars[n].p.link_functions));
+
+	rpt_vars[n].longestnode = 0;
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.nodes); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].longestnode)
+			rpt_vars[n].longestnode = j;
+	}
+
 	/*
 	* For this repeater, Determine the length of the longest function 
 	*/
 	rpt_vars[n].longestfunc = 0;
-	vp = ast_variable_browse(cfg, rpt_vars[n].p.functions);
-	while(vp){
-		j = strlen(vp->name);
-		if (j > rpt_vars[n].longestfunc)
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.functions); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].longestfunc)
 			rpt_vars[n].longestfunc = j;
-		vp = vp->next;
-	}
-	/*
-	* For this repeater, Determine the length of the longest function 
-	*/
+	}
+
 	rpt_vars[n].link_longestfunc = 0;
-	vp = ast_variable_browse(cfg, rpt_vars[n].p.link_functions);
-	while(vp){
-		j = strlen(vp->name);
-		if (j > rpt_vars[n].link_longestfunc)
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.link_functions); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].link_longestfunc)
 			rpt_vars[n].link_longestfunc = j;
-		vp = vp->next;
-	}
+	}
+
 	rpt_vars[n].phone_longestfunc = 0;
-	if (rpt_vars[n].p.phone_functions)
-	{
-		vp = ast_variable_browse(cfg, rpt_vars[n].p.phone_functions);
-		while(vp){
-			j = strlen(vp->name);
-			if (j > rpt_vars[n].phone_longestfunc)
-				rpt_vars[n].phone_longestfunc = j;
-			vp = vp->next;
-		}
-	}
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.phone_functions); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].phone_longestfunc)
+			rpt_vars[n].phone_longestfunc = j;
+	}
+
 	rpt_vars[n].dphone_longestfunc = 0;
-	if (rpt_vars[n].p.dphone_functions)
-	{
-		vp = ast_variable_browse(cfg, rpt_vars[n].p.dphone_functions);
-		while(vp){
-			j = strlen(vp->name);
-			if (j > rpt_vars[n].dphone_longestfunc)
-				rpt_vars[n].dphone_longestfunc = j;
-			vp = vp->next;
-		}
-	}
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.dphone_functions); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].dphone_longestfunc)
+			rpt_vars[n].dphone_longestfunc = j;
+	}
+
 	rpt_vars[n].macro_longest = 1;
-	vp = ast_variable_browse(cfg, rpt_vars[n].p.macro);
-	while(vp){
-		j = strlen(vp->name);
-		if (j > rpt_vars[n].macro_longest)
+	for (vp = ast_variable_browse(cfg, rpt_vars[n].p.macro); vp; vp = vp->next) {
+		if ((j = strlen(vp->name)) > rpt_vars[n].macro_longest)
 			rpt_vars[n].macro_longest = j;
-		vp = vp->next;
 	}
 	ast_mutex_unlock(&rpt_vars[n].lock);
 }
@@ -1156,43 +1107,39 @@
 /*
 * Enable or disable debug output at a given level at the console
 */
-                                                                                                                                 
 static int rpt_do_debug(int fd, int argc, char *argv[])
 {
 	int newlevel;
 
-        if (argc != 4)
-                return RESULT_SHOWUSAGE;
-        newlevel = myatoi(argv[3]);
-        if((newlevel < 0) || (newlevel > 7))
-                return RESULT_SHOWUSAGE;
-        if(newlevel)
-                ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel);
-        else
-                ast_cli(fd, "app_rpt Debugging disabled\n");
-
-        debug = newlevel;                                                                                                                          
-        return RESULT_SUCCESS;
+	if (argc != 4)
+		return RESULT_SHOWUSAGE;
+	newlevel = myatoi(argv[3]);
+	if ((newlevel < 0) || (newlevel > 7))
+		return RESULT_SHOWUSAGE;
+	if (newlevel)
+		ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel);
+	else
+		ast_cli(fd, "app_rpt Debugging disabled\n");
+
+	debug = newlevel;                                                                                                                          
+	return RESULT_SUCCESS;
 }
 
 /*
 * Dump rpt struct debugging onto console
 */
-                                                                                                                                 
 static int rpt_do_dump(int fd, int argc, char *argv[])
 {
 	int i;
 
-        if (argc != 3)
-                return RESULT_SHOWUSAGE;
-
-	for(i = 0; i < nrpts; i++)
-	{
-		if (!strcmp(argv[2],rpt_vars[i].name))
-		{
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+
+	for (i = 0; i < nrpts; i++) {
+		if (!strcmp(argv[2], rpt_vars[i].name)) {
 			rpt_vars[i].disgorgetime = time(NULL) + 10; /* Do it 10 seconds later */
-		        ast_cli(fd, "app_rpt struct dump requested for node %s\n",argv[2]);
-		        return RESULT_SUCCESS;
+			ast_cli(fd, "app_rpt struct dump requested for node %s\n",argv[2]);
+			return RESULT_SUCCESS;
 		}
 	}
 	return RESULT_FAILURE;
@@ -1201,15 +1148,14 @@
 /*
 * Dump statistics onto console
 */
-
 static int rpt_do_stats(int fd, int argc, char *argv[])
 {
-	int i,j;
+	int i, j;
 	int dailytxtime, dailykerchunks;
 	int totalkerchunks, dailykeyups, totalkeyups, timeouts;
 	int totalexecdcommands, dailyexecdcommands, hours, minutes, seconds;
 	long long totaltxtime;
-	struct	rpt_link *l;
+	struct rpt_link *l;
 	char *listoflinks[MAX_STAT_LINKS];	
 	char *lastnodewhichkeyedusup, *lastdtmfcommand;
 	char *tot_state, *ider_state, *patch_state;
@@ -1218,10 +1164,10 @@
 
 	static char *not_applicable = "N/A";
 
-	if(argc != 3)
+	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 
-	for(i = 0 ; i <= MAX_STAT_LINKS; i++)
+	for (i = 0 ; i <= MAX_STAT_LINKS; i++)
 		listoflinks[i] = NULL;
 
 	tot_state = ider_state = 
@@ -1229,9 +1175,8 @@
 	input_signal = called_number = 
 	lastdtmfcommand = not_applicable;
 
-	for(i = 0; i < nrpts; i++)
-	{
-		if (!strcmp(argv[2],rpt_vars[i].name)){
+	for (i = 0; i < nrpts; i++) {
+		if (!strcmp(argv[2], rpt_vars[i].name)) {
 			/* Make a copy of all stat variables while locked */
 			myrpt = &rpt_vars[i];
 			rpt_mutex_lock(&myrpt->lock); /* LOCK */
@@ -1250,76 +1195,68 @@
 			reverse_patch_state = "DOWN";
 			j = 0;
 			l = myrpt->links.next;
-			while(l != &myrpt->links){
-				if (l->name[0] == '0'){ /* Skip '0' nodes */
+			while (l != &myrpt->links) {
+				if (l->name[0] == '0') { /* Skip '0' nodes */
 					reverse_patch_state = "UP";
 					l = l->next;
 					continue;
 				}
 				listoflinks[j] = ast_strdupa(l->name);
-				if(listoflinks[j])
+				if (listoflinks[j])
 					j++;
 				l = l->next;
 			}
 
 			lastnodewhichkeyedusup = ast_strdupa(myrpt->lastnodewhichkeyedusup);			
-			if((!lastnodewhichkeyedusup) || (!strlen(lastnodewhichkeyedusup)))
+			if ((!lastnodewhichkeyedusup) || (ast_strlen_zero(lastnodewhichkeyedusup)))
 				lastnodewhichkeyedusup = not_applicable;
 
-			if(myrpt->keyed)
+			if (myrpt->keyed)
 				input_signal = "YES";
 			else
 				input_signal = "NO";
 
-			if(myrpt->enable)
+			if (myrpt->enable)
 				enable_state = "YES";
 			else
 				enable_state = "NO";
 
-			if(!myrpt->totimer)
+			if (!myrpt->totimer)
 				tot_state = "TIMED OUT!";
-			else if(myrpt->totimer != myrpt->p.totime)
+			else if (myrpt->totimer != myrpt->p.totime)
 				tot_state = "ARMED";
 			else
 				tot_state = "RESET";
 
-			if(myrpt->tailid)
+			if (myrpt->tailid)
 				ider_state = "QUEUED IN TAIL";
-			else if(myrpt->mustid)
+			else if (myrpt->mustid)
 				ider_state = "QUEUED FOR CLEANUP";
 			else
 				ider_state = "CLEAN";
 
-			switch(myrpt->callmode){
-				case 1:
-					patch_state = "DIALING";
-					break;
-				case 2:
-					patch_state = "CONNECTING";
-					break;
-				case 3:
-					patch_state = "UP";
-					break;
-
-				case 4:
-					patch_state = "CALL FAILED";
-					break;
-
-				default:
-					patch_state = "DOWN";
-			}
-
-			if(strlen(myrpt->exten)){
+			switch (myrpt->callmode) {
+			case 1:
+				patch_state = "DIALING";
+				break;
+			case 2:
+				patch_state = "CONNECTING";
+				break;
+			case 3:
+				patch_state = "UP";
+				break;
+			case 4:
+				patch_state = "CALL FAILED";
+				break;
+			default:
+				patch_state = "DOWN";
+			}
+
+			if (!ast_strlen_zero(myrpt->exten))
 				called_number = ast_strdupa(myrpt->exten);
-				if(!called_number)
-					called_number = not_applicable;
-			}
-
-			if(strlen(myrpt->lastdtmfcommand)){
+
+			if (!ast_strlen_zero(myrpt->lastdtmfcommand))
 				lastdtmfcommand = ast_strdupa(myrpt->lastdtmfcommand);
-				if(!lastdtmfcommand)
-					lastdtmfcommand = not_applicable;
-			}
 
 			rpt_mutex_unlock(&myrpt->lock); /* UNLOCK */
 
@@ -1337,51 +1274,50 @@
 			ast_cli(fd, "DTMF commands since system initialization........: %d\n", totalexecdcommands);
 			ast_cli(fd, "Last DTMF command executed.......................: %s\n", lastdtmfcommand);
 
-			hours = dailytxtime/3600000;
+			hours = dailytxtime / 3600000;
 			dailytxtime %= 3600000;
-			minutes = dailytxtime/60000;
+			minutes = dailytxtime / 60000;
 			dailytxtime %= 60000;
-			seconds = dailytxtime/1000;
+			seconds = dailytxtime / 1000;
 			dailytxtime %= 1000;
 
 			ast_cli(fd, "TX time today ...................................: %02d:%02d:%02d.%d\n",
 				hours, minutes, seconds, dailytxtime);
 
-			hours = (int) totaltxtime/3600000;
+			hours = (int) totaltxtime / 3600000;
 			totaltxtime %= 3600000;
-			minutes = (int) totaltxtime/60000;
+			minutes = (int) totaltxtime / 60000;
 			totaltxtime %= 60000;
-			seconds = (int)  totaltxtime/1000;
+			seconds = (int)  totaltxtime / 1000;
 			totaltxtime %= 1000;
 
 			ast_cli(fd, "TX time since system initialization..............: %02d:%02d:%02d.%d\n",
 				 hours, minutes, seconds, (int) totaltxtime);
 			ast_cli(fd, "Nodes currently connected to us..................: ");
-			for(j = 0 ;; j++){
-				if(!listoflinks[j]){
-					if(!j){
-						ast_cli(fd,"<NONE>");
+			for (j = 0;; j++) {
+				if (!listoflinks[j]) {
+					if (!j) {
+						ast_cli(fd, "<NONE>");
 					}
 					break;
 				}
 				ast_cli(fd, "%s", listoflinks[j]);
-				if(j % 4 == 3){
+				if (j % 4 == 3) {
 					ast_cli(fd, "\n");
 					ast_cli(fd, "                                                 : ");
-				}
-				else{
-					if(listoflinks[j + 1])
+				} else {
+					if (listoflinks[j + 1])
 						ast_cli(fd, ", ");
 				}
 			}
-			ast_cli(fd,"\n");
+			ast_cli(fd, "\n");
 

[... 9018 lines stripped ...]


More information about the asterisk-commits mailing list