Blockquote
As per the documentation “The order of matching within a context is always exact extensions, pattern match extensions, includes, and switches.”. My dialplan looks like this:
[context_one]
include => context_two
Exten => _X.,1,Dial(DAHDI/${EXTEN})
[context_two]
Exten => _300X.,1,Noop()
same => n, PlayBack(beep)
same => n, Hangup()
Exten => _440X.,1,Noop()
same => n, PlayBack(you-dialed-wrong)
same => n, Hangup()
Dialing 30000 or 4400 will never work since the priority is Exact, pattern and only then include. Is there any way around this? Could I do this with a GoSub or some other way? I am trying to block calls where people try to call a country but add an invalid 0. One option that comes to mind is a very long regexp match but it will have 200+ conditions to check and that would be rather messy not to mention may not work because of the length of the line.
[context_two]
Exten => _300X.,1,Noop()
same => n, PlayBack(beep)
same => n, Hangup()
Exten => _440X.,1,Noop()
same => n, PlayBack(you-dialed-wrong)
same => n, Hangup()
[context_one](context_two)
Exten => _X.,1,Dial(DAHDI/${EXTEN})
The simplest thing I think is simply move the catch all (_X., which by the way, is probably not what you want, but _X! instead), into an include, putting it on an equal basis with the others.
The other patterns should then match before that one does.
Another approach is to have a context containing pattern matches of blocked destinations, can you use DIALPLAN_EXISTS or EVAL_EXTEN to check for existence of a pattern before proceeding.
But yeah, sometimes things are clunky. For example, there’s no elegant way to pattern match toll free numbers in the NANPA, either.
I’m talking about routing here, independent of the technology.
_X. detects more than 1 digit, while _X! detects 1 or more digits. For that reason, _X. is rarely ever correct in practice. It won’t match the extension “0”, for instance.
For that matter, _X! is often not correct either, a “complete match” would be _[0-9A-D*#]!
! terminates the match quickly, and is much more than the difference between [0-9]* and [0-9]+ in standard regular expression notation.
The documentation is a bit confusing, and I haven’t deciphered the code in detail, but in a situation where digits arrive one by one, _X! will declare end of number according to one of the following interpretations:
immediately on receiving one digit; or
immediately on receiving a digit that isn’t compatible with a more specific pattern.
As I said, I’m ignoring cases where digits are arriving one by one. That’s a whole another can of worms.
I’m referring to cases where you already have a full extension and are routing it around the dialplan.
If you sent a call to a context with a _X. pattern match, 99% of the time that is simply wrong, taking the trivial example that the 0 extension will not match here.
Even in the case you’re referring to, _X. will still terminate after getting 2 or more digits so if digits are arriving one by one, such as with simple switch or WaitExten, it is still likely the wrong pattern.
Just my observation that I have pretty much never seen anyone use this pattern correctly, only people try to use it as a catch all when they meant to use _X!, or something even more robust, instead. Newbies make this mistake a lot.
The _X. pattern has a built in wait for more digits before it matches while _X! has no such wait. Another way to say it is that _X. is greedy and _X! is not greedy.