[asterisk-commits] rmudgett: branch group/CCSS r237698 - /team/group/CCSS/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 5 11:15:14 CST 2010


Author: rmudgett
Date: Tue Jan  5 11:15:13 2010
New Revision: 237698

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=237698
Log:
Ensure analog ports will work for CCSS when ISDN is also present.

*  Fix downcast error in dahdi_cc_callback() when ISDN is available.  The
p->sig_pvt pointer cannot be dereferenced unless you know what signaling
structrue it is pointing toward.
*  Make create_channel_name() work better with ISDN.
*  Minimized cumulative CCSS changes to chan_dahdi.c so far.

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=237698&r1=237697&r2=237698
==============================================================================
--- team/group/CCSS/channels/chan_dahdi.c (original)
+++ team/group/CCSS/channels/chan_dahdi.c Tue Jan  5 11:15:13 2010
@@ -8584,14 +8584,16 @@
 	ast_mutex_unlock(&p->lock);
 	return res;
 }
-#ifdef HAVE_PRI
-static struct ast_str *create_channel_name(struct dahdi_pvt *i, char *address, struct sig_pri_pri *pri)
+
+#if defined(HAVE_PRI)
+static struct ast_str *create_channel_name(struct dahdi_pvt *i, int is_outgoing, char *address)
 #else
 static struct ast_str *create_channel_name(struct dahdi_pvt *i)
-#endif
+#endif	/* defined(HAVE_PRI) */
 {
 	struct ast_str *chan_name;
 	int x, y;
+
 	/* Create the new channel name tail. */
 	if (!(chan_name = ast_str_create(32))) {
 		return NULL;
@@ -8599,21 +8601,21 @@
 	if (i->channel == CHAN_PSEUDO) {
 		ast_str_set(&chan_name, 0, "pseudo-%ld", ast_random());
 #if defined(HAVE_PRI)
-	} else if (pri) {
-		ast_mutex_lock(&pri->lock);
-		y = ++pri->new_chan_seq;
-		if (i->outgoing) {
-			ast_str_set(&chan_name, 0, "i%d/%s-%x", pri->span, address, y);
+	} else if (i->pri) {
+		ast_mutex_lock(&i->pri->lock);
+		y = ++i->pri->new_chan_seq;
+		if (is_outgoing) {
+			ast_str_set(&chan_name, 0, "i%d/%s-%x", i->pri->span, address, y);
 			address[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", pri->span, i->cid_num, y);
+			ast_str_set(&chan_name, 0, "i%d/%s-%x", i->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", pri->span, i->cid_num,
+			ast_str_set(&chan_name, 0, "i%d/%s:%s-%x", i->pri->span, i->cid_num,
 				i->cid_subaddr, y);
 		}
-		ast_mutex_unlock(&pri->lock);
+		ast_mutex_unlock(&i->pri->lock);
 #endif	/* defined(HAVE_PRI) */
 	} else {
 		y = 1;
@@ -8647,16 +8649,15 @@
 		return NULL;
 	}
 
-#ifdef HAVE_PRI
+#if defined(HAVE_PRI)
 	/*
 	 * The dnid has been stuffed with the called-number[:subaddress]
-	 * by dahdi_request().
+	 * by dahdi_request() for outgoing calls.
 	 */
-	chan_name = create_channel_name(i, i->dnid, i->pri);
+	chan_name = create_channel_name(i, i->outgoing, i->dnid);
 #else
 	chan_name = create_channel_name(i);
-#endif
-
+#endif	/* defined(HAVE_PRI) */
 	if (!chan_name) {
 		return NULL;
 	}
@@ -11879,7 +11880,27 @@
 	return tmp;
 }
 
-static inline int available(struct dahdi_pvt *p, int channelmatch, ast_group_t groupmatch, int *reason, int *channelmatched, int *groupmatched)
+static int is_group_or_channel_match(struct dahdi_pvt *p, ast_group_t groupmatch, int *groupmatched, int channelmatch, int *channelmatched)
+{
+	/* First, check group matching */
+	if (groupmatch) {
+		if ((p->group & groupmatch) != groupmatch)
+			/* Doesn't match the specified group, try the next one */
+			return 0;
+		*groupmatched = 1;
+	}
+	/* Check to see if we have a channel match */
+	if (channelmatch != -1) {
+		if (p->channel != channelmatch)
+			/* Doesn't match the specified channel, try the next one */
+			return 0;
+		*channelmatched = 1;
+	}
+
+	return 1;
+}
+
+static int available(struct dahdi_pvt *p, int channelmatch, ast_group_t groupmatch, int *reason, int *channelmatched, int *groupmatched)
 {
 
 	if (p->inalarm)
@@ -12168,25 +12189,6 @@
 	return p;
 }
 
-static int is_group_or_channel_match(struct dahdi_pvt *p, ast_group_t groupmatch, int *groupmatched, int channelmatch, int *channelmatched)
-{
-	if (groupmatch) {
-		if ((p->group & groupmatch) != groupmatch)
-			/* Doesn't match the specified group, try the next one */
-			return 0;
-		*groupmatched = 1;
-	}
-	/* Check to see if we have a channel match */
-	if (channelmatch != -1) {
-		if (p->channel != channelmatch)
-			/* Doesn't match the specified channel, try the next one */
-			return 0;
-		*channelmatched = 1;
-	}
-
-	return 1;
-}
-
 static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
 {
 	ast_group_t groupmatch = 0;
@@ -12215,12 +12217,8 @@
 #if 0
 		ast_verbose("name = %s, %d, %d, %llu\n",p->owner ? p->owner->name : "<none>", p->channel, channelmatch, groupmatch);
 #endif
-		/* First, check group matching */
-		if (!is_group_or_channel_match(p, groupmatch, &groupmatched, channelmatch, &channelmatched)) {
-			goto next;
-		}
-		
-		if (p && available(p, channelmatch, groupmatch, &unavailreason, &channelmatched, &groupmatched)) {
+		if (is_group_or_channel_match(p, groupmatch, &groupmatched, channelmatch, &channelmatched)
+			&& available(p, channelmatch, groupmatch, &unavailreason, &channelmatched, &groupmatched)) {
 			ast_debug(1, "Using channel %d\n", p->channel);
 
 			callwait = (p->owner != NULL);
@@ -12284,7 +12282,9 @@
 				tmp->cdrflags |= AST_CDR_CALLWAIT;
 			break;
 		}
+#ifdef HAVE_OPENR2
 next:
+#endif
 		if (backwards) {
 			p = p->prev;
 			if (!p)
@@ -12327,25 +12327,27 @@
 	int backwards = 0;
 	int roundrobin = 0;
 	int rr_starting_point = 0;
+
 	p = determine_starting_point((char *)dest, &groupmatch, &channelmatch, &backwards, &roundrobin, &rr_starting_point);
 	exitpvt = p;
-	for(;;) {
+	for (;;) {
 		if (is_group_or_channel_match(p, groupmatch, &groupmatched, channelmatch, &channelmatched)) {
 			/* We found a potential match. call the callback */
 			struct ast_str *interface_name;
 			char dialstring[AST_CHANNEL_NAME];
 			char full_interface_name[AST_CHANNEL_NAME];
-#ifdef HAVE_PRI
+#if defined(HAVE_PRI)
 			char address[AST_CHANNEL_NAME];
 
-			sig_pri_extract_called_num_subaddr(p->sig_pvt, dest, address, sizeof(address));
-			/* XXX I have no idea how chan_dahdi works and I have no idea where to get the
-			 * proper "pri" argument for create_channel_name in this case
-			 */
-			interface_name = create_channel_name(p, address, NULL);
+			if (dahdi_sig_pri_lib_handles(p->sig)) {
+				sig_pri_extract_called_num_subaddr(p->sig_pvt, dest, address, sizeof(address));
+			} else {
+				address[0] = '\0';
+			}
+			interface_name = create_channel_name(p, 1, address);
 #else
 			interface_name = create_channel_name(p);
-#endif
+#endif	/* defined(HAVE_PRI) */
 			snprintf(full_interface_name, sizeof(full_interface_name) - 1, "DAHDI/%s", ast_str_buffer(interface_name));
 			snprintf(dialstring, sizeof(dialstring) - 1, "DAHDI/%s", dest);
 			callback(inbound, p->cc_params, full_interface_name, dialstring);




More information about the asterisk-commits mailing list