aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-11 08:00:35 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-11 08:00:35 +0000
commitd0d0c79cb4797a40017ba2cb4205e4b4741976e7 (patch)
tree6b5c6c581420690a8ce4779430069b2807cc1428 /pbx.c
parent01c2f6e42d5aaefd183f5ebfef833cecba1afdc9 (diff)
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: http://svn.digium.com/svn/asterisk/trunk@26723 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rw-r--r--pbx.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/pbx.c b/pbx.c
index b458e1742..12229a7b1 100644
--- a/pbx.c
+++ b/pbx.c
@@ -945,37 +945,38 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan,
q->status = STATUS_NO_EXTENSION;
/* 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);
/* 0 on fail, 1 on match, 2 on earlymatch */
- if (match && (!eroot->matchcid || matchcid(eroot->cidmatch, callerid))) {
- if (match == 2 && action == E_MATCHMORE) {
- /* We match an extension ending in '!'.
- * The decision in this case is final and is NULL (no match).
- */
- return NULL;
- } else {
- if (q->status < STATUS_NO_PRIORITY)
- q->status = STATUS_NO_PRIORITY;
- /* now look for the right priority */
- for (e = eroot; e; e = e->peer) {
- /* Match priority */
- if (action == E_FINDLABEL) {
- if (q->status < STATUS_NO_LABEL)
- q->status = STATUS_NO_LABEL;
- if (label && e->label && !strcmp(label, e->label)) {
- q->status = STATUS_SUCCESS;
- q->foundcontext = context;
- return e;
- }
- } else if (e->priority == priority) {
- q->status = STATUS_SUCCESS;
- q->foundcontext = context;
- return e;
- }
- }
- }
+ if (!match || (eroot->matchcid && matchcid(eroot->cidmatch, callerid)))
+ continue; /* keep trying */
+ if (match == 2 && action == E_MATCHMORE) {
+ /* We match an extension ending in '!'.
+ * The decision in this case is final and is NULL (no match).
+ */
+ return NULL;
+ }
+ /* found entry, now look for the right priority */
+ if (q->status < STATUS_NO_PRIORITY)
+ q->status = STATUS_NO_PRIORITY;
+ e = NULL;
+ while ( (e = ast_walk_extension_priorities(eroot, e)) ) {
+ /* Match label or priority */
+ if (action == E_FINDLABEL) {
+ if (q->status < STATUS_NO_LABEL)
+ q->status = STATUS_NO_LABEL;
+ if (label && e->label && !strcmp(label, e->label))
+ break; /* found it */
+ } else if (e->priority == priority) {
+ break; /* found it */
+ } /* else keep searching */
+ }
+ if (e) { /* found a valid match */
+ q->status = STATUS_SUCCESS;
+ q->foundcontext = context;
+ return e;
}
}
/* Check alternative switches */