[asterisk-commits] tilghman: branch 1.4 r114180 - /branches/1.4/channels/chan_vpb.cc

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 16 14:59:37 CDT 2008


Author: tilghman
Date: Wed Apr 16 14:59:37 2008
New Revision: 114180

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114180
Log:
Backport revisions for latest vpb drivers to 1.4
(Closes issue #12457)

Modified:
    branches/1.4/channels/chan_vpb.cc

Modified: branches/1.4/channels/chan_vpb.cc
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_vpb.cc?view=diff&rev=114180&r1=114179&r2=114180
==============================================================================
--- branches/1.4/channels/chan_vpb.cc (original)
+++ branches/1.4/channels/chan_vpb.cc Wed Apr 16 14:59:37 2008
@@ -33,6 +33,8 @@
 	<depend>vpbapi</depend>
  ***/
 
+#include <vpbapi.h>
+
 extern "C" {
 
 #include "asterisk.h"
@@ -66,7 +68,6 @@
 #include <sys/ioctl.h>
 #include <ctype.h>
 
-#include <vpbapi.h>
 #include <assert.h>
 
 #ifdef pthread_create
@@ -100,18 +101,36 @@
 static const char tdesc[] = "Standard VoiceTronix API Driver";
 static const char config[] = "vpb.conf";
 
+/* Backwards compatibility from trunk */
+#define ast_verb(level, ...) do { \
+	if (option_verbose >= level) { \
+		if (level >= 4) \
+			ast_verbose(VERBOSE_PREFIX_4 __VA_ARGS__); \
+		else if (level == 3) \
+			ast_verbose(VERBOSE_PREFIX_3 __VA_ARGS__); \
+		else if (level == 2) \
+			ast_verbose(VERBOSE_PREFIX_2 __VA_ARGS__); \
+		else if (level == 1) \
+			ast_verbose(VERBOSE_PREFIX_1 __VA_ARGS__); \
+		else \
+			ast_verbose(__VA_ARGS__); \
+	} \
+} while (0)
+
+#define ast_debug(level, ...) do {       \
+	if (option_debug >= (level)) \
+		ast_log(LOG_DEBUG, __VA_ARGS__); \
+} while (0)
+
 /* Default context for dialtone mode */
 static char context[AST_MAX_EXTENSION] = "default";
 
 /* Default language */
 static char language[MAX_LANGUAGE] = "";
-static int usecnt =0;
 
 static int gruntdetect_timeout = 3600000; /* Grunt detect timeout is 1hr. */
 
 static const int prefformat = AST_FORMAT_SLINEAR;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 /* Protect the interface list (of vpb_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
@@ -182,7 +201,7 @@
 static int break_for_dtmf=1;
 
 /* Set EC suppression threshold */
-static int ec_supp_threshold=-1;
+static short ec_supp_threshold=-1;
 
 /* Inter Digit Delay for collecting DTMF's */
 static int dtmf_idd = 3000;
@@ -192,26 +211,26 @@
 #define TIMER_PERIOD_RING 4000
 static int timer_period_ring = TIMER_PERIOD_RING;
 	  
-#define VPB_EVENTS_ALL (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
-			|VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
+#define VPB_EVENTS_ALL (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP \
+			|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
 			|VPB_MRING_OFF|VPB_MDROP|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_NODROP (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
-			|VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
+#define VPB_EVENTS_NODROP (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP \
+			|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
 			|VPB_MRING_OFF|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_NODTMF (VPB_MRING|VPB_MDIGIT|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
-			|VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
+#define VPB_EVENTS_NODTMF (VPB_MRING|VPB_MDIGIT|VPB_MTONEDETECT|VPB_MTIMEREXP \
+			|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
 			|VPB_MRING_OFF|VPB_MDROP|VPB_MSTATION_FLASH)
-#define VPB_EVENTS_STAT (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP|VPB_MPLAY_UNDERFLOW \
-			|VPB_MRECORD_OVERFLOW|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
+#define VPB_EVENTS_STAT (VPB_MRING|VPB_MDIGIT|VPB_MDTMF|VPB_MTONEDETECT|VPB_MTIMEREXP \
+			|VPB_MSTATION_OFFHOOK|VPB_MSTATION_ONHOOK \
 			|VPB_MRING_OFF|VPB_MSTATION_FLASH)
 
 
 /* Dialing parameters for Australia */
 /* #define DIAL_WITH_CALL_PROGRESS */
-VPB_TONE_MAP DialToneMap[] = { 	{ VPB_BUSY_AUST, VPB_CALL_DISCONNECT, 0 },
+VPB_TONE_MAP DialToneMap[] = { 	{ VPB_BUSY, VPB_CALL_DISCONNECT, 0 },
   				{ VPB_DIAL, VPB_CALL_DIALTONE, 0 },
-				{ VPB_RINGBACK_308, VPB_CALL_RINGBACK, 0 },
-				{ VPB_BUSY_AUST, VPB_CALL_BUSY, 0 },
+				{ VPB_RINGBACK, VPB_CALL_RINGBACK, 0 },
+				{ VPB_BUSY, VPB_CALL_BUSY, 0 },
 				{ VPB_GRUNT, VPB_CALL_GRUNT, 0 },
 				{ 0, 0, 1 } };
 #define VPB_DIALTONE_WAIT 2000 /* Wait up to 2s for a dialtone */
@@ -339,7 +358,7 @@
 
 } *iflist = NULL;
 
-static struct ast_channel *vpb_new(struct vpb_pvt *i, enum ast_channel_state state, char *context);
+static struct ast_channel *vpb_new(struct vpb_pvt *i, enum ast_channel_state state, const char *context);
 static void *do_chanreads(void *pvt);
 static struct ast_channel *vpb_request(const char *type, int format, void *data, int *cause);
 static int vpb_digit_begin(struct ast_channel *ast, char digit);
@@ -435,7 +454,7 @@
 	cs[1] = c1;
 
 	#ifdef BAD_V4PCI_BRIDGE
-	if(p0->vpb_model==vpb_model_v4pci)
+	if (p0->vpb_model==vpb_model_v4pci)
 		return AST_BRIDGE_FAILED_NOWARN;
 	#endif
 	if ( UseNativeBridge != 1){
@@ -449,20 +468,20 @@
 
 	/* Bridge channels, check if we can.  I believe we always can, so find a slot.*/
 
-	ast_mutex_lock(&bridge_lock); {
-		for (i = 0; i < max_bridges; i++) 
-			if (!bridges[i].inuse)
-				break;
-		if (i < max_bridges) {
-			bridges[i].inuse = 1;
-			bridges[i].endbridge = 0;
-			bridges[i].flags = flags;
-			bridges[i].rc = rc;
-			bridges[i].fo = fo;
-			bridges[i].c0 = c0;
-			bridges[i].c1 = c1;
-		} 	       
-	} ast_mutex_unlock(&bridge_lock); 
+	ast_mutex_lock(&bridge_lock);
+	for (i = 0; i < max_bridges; i++) 
+		if (!bridges[i].inuse)
+			break;
+	if (i < max_bridges) {
+		bridges[i].inuse = 1;
+		bridges[i].endbridge = 0;
+		bridges[i].flags = flags;
+		bridges[i].rc = rc;
+		bridges[i].fo = fo;
+		bridges[i].c0 = c0;
+		bridges[i].c1 = c1;
+	} 	       
+	ast_mutex_unlock(&bridge_lock); 
 
 	if (i == max_bridges) {
 		ast_log(LOG_WARNING, "%s: vpb_bridge: Failed to bridge %s and %s!\n", p0->dev, c0->name, c1->name);
@@ -471,30 +490,27 @@
 		return AST_BRIDGE_FAILED_NOWARN;
 	} else {
 		/* Set bridge pointers. You don't want to take these locks while holding bridge lock.*/
-		ast_mutex_lock(&p0->lock); {
-			p0->bridge = &bridges[i];
-		} ast_mutex_unlock(&p0->lock);
-
-		ast_mutex_lock(&p1->lock); {
-			p1->bridge = &bridges[i];
-		} ast_mutex_unlock(&p1->lock);
-
-		if (option_verbose>1) 
-			ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Bridging call entered with [%s, %s]\n",p0->dev, c0->name, c1->name);
-	}
-
-	if (option_verbose > 2) 
-		ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s\n", c0->name, c1->name);
+		ast_mutex_lock(&p0->lock);
+		p0->bridge = &bridges[i];
+		ast_mutex_unlock(&p0->lock);
+
+		ast_mutex_lock(&p1->lock);
+		p1->bridge = &bridges[i];
+		ast_mutex_unlock(&p1->lock);
+
+		ast_verb(2, "%s: vpb_bridge: Bridging call entered with [%s, %s]\n", p0->dev, c0->name, c1->name);
+	}
+
+	ast_verb(3, "Native bridging %s and %s\n", c0->name, c1->name);
 
 	#ifdef HALF_DUPLEX_BRIDGE
 
-	if (option_verbose>1) 
-		ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Starting half-duplex bridge [%s, %s]\n",p0->dev, c0->name, c1->name);
+	ast_debug(2, "%s: vpb_bridge: Starting half-duplex bridge [%s, %s]\n", p0->dev, c0->name, c1->name);
 
 	int dir = 0;
 
-	memset(p0->buf, 0, sizeof p0->buf);
-	memset(p1->buf, 0, sizeof p1->buf);
+	memset(p0->buf, 0, sizeof(p0->buf));
+	memset(p1->buf, 0, sizeof(p1->buf));
 
 	vpb_record_buf_start(p0->handle, VPB_ALAW);
 	vpb_record_buf_start(p1->handle, VPB_ALAW);
@@ -502,9 +518,9 @@
 	vpb_play_buf_start(p0->handle, VPB_ALAW);
 	vpb_play_buf_start(p1->handle, VPB_ALAW);
 
-	while( !bridges[i].endbridge ) {
+	while (!bridges[i].endbridge) {
 		struct vpb_pvt *from, *to;
-		if(++dir%2) {
+		if (++dir % 2) {
 			from = p0;
 			to = p1;
 		} else {
@@ -521,17 +537,16 @@
 	vpb_play_buf_finish(p0->handle);
 	vpb_play_buf_finish(p1->handle);
 
-	if (option_verbose>1) 
-		ast_verbose(VERBOSE_PREFIX_2 "%s: vpb_bridge: Finished half-duplex bridge [%s, %s]\n",p0->dev, c0->name, c1->name);
+	ast_debug(2, "%s: vpb_bridge: Finished half-duplex bridge [%s, %s]\n", p0->dev, c0->name, c1->name);
 
 	res = VPB_OK;
 
 	#else
 
-	res = vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_ON, i+1 /* resource 1 & 2 only for V4PCI*/ );
+	res = vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_ON);
 	if (res == VPB_OK) {
 		/* pthread_cond_wait(&bridges[i].cond, &bridges[i].lock);*/ /* Wait for condition signal. */
-		while( !bridges[i].endbridge ) {
+		while (!bridges[i].endbridge) {
 			/* Are we really ment to be doing nothing ?!?! */
 			who = ast_waitfor_n(cs, 2, &timeoutms);
 			if (!who) {
@@ -539,7 +554,7 @@
 					res = AST_BRIDGE_RETRY;
 					break;
 				}
-				ast_log(LOG_DEBUG, "%s: vpb_bridge: Empty frame read...\n",p0->dev);
+				ast_debug(1, "%s: vpb_bridge: Empty frame read...\n", p0->dev);
 				/* check for hangup / whentohangup */
 				if (ast_check_hangup(c0) || ast_check_hangup(c1))
 					break;
@@ -551,24 +566,23 @@
 				       ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
 				*fo = f;
 				*rc = who;
-				ast_log(LOG_DEBUG, "%s: vpb_bridge: Got a [%s]\n",p0->dev, f ? "digit" : "hangup");
-/*
-				if ((c0->tech_pvt == pvt0) && (!c0->_softhangup)) {
+				ast_debug(1, "%s: vpb_bridge: Got a [%s]\n", p0->dev, f ? "digit" : "hangup");
+#if 0
+				if ((c0->tech_pvt == pvt0) && (!ast_check_hangup(c0))) {
 					if (pr0->set_rtp_peer(c0, NULL, NULL, 0)) 
 						ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
 				}
-				if ((c1->tech_pvt == pvt1) && (!c1->_softhangup)) {
+				if ((c1->tech_pvt == pvt1) && (!ast_check_hangup(c1))) {
 					if (pr1->set_rtp_peer(c1, NULL, NULL, 0)) 
 						ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
 				}
-*/
 				/* That's all we needed */
-				/*return 0; */
+				return 0;
+#endif
 				/* Check if we need to break */
-				if (break_for_dtmf){
+				if (break_for_dtmf) {
 					break;
-				}
-				else if ((f->frametype == AST_FRAME_DTMF) && ((f->subclass == '#')||(f->subclass == '*'))){
+				} else if ((f->frametype == AST_FRAME_DTMF) && ((f->subclass == '#') || (f->subclass == '*'))) {
 					break;
 				}
 			} else {
@@ -592,27 +606,26 @@
 			cs[0] = cs[1];
 			cs[1] = cs[2];
 		};
-		vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_OFF, i+1 /* resource 1 & 2 only for V4PCI*/ ); 
+		vpb_bridge(p0->handle, p1->handle, VPB_BRIDGE_OFF); 
 	}
 
 	#endif
 
-	ast_mutex_lock(&bridge_lock); {
-		bridges[i].inuse = 0;
-	} ast_mutex_unlock(&bridge_lock); 
+	ast_mutex_lock(&bridge_lock);
+	bridges[i].inuse = 0;
+	ast_mutex_unlock(&bridge_lock); 
 
 	p0->bridge = NULL;
 	p1->bridge = NULL;
 
 
-	if (option_verbose>1) 
-		ast_verbose(VERBOSE_PREFIX_2 "Bridging call done with [%s, %s] => %d\n", c0->name, c1->name, res);
+	ast_verb(2, "Bridging call done with [%s, %s] => %d\n", c0->name, c1->name, res);
 
 /*
 	ast_mutex_unlock(&p0->lock);
 	ast_mutex_unlock(&p1->lock);
 */
-	return (res==VPB_OK) ? AST_BRIDGE_COMPLETE : AST_BRIDGE_FAILED;
+	return (res == VPB_OK) ? AST_BRIDGE_COMPLETE : AST_BRIDGE_FAILED;
 }
 
 /* Caller ID can be located in different positions between the rings depending on your Telco
@@ -638,19 +651,17 @@
 #endif
 
 
-	if( ast_mutex_trylock(&p->record_lock) == 0 ) {
+	if (ast_mutex_trylock(&p->record_lock) == 0) {
 
 		cid_record_time = ast_tvnow();
-		if (option_verbose>3) 
-			ast_verbose(VERBOSE_PREFIX_4 "CID record - start\n");
+		ast_verb(4, "CID record - start\n");
 
 		/* Skip any trailing ringtone */
 		if (UsePolarityCID != 1){
 			vpb_sleep(RING_SKIP);
 		}
 
-		if (option_verbose>3) 
-			ast_verbose(VERBOSE_PREFIX_4 "CID record - skipped %dms trailing ring\n",
+		ast_verb(4, "CID record - skipped %dms trailing ring\n",
 				 ast_tvdiff_ms(ast_tvnow(), cid_record_time));
 		cid_record_time = ast_tvnow();
 
@@ -660,73 +671,69 @@
 		vpb_record_buf_finish(p->handle);
 #ifdef ANALYSE_CID
 		vpb_wave_open_write(&ws, file, VPB_LINEAR);
-		vpb_wave_write(ws,(char*)buf,sizeof(buf));
+		vpb_wave_write(ws, (char *)buf, sizeof(buf));
 		vpb_wave_close_write(ws);
 #endif
 
-		if (option_verbose>3) 
-			ast_verbose(VERBOSE_PREFIX_4 "CID record - recorded %dms between rings\n", 
+		ast_verb(4, "CID record - recorded %dms between rings\n",
 				 ast_tvdiff_ms(ast_tvnow(), cid_record_time));
 
 		ast_mutex_unlock(&p->record_lock);
 
-		if( rc != VPB_OK ) {
-			ast_log(LOG_ERROR, "Failed to record caller id sample on %s\n", p->dev );
+		if (rc != VPB_OK) {
+			ast_log(LOG_ERROR, "Failed to record caller id sample on %s\n", p->dev);
 			return;
 		}
 
 		VPB_CID *cli_struct = new VPB_CID;
-		cli_struct->ra_cldn[0]=0;
-		cli_struct->ra_cn[0]=0;
+		cli_struct->ra_cldn[0] = 0;
+		cli_struct->ra_cn[0] = 0;
 		/* This decodes FSK 1200baud type callerid */
-		if ((rc=vpb_cid_decode2(cli_struct, buf, CID_MSECS*8)) == VPB_OK ) {
+		if ((rc = vpb_cid_decode2(cli_struct, buf, CID_MSECS * 8)) == VPB_OK ) {
 			/*
 			if (owner->cid.cid_num)
-				free(owner->cid.cid_num);
+				ast_free(owner->cid.cid_num);
 			owner->cid.cid_num=NULL;
 			if (owner->cid.cid_name)
-				free(owner->cid.cid_name);
+				ast_free(owner->cid.cid_name);
 			owner->cid.cid_name=NULL;
 			*/
 			
-			if (cli_struct->ra_cldn[0]=='\0'){
+			if (cli_struct->ra_cldn[0] == '\0') {
 				/*
-				owner->cid.cid_num = strdup(cli_struct->cldn);
-				owner->cid.cid_name = strdup(cli_struct->cn);
+				owner->cid.cid_num = ast_strdup(cli_struct->cldn);
+				owner->cid.cid_name = ast_strdup(cli_struct->cn);
 				*/
-				if (owner){
+				if (owner) {
 					ast_set_callerid(owner, cli_struct->cldn, cli_struct->cn, cli_struct->cldn);
 				} else {
 					strcpy(p->cid_num, cli_struct->cldn);
 					strcpy(p->cid_name, cli_struct->cn);
-
 				}
-				if (option_verbose>3) 
-					ast_verbose(VERBOSE_PREFIX_4 "CID record - got [%s] [%s]\n",owner->cid.cid_num,owner->cid.cid_name );
-				snprintf(p->callerid,sizeof(p->callerid)-1,"%s %s",cli_struct->cldn,cli_struct->cn);
-			}
-			else {
-				ast_log(LOG_ERROR,"CID record - No caller id avalable on %s \n", p->dev);
+				ast_verb(4, "CID record - got [%s] [%s]\n", owner->cid.cid_num, owner->cid.cid_name);
+				snprintf(p->callerid, sizeof(p->callerid), "%s %s", cli_struct->cldn, cli_struct->cn);
+			} else {
+				ast_log(LOG_ERROR, "CID record - No caller id avalable on %s \n", p->dev);
 			}
 
 		} else {
-			ast_log(LOG_ERROR, "CID record - Failed to decode caller id on %s - %s\n", p->dev, vpb_strerror(rc) );
-			strncpy(p->callerid,"unknown", sizeof(p->callerid) - 1);
+			ast_log(LOG_ERROR, "CID record - Failed to decode caller id on %s - %d\n", p->dev, rc);
+			ast_copy_string(p->callerid, "unknown", sizeof(p->callerid));
 		}
 		delete cli_struct;
 
 	} else 
-		ast_log(LOG_ERROR, "CID record - Failed to set record mode for caller id on %s\n", p->dev );
+		ast_log(LOG_ERROR, "CID record - Failed to set record mode for caller id on %s\n", p->dev);
 }
 
 static void get_callerid_ast(struct vpb_pvt *p)
 {
 	struct callerid_state *cs;
 	char buf[1024];
-	char *name=NULL, *number=NULL;
+	char *name = NULL, *number = NULL;
 	int flags;
-	int rc=0,vrc;
-	int sam_count=0;
+	int rc = 0, vrc;
+	int sam_count = 0;
 	struct ast_channel *owner = p->owner;
 	int which_cid;
 /*
@@ -734,71 +741,66 @@
 */
 #ifdef ANALYSE_CID
 	void * ws;
-	char * file="cidsams.wav";
+	char * file = "cidsams.wav";
 #endif
 
-	if(p->callerid_type == 1) {
-	if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collected caller ID already\n");
+	if (p->callerid_type == 1) {
+		ast_verb(4, "Collected caller ID already\n");
 		return;
 	}
-	else if(p->callerid_type == 2 ) {
-		which_cid=CID_SIG_V23;
-	if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID v23...\n");
-	}
-	else if(p->callerid_type == 3) {
-		which_cid=CID_SIG_BELL;
-	if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID bell...\n");
-	}
-	else {
-		if (option_verbose>3) 
-			ast_verbose(VERBOSE_PREFIX_4 "Caller ID disabled\n");
+	else if (p->callerid_type == 2 ) {
+		which_cid = CID_SIG_V23;
+		ast_verb(4, "Collecting Caller ID v23...\n");
+	}
+	else if (p->callerid_type == 3) {
+		which_cid = CID_SIG_BELL;
+		ast_verb(4, "Collecting Caller ID bell...\n");
+	} else {
+		ast_verb(4, "Caller ID disabled\n");
 		return;
 	}
 /*	vpb_sleep(RING_SKIP); */
 /*	vpb_record_get_gain(p->handle, &old_gain); */
 	cs = callerid_new(which_cid);
-	if (cs){
+	if (cs) {
 #ifdef ANALYSE_CID
 		vpb_wave_open_write(&ws, file, VPB_MULAW); 
 		vpb_record_set_gain(p->handle, 3.0); 
-		vpb_record_set_hw_gain(p->handle,12.0); 
+		vpb_record_set_hw_gain(p->handle, 12.0); 
 #endif
 		vpb_record_buf_start(p->handle, VPB_MULAW);
-		while((rc == 0)&&(sam_count<8000*3)){
+		while ((rc == 0) && (sam_count < 8000 * 3)) {
 			vrc = vpb_record_buf_sync(p->handle, (char*)buf, sizeof(buf));
 			if (vrc != VPB_OK)
-				ast_log(LOG_ERROR, "%s: Caller ID couldnt read audio buffer!\n",p->dev);
-			rc = callerid_feed(cs,(unsigned char *)buf,sizeof(buf),AST_FORMAT_ULAW);
+				ast_log(LOG_ERROR, "%s: Caller ID couldn't read audio buffer!\n", p->dev);
+			rc = callerid_feed(cs, (unsigned char *)buf, sizeof(buf), AST_FORMAT_ULAW);
 #ifdef ANALYSE_CID
-			vpb_wave_write(ws,(char*)buf,sizeof(buf)); 
+			vpb_wave_write(ws, (char *)buf, sizeof(buf)); 
 #endif
-			sam_count+=sizeof(buf);
-			if (option_verbose>3) ast_verbose(VERBOSE_PREFIX_4 "Collecting Caller ID samples [%d][%d]...\n",sam_count,rc);
+			sam_count += sizeof(buf);
+			ast_verb(4, "Collecting Caller ID samples [%d][%d]...\n", sam_count, rc);
 		}
 		vpb_record_buf_finish(p->handle);
 #ifdef ANALYSE_CID
-		vpb_wave_close_write(ws); 
+		vpb_wave_close_write(ws);
 #endif
-		if (rc == 1){
+		if (rc == 1) {
 			callerid_get(cs, &name, &number, &flags);
-			if (option_verbose>0) 
-				ast_verbose(VERBOSE_PREFIX_1 "%s: Caller ID name [%s] number [%s] flags [%d]\n",p->dev,name, number,flags);
-		}
-		else {
-			ast_log(LOG_ERROR, "%s: Failed to decode Caller ID \n", p->dev );
+			ast_debug(1, "%s: Caller ID name [%s] number [%s] flags [%d]\n", p->dev, name, number, flags);
+		} else {
+			ast_log(LOG_ERROR, "%s: Failed to decode Caller ID \n", p->dev);
 		}
 /*		vpb_record_set_gain(p->handle, old_gain); */
 /*		vpb_record_set_hw_gain(p->handle,6.0); */
-	}
-	else {
-		ast_log(LOG_ERROR, "%s: Failed to create Caller ID struct\n", p->dev );
+	} else {
+		ast_log(LOG_ERROR, "%s: Failed to create Caller ID struct\n", p->dev);
 	}
 	if (owner->cid.cid_num) {
-		free(owner->cid.cid_num);
+		ast_free(owner->cid.cid_num);
 		owner->cid.cid_num = NULL;
 	}
 	if (owner->cid.cid_name) {
-		free(owner->cid.cid_name);
+		ast_free(owner->cid.cid_name);
 		owner->cid.cid_name = NULL;
 	}
 	if (number)
@@ -807,26 +809,24 @@
 		number, name,
 		owner->cid.cid_ani ? NULL : number);
 	if (!ast_strlen_zero(name)){
-		snprintf(p->callerid,(sizeof(p->callerid)-1),"%s %s",number,name);
+		snprintf(p->callerid, sizeof(p->callerid), "%s %s", number, name);
 	} else {
-		snprintf(p->callerid,(sizeof(p->callerid)-1),"%s",number);
+		ast_copy_string(p->callerid, number, sizeof(p->callerid));
 	}
 	if (cs)
 		callerid_free(cs);
 }
 
 /* Terminate any tones we are presently playing */
-static void stoptone( int handle)
+static void stoptone(int handle)
 {
 	int ret;
 	VPB_EVENT je;
-	while(vpb_playtone_state(handle)!=VPB_OK){
+	while (vpb_playtone_state(handle) != VPB_OK) {
 		vpb_tone_terminate(handle);
-		ret = vpb_get_event_ch_async(handle,&je);
-		if ((ret == VPB_OK)&&(je.type != VPB_DIALEND)){
-			if (option_verbose > 3){
-					ast_verbose(VERBOSE_PREFIX_4 "Stop tone collected a wrong event!![%d]\n",je.type);
-			}
+		ret = vpb_get_event_ch_async(handle, &je);
+		if ((ret == VPB_OK) && (je.type != VPB_DIALEND)) {
+			ast_verb(4, "Stop tone collected a wrong event!![%d]\n", je.type);
 /*			vpb_put_event(&je); */
 		}
 		vpb_sleep(10);
@@ -836,10 +836,9 @@
 /* Safe vpb_playtone_async */
 static int playtone( int handle, VPB_TONE *tone)
 {
-	int ret=VPB_OK;
+	int ret = VPB_OK;
 	stoptone(handle);
-	if (option_verbose > 3) 
-		ast_verbose(VERBOSE_PREFIX_4 "[%02d]: Playing tone\n", handle);
+	ast_verb(4, "[%02d]: Playing tone\n", handle);
 	ret = vpb_playtone_async(handle, tone);
 	return ret;
 }
@@ -848,259 +847,258 @@
 {
 	struct ast_frame f = {AST_FRAME_CONTROL}; /* default is control, Clear rest. */
 	int endbridge = 0;
-	int res=0;
-
-	if (option_verbose > 3) 
-		ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: got event: [%d=>%d]\n", p->dev, e->type, e->data);
+	int res = 0;
+
+	ast_verb(4, "%s: handle_owned: got event: [%d=>%d]\n", p->dev, e->type, e->data);
 
 	f.src = "vpb";
 	switch (e->type) {
-		case VPB_RING:
-			if (p->mode == MODE_FXO) {
-				f.subclass = AST_CONTROL_RING;
+	case VPB_RING:
+		if (p->mode == MODE_FXO) {
+			f.subclass = AST_CONTROL_RING;
+			vpb_timer_stop(p->ring_timer);
+			vpb_timer_start(p->ring_timer);
+		} else
+			f.frametype = AST_FRAME_NULL; /* ignore ring on station port. */
+		break;
+
+	case VPB_RING_OFF:
+		f.frametype = AST_FRAME_NULL;
+		break;
+
+	case VPB_TIMEREXP:
+		if (e->data == p->busy_timer_id) {
+			playtone(p->handle, &Busytone);
+			p->state = VPB_STATE_PLAYBUSY;
+			vpb_timer_stop(p->busy_timer);
+			vpb_timer_start(p->busy_timer);
+			f.frametype = AST_FRAME_NULL;
+		} else if (e->data == p->ringback_timer_id) {
+			playtone(p->handle, &Ringbacktone);
+			vpb_timer_stop(p->ringback_timer);
+			vpb_timer_start(p->ringback_timer);
+			f.frametype = AST_FRAME_NULL;
+		} else if (e->data == p->ring_timer_id) {
+			/* We didnt get another ring in time! */
+			if (p->owner->_state != AST_STATE_UP)  {
+				 /* Assume caller has hung up */
 				vpb_timer_stop(p->ring_timer);
-				vpb_timer_start(p->ring_timer);
-			} else
-				f.frametype = AST_FRAME_NULL; /* ignore ring on station port. */
-			break;
-
-		case VPB_RING_OFF:
+				f.subclass = AST_CONTROL_HANGUP;
+			} else {
+				vpb_timer_stop(p->ring_timer);
+				f.frametype = AST_FRAME_NULL;
+			}
+				
+		} else {
+				f.frametype = AST_FRAME_NULL; /* Ignore. */
+		}
+		break;
+
+	case VPB_DTMF_DOWN:
+	case VPB_DTMF:
+		if (use_ast_dtmfdet) {
 			f.frametype = AST_FRAME_NULL;
-			break;
-
-		case VPB_TIMEREXP:
-			if (e->data == p->busy_timer_id) {
-				playtone(p->handle,&Busytone);
-				p->state = VPB_STATE_PLAYBUSY;
-				vpb_timer_stop(p->busy_timer);
-				vpb_timer_start(p->busy_timer);
+		} else if (p->owner->_state == AST_STATE_UP) {
+			f.frametype = AST_FRAME_DTMF;
+			f.subclass = e->data;
+		} else
+			f.frametype = AST_FRAME_NULL;
+		break;
+
+	case VPB_TONEDETECT:
+		if (e->data == VPB_BUSY || e->data == VPB_BUSY_308 || e->data == VPB_BUSY_AUST ) {
+			ast_debug(4, "%s: handle_owned: got event: BUSY\n", p->dev);
+			if (p->owner->_state == AST_STATE_UP) {
+				f.subclass = AST_CONTROL_HANGUP;
+			} else {
+				f.subclass = AST_CONTROL_BUSY;
+			}
+		} else if (e->data == VPB_FAX) {
+			if (!p->faxhandled) {
+				if (strcmp(p->owner->exten, "fax")) {
+					const char *target_context = S_OR(p->owner->macrocontext, p->owner->context);
+
+					if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) {
+						ast_verb(3, "Redirecting %s to fax extension\n", p->owner->name);
+						/* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
+						pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten);
+						if (ast_async_goto(p->owner, target_context, "fax", 1)) {
+							ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context);
+						}
+					} else {
+						ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
+					}
+				} else {
+					ast_debug(1, "Already in a fax extension, not redirecting\n");
+				}
+			} else {
+				ast_debug(1, "Fax already handled\n");
+			}
+		} else if (e->data == VPB_GRUNT) {
+			if (ast_tvdiff_ms(ast_tvnow(), p->lastgrunt) > gruntdetect_timeout) {
+				/* Nothing heard on line for a very long time
+				 * Timeout connection */
+				ast_verb(3, "grunt timeout\n");
+				ast_log(LOG_NOTICE, "%s: Line hangup due of lack of conversation\n", p->dev); 
+				f.subclass = AST_CONTROL_HANGUP;
+			} else {
+				p->lastgrunt = ast_tvnow();
 				f.frametype = AST_FRAME_NULL;
-			} else if (e->data == p->ringback_timer_id) {
-				playtone(p->handle, &Ringbacktone);
-				vpb_timer_stop(p->ringback_timer);
-				vpb_timer_start(p->ringback_timer);
-				f.frametype = AST_FRAME_NULL;
-			} else if (e->data == p->ring_timer_id) {
-				/* We didnt get another ring in time! */
-				if (p->owner->_state != AST_STATE_UP)  {
-					 /* Assume caller has hung up */
-					vpb_timer_stop(p->ring_timer);
-					f.subclass = AST_CONTROL_HANGUP;
-				} else {
-					vpb_timer_stop(p->ring_timer);
-					f.frametype = AST_FRAME_NULL;
-				}
-				
-			} else {
-				f.frametype = AST_FRAME_NULL; /* Ignore. */
-			}
-			break;
-
-		case VPB_DTMF_DOWN:
-		case VPB_DTMF:
-			if (use_ast_dtmfdet){
-				f.frametype = AST_FRAME_NULL;
-			} else if (p->owner->_state == AST_STATE_UP) {
-					f.frametype = AST_FRAME_DTMF;
-					f.subclass = e->data;
-			} else
-				f.frametype = AST_FRAME_NULL;
-			break;
-
-		case VPB_TONEDETECT:
-			if (e->data == VPB_BUSY || e->data == VPB_BUSY_308 || e->data == VPB_BUSY_AUST ) {
-				if (option_verbose > 3) 
-					ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: got event: BUSY\n", p->dev);
-				if (p->owner->_state == AST_STATE_UP) {
-					f.subclass = AST_CONTROL_HANGUP;
-				}
-				else {
-					f.subclass = AST_CONTROL_BUSY;
-				}
-			} 
-			else if (e->data == VPB_FAX){
-				if (!p->faxhandled){
-					if (strcmp(p->owner->exten, "fax")) {
-						const char *target_context = S_OR(p->owner->macrocontext, p->owner->context);
-						
-						if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) {
-							if (option_verbose > 2)
-								ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", p->owner->name);
-							/* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
-							pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten);
-							if (ast_async_goto(p->owner, target_context, "fax", 1))
-								ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context);
-						} else
-							ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
-					} else
-						ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n");
-				} else
-					ast_log(LOG_DEBUG, "Fax already handled\n");
-
-			} 
-			else if (e->data == VPB_GRUNT) {
-				if ( ast_tvdiff_ms(ast_tvnow(), p->lastgrunt) > gruntdetect_timeout ) {
-					/* Nothing heard on line for a very long time
-					 * Timeout connection */
-					if (option_verbose > 2) 
-						ast_verbose(VERBOSE_PREFIX_3 "grunt timeout\n");
-					ast_log(LOG_NOTICE,"%s: Line hangup due of lack of conversation\n",p->dev); 
-					f.subclass = AST_CONTROL_HANGUP;
-				} else {
-					p->lastgrunt = ast_tvnow();
-					f.frametype = AST_FRAME_NULL;
-				}
-			} 
-			else {
-				f.frametype = AST_FRAME_NULL;
-			}
-			break;
-
-		case VPB_CALLEND:
-			#ifdef DIAL_WITH_CALL_PROGRESS
-			if (e->data == VPB_CALL_CONNECTED) 
-				f.subclass = AST_CONTROL_ANSWER;
-			else if (e->data == VPB_CALL_NO_DIAL_TONE || e->data == VPB_CALL_NO_RING_BACK)
-				f.subclass =  AST_CONTROL_CONGESTION;
-			else if (e->data == VPB_CALL_NO_ANSWER || e->data == VPB_CALL_BUSY)
-				f.subclass = AST_CONTROL_BUSY;
-			else if (e->data  == VPB_CALL_DISCONNECTED) 
+			}
+		} else {
+			f.frametype = AST_FRAME_NULL;
+		}
+		break;
+
+	case VPB_CALLEND:
+		#ifdef DIAL_WITH_CALL_PROGRESS
+		if (e->data == VPB_CALL_CONNECTED) {
+			f.subclass = AST_CONTROL_ANSWER;
+		} else if (e->data == VPB_CALL_NO_DIAL_TONE || e->data == VPB_CALL_NO_RING_BACK) {
+			f.subclass =  AST_CONTROL_CONGESTION;
+		} else if (e->data == VPB_CALL_NO_ANSWER || e->data == VPB_CALL_BUSY) {
+			f.subclass = AST_CONTROL_BUSY;
+		} else if (e->data  == VPB_CALL_DISCONNECTED) {
+			f.subclass = AST_CONTROL_HANGUP;
+		}
+		#else
+		ast_log(LOG_NOTICE, "%s: Got call progress callback but blind dialing \n", p->dev); 
+		f.frametype = AST_FRAME_NULL;
+		#endif
+		break;
+
+	case VPB_STATION_OFFHOOK:
+		f.subclass = AST_CONTROL_ANSWER;
+		break;
+
+	case VPB_DROP:
+		if ((p->mode == MODE_FXO) && (UseLoopDrop)) { /* ignore loop drop on stations */
+			if (p->owner->_state == AST_STATE_UP) {
 				f.subclass = AST_CONTROL_HANGUP;
-			#else
-			ast_log(LOG_NOTICE,"%s: Got call progress callback but blind dialing \n", p->dev); 
-			f.frametype = AST_FRAME_NULL;
-			#endif
-			break;
-
-		case VPB_STATION_OFFHOOK:
-			f.subclass = AST_CONTROL_ANSWER;
-			break;
-
-		case VPB_DROP:
-			if ((p->mode == MODE_FXO)&&(UseLoopDrop)){ /* ignore loop drop on stations */
-				if (p->owner->_state == AST_STATE_UP) 
-					f.subclass = AST_CONTROL_HANGUP;
-				else
-					f.frametype = AST_FRAME_NULL;
-			}
-			break;
-		case VPB_LOOP_ONHOOK:
-			if (p->owner->_state == AST_STATE_UP)
-				f.subclass = AST_CONTROL_HANGUP;
-			else
-				f.frametype = AST_FRAME_NULL;
-			break;
-		case VPB_STATION_ONHOOK:
-			f.subclass = AST_CONTROL_HANGUP;
-			break;
-
-		case VPB_STATION_FLASH:
-			f.subclass = AST_CONTROL_FLASH;
-			break;
-
-		/* Called when dialing has finished and ringing starts
-		 * No indication that call has really been answered when using blind dialing
-		 */
-		case VPB_DIALEND:
-			if (p->state < 5){
-				f.subclass = AST_CONTROL_ANSWER;
-				if (option_verbose > 1) 
-					ast_verbose(VERBOSE_PREFIX_2 "%s: Dialend\n", p->dev);
 			} else {
 				f.frametype = AST_FRAME_NULL;
 			}
+		}
+		break;
+	case VPB_LOOP_ONHOOK:
+		if (p->owner->_state == AST_STATE_UP) {
+			f.subclass = AST_CONTROL_HANGUP;
+		} else {
+			f.frametype = AST_FRAME_NULL;
+		}
+		break;
+	case VPB_STATION_ONHOOK:
+		f.subclass = AST_CONTROL_HANGUP;
+		break;
+
+	case VPB_STATION_FLASH:
+		f.subclass = AST_CONTROL_FLASH;
+		break;
+
+	/* Called when dialing has finished and ringing starts
+	 * No indication that call has really been answered when using blind dialing
+	 */
+	case VPB_DIALEND:
+		if (p->state < 5) {
+			f.subclass = AST_CONTROL_ANSWER;
+			ast_verb(2, "%s: Dialend\n", p->dev);
+		} else {
+			f.frametype = AST_FRAME_NULL;
+		}
+		break;
+
+/*	case VPB_PLAY_UNDERFLOW:
+		f.frametype = AST_FRAME_NULL;
+		vpb_reset_play_fifo_alarm(p->handle);
+		break;
+
+	case VPB_RECORD_OVERFLOW:
+		f.frametype = AST_FRAME_NULL;
+		vpb_reset_record_fifo_alarm(p->handle);
+		break;
+*/
+	default:
+		f.frametype = AST_FRAME_NULL;
+		break;
+	}
+
+/*
+	ast_verb(4, "%s: LOCKING in handle_owned [%d]\n", p->dev,res);
+	res = ast_mutex_lock(&p->lock); 
+	ast_verb(4, "%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
+*/
+	if (p->bridge) { /* Check what happened, see if we need to report it. */
+		switch (f.frametype) {
+		case AST_FRAME_DTMF:
+			if (	!(p->bridge->c0 == p->owner && 
+					(p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_0) ) &&
+					!(p->bridge->c1 == p->owner && 
+					(p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_1) )) {
+				/* Kill bridge, this is interesting. */
+				endbridge = 1;
+			}
 			break;
 
-		case VPB_PLAY_UNDERFLOW:
-			f.frametype = AST_FRAME_NULL;
-			vpb_reset_play_fifo_alarm(p->handle);
+		case AST_FRAME_CONTROL:
+			if (!(p->bridge->flags & AST_BRIDGE_IGNORE_SIGS)) {
+			#if 0
+			if (f.subclass == AST_CONTROL_BUSY ||
+			f.subclass == AST_CONTROL_CONGESTION ||
+			f.subclass == AST_CONTROL_HANGUP ||
+			f.subclass == AST_CONTROL_FLASH)
+			#endif
+				endbridge = 1;
+			}
 			break;
 
-		case VPB_RECORD_OVERFLOW:
-			f.frametype = AST_FRAME_NULL;
-			vpb_reset_record_fifo_alarm(p->handle);
+		default:
 			break;
-
-		default:
-			f.frametype = AST_FRAME_NULL;
-			break;
-	}
-
-/*
-	if (option_verbose > 3) ast_verbose("%s: LOCKING in handle_owned [%d]\n", p->dev,res);
-	res = ast_mutex_lock(&p->lock); 
-	if (option_verbose > 3) ast_verbose("%s: LOCKING count[%d] owner[%d] \n", p->dev, p->lock.__m_count,p->lock.__m_owner);
-*/
-	{
-		if (p->bridge) { /* Check what happened, see if we need to report it. */
-			switch (f.frametype) {
-				case AST_FRAME_DTMF:
-					if (	!(p->bridge->c0 == p->owner && 
-							(p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_0) ) &&
-						!(p->bridge->c1 == p->owner && 
-							(p->bridge->flags & AST_BRIDGE_DTMF_CHANNEL_1) )) 
-						/* Kill bridge, this is interesting. */
-						endbridge = 1;
-					break;
-
-				case AST_FRAME_CONTROL:
-					if (!(p->bridge->flags & AST_BRIDGE_IGNORE_SIGS)) 
-					#if 0
-					if (f.subclass == AST_CONTROL_BUSY ||
-					f.subclass == AST_CONTROL_CONGESTION ||
-					f.subclass == AST_CONTROL_HANGUP ||
-					f.subclass == AST_CONTROL_FLASH)
-					#endif
-						endbridge = 1;
-					break;
-
-				default:
-					break;
-			}
-			if (endbridge) {
-				if (p->bridge->fo)
-					*p->bridge->fo = ast_frisolate(&f);
-				if (p->bridge->rc)
-					*p->bridge->rc = p->owner;
-
-				ast_mutex_lock(&p->bridge->lock); {
-					p->bridge->endbridge = 1;
-					ast_cond_signal(&p->bridge->cond);
-				} ast_mutex_unlock(&p->bridge->lock); 	       		   
-			}	  
-		}
-	} 
-
-	if (endbridge){
+		}
+
+		if (endbridge) {
+			if (p->bridge->fo) {
+				*p->bridge->fo = ast_frisolate(&f);
+			}
+
+			if (p->bridge->rc) {
+				*p->bridge->rc = p->owner;
+			}
+
+			ast_mutex_lock(&p->bridge->lock);
+			p->bridge->endbridge = 1;
+			ast_cond_signal(&p->bridge->cond);
+			ast_mutex_unlock(&p->bridge->lock); 	       		   
+		}	  
+	}
+
+	if (endbridge) {
 		res = ast_mutex_unlock(&p->lock);
 /*
-		if (option_verbose > 3) ast_verbose("%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
+		ast_verb(4, "%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
 */
 		return 0;
 	}
 
-	if (option_verbose > 3) 
-		ast_verbose(VERBOSE_PREFIX_4 "%s: handle_owned: Prepared frame type[%d]subclass[%d], bridge=%p owner=[%s]\n",
+	ast_verb(4, "%s: handle_owned: Prepared frame type[%d]subclass[%d], bridge=%p owner=[%s]\n",
 			p->dev, f.frametype, f.subclass, (void *)p->bridge, p->owner->name);
 
 	/* Trylock used here to avoid deadlock that can occur if we
 	 * happen to be in here handling an event when hangup is called
 	 * Problem is that hangup holds p->owner->lock
 	 */
-	if ((f.frametype >= 0)&& (f.frametype != AST_FRAME_NULL)&&(p->owner)) {
-		if (ast_mutex_trylock(&p->owner->lock)==0)  {
+	if ((f.frametype >= 0) && (f.frametype != AST_FRAME_NULL) && (p->owner)) {
+		if (ast_channel_trylock(p->owner) == 0) {
 			ast_queue_frame(p->owner, &f);
-			ast_mutex_unlock(&p->owner->lock);
-			if (option_verbose > 3) 
-				ast_verbose(VERBOSE_PREFIX_4 "%s: handled_owned: Queued Frame to [%s]\n", p->dev,p->owner->name);
+			ast_channel_unlock(p->owner);
+			ast_verb(4, "%s: handled_owned: Queued Frame to [%s]\n", p->dev, p->owner->name);
 		} else {
 			ast_verbose("%s: handled_owned: Missed event %d/%d \n",
-				p->dev,f.frametype, f.subclass);
+				p->dev, f.frametype, f.subclass);
 		}
 	}
 	res = ast_mutex_unlock(&p->lock);
 /*
-	if (option_verbose > 3) ast_verbose("%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
+	ast_verb(4, "%s: unLOCKING in handle_owned [%d]\n", p->dev,res);
 */
 
 	return 0;
@@ -1116,209 +1114,191 @@
 	struct ast_channel *c;
 */
 
-	if (option_verbose > 3) {
-		char str[VPB_MAX_STR];
-		vpb_translate_event(e, str);
-		ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: mode=%d, event[%d][%s]=[%d]\n",
-			p->dev, p->mode, e->type,str, e->data);
-	}
-
-	switch(e->type) {
-		case VPB_LOOP_ONHOOK:
-		case VPB_LOOP_POLARITY:
-			if (UsePolarityCID == 1){
-				if (option_verbose>3)
-					ast_verbose(VERBOSE_PREFIX_4 "Polarity reversal\n");
-				if(p->callerid_type == 1) {
-					if (option_verbose>3)
-						ast_verbose(VERBOSE_PREFIX_4 "Using VPB Caller ID\n");
-					get_callerid(p);        /* UK CID before 1st ring*/
+	char str[VPB_MAX_STR];
+
+	vpb_translate_event(e, str);
+	ast_verb(4, "%s: handle_notowned: mode=%d, event[%d][%s]=[%d]\n", p->dev, p->mode, e->type,str, e->data);
+
+	switch (e->type) {
+	case VPB_LOOP_ONHOOK:
+	case VPB_LOOP_POLARITY:
+		if (UsePolarityCID == 1) {
+			ast_verb(4, "Polarity reversal\n");
+			if (p->callerid_type == 1) {
+				ast_verb(4, "Using VPB Caller ID\n");
+				get_callerid(p);        /* UK CID before 1st ring*/
+			}
+/*			get_callerid_ast(p); */   /* Caller ID using the ast functions */
+		}
+		break;
+	case VPB_RING:
+		if (p->mode == MODE_FXO) /* FXO port ring, start * */ {
+			vpb_new(p, AST_STATE_RING, p->context);
+			if (UsePolarityCID != 1) {
+				if (p->callerid_type == 1) {
+					ast_verb(4, "Using VPB Caller ID\n");
+					get_callerid(p);        /* Australian CID only between 1st and 2nd ring  */
 				}
-/*				get_callerid_ast(p); */   /* Caller ID using the ast functions */
-			}
-			break;
-		case VPB_RING:
-			if (p->mode == MODE_FXO) /* FXO port ring, start * */ {
+				get_callerid_ast(p);    /* Caller ID using the ast functions */
+			} else {
+				ast_log(LOG_ERROR, "Setting caller ID: %s %s\n", p->cid_num, p->cid_name);
+				ast_set_callerid(p->owner, p->cid_num, p->cid_name, p->cid_num);
+				p->cid_num[0] = 0;
+				p->cid_name[0] = 0;
+			}
+
+			vpb_timer_stop(p->ring_timer);
+			vpb_timer_start(p->ring_timer);
+		}
+		break;
+
+	case VPB_RING_OFF:
+		break;
+
+	case VPB_STATION_OFFHOOK:
+		if (p->mode == MODE_IMMEDIATE) {
+			vpb_new(p,AST_STATE_RING, p->context);
+		} else {
+			ast_verb(4, "%s: handle_notowned: playing dialtone\n", p->dev);
+			playtone(p->handle, &Dialtone);
+			p->state = VPB_STATE_PLAYDIAL;
+			p->wantdtmf = 1;
+			p->ext[0] = 0;	/* Just to be sure & paranoid.*/
+		}
+		break;
+
+	case VPB_DIALEND:
+		if (p->mode == MODE_DIALTONE) {
+			if (p->state == VPB_STATE_PLAYDIAL) {
+				playtone(p->handle, &Dialtone);
+				p->wantdtmf = 1;
+				p->ext[0] = 0;	/* Just to be sure & paranoid. */
+			}
+#if 0
+			/* These are not needed as they have timers to restart them */
+			else if (p->state == VPB_STATE_PLAYBUSY) {
+				playtone(p->handle, &Busytone);
+				p->wantdtmf = 1;
+				p->ext[0] = 0;	
+			} else if (p->state == VPB_STATE_PLAYRING) {
+				playtone(p->handle, &Ringbacktone);
+				p->wantdtmf = 1;
+				p->ext[0] = 0;
+			}
+#endif
+		} else {
+			ast_verb(4, "%s: handle_notowned: Got a DIALEND when not really expected\n",p->dev);
+		}
+		break;
+
+	case VPB_STATION_ONHOOK:	/* clear ext */
+		stoptone(p->handle);
+		p->wantdtmf = 1 ;
+		p->ext[0] = 0;
+		p->state = VPB_STATE_ONHOOK;
+		break;
+	case VPB_TIMEREXP:
+		if (e->data == p->dtmfidd_timer_id) {
+			if (ast_exists_extension(NULL, p->context, p->ext, 1, p->callerid)){
+				ast_verb(4, "%s: handle_notowned: DTMF IDD timer out, matching on [%s] in [%s]\n", p->dev, p->ext, p->context);
+
 				vpb_new(p, AST_STATE_RING, p->context);
-				if (UsePolarityCID != 1){
-					if(p->callerid_type == 1) {
-						if (option_verbose>3)
-							ast_verbose(VERBOSE_PREFIX_4 "Using VPB Caller ID\n");
-						get_callerid(p);        /* Australian CID only between 1st and 2nd ring  */
-					}
-					get_callerid_ast(p);    /* Caller ID using the ast functions */
-				}
-				else {
-					ast_log(LOG_ERROR, "Setting caller ID: %s %s\n",p->cid_num, p->cid_name);
-					ast_set_callerid(p->owner, p->cid_num, p->cid_name, p->cid_num);
-					p->cid_num[0]=0;
-					p->cid_name[0]=0;
-				}
-
-				vpb_timer_stop(p->ring_timer);
-				vpb_timer_start(p->ring_timer);
-			}
-			break;
-
-		case VPB_RING_OFF:
-			break;
-
-		case VPB_STATION_OFFHOOK:
-			if (p->mode == MODE_IMMEDIATE) 
-				vpb_new(p,AST_STATE_RING, p->context);
-			else {
-				ast_verbose(VERBOSE_PREFIX_4 "%s: handle_notowned: playing dialtone\n",p->dev);
-				playtone(p->handle, &Dialtone);
-				p->state=VPB_STATE_PLAYDIAL;
-				p->wantdtmf = 1;
-				p->ext[0] = 0;	/* Just to be sure & paranoid.*/
-			}
-			break;
-
-		case VPB_DIALEND:
-			if (p->mode == MODE_DIALTONE){
-				if (p->state == VPB_STATE_PLAYDIAL) {
-					playtone(p->handle, &Dialtone);
-					p->wantdtmf = 1;
-					p->ext[0] = 0;	/* Just to be sure & paranoid. */
-				}

[... 2570 lines stripped ...]



More information about the asterisk-commits mailing list