[asterisk-dev] extensions.conf included contexts priorities
Jared Smith
jaredsmith at jaredsmith.net
Tue Apr 24 09:36:08 MST 2007
On 4/24/07, Andrew Kohlsmith <akohlsmith-asterisk at benshaw.com> wrote:
> I've been using Asterisk for several years now, and I've run across something
> I am *positive* is unintended. Testing against trunk and 1.4, the result is
> the same, so it's something which has been going on for a long long time
> now...
Actually, I think this *is* intentend. As I understand it, here's how
the extension matching works in Asterisk. First, Asterisk tries to
find a match in the current context. If it finds no match, it then
looks for any switch statements to see if it can find a match there.
If there is no match there, it then looks at any include statements.
It should also be noted that for nested includes, Asterisk does a
depth-first search through the includes.
As an example, lets modify your earlier example to look like this:
[bar]
exten => 555,1,NoOp(exten 555, bar context)
exten => _XXX,1,NoOp(wildcard match ${EXTEN}, bar context)
include => baz-1
[foo]
exten => 123,1,NoOp(exten 123, foo context)
exten => 456,1,NoOp(exten 456, foo context)
include => bar
include => baz-2
switch => IAX2/user:pass at otherbox/
exten => 789,1,NoOp(exten 789, foo context)
exten => _5XX,1,NoOp(wildcard match ${EXTEN}, foo context)
[baz-1]
exten => 555,1,NoOp(exten 555, baz-1 context)
exten => 333,1,NoOp(exten 333, baz-1 context)
[baz-2]
exten => 555,1,NoOp(exten 555, baz-2 context)
exten => 333,1,NoOp(exten 333, baz-2 context)
If extenion 555 was dialed in the [foo] context, it would match on the
wildcard in that context. If extension 333 was dialed, it would match
the extension in the [baz-1] context. In other words, Asterisk would
go looking in this order:
1) the [foo] context itself
2) The remote box named otherbox, thanks to the switch statement
3) The first included context ([bar] in this case)
4) Any includes in the [bar] context (which happens to be [baz-1]
and, if it didn't find a match there:
5) the next included context in the [foo] context (which happens to be [baz-2])
In short, we can sum it all up like this: Asterisk checks all
extensions before switches, and all switches before includes. I hope
that clears things up for you. (If I've made a mistake in my
explanation, please let me know.)
-Jared
More information about the asterisk-dev
mailing list