[asterisk-commits] rmudgett: branch group/v14_colp r145695 - in /team/group/v14_colp: channels/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 1 18:55:27 CDT 2008


Author: rmudgett
Date: Wed Oct  1 18:55:27 2008
New Revision: 145695

URL: http://svn.digium.com/view/asterisk?view=rev&rev=145695
Log:
Backported as many chan_misdn related changes from the trunk as possible.

Modified:
    team/group/v14_colp/channels/chan_misdn.c
    team/group/v14_colp/channels/misdn/chan_misdn_config.h
    team/group/v14_colp/channels/misdn/ie.c
    team/group/v14_colp/channels/misdn/isdn_lib.c
    team/group/v14_colp/channels/misdn/isdn_lib.h
    team/group/v14_colp/channels/misdn/isdn_lib_intern.h
    team/group/v14_colp/channels/misdn/isdn_msg_parser.c
    team/group/v14_colp/channels/misdn/portinfo.c
    team/group/v14_colp/channels/misdn_config.c
    team/group/v14_colp/configs/misdn.conf.sample
    team/group/v14_colp/funcs/func_callerid.c
    team/group/v14_colp/include/asterisk/callerid.h
    team/group/v14_colp/main/callerid.c

Modified: team/group/v14_colp/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/v14_colp/channels/chan_misdn.c?view=diff&rev=145695&r1=145694&r2=145695
==============================================================================
--- team/group/v14_colp/channels/chan_misdn.c (original)
+++ team/group/v14_colp/channels/chan_misdn.c Wed Oct  1 18:55:27 2008
@@ -75,6 +75,7 @@
 #include "asterisk/term.h"
 #include "asterisk/sched.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/abstract_jb.h"
 #include "asterisk/causes.h"
 
 #include "chan_misdn_config.h"
@@ -252,8 +253,8 @@
 		if (r->next)
 			free_robin_list_r(r->next);
 		if (r->group)
-			free(r->group);
-		free(r);
+			ast_free(r->group);
+		ast_free(r);
 	}
 }
 
@@ -271,10 +272,9 @@
 		if (!strcasecmp(iter->group, group))
 			return iter;
 	}
-	new = (struct robin_list *) calloc(1, sizeof(struct robin_list));
+	new = ast_calloc(1, sizeof(*new));
 	new->group = strndup(group, strlen(group));
-	new->port = 0;
-	new->channel = 0;
+	new->channel = 1;
 	if (robin) {
 		new->next = robin;
 		robin->prev = new;
@@ -430,6 +430,17 @@
 static void print_facility(struct FacParm *fac, struct misdn_bchannel *bc)
 {
 	switch (fac->Function) {
+#ifdef HAVE_MISDN_FAC_RESULT
+	case Fac_RESULT:
+		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);
+		break;
+#endif
 	case Fac_CD:
 		chan_misdn_log(1,bc->port," --> calldeflect to: %s, screened: %s\n", fac->u.CDeflection.DeflectedToNumber,
 			fac->u.CDeflection.PresentationAllowed ? "yes" : "no");
@@ -460,6 +471,7 @@
 			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");
 		break;
@@ -485,7 +497,7 @@
 {
 	char buf[128];
 
-	if (!ast)
+	if (!bc->AOCD_need_export || !ast)
 		return;
 
 	if (originator == ORG_AST) {
@@ -534,6 +546,8 @@
 	default:
 		break;
 	}
+	
+	bc->AOCD_need_export = 0;
 }
 
 /*************** Helpers END *************/
@@ -945,9 +959,9 @@
 	}
 	
 	if (argc == 3 || onlyport == 0) {
-		ast_cli(fd, "Misdn General-Config:\n");
+		ast_cli(fd, "mISDN General-Config:\n");
 		for (elem = MISDN_GEN_FIRST + 1, linebreak = 1; elem < MISDN_GEN_LAST; elem++, linebreak++) {
-			misdn_cfg_get_config_string(0, elem, buffer, BUFFERSIZE);
+			misdn_cfg_get_config_string(0, elem, buffer, sizeof(buffer));
 			ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
 		}
 		ast_cli(fd, "\n");
@@ -958,7 +972,7 @@
 		for (; port > 0; port = misdn_cfg_get_next_port(port)) {
 			ast_cli(fd, "\n[PORT %d]\n", port);
 			for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
-				misdn_cfg_get_config_string(port, elem, buffer, BUFFERSIZE);
+				misdn_cfg_get_config_string(port, elem, buffer, sizeof(buffer));
 				ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
 			}	
 			ast_cli(fd, "\n");
@@ -969,7 +983,7 @@
 		if (misdn_cfg_is_port_valid(onlyport)) {
 			ast_cli(fd, "[PORT %d]\n", onlyport);
 			for (elem = MISDN_CFG_FIRST + 1, linebreak = 1; elem < MISDN_CFG_LAST; elem++, linebreak++) {
-				misdn_cfg_get_config_string(onlyport, elem, buffer, BUFFERSIZE);
+				misdn_cfg_get_config_string(onlyport, elem, buffer, sizeof(buffer));
 				ast_cli(fd, "%-36s%s", buffer, !(linebreak % 2) ? "\n" : "");
 			}	
 			ast_cli(fd, "\n");
@@ -1041,8 +1055,8 @@
 	free_robin_list();
 	misdn_cfg_reload();
 	misdn_cfg_update_ptp();
-	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, global_tracefile, BUFFERSIZE);
-	misdn_cfg_get(0, MISDN_GEN_DEBUG, &cfg_debug, sizeof(int));
+	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, global_tracefile, sizeof(global_tracefile));
+	misdn_cfg_get(0, MISDN_GEN_DEBUG, &cfg_debug, sizeof(cfg_debug));
 
 	for (i = 0;  i <= max_ports; i++) {
 		misdn_debug[i] = cfg_debug;
@@ -1243,19 +1257,25 @@
 	return 0;
 }
 
-static int misdn_send_cd (int fd, int argc, char *argv[])
+static int misdn_send_facility(int fd, int argc, char *argv[])
 {
 	char *channame; 
 	char *nr;
 	struct chan_list *tmp;
-
-	if (argc != 5)
+	int port; 
+	char *served_nr;
+	struct misdn_bchannel dummy, *bc=&dummy;
+
+	if (argc < 5)
 		return RESULT_SHOWUSAGE;
  
-	
-	{
-		channame = argv[3];
-		nr = argv[4];
+	if (strstr(argv[3], "calldeflect")) {
+		if (argc < 6) {
+			ast_cli(fd, "calldeflect requires 1 arg: ToNumber\n\n");
+			return 0;
+		}
+		channame = argv[4];
+		nr = argv[5];
 
 		ast_cli(fd, "Sending Calldeflection (%s) to %s\n", nr, channame);
 		tmp = get_chan_by_ast_name(channame);
@@ -1271,6 +1291,44 @@
 		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(argv[3],"CFActivate")) {
+		if (argc < 7) {
+			ast_cli(fd, "CFActivate requires 2 args: 1.FromNumber, 2.ToNumber\n\n");
+			return 0;
+		}
+		port = atoi(argv[4]);
+		served_nr = argv[5];
+		nr = argv[6];
+
+		misdn_make_dummy(bc, port, 0, misdn_lib_port_is_nt(port), 0);
+
+		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
+		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(argv[3],"CFDeactivate")) {
+
+		if (argc < 6) {
+			ast_cli(fd, "CFDeactivate requires 1 arg: FromNumber\n\n");
+			return 0;
+		}
+		port = atoi(argv[4]);
+		served_nr = argv[5];
+		
+		misdn_make_dummy(bc, port, 0, misdn_lib_port_is_nt(port), 0);
+		ast_verbose("Sending CFDeactivate  Port:(%d) FromNr. (%s)\n", port, served_nr);
+
+		bc->fac_out.Function = Fac_CFDeactivate;
+		bc->fac_out.u.CFDeactivate.BasicService = 0; //All Services
+		bc->fac_out.u.CFDeactivate.Procedure = 0; //Unconditional
+		
+		ast_copy_string((char *)bc->fac_out.u.CFActivate.ServedUserNumber, served_nr, sizeof(bc->fac_out.u.CFActivate.ServedUserNumber));
+		misdn_lib_send_event(bc, EVENT_FACILITY);
 	}
 
 	return 0;
@@ -1469,7 +1527,7 @@
 			for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_GEN_LAST; ++elem) {
 				if ((elem == MISDN_CFG_LAST) || (elem == MISDN_GEN_FIRST))
 					continue;
-				misdn_cfg_get_name(elem, buffer, BUFFERSIZE);
+				misdn_cfg_get_name(elem, buffer, sizeof(buffer));
 				if (!wordlen || !strncmp(word, buffer, wordlen)) {
 					if (++which > state)
 						return strdup(buffer);
@@ -1487,9 +1545,13 @@
 }
 
 static struct ast_cli_entry chan_misdn_clis[] = {
-	{ {"misdn","send","calldeflect", NULL}, misdn_send_cd, "Sends CallDeflection to mISDN Channel",
-		"Usage: misdn send calldeflect <channel> \"<nr>\" \n", complete_ch },
-	{ {"misdn","send","digit", NULL}, misdn_send_digit,	"Sends DTMF Digit to mISDN Channel",
+	{ {"misdn","send","facility", NULL}, misdn_send_facility, "Sends a Facility Message to the mISDN Channel",
+		"Usage: misdn send facility <type> <channel|port> \"<args>\"\n"
+		"       type is one of:\n"
+		"       - calldeflect\n"
+		"       - CFActivate\n"
+		"       - CFDeactivate\n", complete_ch },
+	{ {"misdn","send","digit", NULL}, misdn_send_digit, "Sends DTMF Digit to mISDN Channel",
 		"Usage: misdn send digit <channel> \"<msg>\" \n"
 		"       Send <digit> to <channel> as DTMF Tone\n"
 		"       when channel is a mISDN channel\n", complete_ch },
@@ -1690,7 +1752,7 @@
 	if (*bc->pipeline)
 		return 0;
 
-	misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
+	misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(ec));
 	if (ec == 1)
 		ast_copy_string(bc->pipeline, "mg2ec", sizeof(bc->pipeline));
 	else if (ec > 1)
@@ -1704,7 +1766,7 @@
 	int ec;
 	int port = bc->port;
 
-	misdn_cfg_get(port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
+	misdn_cfg_get(port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(ec));
 
 	if (ec == 1) {
 		bc->ec_enable = 1;
@@ -1747,18 +1809,18 @@
 	port = bc->port;
 	chan_misdn_log(1, port, "read_config: Getting Config\n");
 
-	misdn_cfg_get(port, MISDN_CFG_LANGUAGE, lang, BUFFERSIZE);
+	misdn_cfg_get(port, MISDN_CFG_LANGUAGE, lang, sizeof(lang));
 	ast_string_field_set(ast, language, lang);
 
-	misdn_cfg_get(port, MISDN_CFG_MUSICCLASS, localmusicclass, BUFFERSIZE);
+	misdn_cfg_get(port, MISDN_CFG_MUSICCLASS, localmusicclass, sizeof(localmusicclass));
 	ast_string_field_set(ast, musicclass, localmusicclass);
 
-	misdn_cfg_get(port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int));
-	misdn_cfg_get(port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int));
-
-	misdn_cfg_get(port, MISDN_CFG_INCOMING_EARLY_AUDIO, &ch->incoming_early_audio, sizeof(int));
-
-	misdn_cfg_get(port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int));
+	misdn_cfg_get(port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(bc->txgain));
+	misdn_cfg_get(port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(bc->rxgain));
+
+	misdn_cfg_get(port, MISDN_CFG_INCOMING_EARLY_AUDIO, &ch->incoming_early_audio, sizeof(ch->incoming_early_audio));
+
+	misdn_cfg_get(port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(bc->send_dtmf));
 	
 	misdn_cfg_get(port, MISDN_CFG_ASTDTMF, &ch->ast_dsp, sizeof(int));
 
@@ -1766,18 +1828,18 @@
 		ch->ignore_dtmf = 1;
 	}
 
-	misdn_cfg_get(port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(int));
-	misdn_cfg_get(port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(int));
-
-	misdn_cfg_get(port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(int));
-
-	misdn_cfg_get(port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(int));
-
-	misdn_cfg_get(port, MISDN_CFG_ALLOWED_BEARERS, &ch->allowed_bearers, BUFFERSIZE);
-
-  	misdn_cfg_get(port, MISDN_CFG_FAXDETECT, faxdetect, BUFFERSIZE);
-
-	misdn_cfg_get(port, MISDN_CFG_HDLC, &hdlc, sizeof(int));
+	misdn_cfg_get(port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(bc->need_more_infos));
+	misdn_cfg_get(port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(ch->nttimeout));
+
+	misdn_cfg_get(port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(ch->noautorespond_on_setup));
+
+	misdn_cfg_get(port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(ch->far_alerting));
+
+	misdn_cfg_get(port, MISDN_CFG_ALLOWED_BEARERS, &ch->allowed_bearers, sizeof(ch->allowed_bearers));
+
+  	misdn_cfg_get(port, MISDN_CFG_FAXDETECT, faxdetect, sizeof(faxdetect));
+
+	misdn_cfg_get(port, MISDN_CFG_HDLC, &hdlc, sizeof(hdlc));
 
 	if (hdlc) {
 		switch (bc->capability) {
@@ -1790,8 +1852,8 @@
 		
 	}
 	/*Initialize new Jitterbuffer*/
-	misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER, &ch->jb_len, sizeof(int));
-	misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, &ch->jb_upper_threshold, sizeof(int));
+	misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER, &ch->jb_len, sizeof(ch->jb_len));
+	misdn_cfg_get(port, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, &ch->jb_upper_threshold, sizeof(ch->jb_upper_threshold));
 
 	config_jitterbuffer(ch);
 
@@ -1805,12 +1867,7 @@
 	update_ec_config(bc);
 #endif
 
-	{
-		int eb3;
-		
-		misdn_cfg_get( bc->port, MISDN_CFG_EARLY_BCONNECT, &eb3, sizeof(int));
-		bc->early_bconnect=eb3;
-	}
+	misdn_cfg_get(bc->port, MISDN_CFG_EARLY_BCONNECT, &bc->early_bconnect, sizeof(bc->early_bconnect));
 
 	misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
 	misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
@@ -1822,7 +1879,7 @@
 	if (orig == ORG_AST) {
 		char callerid[BUFFERSIZE + 1];
 
-		misdn_cfg_get(port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(int));
+		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"))
@@ -1831,15 +1888,15 @@
  				ch->faxdetect = 1;
  		}
 
-		misdn_cfg_get(port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);
+		misdn_cfg_get(port, MISDN_CFG_CALLERID, callerid, sizeof(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));
 		}
 
-		misdn_cfg_get(port, MISDN_CFG_DIALPLAN, &bc->dnumplan, sizeof(int));
-		misdn_cfg_get(port, MISDN_CFG_LOCALDIALPLAN, &bc->onumplan, sizeof(int));
-		misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int));
+		misdn_cfg_get(port, MISDN_CFG_DIALPLAN, &bc->dnumplan, sizeof(bc->dnumplan));
+		misdn_cfg_get(port, MISDN_CFG_LOCALDIALPLAN, &bc->onumplan, sizeof(bc->onumplan));
+		misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(bc->cpnnumplan));
 		debug_numplan(port, bc->dnumplan, "TON");
 		debug_numplan(port, bc->onumplan, "LTON");
 		debug_numplan(port, bc->cpnnumplan, "CTON");
@@ -1855,16 +1912,16 @@
  				ch->faxdetect = 1;
  		}
 
-		misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int));
+		misdn_cfg_get(port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(bc->cpnnumplan));
 		debug_numplan(port, bc->cpnnumplan, "CTON");
 
 		switch (bc->onumplan) {
 		case NUMPLAN_INTERNATIONAL:
-			misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
+			misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, sizeof(prefix));
 			break;
 
 		case NUMPLAN_NATIONAL:
-			misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
+			misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, sizeof(prefix));
 			break;
 		default:
 			break;
@@ -1885,10 +1942,10 @@
 
 		switch (bc->dnumplan) {
 		case NUMPLAN_INTERNATIONAL:
-			misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
+			misdn_cfg_get(bc->port, MISDN_CFG_INTERNATPREFIX, prefix, sizeof(prefix));
 			break;
 		case NUMPLAN_NATIONAL:
-			misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
+			misdn_cfg_get(bc->port, MISDN_CFG_NATPREFIX, prefix, sizeof(prefix));
 			break;
 		default:
 			break;
@@ -1905,8 +1962,8 @@
 
 		if ( !ast_strlen_zero(bc->rad) ) {
 			if (ast->cid.cid_rdnis)
-				free(ast->cid.cid_rdnis);
-			ast->cid.cid_rdnis = strdup(bc->rad);
+				ast_free(ast->cid.cid_rdnis);
+			ast->cid.cid_rdnis = ast_strdup(bc->rad);
 		}
 	
 		misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
@@ -2136,6 +2193,7 @@
 {
 	struct chan_list *p;
 	struct misdn_bchannel *bc;
+	char buf[2] = { digit, 0 };
 
 	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast))) return -1;
 
@@ -2149,33 +2207,15 @@
 	
 	switch (p->state ) {
 	case MISDN_CALLING:
-		{
-			int l;		
-			char buf[8];
-			buf[0]=digit;
-			buf[1]=0;
-			
-			l = sizeof(bc->infos_pending);
-			strncat(bc->infos_pending, buf, l - strlen(bc->infos_pending) - 1);
-		}
+		if (strlen(bc->infos_pending) < sizeof(bc->infos_pending) - 1)
+			strncat(bc->infos_pending, buf, sizeof(bc->infos_pending) - strlen(bc->infos_pending) - 1);
 		break;
 	case MISDN_CALLING_ACKNOWLEDGE:
-		{
-			bc->info_dad[0]=digit;
-			bc->info_dad[1]=0;
-			
-			{
-				int l = sizeof(bc->dad);
-				strncat(bc->dad, bc->info_dad, l - strlen(bc->dad) - 1);
-			}
-			{
-				int l = sizeof(p->ast->exten);
-				strncpy(p->ast->exten, bc->dad, l);
-				p->ast->exten[l-1] = 0;
-			}
-			
-			misdn_lib_send_event( bc, EVENT_INFORMATION);
-		}
+		ast_copy_string(bc->info_dad, buf, sizeof(bc->info_dad));
+		if (strlen(bc->dad) < sizeof(bc->dad) - 1)
+			strncat(bc->dad, buf, sizeof(bc->dad) - strlen(bc->dad) - 1);
+		ast_copy_string(p->ast->exten, bc->dad, sizeof(p->ast->exten));
+		misdn_lib_send_event( bc, EVENT_INFORMATION);
 		break;
 	default:	
 			/* Do not send Digits in CONNECTED State, when
@@ -2373,7 +2413,7 @@
 		cl_dequeue_chan(&cl_te, p);
 		close(p->pipe[0]);
 		close(p->pipe[1]);
-		free(p);
+		ast_free(p);
 		ast_mutex_unlock(&release_lock);
 		
 		if (bc)
@@ -2413,21 +2453,20 @@
 	switch (p->state) {
 	case MISDN_INCOMING_SETUP:
 	case MISDN_CALLING:
+		p->state = MISDN_CLEANING;
 		/* This is the only place in misdn_hangup, where we 
 		 * can call release_chan, else it might create lot's of trouble
 		 * */
 		ast_log(LOG_NOTICE, "release channel, in CALLING/INCOMING_SETUP state.. no other events happened\n");
 		release_chan(bc);
-
-		p->state = MISDN_CLEANING;
-		if (bc->need_release_complete)
-			misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
+		misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
 		break;
 	case MISDN_HOLDED:
 	case MISDN_DIALING:
 		start_bc_tones(p);
 		hanguptone_indicate(p);
 
+		p->state = MISDN_CLEANING;
 		if (bc->need_disconnect)
 			misdn_lib_send_event( bc, EVENT_DISCONNECT);
 		break;
@@ -2726,7 +2765,7 @@
 		return 0;
 	}
 	
-#if MISDN_DEBUG
+#ifdef MISDN_DEBUG
 	{
 		int i, max = 5 > frame->samples ? frame->samples : 5;
 
@@ -2797,15 +2836,15 @@
 	if (!(ch1 && ch2))
 		return -1;
 
-	misdn_cfg_get(ch1->bc->port, MISDN_CFG_BRIDGING, &p1_b, sizeof(int));
-	misdn_cfg_get(ch2->bc->port, MISDN_CFG_BRIDGING, &p2_b, sizeof(int));
+	misdn_cfg_get(ch1->bc->port, MISDN_CFG_BRIDGING, &p1_b, sizeof(p1_b));
+	misdn_cfg_get(ch2->bc->port, MISDN_CFG_BRIDGING, &p2_b, sizeof(p2_b));
 
 	if (! p1_b || ! p2_b) {
 		ast_log(LOG_NOTICE, "Falling back to Asterisk bridging\n");
 		return AST_BRIDGE_FAILED;
 	}
 
-	misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(int));
+	misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(bridging));
 	if (bridging) {
 		/* trying to make a mISDN_dsp conference */
 		chan_misdn_log(1, ch1->bc->port, "I SEND: Making conference with Number:%d\n", ch1->bc->pid + 1);
@@ -2960,7 +2999,7 @@
 {
 	struct chan_list *cl;
 
-	cl = calloc(1, sizeof(struct chan_list));
+	cl = ast_calloc(1, sizeof(*cl));
 	if (!cl) {
 		chan_misdn_log(-1, 0, "misdn_request: malloc failed!");
 		return NULL;
@@ -2980,7 +3019,7 @@
 	struct ast_channel *tmp = NULL;
 	char group[BUFFERSIZE + 1] = "";
 	char buf[128];
-	char buf2[128], *ext = NULL, *port_str;
+	char *buf2 = ast_strdupa(data), *ext = NULL, *port_str;
 	char *tokb = NULL, *p = NULL;
 	int channel = 0, port = 0;
 	struct misdn_bchannel *newbc = NULL;
@@ -2989,7 +3028,6 @@
 	struct chan_list *cl = init_chan_list(ORG_AST);
 
 	snprintf(buf, sizeof(buf), "%s/%s", misdn_type, (char*)data);
-	ast_copy_string(buf2, data, 128);
 
 	port_str = strtok_r(buf2, "/", &tokb);
 
@@ -3030,78 +3068,69 @@
 		}
 
 		if (rr) {
-			int port_start = 0;
-			int port_bak = rr->port;
-			int chan_bak = rr->channel;
-
-			if (!rr->port)
-				rr->port = misdn_cfg_get_next_port_spin(rr->port);
-			
-			for (; rr->port > 0; rr->port = misdn_cfg_get_next_port_spin(rr->port)) {
-				int port_up;
-				int check;
-				int max_chan;
-				int last_chance = 0;
-
-				misdn_cfg_get(rr->port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
-				if (strcasecmp(cfg_group, group))
-					continue;
-
-				misdn_cfg_get(rr->port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(int));
-				port_up = misdn_lib_port_up(rr->port, check);
-
-				if (check && !port_up) 
-					chan_misdn_log(1, rr->port, "L1 is not Up on this Port\n");
-
-				if (check && port_up < 0)
-					ast_log(LOG_WARNING,"This port (%d) is blocked\n", rr->port);
-
-				if ((port_start == rr->port) && (port_up <= 0))
-					break;
-
-				if (!port_start)
-					port_start = rr->port;
-
-				if (port_up <= 0)
-					continue;
-
-				max_chan = misdn_lib_get_maxchans(rr->port);
-
-				for (++rr->channel; !last_chance && rr->channel <= max_chan; ++rr->channel) {
-					if (rr->port == port_bak && rr->channel == chan_bak)
-						last_chance = 1;
-
-					chan_misdn_log(1, 0, "trying port:%d channel:%d\n", rr->port, rr->channel);
-					newbc = misdn_lib_get_free_bc(rr->port, rr->channel, 0, 0);
-					if (newbc) {
-						chan_misdn_log(4, rr->port, " Success! Found port:%d channel:%d\n", newbc->port, newbc->channel);
-						if (port_up)
-							chan_misdn_log(4, rr->port, "portup:%d\n",  port_up);
-						port = rr->port;
-						break;
+			int robin_channel = rr->channel;
+			int port_start;
+			int next_chan = 1;
+
+			do {
+				port_start = 0;
+				for (port = misdn_cfg_get_next_port_spin(rr->port); port > 0 && port != port_start;
+					 port = misdn_cfg_get_next_port_spin(port)) {
+
+					if (!port_start)
+						port_start = port;
+
+					if (port >= port_start)
+						next_chan = 1;
+					
+					if (port <= port_start && next_chan) {
+						int maxbchans=misdn_lib_get_maxchans(port);
+						if (++robin_channel >= maxbchans) {
+							robin_channel = 1;
+						}
+						next_chan = 0;
+					}
+
+					misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, sizeof(cfg_group));
+
+					if (!strcasecmp(cfg_group, group)) {
+						int port_up;
+						int check;
+						misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(check));
+						port_up = misdn_lib_port_up(port, check);
+
+						if (check && !port_up) 
+							chan_misdn_log(1, port, "L1 is not Up on this Port\n");
+						
+						if (check && port_up < 0) {
+							ast_log(LOG_WARNING, "This port (%d) is blocked\n", port);
+						}
+
+						if (port_up > 0)	{
+							newbc = misdn_lib_get_free_bc(port, robin_channel, 0, 0);
+							if (newbc) {
+								chan_misdn_log(4, port, " Success! Found port:%d channel:%d\n", newbc->port, newbc->channel);
+								if (port_up)
+									chan_misdn_log(4, port, "portup:%d\n",  port_up);
+								rr->port = newbc->port;
+								rr->channel = newbc->channel;
+								break;
+							}
+						}
 					}
 				}
-
-				if (newbc || last_chance)
-					break;
-
-				rr->channel = 0;
-			}
-			if (!newbc) {
-				rr->port = port_bak;
-				rr->channel = chan_bak;
-			}
+			} while (!newbc && robin_channel != rr->channel);
 		} else {		
 			for (port = misdn_cfg_get_next_port(0); port > 0;
 				 port = misdn_cfg_get_next_port(port)) {
 
-				misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
+				misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, sizeof(cfg_group));
 
 				chan_misdn_log(3, port, "Group [%s] Port [%d]\n", group, port);
 				if (!strcasecmp(cfg_group, group)) {
 					int port_up;
 					int check;
-					misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(int));
+					misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(check));
 					port_up = misdn_lib_port_up(port, check);
 
 					chan_misdn_log(4, port, "portup:%d\n", port_up);
@@ -3219,6 +3248,7 @@
 {
 	int chan_offset = 0;
 	int tmp_port = misdn_cfg_get_next_port(0);
+	char newname[255];
 	for (; tmp_port > 0; tmp_port = misdn_cfg_get_next_port(tmp_port)) {
 		if (tmp_port == port)
 			break;
@@ -3227,10 +3257,12 @@
 	if (c < 0)
 		c = 0;
 
-	ast_string_field_build(tmp, name, "%s/%d-u%d",
-		misdn_type, chan_offset + c, glob_channel++);
-
-	chan_misdn_log(3, port, " --> updating channel name to [%s]\n", tmp->name);
+	snprintf(newname, sizeof(newname), "%s/%d-", misdn_type, chan_offset + c);
+	if (strncmp(tmp->name, newname, strlen(newname))) {
+		snprintf(newname, sizeof(newname), "%s/%d-u%d", misdn_type, chan_offset + c, glob_channel++);
+		ast_change_name(tmp, newname);
+		chan_misdn_log(3, port, " --> updating channel name to [%s]\n", tmp->name);
+	}
 }
 
 static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char *exten, char *callerid, int format, int port, int c)
@@ -3253,7 +3285,7 @@
 		ast_callerid_parse(callerid, &cid_name, &cid_num);
 	}
 
-	tmp = ast_channel_alloc(1, state, cid_num, cid_name, "", exten, "", 0, "%s/%d-u%d", misdn_type, chan_offset + c, glob_channel++);
+	tmp = ast_channel_alloc(1, state, cid_num, cid_name, "", exten, "", 0, "%s/%s%d-u%d", misdn_type, c ? "" : "tmp", chan_offset + c, glob_channel++);
 	if (tmp) {
 		chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n", exten, callerid);
 
@@ -3266,7 +3298,7 @@
     
 		tmp->tech_pvt = chlist;
 
-		misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(int));
+		misdn_cfg_get(0, MISDN_GEN_BRIDGING, &bridging, sizeof(bridging));
 
 		if (bridging)
 			tmp->tech = &misdn_tech;
@@ -3288,7 +3320,7 @@
 			tmp->cid.cid_ani = ast_strdup(cid_num);
 
 		if (pipe(chlist->pipe) < 0)
-			perror("Pipe failed\n");
+			ast_log(LOG_ERROR, "Pipe failed\n");
 		tmp->fds[0] = chlist->pipe[0];
 
 		if (state == AST_STATE_RING)
@@ -3296,6 +3328,7 @@
 		else
 			tmp->rings = 0;
 		
+		ast_jb_configure(tmp, misdn_get_global_jbconf());
 	} else {
 		chan_misdn_log(-1, 0, "Unable to allocate channel structure\n");
 	}
@@ -3519,7 +3552,7 @@
 			ch->state = MISDN_CLEANING;
 			cl_dequeue_chan(&cl_te, ch);
 
-			free(ch);
+			ast_free(ch);
 		} else {
 			/* chan is already cleaned, so exiting  */
 		}
@@ -3544,12 +3577,10 @@
 
 static void do_immediate_setup(struct misdn_bchannel *bc, struct chan_list *ch, struct ast_channel *ast)
 {
-	char predial[256]="";
-	char *p = predial;
-  
+	char *predial;
 	struct ast_frame fr;
 
-	strncpy(predial, ast->exten, sizeof(predial) -1 );
+	predial = ast_strdupa(ast->exten);
 
 	ch->state = MISDN_DIALING;
 
@@ -3585,9 +3616,9 @@
 	}
   
   
-	while (!ast_strlen_zero(p) ) {
+	while (!ast_strlen_zero(predial) ) {
 		fr.frametype = AST_FRAME_DTMF;
-		fr.subclass = *p;
+		fr.subclass = *predial;
 		fr.src = NULL;
 		fr.data = NULL;
 		fr.datalen = 0;
@@ -3599,7 +3630,7 @@
 		if (ch->ast && MISDN_ASTERISK_PVT(ch->ast) && MISDN_ASTERISK_TECH_PVT(ch->ast)) {
 			ast_queue_frame(ch->ast, &fr);
 		}
-		p++;
+		predial++;
 	}
 }
 
@@ -3711,8 +3742,7 @@
 		pbx_builtin_setvar_helper(chan, "MISDN_URATE", tmp);
 	}
 
-	if (bc->uulen && (bc->uulen < sizeof(bc->uu))) {
-		bc->uu[bc->uulen] = 0;
+	if (bc->uulen) {
 		pbx_builtin_setvar_helper(chan, "MISDN_USERUSER", bc->uu);
 	}
 
@@ -3777,7 +3807,6 @@
 static enum event_response_e
 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
 {
-	int msn_valid;
 	struct chan_list *ch = find_chan_by_bc(cl_te, bc);
 	
 	if (event != EVENT_BCHAN_DATA && event != EVENT_TONE_GENERATE) { /*  Debug Only Non-Bchan */
@@ -3840,7 +3869,7 @@
 	case EVENT_PORT_ALARM:
 		{
 			int boa = 0;
-			misdn_cfg_get(bc->port, MISDN_CFG_ALARM_BLOCK, &boa, sizeof(int));
+			misdn_cfg_get(bc->port, MISDN_CFG_ALARM_BLOCK, &boa, sizeof(boa));
 			if (boa) {
 				cb_log(1, bc->port, " --> blocking\n");
 				misdn_lib_port_block(bc->port); 
@@ -3987,7 +4016,7 @@
 			fr.offset = 0;
 			fr.delivery = ast_tv(0,0);
 
-			misdn_cfg_get(0, MISDN_GEN_APPEND_DIGITS2EXTEN, &digits, sizeof(int));
+			misdn_cfg_get(0, MISDN_GEN_APPEND_DIGITS2EXTEN, &digits, sizeof(digits));
 			if (ch->state != MISDN_CONNECTED ) {
 				if (digits) {
 					strncat(bc->dad, bc->info_dad, sizeof(bc->dad) - strlen(bc->dad) - 1);
@@ -4003,6 +4032,7 @@
 	case EVENT_SETUP:
 	{
 		struct chan_list *ch = find_chan_by_bc(cl_te, bc);
+		int msn_valid = misdn_cfg_is_msn_valid(bc->port, bc->dad);
 		struct ast_channel *chan;
 		int exceed;
 		int pres, screen;
@@ -4020,7 +4050,6 @@
 			}
 		}
 
-		msn_valid = misdn_cfg_is_msn_valid(bc->port, bc->dad);
 		if (!bc->nt && ! msn_valid) {
 			chan_misdn_log(1, bc->port, " --> Ignoring Call, its not in our MSN List\n");
 			return RESPONSE_IGNORE_SETUP; /*  Ignore MSNs which are not in our List */
@@ -4302,9 +4331,6 @@
 	break;
 	case EVENT_PROCEEDING:
 	{
-		if (bc->channel) 
-			update_name(ch->ast, bc->port, bc->channel);
-
 		if (misdn_cap_is_speech(bc->capability) &&
 		     misdn_inband_avail(bc) ) {
 			start_bc_tones(ch);
@@ -4340,9 +4366,6 @@
 		
 	case EVENT_ALERTING:
 	{
-		if (bc->channel) 
-			update_name(ch->ast, bc->port, bc->channel);
-
 		ch->state = MISDN_ALERTING;
 		
 		if (!ch->ast)
@@ -4538,6 +4561,8 @@
 
 	case EVENT_BCHAN_DATA:
 	{
+		if (ch->bc->AOCD_need_export)
+			export_aoc_vars(ch->originator, ch->ast, ch->bc);
 		if (!misdn_cap_is_speech(ch->bc->capability)) {
 			struct ast_frame frame;
 			/*In Data Modes we queue frames*/
@@ -4677,9 +4702,9 @@
 	case EVENT_HOLD:
 	{
 		int hold_allowed;
-		struct ast_channel *bridged;
-
-		misdn_cfg_get(bc->port, MISDN_CFG_HOLD_ALLOWED, &hold_allowed, sizeof(int));
+		struct ast_channel *bridged = ast_bridged_channel(ch->ast);
+
+		misdn_cfg_get(bc->port, MISDN_CFG_HOLD_ALLOWED, &hold_allowed, sizeof(hold_allowed));
 
 		if (!hold_allowed) {
 
@@ -4688,7 +4713,6 @@
 			break;
 		}
 
-		bridged = ast_bridged_channel(ch->ast);
 		if (bridged) {
 			chan_misdn_log(2, bc->port, "Bridge Partner is of type: %s\n", bridged->tech->type);
 			ch->state = MISDN_HOLDED;
@@ -4713,17 +4737,15 @@
 	break;
 	
 	case EVENT_FACILITY:
-		if (!ch) {
-			/* This may come from a call we don't know nothing about, so we ignore it. */
-			chan_misdn_log(-1, bc->port, "Got EVENT_FACILITY but we don't have a ch!\n");
-			break;
-		}
-
 		print_facility(&(bc->fac_in), bc);
 		
 		switch (bc->fac_in.Function) {
+#ifdef HAVE_MISDN_FAC_RESULT
+		case Fac_RESULT:
+		break;
+#endif
 		case Fac_CD:
-			{
+			if (ch) {
 				struct ast_channel *bridged = ast_bridged_channel(ch->ast);
 				struct chan_list *ch_br;
 				if (bridged && MISDN_ASTERISK_TECH_PVT(bridged)) {
@@ -4742,18 +4764,25 @@
 			} 
 			break;
 		case Fac_AOCDCurrency:
-			{
+			if (ch) {
 				bc->AOCDtype = Fac_AOCDCurrency;
-				memcpy(&(bc->AOCD.currency), &(bc->fac_in.u.AOCDcur), sizeof(struct FacAOCDCurrency));
+				memcpy(&(bc->AOCD.currency), &(bc->fac_in.u.AOCDcur), sizeof(bc->AOCD.currency));
+				bc->AOCD_need_export = 1;
 				export_aoc_vars(ch->originator, ch->ast, bc);
 			}
 			break;
 		case Fac_AOCDChargingUnit:
-			{
+			if (ch) {
 				bc->AOCDtype = Fac_AOCDChargingUnit;
-				memcpy(&(bc->AOCD.chargingUnit), &(bc->fac_in.u.AOCDchu), sizeof(struct FacAOCDChargingUnit));
+				memcpy(&(bc->AOCD.chargingUnit), &(bc->fac_in.u.AOCDchu), sizeof(bc->AOCD.chargingUnit));
+				bc->AOCD_need_export = 1;
 				export_aoc_vars(ch->originator, ch->ast, bc);
 			}
+			break;
+		case Fac_None:
+#ifdef HAVE_MISDN_FAC_ERROR
+		case Fac_ERROR:
+#endif
 			break;
 		default:
 			chan_misdn_log(0, bc->port," --> not yet handled: facility type:%d\n", bc->fac_in.Function);
@@ -4812,10 +4841,10 @@
 	misdn_lib_destroy();
   
 	if (misdn_debug)
-		free(misdn_debug);
+		ast_free(misdn_debug);
 	if (misdn_debug_only)
-		free(misdn_debug_only);
- 	free(misdn_ports);
+		ast_free(misdn_debug_only);
+ 	ast_free(misdn_ports);
  	
 	return 0;
 }
@@ -4846,30 +4875,30 @@
 	}
 	g_config_initialized = 1;
 	
-	misdn_debug = (int *) malloc(sizeof(int) * (max_ports + 1));
+	misdn_debug = ast_malloc(sizeof(int) * (max_ports + 1));
 	if (!misdn_debug) {
 		ast_log(LOG_ERROR, "Out of memory for misdn_debug\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	misdn_ports = (int *) malloc(sizeof(int) * (max_ports + 1));
+	misdn_ports = ast_malloc(sizeof(int) * (max_ports + 1));
 	if (!misdn_ports) {
 		ast_log(LOG_ERROR, "Out of memory for misdn_ports\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	misdn_cfg_get(0, MISDN_GEN_DEBUG, &misdn_debug[0], sizeof(int));
+	misdn_cfg_get(0, MISDN_GEN_DEBUG, &misdn_debug[0], sizeof(misdn_debug[0]));
 	for (i = 1; i <= max_ports; i++) {
 		misdn_debug[i] = misdn_debug[0];
 		misdn_ports[i] = i;
 	}
 	*misdn_ports = 0;
-	misdn_debug_only = (int *) calloc(max_ports + 1, sizeof(int));
-
-	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, tempbuf, BUFFERSIZE);
+	misdn_debug_only = ast_calloc(max_ports + 1, sizeof(int));
+
+	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, tempbuf, sizeof(tempbuf));
 	if (!ast_strlen_zero(tempbuf))
 		tracing = 1;
 
-	misdn_in_calls = (int *) malloc(sizeof(int) * (max_ports + 1));
-	misdn_out_calls = (int *) malloc(sizeof(int) * (max_ports + 1));
+	misdn_in_calls = ast_malloc(sizeof(int) * (max_ports + 1));
+	misdn_out_calls = ast_malloc(sizeof(int) * (max_ports + 1));
 
 	for (i = 1; i <= max_ports; i++) {
 		misdn_in_calls[i] = 0;
@@ -4887,17 +4916,17 @@
 	if (misdn_lib_init(ports, &iface, NULL))
 		chan_misdn_log(0, 0, "No te ports initialized\n");
 
-	misdn_cfg_get(0, MISDN_GEN_NTDEBUGFLAGS, &ntflags, sizeof(int));
-	misdn_cfg_get(0, MISDN_GEN_NTDEBUGFILE, &ntfile, BUFFERSIZE);
+	misdn_cfg_get(0, MISDN_GEN_NTDEBUGFLAGS, &ntflags, sizeof(ntflags));
+	misdn_cfg_get(0, MISDN_GEN_NTDEBUGFILE, &ntfile, sizeof(ntfile));
+	misdn_cfg_get( 0, MISDN_GEN_NTKEEPCALLS, &ntkc, sizeof(ntkc));
+
+	misdn_lib_nt_keepcalls(ntkc);
 	misdn_lib_nt_debug_init(ntflags, ntfile);
-
-	misdn_cfg_get( 0, MISDN_GEN_NTKEEPCALLS, &ntkc, sizeof(int));
-	misdn_lib_nt_keepcalls(ntkc);
 
 	if (ast_channel_register(&misdn_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", misdn_type);
 		unload_module();
-		return -1;
+		return AST_MODULE_LOAD_DECLINE;
 	}
   
 	ast_cli_register_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
@@ -4958,7 +4987,7 @@
 		);
 
 
-	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, global_tracefile, BUFFERSIZE);
+	misdn_cfg_get(0, MISDN_GEN_TRACEFILE, global_tracefile, sizeof(global_tracefile));
 
 	/* start the l1 watchers */
 	
@@ -4990,7 +5019,7 @@
 static int misdn_facility_exec(struct ast_channel *chan, void *data)
 {
 	struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(chan);
-	char *tok, *tokb;
+	char *parse, *tok, *tokb;
 
 	chan_misdn_log(0, 0, "TYPE: %s\n", chan->tech->type);
 	
@@ -5004,7 +5033,8 @@
 		return -1;
 	}
 
-	tok = strtok_r((char*) data, "|", &tokb) ;
+	parse = ast_strdupa(data);
+	tok = strtok_r(parse, "|", &tokb) ;
 
 	if (!tok) {
 		ast_log(LOG_WARNING, "misdn_facility Requires arguments\n");
@@ -5034,6 +5064,7 @@
 
 static int misdn_check_l2l1(struct ast_channel *chan, void *data)
 {
+	char *parse;
 	char group[BUFFERSIZE + 1];
 	char *port_str;
 	int port = 0;
@@ -5051,7 +5082,8 @@
 		return -1;
 	}
 
-	AST_STANDARD_APP_ARGS(args, data);
+	parse = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (args.argc != 2) {
 		ast_log(LOG_WARNING, "Wrong argument count\n");
@@ -5075,7 +5107,7 @@
 
 			chan_misdn_log(2, 0, "trying port %d\n", port);
 
-			misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, BUFFERSIZE);
+			misdn_cfg_get(port, MISDN_CFG_GROUPNAME, cfg_group, sizeof(cfg_group));
 
 			if (!strcasecmp(cfg_group, group)) {
 				port_up = misdn_lib_port_up(port, 1);
@@ -5100,7 +5132,7 @@
 
 	if (dowait) {
 		chan_misdn_log(2, 0, "Waiting for '%d' seconds\n", timeout);
-		sleep(timeout);
+		ast_safe_sleep(chan, timeout * 1000);
 	}
 
 	return 0;
@@ -5109,7 +5141,7 @@
 static int misdn_set_opt_exec(struct ast_channel *chan, void *data)
 {
 	struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(chan);
-	char *tok, *tokb;
+	char *tok, *tokb, *parse;
 	int  keyidx = 0;
 	int rxgain = 0;
 	int txgain = 0;
@@ -5125,7 +5157,8 @@
 		return -1;
 	}
 
-	for (tok = strtok_r((char*) data, ":", &tokb);
+	parse = ast_strdupa(data);
+	for (tok = strtok_r(parse, ":", &tokb);
 	     tok;
 	     tok = strtok_r(NULL, ":", &tokb) ) {
 		int neglect = 0;
@@ -5296,7 +5329,7 @@
 		if (!ch->dsp)
 			ch->dsp = ast_dsp_new();
 		if (ch->dsp)
-			ast_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT| DSP_FEATURE_FAX_DETECT);
+			ast_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT | DSP_FEATURE_FAX_DETECT);
 		if (!ch->trans)
 			ch->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, AST_FORMAT_ALAW);
 	}
@@ -5335,7 +5368,7 @@
 	int i;
 	struct misdn_jb *jb;
 
-	jb = malloc(sizeof(struct misdn_jb));
+	jb = ast_malloc(sizeof(*jb));
 	if (!jb) {
 	    chan_misdn_log(-1, 0, "No free Mem for jb\n");
 	    return NULL;
@@ -5347,17 +5380,17 @@
 	jb->state_full = 0;
 	jb->state_empty = 0;
 	jb->bytes_wrote = 0;
-	jb->samples = malloc(size * sizeof(char));
+	jb->samples = ast_malloc(size * sizeof(char));
 	if (!jb->samples) {
-		free(jb);
+		ast_free(jb);
 		chan_misdn_log(-1, 0, "No free Mem for jb->samples\n");
 		return NULL;
 	}
 
-	jb->ok = malloc(size * sizeof(char));
+	jb->ok = ast_malloc(size * sizeof(char));
 	if (!jb->ok) {
-		free(jb->samples);
-		free(jb);
+		ast_free(jb->samples);
+		ast_free(jb);
 		chan_misdn_log(-1, 0, "No free Mem for jb->ok\n");
 		return NULL;
 	}
@@ -5375,8 +5408,8 @@
 {
 	ast_mutex_destroy(&jb->mutexjb);
 	
-	free(jb->samples);
-	free(jb);
+	ast_free(jb->samples);
+	ast_free(jb);
 }
 
 /* fills the jitterbuffer with len data returns < 0 if there was an
@@ -5523,8 +5556,9 @@
 	}
 	
 	if ((level <= misdn_debug[0]) && !ast_strlen_zero(global_tracefile) ) {
+		char ctimebuf[30];
 		time_t tm = time(NULL);
-		char *tmp = ctime(&tm), *p;
+		char *tmp = ctime_r(&tm, ctimebuf), *p;
 
 		FILE *fp = fopen(global_tracefile, "a+");
 

Modified: team/group/v14_colp/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/team/group/v14_colp/channels/misdn/chan_misdn_config.h?view=diff&rev=145695&r1=145694&r2=145695
==============================================================================
--- team/group/v14_colp/channels/misdn/chan_misdn_config.h (original)
+++ team/group/v14_colp/channels/misdn/chan_misdn_config.h Wed Oct  1 18:55:27 2008
@@ -10,6 +10,12 @@
  * This program is free software, distributed under the terms of
  * the GNU General Public License
  */
+
+/*! \file 
+ * \brief Interface to mISDN - Config
+ * \author Christian Richter <crich at beronet.com>
+ */
+
 
 
 
@@ -149,4 +155,6 @@
 int misdn_cfg_get_next_port_in_group(int port, char *group);
 #endif
 
+struct ast_jb_conf *misdn_get_global_jbconf(void);
+
 #endif

Modified: team/group/v14_colp/channels/misdn/ie.c
URL: http://svn.digium.com/view/asterisk/team/group/v14_colp/channels/misdn/ie.c?view=diff&rev=145695&r1=145694&r2=145695
==============================================================================
--- team/group/v14_colp/channels/misdn/ie.c (original)
+++ team/group/v14_colp/channels/misdn/ie.c Wed Oct  1 18:55:27 2008
@@ -13,6 +13,11 @@
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
+ */
+
+/*! \file 
+ * \brief Interface to mISDN
+ * \author Christian Richter <crich at beronet.com>
  */
 
 /*

Modified: team/group/v14_colp/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/group/v14_colp/channels/misdn/isdn_lib.c?view=diff&rev=145695&r1=145694&r2=145695
==============================================================================
--- team/group/v14_colp/channels/misdn/isdn_lib.c (original)
+++ team/group/v14_colp/channels/misdn/isdn_lib.c Wed Oct  1 18:55:27 2008
@@ -58,11 +58,27 @@
 	return -1;
 }
 
-static void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel) 
+int misdn_lib_port_is_nt(int port)
+{
+	struct misdn_stack *stack=get_misdn_stack();
+	for ( ; stack; stack=stack->next) {
+		if (stack->port == port) {
+			return stack->nt;
+		}
+	}
+	
+	return -1;
+}
+
+void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel) 
 {
 	memset (dummybc,0,sizeof(struct misdn_bchannel));
 	dummybc->port=port;
-	dummybc->l3_id=l3id;
+	if (l3id==0) 
+		dummybc->l3_id = MISDN_ID_DUMMY;

[... 1765 lines stripped ...]



More information about the asterisk-commits mailing list