[asterisk-commits] tilghman: trunk r168601 - /trunk/channels/chan_misdn.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 14 12:27:58 CST 2009


Author: tilghman
Date: Wed Jan 14 12:27:57 2009
New Revision: 168601

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=168601
Log:
Mostly spacing changes; no functionality change at all.

Modified:
    trunk/channels/chan_misdn.c

Modified: trunk/channels/chan_misdn.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/channels/chan_misdn.c?view=diff&rev=168601&r1=168600&r2=168601
==============================================================================
--- trunk/channels/chan_misdn.c (original)
+++ trunk/channels/chan_misdn.c Wed Jan 14 12:27:57 2009
@@ -114,27 +114,27 @@
 ast_mutex_t release_lock;
 
 enum misdn_chan_state {
-	MISDN_NOTHING=0,	/*!< at beginning */
-	MISDN_WAITING4DIGS, /*!<  when waiting for infos */
-	MISDN_EXTCANTMATCH, /*!<  when asterisk couldn't match our ext */
-	MISDN_INCOMING_SETUP, /*!<  for incoming setups*/
-	MISDN_DIALING, /*!<  when pbx_start */
-	MISDN_PROGRESS, /*!<  we got a progress */
-	MISDN_PROCEEDING, /*!<  we got a progress */
-	MISDN_CALLING, /*!<  when misdn_call is called */
-	MISDN_CALLING_ACKNOWLEDGE, /*!<  when we get SETUP_ACK */
-	MISDN_ALERTING, /*!<  when Alerting */
-	MISDN_BUSY, /*!<  when BUSY */
-	MISDN_CONNECTED, /*!<  when connected */
-	MISDN_PRECONNECTED, /*!<  when connected */
-	MISDN_DISCONNECTED, /*!<  when connected */
-	MISDN_RELEASED, /*!<  when connected */
-	MISDN_BRIDGED, /*!<  when bridged */
-	MISDN_CLEANING, /*!< when hangup from * but we were connected before */
-	MISDN_HUNGUP_FROM_MISDN, /*!< when DISCONNECT/RELEASE/REL_COMP  came from misdn */
-	MISDN_HUNGUP_FROM_AST, /*!< when DISCONNECT/RELEASE/REL_COMP came out of misdn_hangup */
-	MISDN_HOLDED, /*!< if this chan is holded */
-	MISDN_HOLD_DISCONNECT, /*!< if this chan is holded */
+	MISDN_NOTHING = 0,         /*!< at beginning */
+	MISDN_WAITING4DIGS,        /*!< when waiting for info */
+	MISDN_EXTCANTMATCH,        /*!< when asterisk couldn't match our ext */
+	MISDN_INCOMING_SETUP,      /*!< for incoming setup */
+	MISDN_DIALING,             /*!< when pbx_start */
+	MISDN_PROGRESS,            /*!< we have progress */
+	MISDN_PROCEEDING,          /*!< we have progress */
+	MISDN_CALLING,             /*!< when misdn_call is called */
+	MISDN_CALLING_ACKNOWLEDGE, /*!< when we get SETUP_ACK */
+	MISDN_ALERTING,            /*!< when Alerting */
+	MISDN_BUSY,                /*!< when BUSY */
+	MISDN_CONNECTED,           /*!< when connected */
+	MISDN_PRECONNECTED,        /*!< when connected */
+	MISDN_DISCONNECTED,        /*!< when connected */
+	MISDN_RELEASED,            /*!< when connected */
+	MISDN_BRIDGED,             /*!< when bridged */
+	MISDN_CLEANING,            /*!< when hangup from * but we were connected before */
+	MISDN_HUNGUP_FROM_MISDN,   /*!< when DISCONNECT/RELEASE/REL_COMP came from misdn */
+	MISDN_HUNGUP_FROM_AST,     /*!< when DISCONNECT/RELEASE/REL_COMP came out of misdn_hangup */
+	MISDN_HOLDED,              /*!< when on hold */
+	MISDN_HOLD_DISCONNECT,     /*!< when on hold */
   
 };
 
@@ -196,7 +196,7 @@
 	 */
 	int noautorespond_on_setup;
 	
-	int norxtone;	/* Boolean assigned values but the value is not used. */
+	int norxtone;	/*!< Boolean assigned values but the value is not used. */
 
 	/*!
 	 * \brief TRUE if we are not to generate tones (Playtones)
@@ -341,7 +341,9 @@
 	 */
 	char mohinterpret[MAX_MUSICCLASS];
 
-	//int zero_read_cnt;	/* Not used */
+#if 0
+	int zero_read_cnt;	/* Not used */
+#endif
 
 	/*!
 	 * \brief Number of outgoing audio frames dropped since last debug gripe message.
@@ -399,38 +401,39 @@
 	 * \brief Overlap timer start time.  Timer restarted for every digit received.
 	 */
 	struct timeval overlap_tv;
-  
-	//struct chan_list *peer;	/* Not used */
+
+#if 0
+	struct chan_list *peer;     /* Not used */
+#endif
 
 	/*!
 	 * \brief Next channel call record in the list.
 	 */
 	struct chan_list *next;
-	//struct chan_list *prev;		/* Not used */
-	//struct chan_list *first;	/* Not used */
+#if 0
+	struct chan_list *prev;     /* Not used */
+	struct chan_list *first;    /* Not used */
+#endif
 };
 
+
+int MAXTICS = 8;
 
 
 void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
 void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
-
-struct robin_list {
+static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame);
+
+static struct robin_list {
 	char *group;
 	int port;
 	int channel;
 	struct robin_list *next;
 	struct robin_list *prev;
-};
-static struct robin_list *robin = NULL;
-
-
-
-static struct ast_frame *process_ast_dsp(struct chan_list *tmp, struct ast_frame *frame);
-
-
-
-static inline void free_robin_list_r (struct robin_list *r)
+} *robin = NULL;
+
+
+static inline void free_robin_list_r(struct robin_list *r)
 {
 	if (r) {
 		if (r->next)
@@ -441,22 +444,23 @@
 	}
 }
 
-static void free_robin_list ( void )
+static void free_robin_list(void)
 {
 	free_robin_list_r(robin);
 	robin = NULL;
 }
 
-static struct robin_list* get_robin_position (char *group) 
+static struct robin_list* get_robin_position(char *group) 
 {
 	struct robin_list *new;
 	struct robin_list *iter = robin;
 	for (; iter; iter = iter->next) {
-		if (!strcasecmp(iter->group, group))
+		if (!strcasecmp(iter->group, group)) {
 			return iter;
+		}
 	}
 	new = ast_calloc(1, sizeof(*new));
-	new->group = strndup(group, strlen(group));
+	new->group = strdup(group);
 	new->channel = 1;
 	if (robin) {
 		new->next = robin;
@@ -491,7 +495,7 @@
 
 static const char misdn_type[] = "mISDN";
 
-static int tracing = 0 ;
+static int tracing = 0;
 
 /*! \brief Only alaw and mulaw is allowed for now */
 static int prefformat =  AST_FORMAT_ALAW ; /*  AST_FORMAT_SLINEAR ;  AST_FORMAT_ULAW | */
@@ -502,7 +506,6 @@
 
 static int *misdn_in_calls;
 static int *misdn_out_calls;
-
 
 struct chan_list dummy_cl;
 
@@ -522,8 +525,6 @@
 static struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc);
 static struct chan_list *find_chan_by_pid(struct chan_list *list, int pid);
 
-
-
 static int dialtone_indicate(struct chan_list *cl);
 static int hanguptone_indicate(struct chan_list *cl);
 static int stop_indicate(struct chan_list *cl);
@@ -538,9 +539,7 @@
 
 int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
 
-
 void debug_numplan(int port, int numplan, char *type);
-
 
 int add_out_calls(int port);
 int add_in_calls(int port);
@@ -560,8 +559,10 @@
 {
 	struct chan_list *tmp;
   
-	for (tmp=cl_te; tmp; tmp = tmp->next) {
-		if ( tmp->ast == ast ) return tmp;
+	for (tmp = cl_te; tmp; tmp = tmp->next) {
+		if (tmp->ast == ast) {
+			return tmp;
+		}
 	}
   
 	return NULL;
@@ -571,8 +572,10 @@
 {
 	struct chan_list *tmp;
   
-	for (tmp=cl_te; tmp; tmp = tmp->next) {
-		if ( tmp->ast  && strcmp(tmp->ast->name,name) == 0) return tmp;
+	for (tmp = cl_te; tmp; tmp = tmp->next) {
+		if (tmp->ast && strcmp(tmp->ast->name, name) == 0) {
+			return tmp;
+		}
 	}
   
 	return NULL;
@@ -581,10 +584,10 @@
 
 
 struct allowed_bearers {
-	char *name;			/*!< Bearer capability name string used in /etc/misdn.conf allowed_bearers */
-	char *display;		/*!< Bearer capability displayable name */
-	int cap;			/*!< SETUP message bearer capability field code value */
-	int deprecated;		/*!< TRUE if this entry is deprecated. (Misspelled or bad name to use) */
+	char *name;         /*!< Bearer capability name string used in /etc/misdn.conf allowed_bearers */
+	char *display;      /*!< Bearer capability displayable name */
+	int cap;            /*!< SETUP message bearer capability field code value */
+	int deprecated;     /*!< TRUE if this entry is deprecated. (Misspelled or bad name to use) */
 };
 
 /* *INDENT-OFF* */
@@ -618,56 +621,57 @@
 	switch (fac->Function) {
 #ifdef HAVE_MISDN_FAC_RESULT
 	case Fac_RESULT:
-		chan_misdn_log(0, bc->port," --> Received RESULT Operation\n");
+		chan_misdn_log(0, bc->port, " --> Received RESULT Operation\n");
 		break;
 #endif
 #ifdef HAVE_MISDN_FAC_ERROR
 	case Fac_ERROR:
-		chan_misdn_log(0, bc->port," --> Received Error Operation\n");
-		chan_misdn_log(0, bc->port," --> Value:%d Error:%s\n",fac->u.ERROR.errorValue, fac->u.ERROR.error);
+		chan_misdn_log(0, bc->port, " --> Received Error Operation\n");
+		chan_misdn_log(0, bc->port, " --> Value:%d Error:%s\n", fac->u.ERROR.errorValue, fac->u.ERROR.error);
 		break;
 #endif
 	case Fac_CD:
-		chan_misdn_log(1,bc->port," --> calldeflect to: %s, presentable: %s\n", fac->u.CDeflection.DeflectedToNumber,
+		chan_misdn_log(1, bc->port, " --> calldeflect to: %s, presentable: %s\n", fac->u.CDeflection.DeflectedToNumber,
 			fac->u.CDeflection.PresentationAllowed ? "yes" : "no");
 		break;
 	case Fac_AOCDCurrency:
-		if (fac->u.AOCDcur.chargeNotAvailable)
-			chan_misdn_log(1,bc->port," --> AOCD currency: charge not available\n");
-		else if (fac->u.AOCDcur.freeOfCharge)
-			chan_misdn_log(1,bc->port," --> AOCD currency: free of charge\n");
-		else if (fac->u.AOCDchu.billingId >= 0)
-			chan_misdn_log(1,bc->port," --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s billingId:%d\n",
+		if (fac->u.AOCDcur.chargeNotAvailable) {
+			chan_misdn_log(1, bc->port, " --> AOCD currency: charge not available\n");
+		} else if (fac->u.AOCDcur.freeOfCharge) {
+			chan_misdn_log(1, bc->port, " --> AOCD currency: free of charge\n");
+		} else if (fac->u.AOCDchu.billingId >= 0) {
+			chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s billingId:%d\n",
 				fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
 				(fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDcur.billingId);
-		else
-			chan_misdn_log(1,bc->port," --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s\n",
+		} else {
+			chan_misdn_log(1, bc->port, " --> AOCD currency: currency:%s amount:%d multiplier:%d typeOfChargingInfo:%s\n",
 				fac->u.AOCDcur.currency, fac->u.AOCDcur.currencyAmount, fac->u.AOCDcur.multiplier,
 				(fac->u.AOCDcur.typeOfChargingInfo == 0) ? "subTotal" : "total");
+		}
 		break;
 	case Fac_AOCDChargingUnit:
-		if (fac->u.AOCDchu.chargeNotAvailable)
-			chan_misdn_log(1,bc->port," --> AOCD charging unit: charge not available\n");
-		else if (fac->u.AOCDchu.freeOfCharge)
-			chan_misdn_log(1,bc->port," --> AOCD charging unit: free of charge\n");
-		else if (fac->u.AOCDchu.billingId >= 0)
-			chan_misdn_log(1,bc->port," --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s billingId:%d\n",
+		if (fac->u.AOCDchu.chargeNotAvailable) {
+			chan_misdn_log(1, bc->port, " --> AOCD charging unit: charge not available\n");
+		} else if (fac->u.AOCDchu.freeOfCharge) {
+			chan_misdn_log(1, bc->port, " --> AOCD charging unit: free of charge\n");
+		} else if (fac->u.AOCDchu.billingId >= 0) {
+			chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s billingId:%d\n",
 				fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total", fac->u.AOCDchu.billingId);
-		else
-			chan_misdn_log(1,bc->port," --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s\n",
+		} else {
+			chan_misdn_log(1, bc->port, " --> AOCD charging unit: recordedUnits:%d typeOfChargingInfo:%s\n",
 				fac->u.AOCDchu.recordedUnits, (fac->u.AOCDchu.typeOfChargingInfo == 0) ? "subTotal" : "total");
+		}
 		break;
 	case Fac_None:
 	default:
-		chan_misdn_log(1,bc->port," --> unknown facility\n");
+		chan_misdn_log(1, bc->port, " --> unknown facility\n");
 		break;
 	}
 }
 
 static void print_bearer(struct misdn_bchannel *bc) 
 {
-	
-	chan_misdn_log(2, bc->port, " --> Bearer: %s\n",bearer2str(bc->capability));
+	chan_misdn_log(2, bc->port, " --> Bearer: %s\n", bearer2str(bc->capability));
 	
 	switch(bc->law) {
 	case INFO_CODEC_ALAW:
@@ -683,48 +687,51 @@
 {
 	char buf[128];
 
-	if (!bc->AOCD_need_export || !ast)
+	if (!bc->AOCD_need_export || !ast) {
 		return;
+	}
 
 	if (originator == ORG_AST) {
-		ast = ast_bridged_channel(ast);
-		if (!ast)
+		if (!(ast = ast_bridged_channel(ast))) {
 			return;
+		}
 	}
 
 	switch (bc->AOCDtype) {
 	case Fac_AOCDCurrency:
 		pbx_builtin_setvar_helper(ast, "AOCD_Type", "currency");
-		if (bc->AOCD.currency.chargeNotAvailable)
+		if (bc->AOCD.currency.chargeNotAvailable) {
 			pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
-		else {
+		} else {
 			pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
-			if (bc->AOCD.currency.freeOfCharge)
+			if (bc->AOCD.currency.freeOfCharge) {
 				pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
-			else {
+			} else {
 				pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
 				if (snprintf(buf, sizeof(buf), "%d %s", bc->AOCD.currency.currencyAmount * bc->AOCD.currency.multiplier, bc->AOCD.currency.currency) < sizeof(buf)) {
 					pbx_builtin_setvar_helper(ast, "AOCD_Amount", buf);
-					if (bc->AOCD.currency.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.currency.billingId) < sizeof(buf))
+					if (bc->AOCD.currency.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.currency.billingId) < sizeof(buf)) {
 						pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
+					}
 				}
 			}
 		}
 		break;
 	case Fac_AOCDChargingUnit:
 		pbx_builtin_setvar_helper(ast, "AOCD_Type", "charging_unit");
-		if (bc->AOCD.chargingUnit.chargeNotAvailable)
+		if (bc->AOCD.chargingUnit.chargeNotAvailable) {
 			pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
-		else {
+		} else {
 			pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
-			if (bc->AOCD.chargingUnit.freeOfCharge)
+			if (bc->AOCD.chargingUnit.freeOfCharge) {
 				pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
-			else {
+			} else {
 				pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
 				if (snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.recordedUnits) < sizeof(buf)) {
 					pbx_builtin_setvar_helper(ast, "AOCD_RecordedUnits", buf);
-					if (bc->AOCD.chargingUnit.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.billingId) < sizeof(buf))
+					if (bc->AOCD.chargingUnit.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.billingId) < sizeof(buf)) {
 						pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
+					}
 				}
 			}
 		}
@@ -741,7 +748,7 @@
 static void sighandler(int sig)
 {}
 
-static void* misdn_tasks_thread_func (void *data)
+static void *misdn_tasks_thread_func(void *data)
 {
 	int wait;
 	struct sigaction sa;
@@ -756,16 +763,18 @@
 
 	while (1) {
 		wait = ast_sched_wait(misdn_tasks);
-		if (wait < 0)
+		if (wait < 0) {
 			wait = 8000;
-		if (poll(NULL, 0, wait) < 0)
+		}
+		if (poll(NULL, 0, wait) < 0) {
 			chan_misdn_log(4, 0, "Waking up misdn_tasks thread\n");
+		}
 		ast_sched_runq(misdn_tasks);
 	}
 	return NULL;
 }
 
-static void misdn_tasks_init (void)
+static void misdn_tasks_init(void)
 {
 	sem_t blocker;
 	int i = 5;
@@ -784,7 +793,7 @@
 	sem_destroy(&blocker);
 }
 
-static void misdn_tasks_destroy (void)
+static void misdn_tasks_destroy(void)
 {
 	if (misdn_tasks) {
 		chan_misdn_log(4, 0, "Killing misdn_tasks thread\n");
@@ -796,12 +805,12 @@
 	}
 }
 
-static inline void misdn_tasks_wakeup (void)
+static inline void misdn_tasks_wakeup(void)
 {
 	pthread_kill(misdn_tasks_thread, SIGUSR1);
 }
 
-static inline int _misdn_tasks_add_variable (int timeout, ast_sched_cb callback, const void *data, int variable)
+static inline int _misdn_tasks_add_variable(int timeout, ast_sched_cb callback, const void *data, int variable)
 {
 	int task_id;
 
@@ -814,33 +823,35 @@
 	return task_id;
 }
 
-static int misdn_tasks_add (int timeout, ast_sched_cb callback, const void *data)
+static int misdn_tasks_add(int timeout, ast_sched_cb callback, const void *data)
 {
 	return _misdn_tasks_add_variable(timeout, callback, data, 0);
 }
 
-static int misdn_tasks_add_variable (int timeout, ast_sched_cb callback, const void *data)
+static int misdn_tasks_add_variable(int timeout, ast_sched_cb callback, const void *data)
 {
 	return _misdn_tasks_add_variable(timeout, callback, data, 1);
 }
 
-static void misdn_tasks_remove (int task_id)
+static void misdn_tasks_remove(int task_id)
 {
 	AST_SCHED_DEL(misdn_tasks, task_id);
 }
 
-static int misdn_l1_task (const void *data)
-{
-	misdn_lib_isdn_l1watcher(*(int *)data);
-	chan_misdn_log(5, *(int *)data, "L1watcher timeout\n");
+static int misdn_l1_task(const void *vdata)
+{
+	const int *data = vdata;
+	misdn_lib_isdn_l1watcher(*data);
+	chan_misdn_log(5, *data, "L1watcher timeout\n");
 	return 1;
 }
 
-static int misdn_overlap_dial_task (const void *data)
+static int misdn_overlap_dial_task(const void *data)
 {
 	struct timeval tv_end, tv_now;
 	int diff;
-	struct chan_list *ch = (struct chan_list *)data;
+	struct chan_list *ch = (struct chan_list *) data;
+	char *dad;
 
 	chan_misdn_log(4, ch->bc->port, "overlap dial task, chan_state: %d\n", ch->state);
 
@@ -848,48 +859,48 @@
 		ch->overlap_dial_task = -1;
 		return 0;
 	}
-	
+
 	ast_mutex_lock(&ch->overlap_tv_lock);
 	tv_end = ch->overlap_tv;
 	ast_mutex_unlock(&ch->overlap_tv_lock);
-	
+
 	tv_end.tv_sec += ch->overlap_dial;
 	tv_now = ast_tvnow();
 
-	diff = ast_tvdiff_ms(tv_end, tv_now);
-
-	if (diff <= 100) {
-		char *dad=ch->bc->dad, sexten[]="s";
-		/* if we are 100ms near the timeout, we are satisfied.. */
-		stop_indicate(ch);
-		
-		if (ast_strlen_zero(ch->bc->dad)) {
-			dad=sexten;
-			strcpy(ch->ast->exten, sexten);
-		}
-
-		if (ast_exists_extension(ch->ast, ch->context, dad, 1, ch->bc->oad)) {
-			ch->state=MISDN_DIALING;
-			if (pbx_start_chan(ch) < 0) {
-				chan_misdn_log(-1, ch->bc->port, "ast_pbx_start returned < 0 in misdn_overlap_dial_task\n");
-				goto misdn_overlap_dial_task_disconnect;
-			}
-		} else {
+	if ((diff = ast_tvdiff_ms(tv_end, tv_now)) > 100) {
+		return diff;
+	}
+
+	/* if we are 100ms near the timeout, we are satisfied.. */
+	stop_indicate(ch);
+
+	if (ast_strlen_zero(ch->bc->dad)) {
+		dad = "s";
+		ast_copy_string(ch->ast->exten, "s", sizeof(ch->ast->exten));
+	} else {
+		dad = ch->bc->dad;
+	}
+
+	if (ast_exists_extension(ch->ast, ch->context, dad, 1, ch->bc->oad)) {
+		ch->state = MISDN_DIALING;
+		if (pbx_start_chan(ch) < 0) {
+			chan_misdn_log(-1, ch->bc->port, "ast_pbx_start returned < 0 in misdn_overlap_dial_task\n");
+			goto misdn_overlap_dial_task_disconnect;
+		}
+	} else {
 misdn_overlap_dial_task_disconnect:
-			hanguptone_indicate(ch);
-			ch->bc->out_cause = AST_CAUSE_UNALLOCATED;
-			ch->state=MISDN_CLEANING;
-			misdn_lib_send_event(ch->bc, EVENT_DISCONNECT);
-		}
-		ch->overlap_dial_task = -1;
-		return 0;
-	} else
-		return diff;
-}
-
-static void send_digit_to_chan(struct chan_list *cl, char digit )
-{
-	static const char* dtmf_tones[] = {
+		hanguptone_indicate(ch);
+		ch->bc->out_cause = AST_CAUSE_UNALLOCATED;
+		ch->state = MISDN_CLEANING;
+		misdn_lib_send_event(ch->bc, EVENT_DISCONNECT);
+	}
+	ch->overlap_dial_task = -1;
+	return 0;
+}
+
+static void send_digit_to_chan(struct chan_list *cl, char digit)
+{
+	static const char *dtmf_tones[] = {
 		"!941+1336/100,!0/100",	/* 0 */
 		"!697+1209/100,!0/100",	/* 1 */
 		"!697+1336/100,!0/100",	/* 2 */
@@ -905,18 +916,19 @@
 		"!852+1633/100,!0/100",	/* C */
 		"!941+1633/100,!0/100",	/* D */
 		"!941+1209/100,!0/100",	/* * */
-		"!941+1477/100,!0/100" };	/* # */
-	struct ast_channel *chan=cl->ast; 
+		"!941+1477/100,!0/100", /* # */
+	};
+	struct ast_channel *chan = cl->ast; 
   
-	if (digit >= '0' && digit <='9')
-		ast_playtones_start(chan,0,dtmf_tones[digit-'0'], 0);
-	else if (digit >= 'A' && digit <= 'D')
-		ast_playtones_start(chan,0,dtmf_tones[digit-'A'+10], 0);
-	else if (digit == '*')
-		ast_playtones_start(chan,0,dtmf_tones[14], 0);
-	else if (digit == '#')
-		ast_playtones_start(chan,0,dtmf_tones[15], 0);
-	else {
+	if (digit >= '0' && digit <='9') {
+		ast_playtones_start(chan, 0, dtmf_tones[digit - '0'], 0);
+	} else if (digit >= 'A' && digit <= 'D') {
+		ast_playtones_start(chan, 0, dtmf_tones[digit - 'A' + 10], 0);
+	} else if (digit == '*') {
+		ast_playtones_start(chan, 0, dtmf_tones[14], 0);
+	} else if (digit == '#') {
+		ast_playtones_start(chan, 0, dtmf_tones[15], 0);
+	} else {
 		/* not handled */
 		ast_debug(1, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
 	}
@@ -938,8 +950,9 @@
 		return complete_debug_port(a);
 	}
 
-	if (a->argc < 4 || a->argc > 7)
+	if (a->argc < 4 || a->argc > 7) {
 		return CLI_SHOWUSAGE;
+	}
 
 	if (!strcasecmp(a->argv[3], "on")) {
 		level = 1;
@@ -956,17 +969,18 @@
 			int i;
 			int only = 0;
 			if (a->argc == 5) {
-				if (strncasecmp(a->argv[4], "only", strlen(a->argv[4])))
+				if (strncasecmp(a->argv[4], "only", strlen(a->argv[4]))) {
 					return CLI_SHOWUSAGE;
-				else
+				} else {
 					only = 1;
+				}
 			}
 	
 			for (i = 0; i <= max_ports; i++) {
 				misdn_debug[i] = level;
 				misdn_debug_only[i] = only;
 			}
-			ast_cli(a->fd, "changing debug level for all ports to %d%s\n",misdn_debug[0], only?" (only)":"");
+			ast_cli(a->fd, "changing debug level for all ports to %d%s\n", misdn_debug[0], only ? " (only)" : "");
 		}
 		break;
 	case 6:
@@ -990,14 +1004,16 @@
 				return 0;
 			}
 			if (a->argc == 7) {
-				if (strncasecmp(a->argv[6], "only", strlen(a->argv[6])))
+				if (strncasecmp(a->argv[6], "only", strlen(a->argv[6]))) {
 					return CLI_SHOWUSAGE;
-				else
+				} else {
 					misdn_debug_only[port] = 1;
-			} else
+				}
+			} else {
 				misdn_debug_only[port] = 0;
+			}
 			misdn_debug[port] = level;
-			ast_cli(a->fd, "changing debug level to %d%s for port %d\n", misdn_debug[port], misdn_debug_only[port]?" (only)":"", port);
+			ast_cli(a->fd, "changing debug level to %d%s for port %d\n", misdn_debug[port], misdn_debug_only[port] ? " (only)" : "", port);
 		}
 	}
 
@@ -1018,10 +1034,11 @@
 		return NULL;
 	}
 
-	if (a->argc != 5)
+	if (a->argc != 5) {
 		return CLI_SHOWUSAGE;
-
-	/* Is this supposed to not do anything? */
+	}
+
+	/* XXX Is this supposed to not do anything? XXX */
 
 	return CLI_SUCCESS;
 }
@@ -1039,8 +1056,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_port_block(atoi(a->argv[3]));
 
@@ -1060,8 +1078,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_port_unblock(atoi(a->argv[3]));
 
@@ -1081,8 +1100,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_port_restart(atoi(a->argv[3]));
 
@@ -1102,8 +1122,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_pid_restart(atoi(a->argv[3]));
 
@@ -1123,8 +1144,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_get_port_up(atoi(a->argv[3]));
 
@@ -1144,8 +1166,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	misdn_lib_get_port_down(atoi(a->argv[3]));
 
@@ -1164,15 +1187,17 @@
 	term_color(name, tmp, COLOR_BRWHITE, 0, sizeof(tmp));
 	misdn_cfg_get_desc(elem, desc, sizeof(desc), def, sizeof(def));
 
-	if (elem < MISDN_CFG_LAST)
+	if (elem < MISDN_CFG_LAST) {
 		term_color(section, "PORTS SECTION", COLOR_YELLOW, 0, sizeof(section));
-	else
+	} else {
 		term_color(section, "GENERAL SECTION", COLOR_YELLOW, 0, sizeof(section));
-
-	if (*def)
+	}
+
+	if (*def) {
 		ast_cli(fd, "[%s] %s   (Default: %s)\n\t%s\n", section, name, def, desc);
-	else
+	} else {
 		ast_cli(fd, "[%s] %s\n\t%s\n", section, name, desc);
+	}
 }
 
 static char *handle_cli_misdn_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -1198,10 +1223,11 @@
 		if (!strcmp(a->argv[3], "description")) {
 			if (a->argc == 5) {
 				enum misdn_cfg_elements elem = misdn_cfg_get_elem(a->argv[4]);
-				if (elem == MISDN_CFG_FIRST)
+				if (elem == MISDN_CFG_FIRST) {
 					ast_cli(a->fd, "Unknown element: %s\n", a->argv[4]);
-				else
+				} else {
 					show_config_description(a->fd, elem);
+				}
 				return CLI_SUCCESS;
 			}
 			return CLI_SHOWUSAGE;
@@ -1268,27 +1294,27 @@
 };
 
 static struct state_struct state_array[] = {
-	{MISDN_NOTHING,"NOTHING"}, /* at beginning */
-	{MISDN_WAITING4DIGS,"WAITING4DIGS"}, /*  when waiting for infos */
-	{MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /*  when asterisk couldn't match our ext */
-	{MISDN_INCOMING_SETUP,"INCOMING SETUP"}, /*  when pbx_start */
-	{MISDN_DIALING,"DIALING"}, /*  when pbx_start */
-	{MISDN_PROGRESS,"PROGRESS"}, /*  when pbx_start */
-	{MISDN_PROCEEDING,"PROCEEDING"}, /*  when pbx_start */
-	{MISDN_CALLING,"CALLING"}, /*  when misdn_call is called */
-	{MISDN_CALLING_ACKNOWLEDGE,"CALLING_ACKNOWLEDGE"}, /*  when misdn_call is called */
-	{MISDN_ALERTING,"ALERTING"}, /*  when Alerting */
-	{MISDN_BUSY,"BUSY"}, /*  when BUSY */
-	{MISDN_CONNECTED,"CONNECTED"}, /*  when connected */
-	{MISDN_PRECONNECTED,"PRECONNECTED"}, /*  when connected */
-	{MISDN_DISCONNECTED,"DISCONNECTED"}, /*  when connected */
-	{MISDN_RELEASED,"RELEASED"}, /*  when connected */
-	{MISDN_BRIDGED,"BRIDGED"}, /*  when bridged */
-	{MISDN_CLEANING,"CLEANING"}, /* when hangup from * but we were connected before */
-	{MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
-	{MISDN_HOLDED,"HOLDED"}, /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
-	{MISDN_HOLD_DISCONNECT,"HOLD_DISCONNECT"}, /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
-	{MISDN_HUNGUP_FROM_AST,"HUNGUP_FROM_AST"} /* when DISCONNECT/RELEASE/REL_COMP came out of misdn_hangup */
+	{ MISDN_NOTHING,             "NOTHING" },             /* at beginning */
+	{ MISDN_WAITING4DIGS,        "WAITING4DIGS" },        /*  when waiting for infos */
+	{ MISDN_EXTCANTMATCH,        "EXTCANTMATCH" },        /*  when asterisk couldn't match our ext */
+	{ MISDN_INCOMING_SETUP,      "INCOMING SETUP" },      /*  when pbx_start */
+	{ MISDN_DIALING,             "DIALING" },             /*  when pbx_start */
+	{ MISDN_PROGRESS,            "PROGRESS" },            /*  when pbx_start */
+	{ MISDN_PROCEEDING,          "PROCEEDING" },          /*  when pbx_start */
+	{ MISDN_CALLING,             "CALLING" },             /*  when misdn_call is called */
+	{ MISDN_CALLING_ACKNOWLEDGE, "CALLING_ACKNOWLEDGE" }, /*  when misdn_call is called */
+	{ MISDN_ALERTING,            "ALERTING" },            /*  when Alerting */
+	{ MISDN_BUSY,                "BUSY" },                /*  when BUSY */
+	{ MISDN_CONNECTED,           "CONNECTED" },           /*  when connected */
+	{ MISDN_PRECONNECTED,        "PRECONNECTED" },        /*  when connected */
+	{ MISDN_DISCONNECTED,        "DISCONNECTED" },        /*  when connected */
+	{ MISDN_RELEASED,            "RELEASED" },            /*  when connected */
+	{ MISDN_BRIDGED,             "BRIDGED" },             /*  when bridged */
+	{ MISDN_CLEANING,            "CLEANING" },            /* when hangup from * but we were connected before */
+	{ MISDN_HUNGUP_FROM_MISDN,   "HUNGUP_FROM_MISDN" },   /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
+	{ MISDN_HOLDED,              "HOLDED" },              /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
+	{ MISDN_HOLD_DISCONNECT,     "HOLD_DISCONNECT" },     /* when DISCONNECT/RELEASE/REL_COMP  came from misdn */
+	{ MISDN_HUNGUP_FROM_AST,     "HUNGUP_FROM_AST" },     /* when DISCONNECT/RELEASE/REL_COMP came out of misdn_hangup */
 };
 
 static const char *misdn_get_ch_state(struct chan_list *p) 
@@ -1296,18 +1322,20 @@
 	int i;
 	static char state[8];
 	
-	if( !p) return NULL;
+	if (!p) {
+		return NULL;
+	}
   
-	for (i = 0; i < sizeof(state_array) / sizeof(struct state_struct); i++) {
-		if (state_array[i].state == p->state)
-			return state_array[i].txt; 
+	for (i = 0; i < ARRAY_LEN(state_array); i++) {
+		if (state_array[i].state == p->state) {
+			return state_array[i].txt;
+		}
 	}
 
  	snprintf(state, sizeof(state), "%d", p->state) ;
 
 	return state;
 }
-
 
 
 static void reload_config(void)
@@ -1345,8 +1373,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 2)
+	if (a->argc != 2) {
 		return CLI_SHOWUSAGE;
+	}
 
 	ast_cli(a->fd, "Reloading mISDN configuration\n");
 	reload_config();
@@ -1368,7 +1397,7 @@
 		ast ? ast->context : NULL,
 		misdn_get_ch_state(help)
 		);
-	if (misdn_debug[bc->port] > 0)
+	if (misdn_debug[bc->port] > 0) {
 		ast_cli(fd,
 			"  --> astname: %s\n"
 			"  --> ch_l3id: %x\n"
@@ -1405,7 +1434,7 @@
 			help->norxtone, help->notxtone,
 			bc->holded
 			);
-
+	}
 }
 
 static char *handle_cli_misdn_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -1423,8 +1452,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 3)
+	if (a->argc != 3) {
 		return CLI_SHOWUSAGE;
+	}
 
 	help = cl_te;
   
@@ -1442,8 +1472,9 @@
 			continue;
 		}
 
-		if (misdn_debug[0] > 2)
+		if (misdn_debug[0] > 2) {
 			ast_cli(a->fd, "Bc:%p Ast:%p\n", bc, ast);
+		}
 		if (bc) {
 			print_bc_info(a->fd, help, bc);
 		} else {
@@ -1485,8 +1516,9 @@
 		return complete_ch(a);
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	help = cl_te;
 
@@ -1499,14 +1531,11 @@
 				print_bc_info(a->fd, help, bc);
 				break; 
 			}
-		} 
+		}
 	}
 
 	return CLI_SUCCESS;
 }
-
-ast_mutex_t lock;
-int MAXTICS = 8;
 
 static char *handle_cli_misdn_set_tics(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -1520,9 +1549,11 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
-
+	}
+
+	/* XXX Wow, this does... a whole lot of nothing... XXX */
 	MAXTICS = atoi(a->argv[3]);
 
 	return CLI_SUCCESS;
@@ -1543,8 +1574,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 3)
+	if (a->argc != 3) {
 		return CLI_SHOWUSAGE;
+	}
 
 	ast_cli(a->fd, "BEGIN STACK_LIST:\n");
 	for (port = misdn_cfg_get_next_port(0); port > 0;
@@ -1572,8 +1604,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	ast_cli(a->fd, "Port\tin_calls\tout_calls\n");
 	for (port = misdn_cfg_get_next_port(0); port > 0;
@@ -1601,8 +1634,9 @@
 		return NULL;
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	port = atoi(a->argv[3]);
   
@@ -1636,8 +1670,9 @@
 		return complete_ch(a);
 	}
 
-	if (a->argc < 5)
+	if (a->argc < 5) {
 		return CLI_SHOWUSAGE;
+	}
  
 	if (strstr(a->argv[3], "calldeflect")) {
 		if (a->argc < 6) {
@@ -1650,18 +1685,18 @@
 		ast_verbose("Sending Calldeflection (%s) to %s\n", nr, channame);
 		tmp = get_chan_by_ast_name(channame);
 		if (!tmp) {
-			ast_verbose("Sending CD with nr %s to %s failed: Channel does not exist.\n",nr, channame);
+			ast_verbose("Sending CD with nr %s to %s failed: Channel does not exist.\n", nr, channame);
 			return 0; 
 		}
 
 		if (strlen(nr) >= 15) {
-			ast_verbose("Sending CD with nr %s to %s failed: Number too long (up to 15 digits are allowed).\n",nr, channame);
+			ast_verbose("Sending CD with nr %s to %s failed: Number too long (up to 15 digits are allowed).\n", nr, channame);
 			return 0; 
 		}
 		tmp->bc->fac_out.Function = Fac_CD;
 		ast_copy_string((char *)tmp->bc->fac_out.u.CDeflection.DeflectedToNumber, nr, sizeof(tmp->bc->fac_out.u.CDeflection.DeflectedToNumber));
 		misdn_lib_send_event(tmp->bc, EVENT_FACILITY);
-	} else if (strstr(a->argv[3],"CFActivate")) {
+	} else if (strstr(a->argv[3], "CFActivate")) {
 		if (a->argc < 7) {
 			ast_verbose("CFActivate requires 2 args: 1.FromNumber, 2.ToNumber\n\n");
 			return 0;
@@ -1675,13 +1710,13 @@
 		ast_verbose("Sending CFActivate  Port:(%d) FromNr. (%s) to Nr. (%s)\n", port, served_nr, nr);
 
 		bc->fac_out.Function = Fac_CFActivate;
-		bc->fac_out.u.CFActivate.BasicService = 0; //All Services
-		bc->fac_out.u.CFActivate.Procedure = 0; //Unconditional
+		bc->fac_out.u.CFActivate.BasicService = 0; /* All Services */
+		bc->fac_out.u.CFActivate.Procedure = 0; /* Unconditional */
 		ast_copy_string((char *)bc->fac_out.u.CFActivate.ServedUserNumber, served_nr, sizeof(bc->fac_out.u.CFActivate.ServedUserNumber));
 		ast_copy_string((char *)bc->fac_out.u.CFActivate.ForwardedToNumber, nr, sizeof(bc->fac_out.u.CFActivate.ForwardedToNumber));
 
 		misdn_lib_send_event(bc, EVENT_FACILITY);
-	} else if (strstr(a->argv[3],"CFDeactivate")) {
+	} else if (strstr(a->argv[3], "CFDeactivate")) {
 
 		if (a->argc < 6) {
 			ast_verbose("CFActivate requires 1 arg: FromNumber\n\n");
@@ -1720,8 +1755,9 @@
 		return NULL;
 	}
 
-	if (a->argc < 4 || a->argc > 5)
+	if (a->argc < 4 || a->argc > 5) {
 		return CLI_SHOWUSAGE;
+	}
 
 	port = atoi(a->argv[3]);
 
@@ -1754,8 +1790,9 @@
 		return complete_ch(a);
 	}
 
-	if (a->argc != 5)
+	if (a->argc != 5) {
 		return CLI_SHOWUSAGE;
+	}
 
 	channame = a->argv[3];
 	msg = a->argv[4];
@@ -1799,8 +1836,9 @@
 		return complete_ch(a);
 	}
 
-	if (a->argc != 4)
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
+	}
 
 	channame = a->argv[3];
   
@@ -1846,8 +1884,9 @@
 		return complete_ch(a);
 	}
 
-	if (a->argc != 5)
+	if (a->argc != 5) {
 		return CLI_SHOWUSAGE;
+	}
 
 	channame = a->argv[3];
 	msg = a->argv[4];
@@ -1871,21 +1910,24 @@
 	return ast_complete_channels(a->line, a->word, a->pos, a->n, 3);
 }
 
-static char *complete_debug_port (struct ast_cli_args *a)
-{
-	if (a->n)
+static char *complete_debug_port(struct ast_cli_args *a)
+{
+	if (a->n) {
 		return NULL;
+	}
 
 	switch (a->pos) {
 	case 4:
-		if (a->word[0] == 'p')
+		if (a->word[0] == 'p') {
 			return ast_strdup("port");
-		else if (a->word[0] == 'o')
+		} else if (a->word[0] == 'o') {
 			return ast_strdup("only");
+		}
 		break;
 	case 6:
-		if (a->word[0] == 'o')
+		if (a->word[0] == 'o') {
 			return ast_strdup("only");
+		}
 		break;
 	}
 	return NULL;
@@ -1901,12 +1943,15 @@
 
 	switch (a->pos) {
 	case 3:
-		if ((!strncmp(a->word, "description", wordlen)) && (++which > a->n))
+		if ((!strncmp(a->word, "description", wordlen)) && (++which > a->n)) {
 			return ast_strdup("description");
-		if ((!strncmp(a->word, "descriptions", wordlen)) && (++which > a->n))
+		}
+		if ((!strncmp(a->word, "descriptions", wordlen)) && (++which > a->n)) {
 			return ast_strdup("descriptions");
-		if ((!strncmp(a->word, "0", wordlen)) && (++which > a->n))
+		}
+		if ((!strncmp(a->word, "0", wordlen)) && (++which > a->n)) {
 			return ast_strdup("0");
+		}
 		while ((port = misdn_cfg_get_next_port(port)) != -1) {
 			snprintf(buffer, sizeof(buffer), "%d", port);
 			if ((!strncmp(a->word, buffer, wordlen)) && (++which > a->n)) {
@@ -1917,19 +1962,23 @@
 	case 4:
 		if (strstr(a->line, "description ")) {
 			for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) {
-				if ((elem == MISDN_CFG_LAST) || (elem == MISDN_GEN_FIRST))
+				if ((elem == MISDN_CFG_LAST) || (elem == MISDN_GEN_FIRST)) {
 					continue;
+				}
 				misdn_cfg_get_name(elem, buffer, sizeof(buffer));
 				if (!wordlen || !strncmp(a->word, buffer, wordlen)) {
-					if (++which > a->n)
+					if (++which > a->n) {
 						return ast_strdup(buffer);
+					}
 				}
 			}
 		} else if (strstr(a->line, "descriptions ")) {
-			if ((!wordlen || !strncmp(a->word, "general", wordlen)) && (++which > a->n))
+			if ((!wordlen || !strncmp(a->word, "general", wordlen)) && (++which > a->n)) {
 				return ast_strdup("general");
-			if ((!wordlen || !strncmp(a->word, "ports", wordlen)) && (++which > a->n))
+			}
+			if ((!wordlen || !strncmp(a->word, "ports", wordlen)) && (++which > a->n)) {
 				return ast_strdup("ports");
+			}
 		}
 		break;
 	}
@@ -2063,7 +2112,7 @@
 			len = 1000;
 		}
 
-		if ( threshold > len ) {
+		if (threshold > len) {
 			chan_misdn_log(0, bc->port, "config_jb: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
 		}
 
@@ -2073,10 +2122,11 @@
 			ch->jb = NULL;
 		}
 
-		ch->jb=misdn_jb_init(len, threshold);
-
-		if (!ch->jb ) 
+		ch->jb = misdn_jb_init(len, threshold);
+
+		if (!ch->jb) {
 			bc->nojitter = 1;
+		}
 	}
 }
 
@@ -2111,14 +2161,16 @@
 
 	misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, sizeof(bc->pipeline));
 
-	if (*bc->pipeline)
+	if (*bc->pipeline) {
 		return 0;
+	}
 
 	misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(ec));
-	if (ec == 1)
+	if (ec == 1) {
 		ast_copy_string(bc->pipeline, "mg2ec", sizeof(bc->pipeline));
-	else if (ec > 1)
+	} else if (ec > 1) {
 		snprintf(bc->pipeline, sizeof(bc->pipeline), "mg2ec(deftaps=%d)", ec);
+	}
 
 	return 0;
 }
@@ -2244,14 +2296,11 @@
 		misdn_cfg_get(port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(bc->te_choose_channel));
 
  		if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both")) {
- 			if (strstr(faxdetect, "nojump"))
- 				ch->faxdetect = 2;
- 			else
- 				ch->faxdetect = 1;
+ 			ch->faxdetect = strstr(faxdetect, "nojump") ? 2 : 1;
  		}
 
 		misdn_cfg_get(port, MISDN_CFG_CALLERID, callerid, sizeof(callerid));
-		if ( ! ast_strlen_zero(callerid) ) {
+		if (!ast_strlen_zero(callerid)) {
 			chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
 			ast_copy_string(bc->oad, callerid, sizeof(bc->oad));
 		}
@@ -2269,10 +2318,7 @@
 		char prefix[BUFFERSIZE + 1] = "";
 
  		if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both")) {
- 			if (strstr(faxdetect, "nojump"))
- 				ch->faxdetect = 2;
- 			else
- 				ch->faxdetect = 1;
+ 			ch->faxdetect = (strstr(faxdetect, "nojump")) ? 2 : 1;
  		}
 
 		misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(bc->cpnnumplan));
@@ -2297,7 +2343,7 @@
 			ast_copy_string(bc->orig_dad, bc->dad, sizeof(bc->orig_dad));
 		}
 
-		if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
+		if (ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
 			ast_copy_string(bc->dad, bc->keypad, sizeof(bc->dad));
 		}
 
@@ -2324,8 +2370,9 @@
 		ast_set_callerid(ast, bc->oad, NULL, bc->oad);
 
 		if ( !ast_strlen_zero(bc->rad) ) {
-			if (ast->cid.cid_rdnis)
+			if (ast->cid.cid_rdnis) {
 				ast_free(ast->cid.cid_rdnis);
+			}
 			ast->cid.cid_rdnis = ast_strdup(bc->rad);
 		}
 	
@@ -2337,16 +2384,15 @@
 	
 	if (ch->faxdetect  || ch->ast_dsp) {
 		misdn_cfg_get(port, MISDN_CFG_FAXDETECT_TIMEOUT, &ch->faxdetect_timeout, sizeof(ch->faxdetect_timeout));
-		if (!ch->dsp)
+		if (!ch->dsp) {
 			ch->dsp = ast_dsp_new();
+		}
 		if (ch->dsp) {
-			if (ch->faxdetect) 
-				ast_dsp_set_features(ch->dsp, DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_FAX_DETECT);
-			else 
-				ast_dsp_set_features(ch->dsp, DSP_FEATURE_DIGIT_DETECT );
-		}
-		if (!ch->trans)
+			ast_dsp_set_features(ch->dsp, DSP_FEATURE_DIGIT_DETECT | (ch->faxdetect ? DSP_FEATURE_FAX_DETECT : 0));
+		}
+		if (!ch->trans) {
 			ch->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, AST_FORMAT_ALAW);
+		}
 	}
 
 	/* AOCD initialization */
@@ -2368,19 +2414,18 @@
 	int bridging;
 	struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(ast);
 	struct misdn_bchannel *newbc;
-	char *opts = NULL, *ext, *tokb;
 	char *dest_cp = ast_strdupa(dest);
-
-	ext = strtok_r(dest_cp, "/", &tokb);
-
-	if (ext) {
-		ext = strtok_r(NULL, "/", &tokb);
-		if (ext) {
-			opts = strtok_r(NULL, "/", &tokb);
-		} else {
-			chan_misdn_log(0, 0, "misdn_call: No Extension given!\n");
-			return -1;
-		}
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(type);
+		AST_APP_ARG(ext);
+		AST_APP_ARG(opts);
+	);
+
+	AST_NONSTANDARD_APP_ARGS(args, dest_cp, '/');
+
+	if (ast_strlen_zero(args.ext)) {
+		chan_misdn_log(0, 0, "misdn_call: No Extension given!\n");
+		return -1;
 	}
 
 	if (!ast) {
@@ -2388,7 +2433,7 @@
 		return -1;
 	}
 
-	if (((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) || !dest  ) {
+	if (((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) || !dest) {
 		ast_log(LOG_WARNING, " --> ! misdn_call called on %s, neither down nor reserved (or dest==NULL)\n", ast->name);
 		ast->hangupcause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
 		ast_setstate(ast, AST_STATE_DOWN);
@@ -2426,8 +2471,8 @@
 	

[... 1865 lines stripped ...]



More information about the asterisk-commits mailing list