Asterisk Configuration File Syntax

Source: Internet
Author: User

Asterisk PBX has a set of custom configuration file formats. It reads and writes configuration files through a built-in configuration file parser (parser. After asterisk 1.2, the configuration file format has been improved, and the support for template configuration has been added. The template configuration greatly improves the flexibility and scalability of the configuration.

The configuration file is improved at the general configuration parser level. Therefore, this file introduces this feature to apply to the configuration files of each configuration block of Asterisk PBX. This document briefly introduces the format of the asterisk PBX configuration file.
Basic syntax
The basic format of the asterisk configuration file is similar to the following:

[section]label1 = value1label2 = value2
In some files (such as MGCP. conf, Zapata. conf, and agents. conf), the format is slightly different. The configuration files in these files are similar to the following:
[section]label1 = value1label2 = value2object1 => name1label3 = value3label4 = value4object2 => name2



This configuration file can be said to be the prototype of the configuration template. Simply put, the above configuration generates two configuration maps, the first object1 contains the configuration attributes (excluding label3/label4) from label1 to label2. the second object2 contains the configuration attributes from label1 to label4. In this way, the configuration looks better than the repeated two-Segment configuration, but it is not difficult to see that this configuration method is more difficult if you need to configure more configuration pairs with different attributes.

The new template-based configuration file can better support this requirement. The configuration template is equivalent to a basic class in C ++. You can use this base class to create an object or inherit this class, add base class attributes/methods and reload base class attributes/methods. To put it simply, if you need to configure ten sip users, most of these users are in the friend type, non-fixed IP Access, using GSM divc, then, you can define these attributes as a template. When you configure a user and reference this template, you do not need to define these attributes again.

The format of the template configuration file is slightly changed in the original configuration file. A template configuration file is similar to the following:

[section](options)label = value…
Obviously, the new configuration file adds an options Option parameter to the row of the original section. This option is used to define templates, reference templates, or hide templates. All defined objects can be referenced as a template.

Note: there must be no space between the section name brackets "]" And the configured parentheses.

Comment row

In the configuration file of Asterisk PBX, all rows starting with semicolon (;) are treated as comment rows. The new configuration file introduces support for multi-line comments. Multi-line comments start with semicolons and two minus signs ";-" and end with two minus signs. In addition to multi-line comments, such comments also support intra-row comments, that is, content in the same line, other than ";-" and "-;", will not be treated as comments, it is treated as normal configuration content. Users who know C language can better understand this annotation, because it has the same functions and differences with C ++'s "/" and "/**/" annotations. The comment lines in the configuration file are similar to the following:

; This is a single line comment of the asterisk configuration file, which is the whole line until the carriage return, the next line is the configuration content label = value;-this is a multi-line comment of Asterisk PBX configuration, press enter, well, like this, it doesn't matter. If there is no ending sign, asterisk config parser will always treat all the content as a comment until it appears -;; -You can also mix comments and configurations-; extern => 119,1, dial (Zap/1)
Include other configuration files

All configuration files of Asterisk PBX can contain the content of other configuration files through # include. The content of the included files will be added to the location of include in the current configuration file, for example:

#include sip.conf
The configuration file parser can also include the output content of an executable file to the current configuration file. This can be said to be a very useful improvement, because this allows the user to make some processing based on the current system situation, and then generate the corresponding configuration segment, for example, you can generate the current SIP user configuration from an XML file, or read user information from the data to generate a configuration file. To allow this new feature, you need to set the execincludes attribute in Asterisk. conf:
[options]execincludes=yes
After execincludes is enabled, you can use a method similar to the following to add an exec including:
#exec /usr/local/bin/generate-sip-config.sh
Add content to a defined section

[section]label = value[section](+)label2 = value2
In this example, the plus sign indicates that the content of the Second Configuration node with the same name is a supplement to the first node. The next configuration node can exist in another file (included through # include ). Note that the configuration item containing the plus sign is not an independent project. That is to say, its existence must depend on the previously defined node with the same name. If the node does not exist, the configuration parser of the asterisk PBX will abort an error when parsing the "+" node.

Define a template Node

[section](!)label = value
In this example, an exclamation point is added to the end of the node, indicating that this is a template node. The template Node itself does not represent a configuration that actually takes effect. The template can only be referenced by other nodes, used as a part of other nodes. The reference relationship is similar to the inheritance of C ++, And the template is similar to the virtual class in C ++.

Reference a configuration template or another configuration

[section](name[,name1])label = value
In this example, the name in the brackets is name1... Is the name of one configuration template or another configuration node. This configuration method adds the node name in the brackets to the beginning of the configuration item of the current configuration node. That is to say, the configuration items in this configuration node will include the content of name and name1, and then the configuration items under this node. This is a bit like the inheritance of objects in C ++ or other object-oriented programming languages. Similarly, this node itself can be cited (inherited) by other nodes ). For example, the following Configuration:

[foo]permit=192.168.0.2host=asdfdeny=192.168.0.1[bar]permit=192.168.1.2host=jkl deny=192.168.1.1[baz](foo,bar)permit=192.168.3.1host=bnm
In this example, node Baz references node Foo and Node Bar, and is parsed as follows:
[baz]permit=192.168.0.2host=asdfdeny=192.168.0.1permit=192.168.1.2host=jkldeny=192.168.1.1permit=192.168.3.1host=bnm
Example
Next we will give an example of the SIP configuration in Asterisk PBX, and briefly describe its function. The definitions in SIP. conf are as follows:

[defaults](!)type=friendnat=yesqualify=ondtmfmode=rfc2833disallow=allallow=alaw#include accounts/*/sip.conf



In this configuration file, a template default is defined, and the sip. conf in all subdirectories of the account directory is referenced through # include. The contents of an account/redice/sip. conf sub-directory are as follows:

[redice_tmpl](!,defaults)secret=this_is_not_secretcontext=from-redice-grpcallerid=RediceGrp <300>accountcode=0001[redice](redice_tmpl)[email protected][redice1](redice_tmpl)[email protected]



The configuration file sip. conf defines two sip phones, redice and redice1. The configuration is from the redice_tmpl template. The only difference is that different voice mailboxes are used. The redice_tmpl template contains the defaults template (defined in the SIP. conf file in the main directory.

From this example, we can see that the new asterisk PBX configuration capability is greatly enhanced, and the configuration can be written more easily and flexibly, it is easier to configure asterisk PBX through third-party software.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.