From 62209ede0cff66b28ae1c2746577779b4ddfb784 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" <kpfleming@digium.com> Date: Thu, 29 Sep 2005 17:40:24 +0000 Subject: [PATCH] code cleanups git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6696 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channel.c | 70 ++++++++++++++++++++++------------------ frame.c | 50 ++++++++++++++-------------- include/asterisk/frame.h | 2 +- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/channel.c b/channel.c index 12b423ba96..9296ed10d1 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 : "<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) diff --git a/frame.c b/frame.c index 428a052f2b..27afa34ce4 100755 --- a/frame.c +++ b/frame.c @@ -1001,36 +1001,36 @@ int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best) 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; - - last_format = ast_strdupa(list); - while(last_format) { - if((next_format = strchr(last_format, ','))) { - *next_format = '\0'; - next_format++; + char *parse; + char *this; + int 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 (mask) { + if (allowing) + *mask |= format; + else + *mask &= ~format; } - if ((format_i = ast_getformatbyname(last_format)) > 0) { - if (mask) { + + 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; + } } } diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h index 80af31ad57..47ec5a9842 100755 --- a/include/asterisk/frame.h +++ b/include/asterisk/frame.h @@ -399,7 +399,7 @@ extern int ast_codec_pref_append(struct ast_codec_pref *pref, int format); extern int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best); /* Parse an "allow" or "deny" line and update the mask and pref if provided */ -extern void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, char *list, int allowing); +extern void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, const char *list, int allowing); /* Dump codec preference list into a string */ extern int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size); -- GitLab