[svn-commits] mmichelson: branch group/CCSS r235568 - /team/group/CCSS/channels/chan_dahdi.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 18 13:22:43 CST 2009


Author: mmichelson
Date: Fri Dec 18 13:22:41 2009
New Revision: 235568

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235568
Log:
Separate the logic for naming DAHDI channels to its own function.


Modified:
    team/group/CCSS/channels/chan_dahdi.c

Modified: team/group/CCSS/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_dahdi.c?view=diff&rev=235568&r1=235567&r2=235568
==============================================================================
--- team/group/CCSS/channels/chan_dahdi.c (original)
+++ team/group/CCSS/channels/chan_dahdi.c Fri Dec 18 13:22:41 2009
@@ -8572,47 +8572,40 @@
 	ast_mutex_unlock(&p->lock);
 	return res;
 }
-
-static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, int transfercapability, const char *linkedid)
-{
-	struct ast_channel *tmp;
-	format_t deflaw;
-	int res;
-	int x,y;
-	int features;
+#ifdef HAVE_PRI
+static struct ast_str *create_channel_name(struct dahdi_pvt *i, const char * const dnid, struct dahdi_pri *pri)
+#else
+static struct ast_str *create_channel_name(struct dahdi_pvt *i)
+#endif
+{
 	struct ast_str *chan_name;
-	struct ast_variable *v;
-	struct dahdi_params ps;
-
-	if (i->subs[idx].owner) {
-		ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[idx]);
+	int x, y;
+	/* Create the new channel name tail. */
+	if (!(chan_name = ast_str_create(32))) {
 		return NULL;
 	}
-
-	/* Create the new channel name tail. */
-	chan_name = ast_str_alloca(32);
 	if (i->channel == CHAN_PSEUDO) {
 		ast_str_set(&chan_name, 0, "pseudo-%ld", ast_random());
 #if defined(HAVE_PRI)
-	} else if (i->pri) {
-		ast_mutex_lock(&i->pri->lock);
-		y = ++i->pri->new_chan_seq;
+	} else if (pri) {
+		ast_mutex_lock(&pri->lock);
+		y = ++pri->new_chan_seq;
 		if (i->outgoing) {
 			/*
 			 * The dnid has been stuffed with the called-number[:subaddress]
 			 * by dahdi_request().
 			 */
-			ast_str_set(&chan_name, 0, "i%d/%s-%x", i->pri->span, i->dnid, y);
+			ast_str_set(&chan_name, 0, "i%d/%s-%x", pri->span, dnid, y);
 			i->dnid[0] = '\0';
 		} else if (ast_strlen_zero(i->cid_subaddr)) {
 			/* Put in caller-id number only since there is no subaddress. */
-			ast_str_set(&chan_name, 0, "i%d/%s-%x", i->pri->span, i->cid_num, y);
+			ast_str_set(&chan_name, 0, "i%d/%s-%x", pri->span, i->cid_num, y);
 		} else {
 			/* Put in caller-id number and subaddress. */
-			ast_str_set(&chan_name, 0, "i%d/%s:%s-%x", i->pri->span, i->cid_num,
+			ast_str_set(&chan_name, 0, "i%d/%s:%s-%x", pri->span, i->cid_num,
 				i->cid_subaddr, y);
 		}
-		ast_mutex_unlock(&i->pri->lock);
+		ast_mutex_unlock(&pri->lock);
 #endif	/* defined(HAVE_PRI) */
 	} else {
 		y = 1;
@@ -8626,6 +8619,34 @@
 			}
 			++y;
 		} while (x < 3);
+	}
+	return chan_name;
+}
+
+static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, int transfercapability, const char *linkedid)
+{
+	struct ast_channel *tmp;
+	format_t deflaw;
+	int res;
+	int x;
+	int features;
+	struct ast_str *chan_name;
+	struct ast_variable *v;
+	struct dahdi_params ps;
+
+	if (i->subs[idx].owner) {
+		ast_log(LOG_WARNING, "Channel %d already has a %s call\n", i->channel,subnames[idx]);
+		return NULL;
+	}
+
+#ifdef HAVE_PRI
+	chan_name = create_channel_name(i, i->dnid, i->pri);
+#else
+	chan_name = create_channel_name(i);
+#endif
+
+	if (!chan_name) {
+		return NULL;
 	}
 
 	tmp = ast_channel_alloc(0, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "DAHDI/%s", ast_str_buffer(chan_name));




More information about the svn-commits mailing list