[asterisk-commits] nadi: branch group/trunk-cm-csel-hash r47735 - /team/group/trunk-cm-csel-hash...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Nov 16 08:15:53 MST 2006


Author: nadi
Date: Thu Nov 16 09:15:53 2006
New Revision: 47735

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47735
Log:
chan_list is gone, misdn_ch is born, linked list via AST_RWLIST

Modified:
    team/group/trunk-cm-csel-hash/channels/chan_misdn.c

Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?view=diff&rev=47735&r1=47734&r2=47735
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Thu Nov 16 09:15:53 2006
@@ -86,9 +86,7 @@
 
 #define AST_CID_P(ast)                 ((ast)->cid.cid_num)
 #define AST_BRIDGED_P(ast)             ast_bridged_channel((ast))
-
 #define MISDN_ASTERISK_TECH_PVT(ast)   ((ast)->tech_pvt)
-#define MISDN_ASTERISK_PVT(ast)        1
 
 enum asterisk_events {
 	AEVENT_NOTHING = EVENT_UNKNOWN + 1,
@@ -163,11 +161,10 @@
 	enum event_log_elements additional;
 };
 
-struct chan_list {
-	char allowed_bearers[BUFFERSIZE];
-
+struct misdn_ch {
 	struct statemachine *sm;
 	
+	char allowed_bearers[BUFFERSIZE];
 	int need_queue_hangup;
 	int need_hangup;
 	int need_busy;
@@ -208,12 +205,12 @@
 	char context[BUFFERSIZE];
 	int dropped_frame_cnt;
 	int other_pid;
-	struct chan_list *other_ch;
+	struct misdn_ch *other_ch;
 	const struct tone_zone_sound *ts;
 
 	int destroy_me;
 
-	struct chan_list *next;
+	AST_RWLIST_ENTRY(misdn_ch) next;
 };
 
 struct allowed_bearer {
@@ -250,8 +247,7 @@
 static int                    g_config_initialized = 0;
 static int                    glob_channel = 0;
 
-static struct chan_list     * cl_te = NULL;
-static ast_mutex_t            cl_te_lock;
+static AST_RWLIST_HEAD_STATIC(ch_list, misdn_ch);
 
 static char                ** misdn_key_vector = NULL;
 static int                    misdn_key_vector_size = 0;
@@ -882,7 +878,7 @@
 	return misdn_chan_states[state];
 }
 
-static inline void event_info_string (char *buf, int bufsize, struct chan_list *ch, int *elems, int num)
+static inline void event_info_string (char *buf, int bufsize, struct misdn_ch *ch, int *elems, int num)
 {
 	int first = 0;
 	char tmpbuf[256];
@@ -922,7 +918,7 @@
 
 static void log_event (void *p, int direction, int state, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = p;
 	const struct event_log_info *info = get_event_info(event);
 	int elems;
 	char buf[1024] = "";
@@ -948,14 +944,15 @@
 
 static int send_event (void *p, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = p;
 	struct misdn_bchannel *bc = ch->bc;
 	int re = 0;
 
 	if (event > EVENT_NOTHING && event < EVENT_UNKNOWN) {
 		misdn_lib_send_event(bc, event);
 		if (event == EVENT_HOLD_ACKNOWLEDGE) {
-			/*forget the channel now*/
+			/* XXX find a better place for this */
+			/* forget the channel now */
 			ch->bc = NULL;
 			ch->hold_info.port = bc->port;
 			ch->hold_info.channel = bc->channel;
@@ -1063,115 +1060,140 @@
 	AST_HASH_DESTROY(&group_csel_hash);
 }
 
-/* Chanlist Helpers */
-static struct chan_list * init_chan_list (int orig)
-{
-	struct chan_list *cl = calloc(1, sizeof(struct chan_list));
-
-	if (!cl) {
+/* misdn_ch Helper */
+static struct misdn_ch * misdn_ch_init (int orig)
+{
+	struct misdn_ch *ch = calloc(1, sizeof(struct misdn_ch));
+
+	if (!ch) {
 		chan_misdn_log(-1, 0, "misdn_request: malloc failed!");
 		return NULL;
 	}
 
-	cl->sm = statemachine_create(cl, MISDN_NOTHING, misdn_state_table,
-								  sizeof(misdn_state_table) / sizeof(struct statemachine_transition),
-								  send_event,
-								  log_event);
-	cl->orginator = orig;
-	cl->need_queue_hangup = 1;
-	cl->need_hangup = 1;
-	cl->need_busy = 1;
-	cl->overlap_dial_task = -1;
-
-	return cl;
-}
-
-static void cl_queue_chan(struct chan_list **list, struct chan_list *chan)
-{
-	struct chan_list *help = *list;
-
-	chan_misdn_log(4, chan->bc? chan->bc->port : 0, "* Queuing chan %p\n", chan);
-
-	ast_mutex_lock(&cl_te_lock);
-	if (!*list) {
-		*list = chan;
-	} else {
-		for (; help->next; help = help->next); 
-		help->next = chan;
-	}
-	chan->next = NULL;
-	ast_mutex_unlock(&cl_te_lock);
-}
-
-static void cl_dequeue_chan (struct chan_list **list, struct chan_list *chan) 
-{
-	struct chan_list *help = *list;
-
+	ch->sm = statemachine_create(ch, MISDN_NOTHING, misdn_state_table,
+								 sizeof(misdn_state_table) / sizeof(struct statemachine_transition),
+								 send_event,
+								 log_event);
+	ch->orginator = orig;
+	ch->need_queue_hangup = 1;
+	ch->need_hangup = 1;
+	ch->need_busy = 1;
+	ch->overlap_dial_task = -1;
+
+	return ch;
+}
+
+static void misdn_ch_queue (struct misdn_ch *chan)
+{
+	AST_RWLIST_WRLOCK(&ch_list);
+	AST_RWLIST_INSERT_TAIL(&ch_list, chan, next);
+	AST_RWLIST_UNLOCK(&ch_list);
+}
+
+static void misdn_ch_dequeue (struct misdn_ch *chan) 
+{
 	if (chan->dsp) 
 		ast_dsp_free(chan->dsp);
 
 	if (chan->trans)
 		ast_translator_free_path(chan->trans);
 
-	ast_mutex_lock(&cl_te_lock);
-	if (!help) {
-		ast_mutex_unlock(&cl_te_lock);
-		return;
-	}
-
-	if (help == chan)
-		*list = help->next;
-	else
-		for (; help->next; help = help->next) {
-			if (help->next == chan) {
-				help->next = chan->next;
-				break;
-			}
-		}
+	AST_RWLIST_WRLOCK(&ch_list);
+	AST_RWLIST_REMOVE(&ch_list, chan, next);
+	AST_RWLIST_UNLOCK(&ch_list);
+}
+
+static struct misdn_ch * misdn_ch_by_bc (struct misdn_bchannel *bc)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (ch->bc == bc)
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
+
+	if (!ch)
+		chan_misdn_log(6, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n", bc->oad, bc->dad);
+
+	return ch;
+}
+
+static struct misdn_ch * misdn_ch_by_pid (int pid)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (ch->bc && ch->bc->pid == pid)
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
+
+	if (!ch)
+		chan_misdn_log(6, 0, "$$$ find_chan: No channel found for pid:%d\n", pid);
+
+	return ch;
+}
+
+static struct misdn_ch * misdn_ch_by_ast (struct ast_channel *ast)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (ch->ast == ast)
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
+
+	return ch;
+}
+
+static struct misdn_ch * misdn_ch_by_ast_name (char *name)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (ch->ast && !strcmp(ch->ast->name, name))
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
+
+	return ch;
+}
+
+static struct misdn_ch * misdn_ch_holded (struct misdn_bchannel *bc)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (statemachine_get_state(ch->sm) == MISDN_HOLDED && ch->hold_info.port == bc->port)
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
+
+	if (!ch)
+		chan_misdn_log(6, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n", bc->oad, bc->dad);
+
+	return ch;
+}
+
+static struct misdn_ch * misdn_ch_holded_l3 (unsigned long l3_id)
+{
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (statemachine_get_state(ch->sm) == MISDN_HOLDED && ch->l3id == l3_id) 
+			break;
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
 	
-	ast_mutex_unlock(&cl_te_lock);
-}
-
-static struct chan_list * find_chan_by_bc (struct chan_list *list, struct misdn_bchannel *bc)
-{
-	for (; list; list = list->next)
-		if (list->bc == bc)
-			return list;
-
-	chan_misdn_log(6, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n", bc->oad, bc->dad);
-	return NULL;
-}
-
-static struct chan_list * find_chan_by_pid (struct chan_list *list, int pid)
-{
-	for (; list; list = list->next)
-		if (list->bc && list->bc->pid == pid)
-			return list;
-
-	chan_misdn_log(6, 0, "$$$ find_chan: No channel found for pid:%d\n", pid);
-	return NULL;
-}
-
-static struct chan_list * find_holded (struct chan_list *list, struct misdn_bchannel *bc)
-{
-	for (; list; list = list->next) {
-		chan_misdn_log(4, bc->port, "$$$ find_holded: --> holded:%d channel:%d\n",
-					   statemachine_get_state(list->sm) == MISDN_HOLDED, list->hold_info.channel);
-		if (statemachine_get_state(list->sm) == MISDN_HOLDED && list->hold_info.port == bc->port)
-			return list;
-	}
-	
-	chan_misdn_log(6, bc->port, "$$$ find_chan: No channel found for oad:%s dad:%s\n", bc->oad, bc->dad);
-	return NULL;
-}
-
-static struct chan_list * find_holded_l3 (struct chan_list *list, unsigned long l3_id, int w) 
-{
-	for (; list; list = list->next)
-		if (statemachine_get_state(list->sm) == MISDN_HOLDED && list->l3id == l3_id) 
-			return list;
-
-	return NULL;
+	return ch;
 }
 
 /* Jitterbuffer */
@@ -1291,7 +1313,7 @@
 
 static int bc_jb_empty (struct misdn_bchannel *bc, char *buf, int len) 
 {
-	struct chan_list *ch = find_chan_by_bc(cl_te, bc);
+	struct misdn_ch *ch = misdn_ch_by_bc(bc);
 
 	if (ch && ch->jb)
 		return misdn_jb_empty(ch->jb, buf, len);
@@ -1365,28 +1387,6 @@
 };
 
 /* Simple Helpers */
-static struct chan_list * get_chan_by_ast (struct ast_channel *ast)
-{
-	struct chan_list *tmp;
-
-	for (tmp = cl_te; tmp; tmp = tmp->next)
-		if (tmp->ast == ast)
-			return tmp;
-
-	return NULL;
-}
-
-static struct chan_list * get_chan_by_ast_name (char *name)
-{
-	struct chan_list *tmp;
-
-	for (tmp = cl_te; tmp; tmp = tmp->next)
-		if (tmp->ast && !strcmp(tmp->ast->name, name))
-			return tmp;
-
-	return NULL;
-}
-
 static char * get_bearer_str (int cap)
 {
 	static char unknown[] = "Unknown Bearer";
@@ -1490,9 +1490,9 @@
 	}
 }
 
-static void print_bc_info (int fd, struct chan_list *help, struct misdn_bchannel *bc)
-{
-	struct ast_channel *ast = help->ast;
+static void print_bc_info (int fd, struct misdn_ch *ch, struct misdn_bchannel *bc)
+{
+	struct ast_channel *ast = ch->ast;
 
 	ast_cli(fd,
 			"* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s rad:%s ctx:%s state:%s\n",
@@ -1500,12 +1500,12 @@
 			bc->port,
 			bc->channel,
 			bc->nt ? "NT" : "TE",
-			help->orginator == ORG_AST ? "*" : "I",
+			ch->orginator == ORG_AST ? "*" : "I",
 			ast ? ast->exten : "",
 			ast ? AST_CID_P(ast) : "",
 			bc->rad,
 			ast ? ast->context : "",
-			get_state_string(statemachine_get_state(help->sm)));
+			get_state_string(statemachine_get_state(ch->sm)));
 
 	if (misdn_debug[bc->port] > 0)
 		ast_cli(fd,
@@ -1520,21 +1520,21 @@
 				"  --> echo_cancel: %d\n"
 				"  --> notone : rx %d tx:%d\n"
 				"  --> bc_hold: %d\n",
-				help->ast->name,
-				help->l3id,
-				help->addr,
+				ch->ast->name,
+				ch->l3id,
+				ch->addr,
 				bc->addr,
 				bc->l3_id,
 				bc->display,
 				bc_state2str(bc->bc_state),
 				get_bearer_str(bc->capability),
 				bc->ec_enable,
-				help->norxtone,
-				help->notxtone,
+				ch->norxtone,
+				ch->notxtone,
 				bc->holded);
 }
 
-static void import_ch (struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch)
+static void import_ch (struct ast_channel *chan, struct misdn_bchannel *bc, struct misdn_ch *ch)
 {
 	const char *tmp;
 
@@ -1543,7 +1543,7 @@
 		ch->other_pid = atoi(tmp);
 		chan_misdn_log(2, bc->port, "IMPORT_PID: importing pid:%s\n", tmp);
 		if (ch->other_pid > 0) {
-			ch->other_ch = find_chan_by_pid(cl_te, ch->other_pid);
+			ch->other_ch = misdn_ch_by_pid(ch->other_pid);
 			if (ch->other_ch)
 				ch->other_ch->other_ch = ch;
 		}
@@ -1659,14 +1659,14 @@
 }
 
 /* Channel Helpers */
-static int pbx_start_chan (struct chan_list *ch)
+static int pbx_start_chan (struct misdn_ch *ch)
 {
 	int ret = ast_pbx_start(ch->ast);	
 	ch->need_hangup = ret >= 0 ? 0 : 1;
 	return ret;
 }
 
-static void export_chan (struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch)
+static void export_chan (struct ast_channel *chan, struct misdn_bchannel *bc, struct misdn_ch *ch)
 {
 	char tmp[32];
 	chan_misdn_log(2, bc->port, "EXPORT_PID: pid:%d\n", bc->pid);
@@ -1674,9 +1674,9 @@
 	pbx_builtin_setvar_helper(chan, "_MISDN_PID", tmp);
 }
 
-static void send_digit_to_chan (struct chan_list *cl, char digit)
-{
-	struct ast_channel *chan = cl->ast; 
+static void send_digit_to_chan (struct misdn_ch *ch, char digit)
+{
+	struct ast_channel *chan = ch->ast; 
 	static const char *dtmf_tones[] = {
 		"!941+1336/100, !0/100",	/* 0 */
 		"!697+1209/100, !0/100",	/* 1 */
@@ -1708,7 +1708,7 @@
 		ast_log(LOG_DEBUG, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
 }
 
-static void send_cause_to_ast (struct ast_channel *ast, struct misdn_bchannel *bc, struct chan_list *ch)
+static void send_cause_to_ast (struct ast_channel *ast, struct misdn_bchannel *bc, struct misdn_ch *ch)
 {
 	if (!ast) {
 		chan_misdn_log(2, 0, "send_cause_to_ast: No Ast\n");
@@ -1737,63 +1737,63 @@
 	}
 }
 
-static int dialtone_indicate (struct chan_list *cl)
+static int dialtone_indicate (struct misdn_ch *ch)
 {
 	const struct tone_zone_sound *ts= NULL;
 	int nd = 0;
 
-	if (!cm_get_strcasecmp(misdn_cm, "yes", PORT, MCFG_NODIALTONE, cl->bc->port))
+	if (!cm_get_strcasecmp(misdn_cm, "yes", PORT, MCFG_NODIALTONE, ch->bc->port))
 		nd = 1;
 	if (nd) {
-		chan_misdn_log(2, cl->bc->port, "Not sending Dialtone, because config wants it\n");
+		chan_misdn_log(2, ch->bc->port, "Not sending Dialtone, because config wants it\n");
 		return 0;
 	}
 
-	chan_misdn_log(3, cl->bc->port, " --> Dial\n");
-	ts = ast_get_indication_tone(cl->ast->zone, "dial");
-	cl->ts = ts;	
+	chan_misdn_log(3, ch->bc->port, " --> Dial\n");
+	ts = ast_get_indication_tone(ch->ast->zone, "dial");
+	ch->ts = ts;	
 
 	if (ts) {
-		cl->notxtone = 0;
-		cl->norxtone = 0;
-		ast_playtones_start(cl->ast, 0, ts->data, 0);
-		chan_misdn_log(4, cl->bc->port, "Starting Playtones\n");
-		misdn_lib_tone_generator_start(cl->bc);
+		ch->notxtone = 0;
+		ch->norxtone = 0;
+		ast_playtones_start(ch->ast, 0, ts->data, 0);
+		chan_misdn_log(4, ch->bc->port, "Starting Playtones\n");
+		misdn_lib_tone_generator_start(ch->bc);
 	}
 
 	return 0;
 }
 
-static int hanguptone_indicate (struct chan_list *cl)
-{
-	misdn_lib_send_tone(cl->bc, TONE_HANGUP);
+static int hanguptone_indicate (struct misdn_ch *ch)
+{
+	misdn_lib_send_tone(ch->bc, TONE_HANGUP);
 	return 0;
 }
 
-static int stop_indicate (struct chan_list *cl)
-{
-	chan_misdn_log(3, cl->bc->port, " --> None\n");
-	misdn_lib_tone_generator_stop(cl->bc);
-	ast_playtones_stop(cl->ast);
+static int stop_indicate (struct misdn_ch *ch)
+{
+	chan_misdn_log(3, ch->bc->port, " --> None\n");
+	misdn_lib_tone_generator_stop(ch->bc);
+	ast_playtones_stop(ch->ast);
 	return 0;
 }
 
-static int start_bc_tones (struct chan_list *cl)
-{
-	misdn_lib_tone_generator_stop(cl->bc);
-	cl->notxtone = 0;
-	cl->norxtone = 0;
+static int start_bc_tones (struct misdn_ch *ch)
+{
+	misdn_lib_tone_generator_stop(ch->bc);
+	ch->notxtone = 0;
+	ch->norxtone = 0;
 	return 0;
 }
 
-static int stop_bc_tones (struct chan_list *cl)
-{
-	cl->notxtone = 1;
-	cl->norxtone = 1;
+static int stop_bc_tones (struct misdn_ch *ch)
+{
+	ch->notxtone = 1;
+	ch->norxtone = 1;
 	return 0;
 }
 
-static void hangup_chan (struct chan_list *ch)
+static void hangup_chan (struct misdn_ch *ch)
 {
 	int port;
 
@@ -1828,7 +1828,7 @@
 }
 
 /* Isdn asks us to release channel, pendant to misdn_hangup */
-static void release_chan (struct chan_list *ch)
+static void release_chan (struct misdn_ch *ch)
 {
 	struct ast_channel *ast;
 	struct misdn_bchannel *bc = ch->bc;
@@ -1873,19 +1873,19 @@
 		}
 	}
 
-	cl_dequeue_chan(&cl_te, ch);
+	misdn_ch_dequeue(ch);
 	statemachine_destroy(ch->sm);
 	free(ch);
 }
 
-static void misdn_transfer_bc (struct chan_list *tmp_ch, struct chan_list *holded_chan)
-{
-	chan_misdn_log(4, 0, "TRANSFERING %s to %s\n", holded_chan->ast->name, tmp_ch->ast->name);
-	statemachine_set_state(tmp_ch->sm, MISDN_HOLD_DISCONNECT);
-	ast_moh_stop(AST_BRIDGED_P(holded_chan->ast));
-	statemachine_set_state(holded_chan->sm, MISDN_CONNECTED);
-/* 	misdn_lib_transfer(holded_chan->bc); */
-	ast_channel_masquerade(holded_chan->ast, AST_BRIDGED_P(tmp_ch->ast));
+static void misdn_transfer_bc (struct misdn_ch *ch, struct misdn_ch *holded_ch)
+{
+	chan_misdn_log(4, 0, "TRANSFERING %s to %s\n", holded_ch->ast->name, ch->ast->name);
+	statemachine_set_state(ch->sm, MISDN_HOLD_DISCONNECT);
+	ast_moh_stop(AST_BRIDGED_P(holded_ch->ast));
+	statemachine_set_state(holded_ch->sm, MISDN_CONNECTED);
+/* 	misdn_lib_transfer(holded_ch->bc); */
+	ast_channel_masquerade(holded_ch->ast, AST_BRIDGED_P(ch->ast));
 }
 
 static int add_in_calls (int port)
@@ -1929,7 +1929,7 @@
 {
 	struct timeval tv_end, tv_now;
 	int diff;
-	struct chan_list *ch = (struct chan_list *)data;
+	struct misdn_ch *ch = (struct misdn_ch *)data;
 
 	chan_misdn_log(4, ch->bc->port, "overlap dial task, chan_state: %d\n", statemachine_get_state(ch->sm));
 
@@ -2017,7 +2017,7 @@
 {
 	char *channame,
 		 *nr; 
-	struct chan_list *tmp;
+	struct misdn_ch *ch;
 
 	if (argc != 5)
 		return RESULT_SHOWUSAGE;
@@ -2025,17 +2025,17 @@
 	channame = argv[3];
 	nr = argv[4];
 	ast_cli(fd, "Sending Calldeflection (%s) to %s\n", nr, channame);
-	tmp = get_chan_by_ast_name(channame);
-	if (!tmp) {
+	ch = misdn_ch_by_ast_name(channame);
+	if (!ch) {
 		ast_cli(fd, "Sending CD with nr %s to %s failed: Channel does not exist.\n", nr, channame);
 	} else {
 		if (strlen(nr) >= 15) {
 			ast_cli(fd, "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;
-		strncpy((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);
+		ch->bc->fac_out.Function = Fac_CD;
+		strncpy((char *)ch->bc->fac_out.u.CDeflection.DeflectedToNumber, nr, sizeof(ch->bc->fac_out.u.CDeflection.DeflectedToNumber));
+		misdn_lib_send_event(ch->bc, EVENT_FACILITY);
 	}
 
 	return 0; 
@@ -2045,7 +2045,7 @@
 {
 	char *channame,
 		 *msg; 
-	struct chan_list *tmp;
+	struct misdn_ch *ch;
 	int i,
 		msglen;
 
@@ -2055,14 +2055,14 @@
 	channame = argv[3];
 	msg = argv[4];
 	ast_cli(fd, "Sending %s to %s\n", msg, channame);
-	tmp = get_chan_by_ast_name(channame);
-	if (!tmp) {
+	ch = misdn_ch_by_ast_name(channame);
+	if (!ch) {
 		ast_cli(fd, "Sending %s to %s failed Channel does not exist\n", msg, channame);
 	} else {
 		msglen = strlen(msg);
 		for (i = 0; i < msglen; ++i) {
 			ast_cli(fd, "Sending: %c\n", msg[i]);
-			send_digit_to_chan(tmp, msg[i]);
+			send_digit_to_chan(ch, msg[i]);
 			usleep(250000);
 		}
 	}
@@ -2073,7 +2073,7 @@
 static int misdn_toggle_echocancel (int fd, int argc, char *argv[])
 {
 	char *channame; 
-	struct chan_list *tmp;
+	struct misdn_ch *ch;
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
@@ -2081,16 +2081,16 @@
 	channame = argv[3];
 	ast_cli(fd, "Toggling EchoCancel on %s\n", channame);
 
-	tmp = get_chan_by_ast_name(channame);
-	if (!tmp) {
+	ch = misdn_ch_by_ast_name(channame);
+	if (!ch) {
 		ast_cli(fd, "Toggling EchoCancel %s failed Channel does not exist\n", channame);
 	} else {
-		tmp->toggle_ec = tmp->toggle_ec ? 0 : 1;
-		if (tmp->toggle_ec) {
-			config_bc_echocancel(tmp->bc);
-			manager_ec_enable(tmp->bc);
+		ch->toggle_ec = ch->toggle_ec ? 0 : 1;
+		if (ch->toggle_ec) {
+			config_bc_echocancel(ch->bc);
+			manager_ec_enable(ch->bc);
 		} else {
-			manager_ec_disable(tmp->bc);
+			manager_ec_disable(ch->bc);
 		}
 	}
 
@@ -2101,7 +2101,7 @@
 {
 	char *channame,
 		 *msg; 
-	struct chan_list *tmp;
+	struct misdn_ch *ch;
 
 	if (argc != 5)
 		return RESULT_SHOWUSAGE;
@@ -2109,10 +2109,10 @@
 	channame = argv[3];
 	msg = argv[4];
 	ast_cli(fd, "Sending %s to %s\n", msg, channame);
-	tmp = get_chan_by_ast_name(channame);
-	if (tmp && tmp->bc) {
-		ast_copy_string(tmp->bc->display, msg, sizeof(tmp->bc->display));
-		misdn_lib_send_event(tmp->bc, EVENT_INFORMATION);
+	ch = misdn_ch_by_ast_name(channame);
+	if (ch && ch->bc) {
+		ast_copy_string(ch->bc->display, msg, sizeof(ch->bc->display));
+		misdn_lib_send_event(ch->bc, EVENT_INFORMATION);
 	} else {
 		ast_cli(fd, "No such channel %s\n", channame);
 		return RESULT_FAILURE;
@@ -2135,50 +2135,44 @@
 
 static int misdn_show_cls (int fd, int argc, char *argv[])
 {
-	struct misdn_bchannel *bc;
-	struct ast_channel *ast;
-	struct chan_list *help = cl_te;
-
-	ast_cli(fd, "Chan List: %p\n", cl_te); 
-
-	for (; help; help = help->next) {
-		bc = help->bc;   
-		ast = help->ast;
+	struct misdn_ch *ch;
+
+	AST_RWLIST_RDLOCK(&ch_list);
+	ast_cli(fd, "Chan List:\n");
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
 		if (misdn_debug[0] > 2)
-			ast_cli(fd, "Bc:%p Ast:%p\n", bc, ast);
-		if (bc) {
-			print_bc_info(fd, help, bc);
+			ast_cli(fd, "Bc:%p Ast:%p\n", ch->bc, ch->ast);
+		if (ch->bc) {
+			print_bc_info(fd, ch, ch->bc);
 		} else {
-			if (statemachine_get_state(help->sm) == MISDN_HOLDED)
+			if (statemachine_get_state(ch->sm) == MISDN_HOLDED)
 				chan_misdn_log(0, 0, "IT'S A HOLDED BC:\n --> l3_id: %x\n --> dad:%s oad:%s\n --> hold_port: %d\n --> hold_channel: %d\n",
-							   help->l3id, ast->exten, AST_CID_P(ast), help->hold_info.port, help->hold_info.channel);
+							   ch->l3id, ch->ast->exten, AST_CID_P(ch->ast), ch->hold_info.port, ch->hold_info.channel);
 			else
-				ast_cli(fd,"* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", ast->exten, AST_CID_P(ast));
-		}
-	}
+				ast_cli(fd,"* Channel in unknown STATE !!! Exten:%s, Callerid:%s\n", ch->ast->exten, AST_CID_P(ch->ast));
+		}
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
 
 	return 0;
 }
 
 static int misdn_show_cl (int fd, int argc, char *argv[])
 {
-	struct misdn_bchannel *bc;
-	struct ast_channel *ast;
-	struct chan_list *help = cl_te;
+	struct misdn_ch *ch;
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 
-	for (; help; help = help->next) {
-		bc = help->bc;   
-		ast = help->ast;
-		if (bc && ast) {
-			if (!strcasecmp(ast->name, argv[3])) {
-				print_bc_info(fd, help, bc);
-				break; 
-			}
-		} 
-	}
+	AST_RWLIST_RDLOCK(&ch_list);
+	ast_cli(fd, "Chan List:\n");
+	AST_RWLIST_TRAVERSE(&ch_list, ch, next) {
+		if (ch->bc && ch->ast && !strcasecmp(ch->ast->name, argv[3])) {
+			print_bc_info(fd, ch, ch->bc);
+			break; 
+		}
+	}
+	AST_RWLIST_UNLOCK(&ch_list);
 
 	return 0;
 }
@@ -2392,7 +2386,7 @@
 };
 
 /* Channel configuration */
-static int config_ch_pres_screen (struct chan_list *ch)
+static int config_ch_pres_screen (struct misdn_ch *ch)
 {
 	struct ast_channel *ast;
 	struct misdn_bchannel *bc;
@@ -2489,7 +2483,7 @@
 	return 0;
 }
 
-static int config_ch_hdlc (struct chan_list *ch)
+static int config_ch_hdlc (struct misdn_ch *ch)
 {
 	struct misdn_bchannel *bc = ch->bc;
 	int hdlc;
@@ -2508,7 +2502,7 @@
 	return 0;
 }
 
-static void config_ch_jitterbuffer (struct chan_list *ch)
+static void config_ch_jitterbuffer (struct misdn_ch *ch)
 {
 	struct misdn_bchannel *bc = ch->bc;
 	int len = ch->jb_len,
@@ -2550,7 +2544,7 @@
 	return 0;
 }
 
-static int config_ch (struct chan_list *ch, int orig)
+static int config_ch (struct misdn_ch *ch, int orig)
 {
 	struct ast_channel *ast;
 	struct misdn_bchannel *bc;
@@ -2694,7 +2688,7 @@
 }
 
 /* mISDN ast_channel Constructor */
-static struct ast_channel * misdn_new (struct chan_list *chlist, int state,  char *exten, char *callerid, int format, int port, int c)
+static struct ast_channel * misdn_new (struct misdn_ch *ch, int state,  char *exten, char *callerid, int format, int port, int c)
 {
 	int bridging,
 		chan_offset = 0,
@@ -2724,7 +2718,7 @@
 		tmp->rawreadformat = format;
 		tmp->writeformat = format;
 		tmp->rawwriteformat = format;
-		tmp->tech_pvt = chlist;
+		tmp->tech_pvt = ch;
 		tmp->priority = 1;
 
 		if (cm_get_int(misdn_cm, bridging, GENERAL, MCFG_BRIDGING))
@@ -2745,9 +2739,9 @@
 			tmp->cid.cid_name = ast_strdup(cid_name);
 		}
 
-		if (pipe(chlist->pipe) < 0)
+		if (pipe(ch->pipe) < 0)
 			perror("Pipe failed\n");
-		tmp->fds[0] = chlist->pipe[0];
+		tmp->fds[0] = ch->pipe[0];
 		tmp->rings = (state == AST_STATE_RING);
 	} else
 		chan_misdn_log(-1, 0, "Unable to allocate channel structure\n");
@@ -2768,7 +2762,7 @@
 		port = 0;
 	struct misdn_bchannel *newbc = NULL;
 	struct csel *cs = NULL;
-	struct chan_list *cl = init_chan_list(ORG_AST);
+	struct misdn_ch *ch = misdn_ch_init(ORG_AST);
 
 	ast_copy_string(buf, data, sizeof(buf));
 
@@ -2812,19 +2806,19 @@
 	}
 
 	/* create ast_channel and link all the objects together */
-	cl->bc = newbc;
-	cl->ast = misdn_new(cl, AST_STATE_RESERVED, ext, NULL, format, port, channel);
+	ch->bc = newbc;
+	ch->ast = misdn_new(ch, AST_STATE_RESERVED, ext, NULL, format, port, channel);
 
 	/* register chan in local list */
-	cl_queue_chan(&cl_te, cl) ;
+	misdn_ch_queue(ch) ;
 
 	/* fill in the config into the objects */
-	config_ch(cl, ORG_AST);
+	config_ch(ch, ORG_AST);
 
 	/* important */
-	cl->need_hangup = 0;
-
-	return cl->ast;
+	ch->need_hangup = 0;
+
+	return ch->ast;
 }
 
 static int misdn_digit_begin (struct ast_channel *chan, char digit)
@@ -2836,13 +2830,13 @@
 static int misdn_digit_end (struct ast_channel *ast, char digit)
 {
 	struct misdn_bchannel *bc;
-	struct chan_list *p;
+	struct misdn_ch *ch;
 	char buf[8];
 
-	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)))
+	if (!ast || !(ch = MISDN_ASTERISK_TECH_PVT(ast)))
 		return -1;
 
-	bc = p->bc;
+	bc = ch->bc;
 	if (!bc) {
 		ast_log(LOG_WARNING, " --> !! Got Digit Event withut having bchannel Object\n");
 		return -1;
@@ -2850,7 +2844,7 @@
 	
 	chan_misdn_log(2, bc->port, "* IND : Digit %c\n", digit);
 
-	switch (statemachine_get_state(p->sm)) {
+	switch (statemachine_get_state(ch->sm)) {
 	case MISDN_CALLING:
 		buf[0] = digit;
 		buf[1] = 0;
@@ -2862,13 +2856,13 @@
 		bc->info_dad[1] = 0;
 		strncat(bc->dad, bc->info_dad, sizeof(bc->dad) - strlen(bc->dad));
 		bc->dad[sizeof(bc->dad) - 1] = 0;
-		strncpy(p->ast->exten, bc->dad, sizeof(p->ast->exten));
-		p->ast->exten[sizeof(p->ast->exten) - 1] = 0;
+		strncpy(ch->ast->exten, bc->dad, sizeof(ch->ast->exten));
+		ch->ast->exten[sizeof(ch->ast->exten) - 1] = 0;
 		misdn_lib_send_event(bc, EVENT_INFORMATION);
 		break;
 	default:
 		if (bc->send_dtmf)
-			send_digit_to_chan(p, digit);
+			send_digit_to_chan(ch, digit);
 	}
 
 	return 0;
@@ -2879,7 +2873,7 @@
 	int port = 0;
 	int r;
 	int exceed;
-	struct chan_list *ch = MISDN_ASTERISK_TECH_PVT(ast);
+	struct misdn_ch *ch = MISDN_ASTERISK_TECH_PVT(ast);
 	struct misdn_bchannel *newbc;
 	char *opts = NULL,
 		 *ext,
@@ -2987,15 +2981,15 @@
 static enum ast_bridge_result misdn_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags,
 											struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
 {
-	struct chan_list *ch1, *ch2;
+	struct misdn_ch *ch1, *ch2;
 	struct ast_channel *carr[2], *who;
 	struct ast_frame *f;
 	int to = -1,
 		bridging = 0,
 		ec = 0;
 
-	ch1 = get_chan_by_ast(c0);
-	ch2 = get_chan_by_ast(c1);
+	ch1 = misdn_ch_by_ast(c0);
+	ch2 = misdn_ch_by_ast(c1);
 
 	carr[0] = c0;
 	carr[1] = c1;
@@ -3069,24 +3063,24 @@
 
 static int misdn_hangup (struct ast_channel *ast)
 {
-	struct chan_list *p;
+	struct misdn_ch *ch;
 	struct misdn_bchannel *bc;
 	const char *varcause;
 	int tmpcause,
 		re;
 	int state;
 
-	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)))
+	if (!ast || !(ch = MISDN_ASTERISK_TECH_PVT(ast)))
 		return -1;
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "misdn_hangup(%s)\n", ast->name);
 
-	bc = p->bc;
+	bc = ch->bc;
 	MISDN_ASTERISK_TECH_PVT(ast) = NULL;
-	p->ast = NULL;
-
-	state = statemachine_get_state(p->sm);
+	ch->ast = NULL;
+
+	state = statemachine_get_state(ch->sm);
 
 	if (!bc ||
 		ast->_state == AST_STATE_RESERVED ||
@@ -3097,20 +3091,20 @@
 		/* between request and call */
 		if (!bc)
 			ast_log(LOG_WARNING,"Hangup with private but no bc ? state:%s l3id:%x\n",
-					get_state_string(statemachine_get_state(p->sm)), p->l3id);
+					get_state_string(statemachine_get_state(ch->sm)), ch->l3id);
 		if (option_debug)
 			ast_log(LOG_DEBUG, "State Reserved (or nothing) => chanIsAvail\n");
-		cl_dequeue_chan(&cl_te, p);
-		close(p->pipe[0]);
-		close(p->pipe[1]);
-		free(p);
+		misdn_ch_dequeue(ch);
+		close(ch->pipe[0]);
+		close(ch->pipe[1]);
+		free(ch);
 		misdn_lib_release(bc);
 		return 0;
 	}
 
-	p->need_hangup = p->need_queue_hangup = p->need_busy = 0;
+	ch->need_hangup = ch->need_queue_hangup = ch->need_busy = 0;
 	if (!bc->nt) 
-		stop_bc_tones(p);
+		stop_bc_tones(ch);
 	bc->out_cause = ast->hangupcause ? ast->hangupcause : 16;
 
 	if ((varcause = pbx_builtin_getvar_helper(ast, "HANGUPCAUSE")) ||
@@ -3122,24 +3116,24 @@
 	chan_misdn_log(2, bc->port,
 				   "* IND : HANGUP\tpid:%d ctx:%s dad:%s oad:%s state:%s\n"
 				   " --> l3id:%x\n --> cause:%d\n --> out_cause:%d\n",
-				   p->bc ? p->bc->pid : -1, ast->context, ast->exten, AST_CID_P(ast),
-				   get_state_string(statemachine_get_state(p->sm)),
-				   p->l3id, bc->cause, bc->out_cause);
-
-	if ((re = statemachine_run(p->sm, AEVENT_HANGUP))) {
+				   ch->bc ? ch->bc->pid : -1, ast->context, ast->exten, AST_CID_P(ast),
+				   get_state_string(statemachine_get_state(ch->sm)),
+				   ch->l3id, bc->cause, bc->out_cause);
+
+	if ((re = statemachine_run(ch->sm, AEVENT_HANGUP))) {
 		chan_misdn_log(0, bc->port, "statemachine_run failed on AEVENT_HANGUP: %d!\n", re);
 		return -1;
 	}
 	
 	chan_misdn_log(2, bc->port, "Channel: %s hanguped new state:%s\n", ast->name,
-				   get_state_string(statemachine_get_state(p->sm)));
+				   get_state_string(statemachine_get_state(ch->sm)));
 
 	return 0;
 }
 
 static struct statemachine_handle_retval handle_aevent_hangup (void *p, int state, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = ch;
 	struct misdn_bchannel *bc = ch->bc;
 	int re = EVENT_DEFAULT;
 
@@ -3188,57 +3182,57 @@
 
 static int misdn_answer (struct ast_channel *ast)
 {
-	struct chan_list *p;
+	struct misdn_ch *ch;
 	const char *tmp_key, *nodsp;
 
-	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)) || !p->bc)
+	if (!ast || !(ch = MISDN_ASTERISK_TECH_PVT(ast)) || !ch->bc)
 		return -1;
 
-	chan_misdn_log(2, p->bc->port, "* ANSWER:\n");
-
-	tmp_key = pbx_builtin_getvar_helper(p->ast, "CRYPT_KEY");
+	chan_misdn_log(2, ch->bc->port, "* ANSWER:\n");
+
+	tmp_key = pbx_builtin_getvar_helper(ch->ast, "CRYPT_KEY");
 	if (tmp_key) {
-		chan_misdn_log(2, p->bc->port, " --> Connection will be BF crypted\n");
-		strncpy(p->bc->crypt_key, tmp_key, sizeof(p->bc->crypt_key));
-		p->bc->crypt_key[sizeof(p->bc->crypt_key) - 1] = 0;
+		chan_misdn_log(2, ch->bc->port, " --> Connection will be BF crypted\n");
+		strncpy(ch->bc->crypt_key, tmp_key, sizeof(ch->bc->crypt_key));
+		ch->bc->crypt_key[sizeof(ch->bc->crypt_key) - 1] = 0;
 	} else
-		chan_misdn_log(3, p->bc->port, " --> Connection is without BF encryption\n");
+		chan_misdn_log(3, ch->bc->port, " --> Connection is without BF encryption\n");
 
 	nodsp = pbx_builtin_getvar_helper(ast, "MISDN_DIGITAL_TRANS");
 	if (nodsp) {
-		chan_misdn_log(2, p->bc->port, " --> Connection is transparent digital\n");
-		p->bc->nodsp = 1;
-		p->bc->hdlc = 0;
-		p->bc->nojitter = 1;
+		chan_misdn_log(2, ch->bc->port, " --> Connection is transparent digital\n");
+		ch->bc->nodsp = 1;
+		ch->bc->hdlc = 0;
+		ch->bc->nojitter = 1;
 	}
 	
-	misdn_lib_echo(p->bc, 0);
-	stop_indicate(p);
-
-	if (ast_strlen_zero(p->bc->cad)) {
-		chan_misdn_log(2, p->bc->port, " --> empty cad using dad\n");
-		ast_copy_string(p->bc->cad, p->bc->dad, sizeof(p->bc->cad));
-	}
-
-	statemachine_run(p->sm, AEVENT_ANSWER);
+	misdn_lib_echo(ch->bc, 0);
+	stop_indicate(ch);
+
+	if (ast_strlen_zero(ch->bc->cad)) {
+		chan_misdn_log(2, ch->bc->port, " --> empty cad using dad\n");
+		ast_copy_string(ch->bc->cad, ch->bc->dad, sizeof(ch->bc->cad));
+	}
+
+	statemachine_run(ch->sm, AEVENT_ANSWER);
 	
-	start_bc_tones(p);
+	start_bc_tones(ch);
 
 	return 0;
 }
 
-static struct ast_frame * process_ast_dsp (struct chan_list *tmp, struct ast_frame *frame)
+static struct ast_frame * process_ast_dsp (struct misdn_ch *ch, struct ast_frame *frame)
 {
 	struct ast_frame *f, *f2;
 	struct ast_channel *ast;
 	char *context,
 		 context_tmp[BUFFERSIZE];
 
-	if (tmp->trans) {
-		f2 = ast_translate(tmp->trans, frame, 0);
-		f = ast_dsp_process(tmp->ast, tmp->dsp, f2);
+	if (ch->trans) {
+		f2 = ast_translate(ch->trans, frame, 0);
+		f = ast_dsp_process(ch->ast, ch->dsp, f2);
 	} else {
-		chan_misdn_log(0, tmp->bc->port, "No T-Path found\n");
+		chan_misdn_log(0, ch->bc->port, "No T-Path found\n");
 		return NULL;
 	}
 
@@ -3248,23 +3242,23 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c\n", f->subclass);
 
-	if (tmp->faxdetect && (f->subclass == 'f')) {
+	if (ch->faxdetect && (f->subclass == 'f')) {
 		/* Fax tone -- Handle and return NULL */
-		if (!tmp->faxhandled) {
-			ast = tmp->ast;
-			tmp->faxhandled++;
-			chan_misdn_log(0, tmp->bc->port, "Fax detected, preparing %s for fax transfer.\n", ast->name);
-			tmp->bc->rxgain = 0;
-			isdn_lib_update_rxgain(tmp->bc);
-			tmp->bc->txgain = 0;
-			isdn_lib_update_txgain(tmp->bc);
-			tmp->bc->ec_enable = 0;
-			isdn_lib_update_ec(tmp->bc);
-			isdn_lib_stop_dtmf(tmp->bc);
-			switch (tmp->faxdetect) {
+		if (!ch->faxhandled) {
+			ast = ch->ast;
+			ch->faxhandled++;
+			chan_misdn_log(0, ch->bc->port, "Fax detected, preparing %s for fax transfer.\n", ast->name);
+			ch->bc->rxgain = 0;
+			isdn_lib_update_rxgain(ch->bc);
+			ch->bc->txgain = 0;
+			isdn_lib_update_txgain(ch->bc);
+			ch->bc->ec_enable = 0;
+			isdn_lib_update_ec(ch->bc);
+			isdn_lib_stop_dtmf(ch->bc);
+			switch (ch->faxdetect) {
 			case 1:
 				if (strcmp(ast->exten, "fax")) {
-					cm_get(misdn_cm, context_tmp, sizeof(context_tmp), PORT, MCFG_FAXDETECT_TIMEOUT, tmp->bc->port);
+					cm_get(misdn_cm, context_tmp, sizeof(context_tmp), PORT, MCFG_FAXDETECT_TIMEOUT, ch->bc->port);
 					context = ast_strlen_zero(context_tmp) ? (ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext) : context_tmp;
 					if (ast_exists_extension(ast, context, "fax", 1, AST_CID_P(ast))) {
 						if (option_verbose > 2)
@@ -3286,15 +3280,15 @@
 			ast_log(LOG_DEBUG, "Fax already handled\n");
 	}
 
-	if (tmp->ast_dsp && (f->subclass != 'f'))
-		chan_misdn_log(2, tmp->bc->port, " --> * SEND: DTMF (AST_DSP) :%c\n", f->subclass);
+	if (ch->ast_dsp && (f->subclass != 'f'))
+		chan_misdn_log(2, ch->bc->port, " --> * SEND: DTMF (AST_DSP) :%c\n", f->subclass);
 
 	return frame;
 }
 
 static struct ast_frame * misdn_read (struct ast_channel *ast)
 {
-	struct chan_list *tmp;
+	struct misdn_ch *ch;
 	struct timeval tv_now;
 	int diff, len;
 
@@ -3302,59 +3296,59 @@
 		chan_misdn_log(2, 0, "misdn_read called without ast\n");
 		return NULL;
 	}
-	if (!(tmp = MISDN_ASTERISK_TECH_PVT(ast))) {
+	if (!(ch = MISDN_ASTERISK_TECH_PVT(ast))) {
 		chan_misdn_log(2, 0, "misdn_read called without ast->pvt\n");
 		return NULL;
 	}
-	if (!tmp->bc) {
+	if (!ch->bc) {
 		chan_misdn_log(2, 0, "misdn_read called without bc\n");
 		return NULL;
 	}
 
-	len = read(tmp->pipe[0], tmp->ast_rd_buf, sizeof(tmp->ast_rd_buf));
+	len = read(ch->pipe[0], ch->ast_rd_buf, sizeof(ch->ast_rd_buf));
 	if (len <= 0) {
 		/* we hangup here, since our pipe is closed */
-		chan_misdn_log(2, tmp->bc->port, "misdn_read: Pipe closed, hanging up\n");
+		chan_misdn_log(2, ch->bc->port, "misdn_read: Pipe closed, hanging up\n");
 		return NULL;
 	}
 
-	tmp->frame.frametype = AST_FRAME_VOICE;
-	tmp->frame.subclass = AST_FORMAT_ALAW;
-	tmp->frame.datalen = len;
-	tmp->frame.samples = len;
-	tmp->frame.mallocd = 0;
-	tmp->frame.offset = 0;
-	tmp->frame.delivery = ast_tv(0, 0);
-	tmp->frame.src = NULL;
-	tmp->frame.data = tmp->ast_rd_buf;
-
-	if (tmp->faxdetect && !tmp->faxhandled) {
-		if (tmp->faxdetect_timeout) {
-			if (ast_tvzero(tmp->faxdetect_tv)) {
-				tmp->faxdetect_tv = ast_tvnow();
-				chan_misdn_log(2, tmp->bc->port, "faxdetect: starting detection with timeout: %ds ...\n", tmp->faxdetect_timeout);
-				return process_ast_dsp(tmp, &tmp->frame);
+	ch->frame.frametype = AST_FRAME_VOICE;
+	ch->frame.subclass = AST_FORMAT_ALAW;
+	ch->frame.datalen = len;
+	ch->frame.samples = len;
+	ch->frame.mallocd = 0;
+	ch->frame.offset = 0;
+	ch->frame.delivery = ast_tv(0, 0);
+	ch->frame.src = NULL;
+	ch->frame.data = ch->ast_rd_buf;
+
+	if (ch->faxdetect && !ch->faxhandled) {
+		if (ch->faxdetect_timeout) {
+			if (ast_tvzero(ch->faxdetect_tv)) {
+				ch->faxdetect_tv = ast_tvnow();
+				chan_misdn_log(2, ch->bc->port, "faxdetect: starting detection with timeout: %ds ...\n", ch->faxdetect_timeout);
+				return process_ast_dsp(ch, &ch->frame);
 			}
 			tv_now = ast_tvnow();
-			diff = ast_tvdiff_ms(tv_now, tmp->faxdetect_tv);
-			if (diff <= (tmp->faxdetect_timeout * 1000)) {
-				chan_misdn_log(5, tmp->bc->port, "faxdetect: detecting ...\n");
-				return process_ast_dsp(tmp, &tmp->frame);
+			diff = ast_tvdiff_ms(tv_now, ch->faxdetect_tv);
+			if (diff <= (ch->faxdetect_timeout * 1000)) {
+				chan_misdn_log(5, ch->bc->port, "faxdetect: detecting ...\n");
+				return process_ast_dsp(ch, &ch->frame);
 			}
-			chan_misdn_log(2, tmp->bc->port, "faxdetect: stopping detection (time ran out) ...\n");
-			tmp->faxdetect = 0;
-			return &tmp->frame;
-		}
-		chan_misdn_log(5, tmp->bc->port, "faxdetect: detecting ... (no timeout)\n");
-		return process_ast_dsp(tmp, &tmp->frame);
+			chan_misdn_log(2, ch->bc->port, "faxdetect: stopping detection (time ran out) ...\n");
+			ch->faxdetect = 0;
+			return &ch->frame;
+		}
+		chan_misdn_log(5, ch->bc->port, "faxdetect: detecting ... (no timeout)\n");
+		return process_ast_dsp(ch, &ch->frame);
 	}
 	
-	return tmp->ast_dsp ? process_ast_dsp(tmp, &tmp->frame) : &tmp->frame;
+	return ch->ast_dsp ? process_ast_dsp(ch, &ch->frame) : &ch->frame;
 }
 
 static int misdn_write (struct ast_channel *ast, struct ast_frame *frame)
 {
-	struct chan_list *ch;
+	struct misdn_ch *ch;
 	int i = 0;
 
 	if (!ast || !(ch = MISDN_ASTERISK_TECH_PVT(ast)))
@@ -3417,7 +3411,7 @@
 
 static int misdn_indication (struct ast_channel *ast, int cond, const void *data, size_t datalen)
 {
-	struct chan_list *p;
+	struct misdn_ch *p;
 	
 	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)) || !p->bc) {
 		ast_log(LOG_WARNING, "Returned -1 in misdn_indication\n");
@@ -3524,7 +3518,7 @@
 
 static int misdn_fixup (struct ast_channel *oldast, struct ast_channel *ast)
 {
-	struct chan_list *p;
+	struct misdn_ch *p;
 
 	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)))
 		return -1;
@@ -3537,11 +3531,11 @@
 
 static int misdn_send_text (struct ast_channel *chan, const char *text)
 {
-	struct chan_list *tmp = chan->tech_pvt;
-
-	if (tmp && tmp->bc) {
-		ast_copy_string(tmp->bc->display, text, sizeof(tmp->bc->display));
-		misdn_lib_send_event(tmp->bc, EVENT_INFORMATION);
+	struct misdn_ch *ch = chan->tech_pvt;
+
+	if (ch && ch->bc) {
+		ast_copy_string(ch->bc->display, text, sizeof(ch->bc->display));
+		misdn_lib_send_event(ch->bc, EVENT_INFORMATION);
 	} else {
 		ast_log(LOG_WARNING, "No chan_list but send_text request?\n");
 		return -1;
@@ -3553,7 +3547,7 @@
 /* misdn event handler functions, called by statemachine on event */
 static struct statemachine_handle_retval handle_mevent_setup (void *p, int state, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = p;
 	struct misdn_bchannel *bc = ch->bc;
 	int i;
 
@@ -3575,7 +3569,7 @@
 
 static struct statemachine_handle_retval handle_mevent_setup_followup (void *p, int state, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = p;
 	struct misdn_bchannel *bc = ch->bc;
 	int im,
 		dad_len;
@@ -3666,7 +3660,7 @@
 
 static struct statemachine_handle_retval handle_mevent_information (void *p, int state, int event)
 {
-	struct chan_list *ch = p;
+	struct misdn_ch *ch = p;
 	struct misdn_bchannel *bc = ch->bc;
 
 	stop_indicate(ch);
@@ -3685,7 +3679,7 @@
 
 static struct statemachine_handle_retval handle_mevent_information_dtmf (void *p, int state, int event)
 {
-	struct chan_list *ch = p;

[... 276 lines stripped ...]


More information about the asterisk-commits mailing list