telephony@jonjay.com
2005-Sep-24 18:45 UTC
[Asterisk-Users] Need good explanation on contexts and extensions
Hello: My Asterisk book is on its way, so please bear with me. Based on what I have read and my actual Asterisk experiences, I am not too clear on the context-extension relationship. I am not sure if some of the error messages (Not Found) are a result of a bug or a feature. My experience so far is limited to sip.conf and extensions.conf, as I don't have a hardware board yet. First: It seems like an extension can be part of more than one context? If you have something like this: sip.conf: ------------------- [general] port = 5060 context = incoming [1234] context = internal ------------------- What's the meaning of the above? Is this like a programming language where the global variable 'context' is shadowed by the local variable with the same name? Or is the extension '1234' somehow related to both contexts ('incoming' and 'internal')? Thanks, -Ramon F Herrera
Leif Madsen
2005-Sep-24 23:34 UTC
[Asterisk-Users] Need good explanation on contexts and extensions
On 9/24/05, telephony@jonjay.com <telephony@jonjay.com> wrote:> My Asterisk book is on its way, so please bear with me. > My experience so far is limited to sip.conf and extensions.conf, as I > don't have a hardware board yet. > > First: It seems like an extension can be part of more than one context?An extension in sip.conf is associated with one context in the dialplan. A context should be thought of as a security boundary - a place with which to control calls. These calls may either be incoming or outgoing from the viewpoint of Asterisk. You have provided the following pseudo configuration:> sip.conf: > ------------------- > [general] > port = 5060 > context = incoming > > [1234] > context = internal > -------------------Here we have two sections in the sip.conf file - I like to call them defintions; they define the parameters which control call authentication and negotiation. Each sip.conf file (which is the 'channel configuration' file - there are different ones for the IAX, H.323, and MGCP channels) has a default section called [general]. Within the [general] context we define both channel and global options. Some options (such as 'port') are only defined once for the protocol. Other options such as 'context' or 'disallow' / 'allow' can be used to control the "default" for all defintions within the file. In the general section, when you define the context, think of it as a "catch all" bucket where you send calls you don't know what to do with. In this case all calls which do not authenticate (guest) are placed within the [incoming] context in extensions.conf. Within the dialplan we can perform either exact matching (exten => 1234) or pattern matching (exten => _XXXX) to perform the same option on any string which patches the "pattern". The part we match on is everything after the sip: and before the @ in the INVITE line of a SIP message (i.e. INVITE sip:1234@192.168.1.1;user=phone SIP/2.0)> What's the meaning of the above? Is this like a programming language > where the global variable 'context' is shadowed by the local variable > with the same name?In the above snippit, it means that incoming calls to the Asterisk box (which authenticate correctly) are controlled by the dialplan configured in the corresponding context - i.e. calls placed by extension 1234 (if a phone) are controlled by the dialplan logic within the [internal] context in the extensions.conf file. Basically, a phone registers to Asterisk, and when it wishes to place a call (initiated with an INVITE command), what the phone is allowed to do is controlled from within that context. The same thing applies to incoming calls from other servers - if they authenticate correctly, they are directed to a context in extensions.conf where the call is handled. You would of course use different call logic and a different context (such as pstn_incoming) - but the principle still holds.> Or is the extension '1234' somehow related to both contexts ('incoming' > and 'internal')?The extension 1234 is only related to the context configured by its definition within the sip.conf file. In this case only to the 'internal' context, and not by the 'incoming' context. -- Leif Madsen - http://www.leifmadsen.com Astricon 2005, Anaheim, CA, October 12-14 http://www.astricon.net http://www.oreilly.com/catalog/asterisk/