From 0fdee4f59cb1e46bf5a1057800c84cff8353f3d6 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Thu, 29 Sep 2005 17:40:24 +0000 Subject: code cleanups git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6696 f38db490-d61c-443f-a65b-d21fe96a405b --- channel.c | 70 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'channel.c') diff --git a/channel.c b/channel.c index 12b423ba9..9296ed10d 100755 --- a/channel.c +++ b/channel.c @@ -2203,7 +2203,7 @@ struct ast_channel *ast_request_and_dial(const char *type, int format, void *dat 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 @@ struct ast_channel *ast_request(const char *type, int format, void *data, int *c 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 : "", c->cid.cid_name ? c->cid.cid_name : "",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 : "", + c->cid.cid_name ? c->cid.cid_name : "", + 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) -- cgit v1.2.3