[asterisk-commits] russell: branch russell/events r102965 - in /team/russell/events: ./ apps/ ch...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 7 19:12:21 CST 2008


Author: russell
Date: Thu Feb  7 19:12:20 2008
New Revision: 102965

URL: http://svn.digium.com/view/asterisk?view=rev&rev=102965
Log:
resolve, reset

Modified:
    team/russell/events/   (props changed)
    team/russell/events/apps/app_adsiprog.c
    team/russell/events/apps/app_alarmreceiver.c
    team/russell/events/apps/app_chanspy.c
    team/russell/events/apps/app_dial.c
    team/russell/events/apps/app_dumpchan.c
    team/russell/events/apps/app_followme.c
    team/russell/events/apps/app_minivm.c
    team/russell/events/apps/app_privacy.c
    team/russell/events/apps/app_queue.c
    team/russell/events/apps/app_voicemail.c
    team/russell/events/apps/app_zapras.c
    team/russell/events/channels/chan_mgcp.c
    team/russell/events/channels/chan_sip.c
    team/russell/events/channels/chan_unistim.c
    team/russell/events/channels/chan_usbradio.c
    team/russell/events/configs/features.conf.sample
    team/russell/events/configs/zapata.conf.sample
    team/russell/events/configure
    team/russell/events/configure.ac
    team/russell/events/funcs/func_realtime.c
    team/russell/events/include/asterisk/autoconfig.h.in
    team/russell/events/main/asterisk.c
    team/russell/events/main/astmm.c
    team/russell/events/main/features.c
    team/russell/events/main/loader.c
    team/russell/events/main/logger.c
    team/russell/events/main/pbx.c
    team/russell/events/main/tcptls.c
    team/russell/events/res/res_agi.c
    team/russell/events/res/res_clioriginate.c
    team/russell/events/res/res_jabber.c
    team/russell/events/utils/muted.c

Propchange: team/russell/events/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/russell/events/
------------------------------------------------------------------------------
Binary property 'branch-1.4-blocked' - no diff available.

Propchange: team/russell/events/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/russell/events/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Feb  7 19:12:20 2008
@@ -1,1 +1,1 @@
-/trunk:1-102317
+/trunk:1-102964

Modified: team/russell/events/apps/app_adsiprog.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/apps/app_adsiprog.c?view=diff&rev=102965&r1=102964&r2=102965
==============================================================================
--- team/russell/events/apps/app_adsiprog.c (original)
+++ team/russell/events/apps/app_adsiprog.c Thu Feb  7 19:12:20 2008
@@ -21,7 +21,7 @@
  * \brief Program Asterisk ADSI Scripts into phone
  *
  * \author Mark Spencer <markster at digium.com>
- * 
+ *
  * \ingroup applications
  */
 
@@ -36,7 +36,7 @@
 #include <netinet/in.h>
 #include <ctype.h>
 
-#include "asterisk/paths.h"	/* use ast_config_AST_CONFIG_DIR */
+#include "asterisk/paths.h" /* use ast_config_AST_CONFIG_DIR */
 #include "asterisk/file.h"
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
@@ -94,25 +94,25 @@
 	{ 3, "INDENT" },
 };
 
-#define STATE_NORMAL		0
-#define STATE_INKEY		1
-#define STATE_INSUB		2
-#define STATE_INIF		3
-
-#define MAX_RET_CODE		20
-#define MAX_SUB_LEN		255
-#define MAX_MAIN_LEN		1600
-
-#define ARG_STRING		(1 << 0)
-#define ARG_NUMBER		(1 << 1)
+#define STATE_NORMAL 0
+#define STATE_INKEY  1
+#define STATE_INSUB  2
+#define STATE_INIF   3
+
+#define MAX_RET_CODE 20
+#define MAX_SUB_LEN  255
+#define MAX_MAIN_LEN 1600
+
+#define ARG_STRING (1 << 0)
+#define ARG_NUMBER (1 << 1)
 
 struct adsi_soft_key {
-	char vname[40];		/* Which "variable" is associated with it */
-	int retstrlen;		/* Length of return string */
-	int initlen;		/* initial length */
+	char vname[40];  /* Which "variable" is associated with it */
+	int retstrlen;   /* Length of return string */
+	int initlen;     /* initial length */
 	int id;
 	int defined;
-	char retstr[80];	/* Return string data */
+	char retstr[80]; /* Return string data */
 };
 
 struct adsi_subscript {
@@ -267,7 +267,7 @@
 
 	a = dtmfstr;
 
-	while(*a) {
+	while (*a) {
 		if (strchr(validdtmf, *a)) {
 			*buf = *a;
 			buf++;
@@ -292,11 +292,11 @@
 		return 0;
 	}
 
-	if (!strcasecmp(page, "INFO")) {
+	if (!strcasecmp(page, "INFO"))
 		cmd = 0;
-	} else if (!strcasecmp(page, "COMM")) {
+	else if (!strcasecmp(page, "COMM"))
 		cmd = 0x80;
-	} else {
+	else {
 		ast_log(LOG_WARNING, "Expecting either 'INFO' or 'COMM' page, got got '%s' at line %d of %s\n", page, lineno, script);
 		return 0;
 	}
@@ -325,11 +325,11 @@
 		return 0;
 	}
 
-	if (!strcasecmp(dir, "UP")) {
+	if (!strcasecmp(dir, "UP"))
 		cmd = 0;
-	} else if (!strcasecmp(dir, "DOWN")) {
+	else if (!strcasecmp(dir, "DOWN"))
 		cmd = 0x20;
-	} else {
+	else {
 		ast_log(LOG_WARNING, "Expecting either 'UP' or 'DOWN' direction, got '%s' at line %d of %s\n", dir, lineno, script);
 		return 0;
 	}
@@ -396,7 +396,7 @@
 {
 	char *tok = get_token(&args, script, lineno);
 
-	if (tok) 
+	if (tok)
 		ast_log(LOG_WARNING, "Clearing timer requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
 
 	buf[0] = id;
@@ -415,7 +415,7 @@
 	int x;
 
 	for (x = 0; x < state->numflags; x++) {
-		if (!strcasecmp(state->flags[x].vname, name)) 
+		if (!strcasecmp(state->flags[x].vname, name))
 			return &state->flags[x];
 	}
 
@@ -540,7 +540,7 @@
 	int x;
 
 	for (x = 0; x < state->numkeys; x++) {
-		if (!strcasecmp(state->keys[x].vname, name)) 
+		if (!strcasecmp(state->keys[x].vname, name))
 			return &state->keys[x];
 	}
 
@@ -561,7 +561,7 @@
 	int x;
 
 	for (x = 0; x < state->numsubs; x++) {
-		if (!strcasecmp(state->subs[x].vname, name)) 
+		if (!strcasecmp(state->subs[x].vname, name))
 			return &state->subs[x];
 	}
 
@@ -582,7 +582,7 @@
 	int x;
 
 	for (x = 0; x <state->numstates; x++) {
-		if (!strcasecmp(state->states[x].vname, name)) 
+		if (!strcasecmp(state->states[x].vname, name))
 			return &state->states[x];
 	}
 
@@ -607,7 +607,7 @@
 	int x;
 
 	for (x = 0; x < state->numdisplays; x++) {
-		if (!strcasecmp(state->displays[x].vname, name)) 
+		if (!strcasecmp(state->displays[x].vname, name))
 			return &state->displays[x];
 	}
 
@@ -641,13 +641,13 @@
 			break;
 		if (!strcasecmp(tok, "UNLESS")) {
 			/* Check for trailing UNLESS flag */
-			if (!(tok = get_token(&args, script, lineno))) {
+			if (!(tok = get_token(&args, script, lineno)))
 				ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script);
-			} else if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) {
+			else if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING))
 				ast_log(LOG_WARNING, "Invalid flag name '%s' at line %d of %s\n", tok, lineno, script);
-			} else if (!(flag = getflagbyname(state, newkey, script, lineno, 0))) {
+			else if (!(flag = getflagbyname(state, newkey, script, lineno, 0)))
 				ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", newkey, lineno, script);
-			} else
+			else
 				flagid = flag->id;
 			if ((tok = get_token(&args, script, lineno)))
 				ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script);
@@ -658,19 +658,19 @@
 			break;
 		}
 		if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) {
-			ast_log(LOG_WARNING, "Invalid token for key name: %s\n", tok);	
+			ast_log(LOG_WARNING, "Invalid token for key name: %s\n", tok);
 			continue;
 		}
-				   
+
 		if (!(key = getkeybyname(state, newkey, script, lineno)))
 			break;
 		keyid[x] = key->id;
 	}
 	buf[0] = id;
 	buf[1] = (flagid & 0x7) << 3 | (x & 0x7);
-	for (bytes = 0; bytes < x; bytes++) {
+	for (bytes = 0; bytes < x; bytes++)
 		buf[bytes + 2] = keyid[bytes];
-	}
+
 	return 2 + x;
 }
 
@@ -709,17 +709,17 @@
 
 	if (tok && !strcasecmp(tok, "UNLESS")) {
 		/* Check for trailing UNLESS flag */
-		if (!(tok = get_token(&args, script, lineno))) {
+		if (!(tok = get_token(&args, script, lineno)))
 			ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script);
-		} else if (process_token(&flag, tok, sizeof(flag), ARG_NUMBER)) {
+		else if (process_token(&flag, tok, sizeof(flag), ARG_NUMBER))
 			ast_log(LOG_WARNING, "Invalid flag number '%s' at line %d of %s\n", tok, lineno, script);
-		}
+
 		if ((tok = get_token(&args, script, lineno)))
 			ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script);
 	}
-				   
+
 	buf[0] = id;
-	buf[1] = (cmd << 6) | (disp->id & 0x3f); 
+	buf[1] = (cmd << 6) | (disp->id & 0x3f);
 	buf[2] = ((line & 0x1f) << 3) | (flag & 0x7);
 
 	return 3;
@@ -729,7 +729,7 @@
 {
 	char *tok = get_token(&args, script, lineno);
 
-	if (tok) 
+	if (tok)
 		ast_log(LOG_WARNING, "Clearing display requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
 
 	buf[0] = id;
@@ -741,7 +741,7 @@
 {
 	char *tok = get_token(&args, script, lineno);
 
-	if (tok) 
+	if (tok)
 		ast_log(LOG_WARNING, "Digitdirect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
 
 	buf[0] = id;
@@ -765,7 +765,7 @@
 {
 	char *tok = get_token(&args, script, lineno);
 
-	if (tok) 
+	if (tok)
 		ast_log(LOG_WARNING, "Digitcollect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script);
 
 	buf[0] = id;
@@ -816,8 +816,7 @@
 	}
 
 	tok = get_token(&args, script, lineno);
-	while ((!sawin && !strcasecmp(tok, "IN")) ||
-	       (sawin && !strcasecmp(tok, "OR"))) {
+	while ((!sawin && !strcasecmp(tok, "IN")) || (sawin && !strcasecmp(tok, "OR"))) {
 		sawin = 1;
 		if (scnt > 7) {
 			ast_log(LOG_WARNING, "No more than 8 states may be specified for inclusion at line %d of %s\n", lineno, script);
@@ -840,7 +839,7 @@
 	if (!tok || strcasecmp(tok, "GOTO")) {
 		if (!tok)
 			tok = "<nothing>";
-		if (sawin) 
+		if (sawin)
 			ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'OR' at line %d of %s\n", tok, lineno, script);
 		else
 			ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'IN' at line %d of %s\n", tok, lineno, script);
@@ -941,17 +940,17 @@
 			if (kcmds[x].add_args) {
 				res = kcmds[x].add_args(key->retstr + key->retstrlen,
 						code, kcmds[x].id, args, state, script, lineno);
-				if ((key->retstrlen + res - key->initlen) <= MAX_RET_CODE) 
+				if ((key->retstrlen + res - key->initlen) <= MAX_RET_CODE)
 					key->retstrlen += res;
-				else 
+				else
 					ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script);
 			} else {
-				if ((unused = get_token(&args, script, lineno))) 
+				if ((unused = get_token(&args, script, lineno)))
 					ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", kcmds[x].name, lineno, script, unused);
 				if ((key->retstrlen + 1 - key->initlen) <= MAX_RET_CODE) {
 					key->retstr[key->retstrlen] = kcmds[x].id;
 					key->retstrlen++;
-				} else 
+				} else
 					ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script);
 			}
 			return 0;
@@ -970,14 +969,14 @@
 			if (opcmds[x].add_args) {
 				res = opcmds[x].add_args(sub->data + sub->datalen,
 						code, opcmds[x].id, args, state, script, lineno);
-				if ((sub->datalen + res + 1) <= max) 
+				if ((sub->datalen + res + 1) <= max)
 					sub->datalen += res;
 				else {
 					ast_log(LOG_WARNING, "No space for '%s' code in subscript '%s' at line %d of %s\n", opcmds[x].name, sub->vname, lineno, script);
 					return -1;
 				}
 			} else {
-				if ((unused = get_token(&args, script, lineno))) 
+				if ((unused = get_token(&args, script, lineno)))
 					ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", opcmds[x].name, lineno, script, unused);
 				if ((sub->datalen + 2) <= max) {
 					sub->data[sub->datalen] = opcmds[x].id;
@@ -1005,7 +1004,7 @@
 	struct adsi_display *disp;
 	struct adsi_subscript *newsub;
 
-	if (!keyword) 
+	if (!keyword)
 		return 0;
 
 	switch(state->state) {
@@ -1141,7 +1140,7 @@
 				break;
 			}
 			state->state = STATE_INSUB;
- 		} else if (!strcasecmp(keyword, "STATE")) {
+		} else if (!strcasecmp(keyword, "STATE")) {
 			if (!(args = get_token(&buf, script, lineno))) {
 				ast_log(LOG_WARNING, "STATE definition missing name at line %d of %s\n", lineno, script);
 				break;
@@ -1155,7 +1154,7 @@
 				break;
 			}
 			getstatebyname(state, vname, script, lineno, 1);
- 		} else if (!strcasecmp(keyword, "FLAG")) {
+		} else if (!strcasecmp(keyword, "FLAG")) {
 			if (!(args = get_token(&buf, script, lineno))) {
 				ast_log(LOG_WARNING, "FLAG definition missing name at line %d of %s\n", lineno, script);
 				break;
@@ -1217,7 +1216,7 @@
 				disp->datalen += strlen(tmp);
 				args = get_token(&buf, script, lineno);
 			}
-			while(args) {
+			while (args) {
 				if (!strcasecmp(args, "JUSTIFY")) {
 					args = get_token(&buf, script, lineno);
 					if (!args) {
@@ -1324,8 +1323,7 @@
 					break;
 				}
 				state->sub->ifinscount = 0;
-				state->sub->ifdata = state->sub->data + 
-						state->sub->datalen;
+				state->sub->ifdata = state->sub->data + state->sub->datalen;
 				/* Reserve header and insert op codes */
 				state->sub->ifdata[0] = 0x1;
 				state->sub->ifdata[1] = event;
@@ -1370,7 +1368,7 @@
 
 	/* Create "main" as first subroutine */
 	getsubbyname(scr, "main", NULL, 0);
-	while(!feof(f)) {
+	while (!feof(f)) {
 		fgets(buf, sizeof(buf), f);
 		if (!feof(f)) {
 			lineno++;
@@ -1447,7 +1445,7 @@
 		return -1;
 
 	/* Start an empty ADSI Session */
-	if (ast_adsi_load_session(chan, NULL, 0, 1) < 1) 
+	if (ast_adsi_load_session(chan, NULL, 0, 1) < 1)
 		return -1;
 
 	/* Now begin the download attempt */
@@ -1530,7 +1528,6 @@
 			return -1;
 		}
 	}
-
 
 	bytes = 0;
 	bytes += ast_adsi_display(buf, ADSI_INFO_PAGE, 1, ADSI_JUST_LEFT, 0, "Download complete.", "");
@@ -1555,14 +1552,14 @@
 	
 	if (ast_strlen_zero(data))
 		data = "asterisk.adsi";
-	
+
 	if (!ast_adsi_available(chan)) {
 		ast_verb(3, "ADSI Unavailable on CPE.  Not bothering to try.\n");
 	} else {
 		ast_verb(3, "ADSI Available on CPE.  Attempting Upload.\n");
 		res = adsi_prog(chan, data);
 	}
-	
+
 	return res;
 }
 

Modified: team/russell/events/apps/app_alarmreceiver.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/apps/app_alarmreceiver.c?view=diff&rev=102965&r1=102964&r2=102965
==============================================================================
--- team/russell/events/apps/app_alarmreceiver.c (original)
+++ team/russell/events/apps/app_alarmreceiver.c Thu Feb  7 19:12:20 2008
@@ -17,18 +17,18 @@
  */
 
 /*! \file
- * \brief Central Station Alarm receiver for Ademco Contact ID  
+ * \brief Central Station Alarm receiver for Ademco Contact ID
  * \author Steve Rodgers <hwstar at rodgers.sdcoxmail.com>
- * 
- * *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** 
+ *
+ * *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  *
  * Use at your own risk. Please consult the GNU GPL license document included with Asterisk.         *
  *
  * *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  *
  * \ingroup applications
- */ 
- 
+ */
+
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -73,13 +73,12 @@
 "until the panel hangs up. Once the panel hangs up, the application will run the\n"
 "system command specified by the eventcmd setting in alarmreceiver.conf and pipe\n"
 "the events to the standard input of the application. The configuration file also\n"
-"contains settings for DTMF timing, and for the loudness of the acknowledgement\n" 
+"contains settings for DTMF timing, and for the loudness of the acknowledgement\n"
 "tones.\n";
 
 /* Config Variables */
-
 static int fdtimeout = 2000;
-static int sdtimeout = 200; 
+static int sdtimeout = 200;
 static int toneloudness = 4096;
 static int log_individual_events = 0;
 static char event_spool_dir[128] = {'\0'};
@@ -88,7 +87,6 @@
 static char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"};
 
 /* Misc variables */
-	
 static char event_file[14] = "/event-XXXXXX";
 
 /*
@@ -98,7 +96,6 @@
 * in this family if it is defined. If the new key doesn't exist in the
 * family, then create it and set its value to 1.
 */
-
 static void database_increment( char *key )
 {
 	int res = 0;
@@ -111,7 +108,7 @@
 	
 	res = ast_db_get(db_family, key, value, sizeof(value) - 1);
 	
-	if(res){
+	if (res) {
 		ast_verb(4, "AlarmReceiver: Creating database entry %s and setting to 1\n", key);
 		/* Guess we have to create it */
 		res = ast_db_put(db_family, key, "1");
@@ -120,46 +117,44 @@
 	
 	sscanf(value, "%u", &v);
 	v++;
-	
-	if(option_verbose >= 4)
-		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: New value for %s: %u\n", key, v);
-		
+
+	ast_verb(4, "AlarmReceiver: New value for %s: %u\n", key, v);
+
 	snprintf(value, sizeof(value), "%u", v);
-	
+
 	res = ast_db_put(db_family, key, value);
-	
-	if((res)&&(option_verbose >= 4))
-		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: database_increment write error\n");
-	
-	return;	
+
+	if (res)
+		ast_verb(4, "AlarmReceiver: database_increment write error\n");
+
+	return;
 }
 
 
 /*
 * Build a MuLaw data block for a single frequency tone
 */
-
 static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
 {
 	int     i;
 	float   val;
-                                                                                                                                    
-        for(i = 0; i < len; i++){
+
+	for (i = 0; i < len; i++) {
 		val = loudness * sin((freq * 2.0 * M_PI * (*x)++)/8000.0);
 		data[i] = AST_LIN2MU((int)val);
 	}
 
 	/* wrap back around from 8000 */
 
-	if (*x >= 8000) *x = 0;
+	if (*x >= 8000)
+		*x = 0;
 	return;
 }
 
 /*
-* Send a single tone burst for a specifed duration and frequency. 
+* Send a single tone burst for a specifed duration and frequency.
 * Returns 0 if successful
 */
-
 static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
 {
 	int res = 0;
@@ -172,20 +167,19 @@
 		unsigned char buf[640];
 	} tone_block;
 
-	for(;;)
-	{
-	
-		if (ast_waitfor(chan, -1) < 0){
+	for (;;) {
+
+		if (ast_waitfor(chan, -1) < 0) {
 			res = -1;
 			break;
 		}
-		
+
 		f = ast_read(chan);
-		if (!f){
+		if (!f) {
 			res = -1;
 			break;
 		}
-		
+
 		if (f->frametype == AST_FRAME_VOICE) {
 			wf.frametype = AST_FRAME_VOICE;
 			wf.subclass = AST_FORMAT_ULAW;
@@ -202,7 +196,7 @@
 				ast_frfree(f);
 				break;
 			}
-			if (ast_write(chan, &wf)){
+			if (ast_write(chan, &wf)) {
 				ast_verb(4, "AlarmReceiver: Failed to write frame on %s\n", chan->name);
 				ast_log(LOG_WARNING, "AlarmReceiver Failed to write frame on %s\n",chan->name);
 				res = -1;
@@ -210,7 +204,7 @@
 				break;
 			}
 		}
-		
+
 		ast_frfree(f);
 	}
 	return res;
@@ -226,7 +220,6 @@
 * Returns -1 if the caller hung up or there was a channel error.
 *
 */
-
 static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto)
 {
 	int res = 0;
@@ -234,67 +227,60 @@
 	int r;
 	struct ast_frame *f;
 	struct timeval lastdigittime;
-	
+
 	lastdigittime = ast_tvnow();
-	for(;;){
-		  /* if outa time, leave */
-		if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
-		    ((i > 0) ? sdto : fdto)){
-			if(option_verbose >= 4)
-				ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
-				
+	for (;;) {
+		/* if outa time, leave */
+		if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > ((i > 0) ? sdto : fdto)) {
+			ast_verb(4, "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
 			ast_debug(1,"AlarmReceiver: DTMF timeout on chan %s\n",chan->name);
-				
 			res = 1;
 			break;
 		}
-		
+
 		if ((r = ast_waitfor(chan, -1) < 0)) {
 			ast_debug(1, "Waitfor returned %d\n", r);
 			continue;
 		}
-			
+
 		f = ast_read(chan);
-		
-		if (f == NULL){
+
+		if (f == NULL) {
 			res = -1;
 			break;
 		}
-		
+
 		/* If they hung up, leave */
-		if ((f->frametype == AST_FRAME_CONTROL) &&
-		    (f->subclass == AST_CONTROL_HANGUP)){
+		if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
 			ast_frfree(f);
 			res = -1;
 			break;
 		}
-		
+
 		/* if not DTMF, just do it again */
-		if (f->frametype != AST_FRAME_DTMF){
+		if (f->frametype != AST_FRAME_DTMF) {
 			ast_frfree(f);
 			continue;
 		}
 
 		digit_string[i++] = f->subclass;  /* save digit */
-		
+
 		ast_frfree(f);
-		
+
 		/* If we have all the digits we expect, leave */
 		if(i >= length)
 			break;
-		
+
 		lastdigittime = ast_tvnow();
 	}
-	
+
 	digit_string[i] = '\0'; /* Nul terminate the end of the digit string */
 	return res;
-
 }
 
 /*
 * Write the metadata to the log file
 */
-
 static int write_metadata( FILE *logfile, char *signalling_type, struct ast_channel *chan)
 {
 	int res = 0;
@@ -308,46 +294,39 @@
 	if (chan->cid.cid_num)
 		ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring));
 	workstring[sizeof(workstring) - 1] = '\0';
-	
+
 	ast_callerid_parse(workstring, &cn, &cl);
-	if (cl) 
+	if (cl)
 		ast_shrink_phone_number(cl);
-                
 
 	/* Get the current time */
-		
 	t = ast_tvnow();
 	ast_localtime(&t, &now, NULL);
-	
+
 	/* Format the time */
-	
-	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now); 
-
-	
+	ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
+
 	res = fprintf(logfile, "\n\n[metadata]\n\n");
-	
-	if(res >= 0)
+
+	if (res >= 0)
 		res = fprintf(logfile, "PROTOCOL=%s\n", signalling_type);
-		
-	if(res >= 0)	
+
+	if (res >= 0)
 		res = fprintf(logfile, "CALLINGFROM=%s\n", (!cl) ? "<unknown>" : cl);
-		
-	if(res >- 0)
+
+	if (res >- 0)
 		res = fprintf(logfile, "CALLERNAME=%s\n", (!cn) ? "<unknown>" : cn);
-		
-	if(res >= 0)
+
+	if (res >= 0)
 		res = fprintf(logfile, "TIMESTAMP=%s\n\n", timestamp);
-	
-	if(res >= 0)
+
+	if (res >= 0)
 		res = fprintf(logfile, "[events]\n\n");
-	
-	if(res < 0){
-		if (option_verbose >= 3 )
-		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't write metadata\n");	
-		
+
+	if (res < 0) {
+		ast_verb(3, "AlarmReceiver: can't write metadata\n");
 		ast_debug(1,"AlarmReceiver: can't write metadata\n");
-	}
-	else
+	} else
 		res = 0;
 
 	return res;
@@ -356,23 +335,20 @@
 /*
 * Write a single event to the log file
 */
-
 static int write_event( FILE *logfile,  event_node_t *event)
 {
 	int res = 0;
 
-	if( fprintf(logfile, "%s\n", event->data) < 0)
+	if (fprintf(logfile, "%s\n", event->data) < 0)
 		res = -1;
-			
+
 	return res;
 }
-
 
 /*
 * If we are configured to log events, do so here.
 *
 */
-
 static int log_events(struct ast_channel *chan,  char *signalling_type, event_node_t *event)
 {
 
@@ -385,46 +361,42 @@
 	if (!ast_strlen_zero(event_spool_dir)) {
 		
 		/* Make a template */
-		
 		ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
 		strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
 		
 		/* Make the temporary file */
-		
 		fd = mkstemp(workstring);
 		
-		if(fd == -1) {
-			if (option_verbose >= 3)
-				ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: can't make temporary file\n");	
+		if (fd == -1) {
+			ast_verb(3, "AlarmReceiver: can't make temporary file\n");
 			ast_debug(1,"AlarmReceiver: can't make temporary file\n");
 			res = -1;
 		}
-		
-		if(!res){
+
+		if (!res) {
 			logfile = fdopen(fd, "w");
-			if(logfile){
+			if (logfile) {
 				/* Write the file */
 				res = write_metadata(logfile, signalling_type, chan);
-				if(!res)
-					while((!res) && (elp != NULL)){
+				if (!res)
+					while ((!res) && (elp != NULL)) {
 						res = write_event(logfile, elp);
 						elp = elp->next;
 					}
-				if(!res){
-					if(fflush(logfile) == EOF)
+				if (!res) {
+					if (fflush(logfile) == EOF)
 						res = -1;
-					if(!res){
-						if(fclose(logfile) == EOF)
+					if (!res) {
+						if (fclose(logfile) == EOF)
 							res = -1;
-					}				
+					}
 				}
-			}
-			else
+			} else
 				res = -1;
 		}
 	}
 
-	return res;	
+	return res;
 }
 
 /*
@@ -432,10 +404,9 @@
 *
 * The function will return 0 when the caller hangs up, else a -1 if there was a problem.
 */
-
 static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int fdto, int sdto, int tldn, event_node_t **ehead)
 {
-	int i,j;
+	int i, j;
 	int res = 0;
 	int checksum;
 	char event[17];
@@ -445,94 +416,72 @@
 	int ack_retries = 0;
 	
 	static char digit_map[15] = "0123456789*#ABC";
-        static unsigned char digit_weights[15] = {10,1,2,3,4,5,6,7,8,9,11,12,13,14,15};
-                                                                                                                      
+	static unsigned char digit_weights[15] = {10,1,2,3,4,5,6,7,8,9,11,12,13,14,15};
+
 	database_increment("calls-received");
 
 	/* Wait for first event */
-
-	if(option_verbose >= 4)
-		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Waiting for first event from panel\n");
-
-	while(res >= 0){
-
-		if(got_some_digits == 0){
-
-	        	/* Send ACK tone sequence */
-                        
-		                                                                                                                    
-        		if(option_verbose >= 4)
-                		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
-                                                                                                                                            
-                                                                                                                                            
-        		res = send_tone_burst(chan, 1400.0, 100, tldn);
-                                                                                                                                            
-        		if(!res)
-                		res = ast_safe_sleep(chan, 100);
-                                                                                                                                            
-        		if(!res){
-                		if(option_verbose >= 4)
-                        		ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
-                                                                                                                                            
-                		res = send_tone_burst(chan, 2300.0, 100, tldn);
-        		}
-                                                                                                                                            
-		}
-
-		if( res >= 0)
+	ast_verb(4, "AlarmReceiver: Waiting for first event from panel\n");
+
+	while (res >= 0) {
+		if (got_some_digits == 0) {
+			/* Send ACK tone sequence */
+			ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
+			res = send_tone_burst(chan, 1400.0, 100, tldn);
+			if (!res)
+				res = ast_safe_sleep(chan, 100);
+			if (!res) {
+				ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
+				res = send_tone_burst(chan, 2300.0, 100, tldn);
+			}
+		}
+		if ( res >= 0)
 			res = receive_dtmf_digits(chan, event, sizeof(event) - 1, fdto, sdto);
-		
-		if (res < 0){
-		
-			if(events_received == 0)
+		if (res < 0) {
+			if (events_received == 0) {
 				/* Hangup with no events received should be logged in the DB */
 				database_increment("no-events-received");
-			else{
-				if(ack_retries){
-					if(option_verbose >= 4)
-						ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
-					
+			} else {
+				if (ack_retries) {
+					ast_verb(4, "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
 					database_increment("ack-retries");
 				}
 			}
-			if(option_verbose >= 4)
-				ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: App exiting...\n");
+			ast_verb(4, "AlarmReceiver: App exiting...\n");
 			res = -1;
 			break;
 		}
-		
-		if(res != 0){
-			 /* Didn't get all of the digits */
-			if(option_verbose >= 2)
-				ast_verbose(VERBOSE_PREFIX_2 "AlarmReceiver: Incomplete string: %s, trying again...\n", event);
-
-			if(!got_some_digits){
+
+		if (res != 0) {
+			/* Didn't get all of the digits */
+			ast_verb(2, "AlarmReceiver: Incomplete string: %s, trying again...\n", event);
+
+			if (!got_some_digits) {
 				got_some_digits = (!ast_strlen_zero(event)) ? 1 : 0;
 				ack_retries++;
 			}
-			continue;	
-		}		
-		
+			continue;
+		}
+
 		got_some_digits = 1;
 
 		ast_verb(2, "AlarmReceiver: Received Event %s\n", event);
 		ast_debug(1, "AlarmReceiver: Received event: %s\n", event);
-		
+
 		/* Calculate checksum */
-		
-		for(j = 0, checksum = 0; j < 16; j++){
-			for(i = 0 ; i < sizeof(digit_map) ; i++){
-				if(digit_map[i] == event[j])
+
+		for (j = 0, checksum = 0; j < 16; j++) {
+			for (i = 0; i < sizeof(digit_map); i++) {
+				if (digit_map[i] == event[j])
 					break;
 			}
-			
-			if(i == 16)
+
+			if (i == 16)
 				break;
-				
+
 			checksum += digit_weights[i];
 		}
-		
-		if(i == 16){
+		if (i == 16) {
 			ast_verb(2, "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
 			continue; /* Bad character */
 		}
@@ -550,8 +499,8 @@
 
 		/* Check the message type for correctness */
 
-		if(strncmp(event + 4, "18", 2)){
-			if(strncmp(event + 4, "98", 2)){
+		if (strncmp(event + 4, "18", 2)) {
+			if (strncmp(event + 4, "98", 2)) {
 				database_increment("format-errors");
 				ast_verb(2, "AlarmReceiver: Wrong message type\n");
 				ast_debug(1, "AlarmReceiver: Wrong message type\n");
@@ -560,129 +509,102 @@
 		}
 
 		events_received++;
-		
-		/* Queue the Event */		
+
+		/* Queue the Event */
 		if (!(enew = ast_calloc(1, sizeof(*enew)))) {
 			res = -1;
 			break;
 		}
-		
+
 		enew->next = NULL;
 		ast_copy_string(enew->data, event, sizeof(enew->data));
 
 		/*
 		* Insert event onto end of list
 		*/
-		
-		if(*ehead == NULL){
+		if (*ehead == NULL)
 			*ehead = enew;
-		}
-		else{
+		else {
 			for(elp = *ehead; elp->next != NULL; elp = elp->next)
 			;
-			
 			elp->next = enew;
 		}
-		
-		if(res > 0)
+
+		if (res > 0)
 			res = 0;
-		
+
 		/* Let the user have the option of logging the single event before sending the kissoff tone */
-
-		if((res == 0) && (log_individual_events))
+		if ((res == 0) && (log_individual_events))
 			res = log_events(chan, ADEMCO_CONTACT_ID, enew);
-	
-		/* Wait 200 msec before sending kissoff */	
-			
-		if(res == 0)	
+		/* Wait 200 msec before sending kissoff */
+		if (res == 0)
 			res = ast_safe_sleep(chan, 200);
 
 		/* Send the kissoff tone */
-
-		if(res == 0)		
+		if (res == 0)
 			res = send_tone_burst(chan, 1400.0, 900, tldn);
 	}
 
-	
 	return res;
 }
-
 
 /*
 * This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
 * This function will always return 0.
 */
-
 static int alarmreceiver_exec(struct ast_channel *chan, void *data)
 {
 	int res = 0;
 	event_node_t *elp, *efree;
 	char signalling_type[64] = "";
-
 	event_node_t *event_head = NULL;
 
 	/* Set write and read formats to ULAW */
-
 	ast_verb(4, "AlarmReceiver: Setting read and write formats to ULAW\n");
 
-	if (ast_set_write_format(chan,AST_FORMAT_ULAW)){
+	if (ast_set_write_format(chan,AST_FORMAT_ULAW)) {
 		ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",chan->name);
 		return -1;
 	}
-	
-	if (ast_set_read_format(chan,AST_FORMAT_ULAW)){
+
+	if (ast_set_read_format(chan,AST_FORMAT_ULAW)) {
 		ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",chan->name);
 		return -1;
 	}
 
 	/* Set default values for this invocation of the application */
-	
 	ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type));
 
-
 	/* Answer the channel if it is not already */
-
 	ast_verb(4, "AlarmReceiver: Answering channel\n");
-
 	if (chan->_state != AST_STATE_UP) {
 		if ((res = ast_answer(chan)))
 			return -1;
 	}
 
 	/* Wait for the connection to settle post-answer */
-
 	ast_verb(4, "AlarmReceiver: Waiting for connection to stabilize\n");
-
 	res = ast_safe_sleep(chan, 1250);
 
 	/* Attempt to receive the events */
-
-	if(!res){
-	
+	if (!res) {
 		/* Determine the protocol to receive in advance */
 		/* Note: Ademco contact is the only one supported at this time */
 		/* Others may be added later */
-		
 		if(!strcmp(signalling_type, ADEMCO_CONTACT_ID))
 			receive_ademco_contact_id(chan, data, fdtimeout, sdtimeout, toneloudness, &event_head);
 		else
 			res = -1;
 	}
-	
-		
-	
+
 	/* Events queued by receiver, write them all out here if so configured */
-
-	if((!res) && (log_individual_events == 0)){
+	if ((!res) && (log_individual_events == 0))
 		res = log_events(chan, signalling_type, event_head);
-
-	}
 
 	/*
 	* Do we exec a command line at the end?
 	*/
-	
-	if((!res) && (!ast_strlen_zero(event_app)) && (event_head)){
+	if ((!res) && (!ast_strlen_zero(event_app)) && (event_head)) {
 		ast_debug(1,"Alarmreceiver: executing: %s\n", event_app);
 		ast_safe_system(event_app);
 	}
@@ -690,8 +612,7 @@
 	/*
 	* Free up the data allocated in our linked list
 	*/
-		
-	for(elp = event_head; (elp != NULL);){
+	for (elp = event_head; (elp != NULL);) {
 		efree = elp;
 		elp = elp->next;
 		ast_free(efree);
@@ -700,10 +621,9 @@
 	return 0;
 }
 
-/* 
+/*
 * Load the configuration from the configuration file
 */
-
 static int load_config(void)
 {
 	struct ast_config *cfg;
@@ -711,27 +631,19 @@
 	struct ast_flags config_flags = { 0 };
 
 	/* Read in the config file */
-
 	cfg = ast_config_load(ALMRCV_CONFIG, config_flags);
-                                                                                                                                  
-	if(!cfg){
-	
-		if(option_verbose >= 4)
-			ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: No config file\n");
+
+	if (!cfg) {
+		ast_verb(4, "AlarmReceiver: No config file\n");
 		return 0;
-	}
-	else{
-
-		
+	} else {
 		p = ast_variable_retrieve(cfg, "general", "eventcmd");
-		
-		if(p){
+		if (p) {
 			ast_copy_string(event_app, p, sizeof(event_app));
 			event_app[sizeof(event_app) - 1] = '\0';
 		}
-		
 		p = ast_variable_retrieve(cfg, "general", "loudness");
-		if(p){
+		if (p) {
 			toneloudness = atoi(p);
 			if(toneloudness < 100)
 				toneloudness = 100;
@@ -739,61 +651,52 @@
 				toneloudness = 8192;
 		}
 		p = ast_variable_retrieve(cfg, "general", "fdtimeout");
-		if(p){
+		if (p) {
 			fdtimeout = atoi(p);
 			if(fdtimeout < 1000)
 				fdtimeout = 1000;
 			if(fdtimeout > 10000)
-				fdtimeout = 10000;	
-		}
-		
+				fdtimeout = 10000;
+		}
+
 		p = ast_variable_retrieve(cfg, "general", "sdtimeout");
-		if(p){
+		if (p) {
 			sdtimeout = atoi(p);
 			if(sdtimeout < 110)
 				sdtimeout = 110;
 			if(sdtimeout > 4000)
-				sdtimeout = 4000;			
-
-		}
-		
+				sdtimeout = 4000;
+		}
+
 		p = ast_variable_retrieve(cfg, "general", "logindividualevents");
-		if(p){
+		if (p)
 			log_individual_events = ast_true(p);
 
-		}
-		
 		p = ast_variable_retrieve(cfg, "general", "eventspooldir");
-			
-		if(p){
+		if (p) {
 			ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
 			event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
 		}
-		
+
 		p = ast_variable_retrieve(cfg, "general", "timestampformat");
-			
-		if(p){
+		if (p) {
 			ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
 			time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
 		}
 
 		p = ast_variable_retrieve(cfg, "general", "db-family");
-                                                                                                                                            
-		if(p){
+		if (p) {
 			ast_copy_string(db_family, p, sizeof(db_family));
 			db_family[sizeof(db_family) - 1] = '\0';
 		}
 		ast_config_destroy(cfg);
 	}
 	return 1;
-
 }
 
 /*
 * These functions are required to implement an Asterisk App.
 */
-
-
 static int unload_module(void)
 {
 	return ast_unregister_application(app);
@@ -801,12 +704,11 @@
 
 static int load_module(void)
 {
-	if(load_config()) {
+	if (load_config()) {
 		if (ast_register_application(app, alarmreceiver_exec, synopsis, descrip))
 			return AST_MODULE_LOAD_FAILURE;
 		return AST_MODULE_LOAD_SUCCESS;
-	}	
-	else
+	} else
 		return AST_MODULE_LOAD_DECLINE;
 }
 

Modified: team/russell/events/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/apps/app_chanspy.c?view=diff&rev=102965&r1=102964&r2=102965
==============================================================================
--- team/russell/events/apps/app_chanspy.c (original)
+++ team/russell/events/apps/app_chanspy.c Thu Feb  7 19:12:20 2008
@@ -88,6 +88,9 @@
 "                    specified by the SPY_EXIT_CONTEXT channel variable. The\n"
 "                    name of the last channel that was spied on will be stored\n"
 "                    in the SPY_CHANNEL variable.\n"
+"    e(ext)        - Enable 'enforced' mode, so the spying channel can\n"
+"                    only monitor extensions whose name is in the 'ext' : \n"
+"                    delimited list.\n"
 ;
 
 static const char *app_ext = "ExtenSpy";
@@ -137,12 +140,14 @@
 	OPTION_PRIVATE   = (1 << 6),	/* Private Whisper mode */
 	OPTION_READONLY  = (1 << 7),	/* Don't mix the two channels */
 	OPTION_EXIT      = (1 << 8),	/* Exit to a valid single digit extension */
+	OPTION_ENFORCED  = (1 << 9),    /* Enforced mode */
 } chanspy_opt_flags;
 
 enum {
 	OPT_ARG_VOLUME = 0,
 	OPT_ARG_GROUP,
 	OPT_ARG_RECORD,
+	OPT_ARG_ENFORCED,
 	OPT_ARG_ARRAY_SIZE,
 } chanspy_opt_args;
 
@@ -154,6 +159,7 @@
 	AST_APP_OPTION_ARG('v', OPTION_VOLUME, OPT_ARG_VOLUME),
 	AST_APP_OPTION_ARG('g', OPTION_GROUP, OPT_ARG_GROUP),
 	AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD),
+	AST_APP_OPTION_ARG('e', OPTION_ENFORCED, OPT_ARG_ENFORCED),
 	AST_APP_OPTION('o', OPTION_READONLY),
 	AST_APP_OPTION('X', OPTION_EXIT),
 });
@@ -378,11 +384,12 @@
 					const char *exten, const char *context)
 {
 	struct ast_channel *this;
-
+	
 	redo:
-	if (spec)
+	if (!ast_strlen_zero(spec))
 		this = ast_walk_channel_by_name_prefix_locked(last, spec, strlen(spec));
-	else if (exten)
+
+	else if (!ast_strlen_zero(exten))
 		this = ast_walk_channel_by_exten_locked(last, exten, context);
 	else
 		this = ast_channel_walk_locked(last);
@@ -397,8 +404,8 @@
 }
 
 static int common_exec(struct ast_channel *chan, const struct ast_flags *flags,
-		       int volfactor, const int fd, const char *mygroup, const char *spec,
-		       const char *exten, const char *context)
+		       int volfactor, const int fd, const char *mygroup, const char *myenforced,
+		       const char *spec, const char *exten, const char *context)
 {
 	struct ast_channel *peer, *prev, *next;
 	char nameprefix[AST_NAME_STRLEN];
@@ -478,7 +485,12 @@
 			char *dup_group;
 			int x;
 			char *s;
-				
+			char *buffer;
+			char *end;
+			char *ext;
+			char *form_enforced;
+			int ienf = !myenforced;
+	
 			if (peer == prev)
 				break;
 
@@ -507,6 +519,37 @@
 			}
 			
 			if (!igrp)
+				continue;
+
+			if (myenforced) {
+ 
+				/* We don't need to allocate more space than just the
+				length of (peer->name) for ext as we will cut the
+				channel name's ending before copying into ext */
+
+				ext = alloca(strlen(peer->name));
+
+ 				form_enforced = alloca(strlen(myenforced) + 3);
+			
+				strcpy(form_enforced, ":");
+				strcat(form_enforced, myenforced);
+				strcat(form_enforced, ":");
+				
+				buffer = ast_strdupa(peer->name);
+				
+				if ((end = strchr(buffer, '-'))) {
+				    *end++ = ':';
+				    *end = '\0';
+				}
+				
+				strcpy(ext, ":");
+				strcat(ext, buffer);				
+
+				if (strcasestr(form_enforced, ext))
+					ienf = 1;
+			}
+
+			if (!ienf)
 				continue;
 
 			strcpy(peer_name, "spy-");
@@ -562,6 +605,7 @@
 
 static int chanspy_exec(struct ast_channel *chan, void *data)

[... 2117 lines stripped ...]



More information about the asterisk-commits mailing list