[Asterisk-cvs] asterisk channel.c,1.242,1.243 frame.c,1.63,1.64

kpfleming kpfleming
Thu Sep 29 13:43:51 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv14109

Modified Files:
	channel.c frame.c 
Log Message:
code cleanups


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.242
retrieving revision 1.243
diff -u -d -r1.242 -r1.243
--- channel.c	15 Sep 2005 16:34:39 -0000	1.242
+++ channel.c	29 Sep 2005 17:40:24 -0000	1.243
@@ -2203,7 +2203,7 @@
 struct ast_channel *ast_request(const char *type, int format, void *data, int *cause)
 {
 	struct chanlist *chan;
-	struct ast_channel *c = NULL;
+	struct ast_channel *c;
 	int capabilities;
 	int fmt;
 	int res;
@@ -2212,45 +2212,51 @@
 	if (!cause)
 		cause = &foo;
 	*cause = AST_CAUSE_NOTDEFINED;
+
 	if (ast_mutex_lock(&chlock)) {
 		ast_log(LOG_WARNING, "Unable to lock channel list\n");
 		return NULL;
 	}
-	chan = backends;
-	while(chan) {
-		if (!strcasecmp(type, chan->tech->type)) {
-			capabilities = chan->tech->capabilities;
-			fmt = format;
-			res = ast_translator_best_choice(&fmt, &capabilities);
-			if (res < 0) {
-				ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
-				ast_mutex_unlock(&chlock);
-				return NULL;
-			}
+
+	for (chan = backends; chan; chan = chan->next) {
+		if (strcasecmp(type, chan->tech->type))
+			continue;
+
+		capabilities = chan->tech->capabilities;
+		fmt = format;
+		res = ast_translator_best_choice(&fmt, &capabilities);
+		if (res < 0) {
+			ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
 			ast_mutex_unlock(&chlock);
-			if (chan->tech->requester)
-				c = chan->tech->requester(type, capabilities, data, cause);
-			if (c) {
-				if (c->_state == AST_STATE_DOWN) {
-					manager_event(EVENT_FLAG_CALL, "Newchannel",
-					"Channel: %s\r\n"
-					"State: %s\r\n"
-					"CallerID: %s\r\n"
-					"CallerIDName: %s\r\n"
-					"Uniqueid: %s\r\n",
-					c->name, ast_state2str(c->_state), c->cid.cid_num ? c->cid.cid_num : "<unknown>", c->cid.cid_name ? c->cid.cid_name : "<unknown>",c->uniqueid);
-				}
-			}
-			return c;
+			return NULL;
 		}
-		chan = chan->next;
-	}
-	if (!chan) {
-		ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
-		*cause = AST_CAUSE_NOSUCHDRIVER;
+		ast_mutex_unlock(&chlock);
+		if (!chan->tech->requester)
+			return NULL;
+		
+		if (!(c = chan->tech->requester(type, capabilities, data, cause)))
+			return NULL;
+
+		if (c->_state == AST_STATE_DOWN) {
+			manager_event(EVENT_FLAG_CALL, "Newchannel",
+				      "Channel: %s\r\n"
+				      "State: %s\r\n"
+				      "CallerID: %s\r\n"
+				      "CallerIDName: %s\r\n"
+				      "Uniqueid: %s\r\n",
+				      c->name, ast_state2str(c->_state),
+				      c->cid.cid_num ? c->cid.cid_num : "<unknown>",
+				      c->cid.cid_name ? c->cid.cid_name : "<unknown>",
+				      c->uniqueid);
+		}
+		return c;
 	}
+
+	ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
+	*cause = AST_CAUSE_NOSUCHDRIVER;
 	ast_mutex_unlock(&chlock);
-	return c;
+
+	return NULL;
 }
 
 int ast_call(struct ast_channel *chan, char *addr, int timeout) 

Index: frame.c
===================================================================
RCS file: /usr/cvsroot/asterisk/frame.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- frame.c	14 Sep 2005 20:46:49 -0000	1.63
+++ frame.c	29 Sep 2005 17:40:24 -0000	1.64
@@ -1001,36 +1001,36 @@
    	return find_best ? ast_best_codec(formats) : 0;
 }
 
-void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, char *list, int allowing) 
+void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, const char *list, int allowing) 
 {
-	int format_i = 0;
-	char *next_format = NULL, *last_format = NULL;
+	char *parse;
+	char *this;
+	int format;
 
-	last_format = ast_strdupa(list);
-	while(last_format) {
-		if((next_format = strchr(last_format, ','))) {
-			*next_format = '\0';
-			next_format++;
+	parse = ast_strdupa(list);
+	while ((this = strsep(&parse, ","))) {
+		if (!(format = ast_getformatbyname(this))) {
+			ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
+			continue;
 		}
-		if ((format_i = ast_getformatbyname(last_format)) > 0) {
-			if (mask) {
+
+		if (mask) {
+			if (allowing)
+				*mask |= format;
+			else
+				*mask &= ~format;
+		}
+
+		if (pref) {
+			if (strcasecmp(this, "all")) {
 				if (allowing)
-					(*mask) |= format_i;
+					ast_codec_pref_append(pref, format);
 				else
-					(*mask) &= ~format_i;
+					ast_codec_pref_remove(pref, format);
+			} else if (!allowing) {
+				memset(pref, 0, sizeof(*pref));
 			}
-			/* can't consider 'all' a prefered codec*/
-			if(pref && strcasecmp(last_format, "all")) {
-				if(allowing)
-					ast_codec_pref_append(pref, format_i);
-				else
-					ast_codec_pref_remove(pref, format_i);
-			} else if(!allowing) /* disallow all must clear your prefs or it makes no sense */
-				memset(pref, 0, sizeof(struct ast_codec_pref));
-		} else
-			ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", last_format);
-
-		last_format = next_format;
+		}
 	}
 }
 




More information about the svn-commits mailing list