mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 16:50:14 +00:00
normalize the code to navigate through extensions and priorities
(use the walk_*() routines so we don't use the link fields directly, and slightly restructure the blocks to reduce the nesting depth). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@26723 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
29
pbx.c
29
pbx.c
@@ -945,39 +945,40 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan,
|
|||||||
q->status = STATUS_NO_EXTENSION;
|
q->status = STATUS_NO_EXTENSION;
|
||||||
|
|
||||||
/* scan the list trying to match extension and CID */
|
/* scan the list trying to match extension and CID */
|
||||||
for (eroot = tmp->root; eroot; eroot = eroot->next) {
|
eroot = NULL;
|
||||||
|
while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) {
|
||||||
int match = extension_match_core(eroot->exten, exten, action);
|
int match = extension_match_core(eroot->exten, exten, action);
|
||||||
/* 0 on fail, 1 on match, 2 on earlymatch */
|
/* 0 on fail, 1 on match, 2 on earlymatch */
|
||||||
|
|
||||||
if (match && (!eroot->matchcid || matchcid(eroot->cidmatch, callerid))) {
|
if (!match || (eroot->matchcid && matchcid(eroot->cidmatch, callerid)))
|
||||||
|
continue; /* keep trying */
|
||||||
if (match == 2 && action == E_MATCHMORE) {
|
if (match == 2 && action == E_MATCHMORE) {
|
||||||
/* We match an extension ending in '!'.
|
/* We match an extension ending in '!'.
|
||||||
* The decision in this case is final and is NULL (no match).
|
* The decision in this case is final and is NULL (no match).
|
||||||
*/
|
*/
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
}
|
||||||
|
/* found entry, now look for the right priority */
|
||||||
if (q->status < STATUS_NO_PRIORITY)
|
if (q->status < STATUS_NO_PRIORITY)
|
||||||
q->status = STATUS_NO_PRIORITY;
|
q->status = STATUS_NO_PRIORITY;
|
||||||
/* now look for the right priority */
|
e = NULL;
|
||||||
for (e = eroot; e; e = e->peer) {
|
while ( (e = ast_walk_extension_priorities(eroot, e)) ) {
|
||||||
/* Match priority */
|
/* Match label or priority */
|
||||||
if (action == E_FINDLABEL) {
|
if (action == E_FINDLABEL) {
|
||||||
if (q->status < STATUS_NO_LABEL)
|
if (q->status < STATUS_NO_LABEL)
|
||||||
q->status = STATUS_NO_LABEL;
|
q->status = STATUS_NO_LABEL;
|
||||||
if (label && e->label && !strcmp(label, e->label)) {
|
if (label && e->label && !strcmp(label, e->label))
|
||||||
q->status = STATUS_SUCCESS;
|
break; /* found it */
|
||||||
q->foundcontext = context;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
} else if (e->priority == priority) {
|
} else if (e->priority == priority) {
|
||||||
|
break; /* found it */
|
||||||
|
} /* else keep searching */
|
||||||
|
}
|
||||||
|
if (e) { /* found a valid match */
|
||||||
q->status = STATUS_SUCCESS;
|
q->status = STATUS_SUCCESS;
|
||||||
q->foundcontext = context;
|
q->foundcontext = context;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Check alternative switches */
|
/* Check alternative switches */
|
||||||
AST_LIST_TRAVERSE(&tmp->alts, sw, list) {
|
AST_LIST_TRAVERSE(&tmp->alts, sw, list) {
|
||||||
struct ast_switch *asw = pbx_findswitch(sw->name);
|
struct ast_switch *asw = pbx_findswitch(sw->name);
|
||||||
|
|||||||
Reference in New Issue
Block a user