From 3bc7e211a435c49aa70ad227799bd7b0c40356a1 Mon Sep 17 00:00:00 2001 From: russell Date: Thu, 15 Mar 2007 22:25:12 +0000 Subject: Merge changes from svn/asterisk/team/russell/LaTeX_docs. * Convert most of the doc directory into a single LaTeX formatted document so that we can generate a PDF, HTML, or other formats from this information. * Add a CLI command to dump the application documentation into LaTeX format which will only be include if the configure script is run with --enable-dev-mode. * The PDF turned out to be close to 1 MB, so it is not included. However, you can simply run "make asterisk.pdf" to generate it yourself. We may include it in release tarballs or have automatically generated ones on the web site, but that has yet to be decided. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@58931 f38db490-d61c-443f-a65b-d21fe96a405b --- doc/00README.1st | 74 - doc/PEERING | 4 + doc/ael.tex | 1222 +++++++++++++ doc/ael.txt | 1260 ------------- doc/ajam.tex | 85 + doc/ajam.txt | 91 - doc/app-sms.tex | 491 ++++++ doc/app-sms.txt | 470 ----- doc/apps.txt | 10 - doc/ast_appdocs.tex | 3225 ++++++++++++++++++++++++++++++++++ doc/asterisk-conf.tex | 130 ++ doc/asterisk-conf.txt | 83 - doc/asterisk.tex | 132 ++ doc/billing.tex | 87 + doc/billing.txt | 105 -- doc/callingpres.txt | 18 - doc/cdrdriver.tex | 431 +++++ doc/cdrdriver.txt | 215 --- doc/chaniax.tex | 84 + doc/chaniax.txt | 369 ---- doc/channels.txt | 44 - doc/channelvariables.tex | 791 +++++++++ doc/channelvariables.txt | 815 --------- doc/cliprompt.tex | 30 + doc/cliprompt.txt | 29 - doc/configuration.tex | 198 +++ doc/configuration.txt | 180 -- doc/cygwin.txt | 9 - doc/dundi.tex | 22 + doc/dundi.txt | 26 - doc/enum.tex | 353 ++++ doc/enum.txt | 308 ---- doc/extconfig.txt | 91 - doc/extensions.tex | 74 + doc/extensions.txt | 58 - doc/freetds.tex | 16 + doc/freetds.txt | 18 - doc/h323.txt | 22 - doc/hardware.tex | 100 ++ doc/hardware.txt | 74 - doc/iax.txt | 67 - doc/ices.tex | 7 + doc/ices.txt | 12 - doc/imapstorage.tex | 174 ++ doc/imapstorage.txt | 202 --- doc/ip-tos.tex | 81 + doc/ip-tos.txt | 81 - doc/jitterbuffer.tex | 98 ++ doc/jitterbuffer.txt | 137 -- doc/linkedlists.txt | 98 -- doc/localchannel.tex | 49 + doc/localchannel.txt | 49 - doc/manager.tex | 250 +++ doc/manager.txt | 311 ---- doc/math.txt | 69 - doc/misdn.tex | 266 +++ doc/misdn.txt | 291 --- doc/model.txt | 15 - doc/mp3.tex | 11 + doc/mp3.txt | 13 - doc/musiconhold-fpm.txt | 8 - doc/mysql.txt | 15 - doc/odbcstorage.tex | 29 + doc/odbcstorage.txt | 30 - doc/privacy.tex | 343 ++++ doc/privacy.txt | 361 ---- doc/queuelog.tex | 96 + doc/queuelog.txt | 99 -- doc/queues-with-callback-members.tex | 531 ++++++ doc/queues-with-callback-members.txt | 524 ------ doc/radius.txt | 203 --- doc/realtime.tex | 130 ++ doc/realtime.txt | 126 -- doc/security.tex | 76 + doc/security.txt | 73 - doc/sla.pdf | Bin 68499 -> 0 bytes doc/sla.tex | 16 +- 77 files changed, 9624 insertions(+), 7161 deletions(-) delete mode 100644 doc/00README.1st create mode 100644 doc/ael.tex delete mode 100644 doc/ael.txt create mode 100644 doc/ajam.tex delete mode 100644 doc/ajam.txt create mode 100644 doc/app-sms.tex delete mode 100644 doc/app-sms.txt delete mode 100644 doc/apps.txt create mode 100644 doc/ast_appdocs.tex create mode 100644 doc/asterisk-conf.tex delete mode 100644 doc/asterisk-conf.txt create mode 100644 doc/asterisk.tex create mode 100644 doc/billing.tex delete mode 100644 doc/billing.txt delete mode 100644 doc/callingpres.txt create mode 100644 doc/cdrdriver.tex delete mode 100644 doc/cdrdriver.txt create mode 100644 doc/chaniax.tex delete mode 100644 doc/chaniax.txt delete mode 100644 doc/channels.txt create mode 100644 doc/channelvariables.tex delete mode 100644 doc/channelvariables.txt create mode 100644 doc/cliprompt.tex delete mode 100644 doc/cliprompt.txt create mode 100644 doc/configuration.tex delete mode 100644 doc/configuration.txt delete mode 100644 doc/cygwin.txt create mode 100644 doc/dundi.tex delete mode 100644 doc/dundi.txt create mode 100644 doc/enum.tex delete mode 100644 doc/enum.txt delete mode 100644 doc/extconfig.txt create mode 100644 doc/extensions.tex delete mode 100644 doc/extensions.txt create mode 100644 doc/freetds.tex delete mode 100644 doc/freetds.txt delete mode 100644 doc/h323.txt create mode 100644 doc/hardware.tex delete mode 100644 doc/hardware.txt delete mode 100644 doc/iax.txt create mode 100644 doc/ices.tex delete mode 100644 doc/ices.txt create mode 100644 doc/imapstorage.tex delete mode 100644 doc/imapstorage.txt create mode 100644 doc/ip-tos.tex delete mode 100644 doc/ip-tos.txt create mode 100644 doc/jitterbuffer.tex delete mode 100644 doc/jitterbuffer.txt delete mode 100644 doc/linkedlists.txt create mode 100644 doc/localchannel.tex delete mode 100644 doc/localchannel.txt create mode 100644 doc/manager.tex delete mode 100644 doc/manager.txt delete mode 100644 doc/math.txt create mode 100644 doc/misdn.tex delete mode 100644 doc/misdn.txt delete mode 100644 doc/model.txt create mode 100644 doc/mp3.tex delete mode 100644 doc/mp3.txt delete mode 100644 doc/musiconhold-fpm.txt delete mode 100644 doc/mysql.txt create mode 100644 doc/odbcstorage.tex delete mode 100644 doc/odbcstorage.txt create mode 100644 doc/privacy.tex delete mode 100644 doc/privacy.txt create mode 100644 doc/queuelog.tex delete mode 100644 doc/queuelog.txt create mode 100644 doc/queues-with-callback-members.tex delete mode 100644 doc/queues-with-callback-members.txt delete mode 100644 doc/radius.txt create mode 100644 doc/realtime.tex delete mode 100644 doc/realtime.txt create mode 100644 doc/security.tex delete mode 100644 doc/security.txt delete mode 100644 doc/sla.pdf (limited to 'doc') diff --git a/doc/00README.1st b/doc/00README.1st deleted file mode 100644 index c006d56a8..000000000 --- a/doc/00README.1st +++ /dev/null @@ -1,74 +0,0 @@ -Files in the /doc directory: ----------------------------- -In addition to these files, there is a lot of documentation of various -configuration options in the sample configuration files, in the /configs -directory of your source code - -Start here ----------- -security.txt IMPORTANT INFORMATION ABOUT ASTERISK SECURITY -hardware.txt Hardware supported by Asterisk - -Configuration -------------- -configuration.txt Features in the configuration parser -extensions.txt Basics about the dialplan -extconfig.txt How to use databases for configuration of Asterisk (ARA) -ip-tos.txt About the IP Type Of Service settings -realtime.txt The Asterisk Realtime Architecture - database support -freetds.txt Information about the FreeTDS support -ael.txt Information about the Asterisk Extension Language - -Misc ----- -PEERING The General Peering Agreement for Dundi -ajam.txt About the HTTP-based manager interface -app_sms.txt How to configure the SMS application -asterisk.conf.txt Documentation of various options in asterisk.conf -callingpres.txt Settings for Caller ID presentation -billing.txt Call Data Record information -cliprompt.txt How to change the Asterisk CLI prompt -dundi.txt Dundi - a discovery protocol -enum.txt Enum support in Asterisk -ices.txt Integrating ICEcast streaming in Asterisk -jitterbuffer.txt About the IAX2 jitterbuffer implementation -math.txt About the math() application -mp3.txt About MP3 support in Asterisk -musiconhold-fpm.txt Free Music On Hold music -mysql.txt About MYSQL support in Asterisk -odbcstorage.txt Voicemail storage of messages in UnixODBC -privacy.txt Privacy enhancements in Asterisk -queuelog.txt Agent and queue logging -channelvariables.txt Channel variables -cdrdrivers.txt About CDR storage in various databases (needs update) -asterisk-mib.txt SNMP mib for Asterisk (net-snmp) -digium-mib.txt SNMP mib for Asterisk (net-snmp) - -Channel drivers ---------------- -misdn.txt The mISDN channel driver for ISDN BRI cards -h323.txt How to compile and configure the H.323 channel -chaniax.txt About the IAX2 protocol support in Asterisk -localchannel.txt The local channel is a "gosub" in the dialplan - -Portability ------------ -cygwin.txt Compiling Asterisk on CygWin platforms (Windows) - -For developers --------------- -See http://www.asterisk.org/developers for more information - -manager.txt About the AMI - Asterisk Manager Interface - for third party call control and PBX management -backtrace.txt How to produce a backtrace when Asterisk crashes -CODING-GUIDELINES Guidelines for developers -channels.txt What is a channel? -externalivr.txt Documentation of the protocol used in externalivr() -linkedlists.txt How to develop linked lists in Asterisk (old) -iax.txt About the IAX protocol -apps.txt About application development -model.txt About the call model in Asterisk (old) -modules.txt How Asterisk modules work -datastores.txt About channel data stores -speechrec.txt The Generic Speech Recognition API diff --git a/doc/PEERING b/doc/PEERING index c1f0b3831..ba05ffb9c 100644 --- a/doc/PEERING +++ b/doc/PEERING @@ -1,3 +1,5 @@ +\begin{verbatim} + DIGIUM GENERAL PEERING AGREEMENT (TM) Version 1.0.0, September 2004 Copyright (C) 2004 Digium, Inc. @@ -497,3 +499,5 @@ member of the Peering System and be able to make Routes available in accordance with this GPA. DUNDi, IAX, Asterisk and GPA are trademarks of Digium, Inc. + +\end{verbatim} diff --git a/doc/ael.tex b/doc/ael.tex new file mode 100644 index 000000000..d675190cc --- /dev/null +++ b/doc/ael.tex @@ -0,0 +1,1222 @@ +\section{Introduction} + +AEL is a specialized language intended purely for +describing Asterisk dial plans. + +The current version was written by Steve Murphy, and is a rewrite of +the original version. + +This new version further extends AEL, and +provides more flexible syntax, better error messages, and some missing +functionality. + +AEL is really the merger of 4 different 'languages', or syntaxes: + +\begin{itemize} + \item The first and most obvious is the AEL syntax itself. A BNF is + provided near the end of this document. + + \item The second syntax is the Expression Syntax, which is normally + handled by Asterisk extension engine, as expressions enclosed in + \$[...]. The right hand side of assignments are wrapped in \$[ ... ] + by AEL, and so are the if and while expressions, among others. + + \item The third syntax is the Variable Reference Syntax, the stuff + enclosed in \${..} curly braces. It's a bit more involved than just + putting a variable name in there. You can include one of dozens of + 'functions', and their arguments, and there are even some string + manipulation notation in there. + + \item The last syntax that underlies AEL, and is not used + directly in AEL, is the Extension Language Syntax. The + extension language is what you see in extensions.conf, and AEL + compiles the higher level AEL language into extensions and + priorities, and passes them via function calls into + Asterisk. Embedded in this language is the Application/AGI + commands, of which one application call per step, or priority + can be made. You can think of this as a "macro assembler" + language, that AEL will compile into. +\end{itemize} + +Any programmer of AEL should be familiar with it's syntax, of course, +as well as the Expression syntax, and the Variable syntax. + + +\section{Asterisk in a Nutshell} + +Asterisk acts as a server. Devices involved in telephony, like Zapata +cards, or Voip phones, all indicate some context that should be +activated in their behalf. See the config file formats for IAX, SIP, +zapata.conf, etc. They all help describe a device, and they all +specify a context to activate when somebody picks up a phone, or a +call comes in from the phone company, or a voip phone, etc. + +\subsection{Contexts} + +Contexts are a grouping of extensions. + +Contexts can also include other contexts. Think of it as a sort of +merge operation at runtime, whereby the included context's extensions +are added to the contexts making the inclusion. + +\subsection{Extensions and priorities} + +A Context contains zero or more Extensions. There are several +predefined extensions. The "s" extension is the "start" extension, and +when a device activates a context the "s" extension is the one that is +going to be run. Other extensions are the timeout "t" extension, the +invalid response, or "i" extension, and there's a "fax" extension. For +instance, a normal call will activate the "s" extension, but an +incoming FAX call will come into the "fax" extension, if it +exists. (BTW, asterisk can tell it's a fax call by the little "beep" +that the calling fax machine emits every so many seconds.). + +Extensions contain several priorities, which are individual +instructions to perform. Some are as simple as setting a variable to a +value. Others are as complex as initiating the Voicemail application, +for instance. Priorities are executed in order. + +When the 's" extension completes, asterisk waits until the timeout for +a response. If the response matches an extension's pattern in the +context, then control is transferred to that extension. Usually the +responses are tones emitted when a user presses a button on their +phone. For instance, a context associated with a desk phone might not +have any "s" extension. It just plays a dialtone until someone starts +hitting numbers on the keypad, gather the number, find a matching +extension, and begin executing it. That extension might Dial out over +a connected telephone line for the user, and then connect the two +lines together. + +The extensions can also contain "goto" or "jump" commands to skip to +extensions in other contexts. Conditionals provide the ability to +react to different stimuli, and there you have it. + +\subsection{Macros} + +Think of a macro as a combination of a context with one nameless +extension, and a subroutine. It has arguments like a subroutine +might. A macro call can be made within an extension, and the +individual statements there are executed until it ends. At this point, +execution returns to the next statement after the macro call. Macros +can call other macros. And they work just like function calls. + +\subsection{Applications} + +Application calls, like "Dial()", or "Hangup()", or "Answer()", are +available for users to use to accomplish the work of the +dialplan. There are over 145 of them at the moment this was written, +and the list grows as new needs and wants are uncovered. Some +applications do fairly simple things, some provide amazingly complex +services. + +Hopefully, the above objects will allow you do anything you need to in +the Asterisk environment! + +\section{Getting Started} + +The AEL parser (pbx\_ael.so) is completely separate from the module +that parses extensions.conf (pbx\_config.so). To use AEL, the only +thing that has to be done is the module pbx\_ael.so must be loaded by +Asterisk. This will be done automatically if using 'autoload=yes' in +/etc/asterisk/modules.conf. When the module is loaded, it will look +for 'extensions.ael' in /etc/asterisk/. extensions.conf and +extensions.ael can be used in conjunction with +each other if that is what is desired. Some users may want to keep +extensions.conf for the features that are configured in the 'general' +section of extensions.conf. + +Reloading extensions.ael + +To reload extensions.ael, the following command can be issued at the +CLI: + + *CLI> ael reload + + +\section{Debugging} + +Right at this moment, the following commands are available, but do +nothing: + +Enable AEL contexts debug + *CLI> ael debug contexts + +Enable AEL macros debug + *CLI> ael debug macros + +Enable AEL read debug + *CLI> ael debug read + +Enable AEL tokens debug + *CLI> ael debug tokens + +Disable AEL debug messages + *CLI> ael no debug + +If things are going wrong in your dialplan, you can use the following +facilities to debug your file: + +1. The messages log in /var/log/asterisk. (from the checks done at load time). +2. the "show dialplan" command in asterisk +3. the standalone executable, "aelparse" built in the utils/ dir in the source. + + +\section{About "aelparse"} + +You can use the "aelparse" program to check your extensions.ael +file before feeding it to asterisk. Wouldn't it be nice to eliminate +most errors before giving the file to asterisk? + +aelparse is compiled in the utils directory of the asterisk release. +It isn't installed anywhere (yet). You can copy it to your favorite +spot in your PATH. + +aelparse has two optional arguments: + +\begin{itemize} + \item -d + \begin{itemize} + \item Override the normal location of the config file dir, (usually + /etc/asterisk), and use the current directory instead as the + config file dir. Aelparse will then expect to find the file + "./extensions.ael" in the current directory, and any included + files in the current directory as well. + \end{itemize} + \item -n + \begin{itemize} + \item don't show all the function calls to set priorities and contexts + within asterisk. It will just show the errors and warnings from + the parsing and semantic checking phases. + \end{itemize} +\end{itemize} + +\section{General Notes about Syntax} + +Note that the syntax and style are now a little more free-form. The +opening '{' (curly-braces) do not have to be on the same line as the +keyword that precedes them. Statements can be split across lines, as +long as tokens are not broken by doing so. More than one statement can +be included on a single line. Whatever you think is best! + +You can just as easily say, + +\begin{verbatim} +if(${x}=1) { NoOp(hello!); goto s|3; } else { NoOp(Goodbye!); goto s|12; } +\end{verbatim} + +as you can say: + +\begin{verbatim} +if(${x}=1) +{ + NoOp(hello!); + goto s|3; +} +else +{ + NoOp(Goodbye!); + goto s|12; +} +\end{verbatim} + +or: + +\begin{verbatim} +if(${x}=1) { + NoOp(hello!); + goto s|3; +} else { + NoOp(Goodbye!); + goto s|12; +} +\end{verbatim} + +or: + +\begin{verbatim} +if (${x}=1) { + NoOp(hello!); goto s|3; +} else { + NoOp(Goodbye!); goto s|12; +} +\end{verbatim} + +\section{Keywords} + +The AEL keywords are case-sensitive. If an application name and a +keyword overlap, there is probably good reason, and you should +consider replacing the application call with an AEL statement. If you +do not wish to do so, you can still use the application, by using a +capitalized letter somewhere in its name. In the Asterisk extension +language, application names are NOT case-sensitive. + +The following are keywords in the AEL language: +\begin{itemize} + \item abstract + \item context + \item macro + \item globals + \item ignorepat + \item switch + \item if + \item ifTime + \item else + \item random + \item goto + \item jump + \item return + \item break + \item continue + \item regexten + \item hint + \item for + \item while + \item case + \item pattern + \item default NOTE: the "default" keyword can be used as a context name, + for those who would like to do so. + \item catch + \item switches + \item eswitches + \item includes +\end{itemize} + + +\section{Procedural Interface and Internals} + +AEL first parses the extensions.ael file into a memory structure representing the file. +The entire file is represented by a tree of "pval" structures linked together. + +This tree is then handed to the semantic check routine. + +Then the tree is handed to the compiler. + +After that, it is freed from memory. + +A program could be written that could build a tree of pval structures, and +a pretty printing function is provided, that would dump the data to a file, +or the tree could be handed to the compiler to merge the data into the +asterisk dialplan. The modularity of the design offers several opportunities +for developers to simplify apps to generate dialplan data. + + +\subsection{AEL version 2 BNF} + +(hopefully, something close to bnf). + +First, some basic objects + +\begin{verbatim} +------------------------ + a lexical token consisting of characters matching this pattern: [-a-zA-Z0-9"_/.\<\>\*\+!$#\[\]][-a-zA-Z0-9"_/.!\*\+\<\>\{\}$#\[\]]* + + a concatenation of up to 3 s. + + all characters encountered until the character that follows the in the grammar. +------------------------- + + :== + + :== + | + + + :== + | + | + | ';' + + + :== 'context' '{' '}' + | 'context' '{' '}' + | 'context' 'default' '{' '}' + | 'context' 'default' '{' '}' + | 'abstract' 'context' '{' '}' + | 'abstract' 'context' '{' '}' + | 'abstract' 'context' 'default' '{' '}' + | 'abstract' 'context' 'default' '{' '}' + + + :== 'macro' '(' ')' '{' '}' + | 'macro' '(' ')' '{' '}' + | 'macro' '(' ')' '{' '}' + | 'macro' '(' ')' '{' '}' + + + :== 'globals' '{' '}' + | 'globals' '{' '}' + + + :== + | + + + :== '=' ';' + + + :== + | ',' + + + :== + | + + + :== + | + | + | + | + | '=' ';' + | ';' + + + :== 'ignorepat' '=>' ';' + + + :== '=>' + | 'regexten' '=>' + | 'hint' '(' ')' '=>' + | 'regexten' 'hint' '(' ')' '=>' + + + :== + | + + :== 'if' '(' ')' + + :== 'random' '(' ')' + + :== 'ifTime' '(' ':' ':' '|' '|' '|' ')' + | 'ifTime' '(' '|' '|' '|' ')' + + + :== + | + | + + :== 'switch' '(' ')' '{' + + + :== '{' '}' + | '=' ';' + | 'goto' ';' + | 'jump' ';' + | ':' + | 'for' '(' ';' ';' ')' + | 'while' '(' ')' + | '}' + | '}' + | '&' macro_call ';' + | ';' + | '=' ';' + | 'break' ';' + | 'return' ';' + | 'continue' ';' + | + | 'else' + | + | 'else' + | + | 'else' + | ';' + + :== + | '|' + | '|' '|' + | 'default' '|' '|' + | ',' + | ',' ',' + | 'default' ',' ',' + + :== + | ',' + | ',' '@' + | '@' + | ',' '@' 'default' + | '@' 'default' + + :== '(' ')' + | '(' ')' + + :== '(' + + :== ')' + | ')' + + :== + | ',' + | /* nothing */ + | ',' /* nothing */ + + :== + | + + + :== 'case' ':' + | 'default' ':' + | 'pattern' ':' + | 'case' ':' + | 'default' ':' + | 'pattern' ':' + + :== + | + + :== + | 'catch' '{' '}' + + :== 'switches' '{' '}' + | 'switches' '{' '}' + + :== 'eswitches' '{' '}' + | 'eswitches' '{' '}' + + :== ';' + | ';' + + :== ';' + | '|' ':' ':' '|' '|' '|' ';' + | '|' '|' '|' '|' ';' + | ';' + | '|' ':' ':' '|' '|' '|' ';' + | '|' '|' '|' '|' ';' + + :== + | 'default' + + :== 'includes' '{' '}' + | 'includes' '{' '}' + +\end{verbatim} + + +\section{AEL Example USAGE} + +\subsection{Comments} + +Comments begin with // and end with the end of the line. + +Comments are removed by the lexical scanner, and will not be +recognized in places where it is busy gathering expressions to wrap in +\$[] , or inside application call argument lists. The safest place to put +comments is after terminating semicolons, or on otherwise empty lines. + + +\subsection{Context} + +Contexts in AEL represent a set of extensions in the same way that +they do in extensions.conf. + +\begin{verbatim} +context default { + +} + + +A context can be declared to be "abstract", in which case, this +declaration expresses the intent of the writer, that this context will +only be included by another context, and not "stand on its own". The +current effect of this keyword is to prevent "goto " statements from +being checked. + +\begin{verbatim} +abstract context longdist { + _1NXXNXXXXXX => NoOp(generic long distance dialing actions in the US); +} +\end{verbatim} + + +\subsection{Extensions} + +To specify an extension in a context, the following syntax is used. If +more than one application is be called in an extension, they can be +listed in order inside of a block. + +\begin{verbatim} +context default { + 1234 => Playback(tt-monkeys); + 8000 => { + NoOp(one); + NoOp(two); + NoOp(three); + }; + _5XXX => NoOp(it's a pattern!); +} +\end{verbatim} + +Two optional items have been added to the AEL syntax, that allow the +specification of hints, and a keyword, regexten, that will force the +numbering of priorities to start at 2. + +The ability to make extensions match by CID is preserved in +AEL; just use '/' and the CID number in the specification. See below. + +\begin{verbatim} +context default { + + regexten _5XXX => NoOp(it's a pattern!); +} +\end{verbatim} + +\begin{verbatim} +context default { + + hint(Sip/1) _5XXX => NoOp(it's a pattern!); +} +\end{verbatim} + +\begin{verbatim} +context default { + + regexten hint(Sip/1) _5XXX => NoOp(it's a pattern!); +} +\end{verbatim} + +The regexten must come before the hint if they are both present. + +CID matching is done as with the extensions.conf file. Follow the extension +name/number with a slash (/) and the number to match against the Caller ID: + +\begin{verbatim} +context zoombo +{ + 819/7079953345 => { NoOp(hello, 3345); } +} +\end{verbatim} + +In the above, the 819/7079953345 extension will only be matched if the +CallerID is 7079953345, and the dialed number is 819. Hopefully you have +another 819 extension defined for all those who wish 819, that are not so lucky +as to have 7079953345 as their CallerID! + + +\subsection{Includes} + +Contexts can be included in other contexts. All included contexts are +listed within a single block. + +\begin{verbatim} +context default { + includes { + local; + longdistance; + international; + } +} +\end{verbatim} + +Time-limited inclusions can be specified, as in extensions.conf +format, with the fields described in the wiki page Asterisk cmd +GotoIfTime. + +\begin{verbatim} +context default { + includes { + local; + longdistance|16:00-23:59|mon-fri|*|*; + international; + } +} +\end{verbatim} + +\subsection{\#include} + +You can include other files with the \#include "filepath" construct. + +\begin{verbatim} + #include "/etc/asterisk/testfor.ael" +\end{verbatim} + +An interesting property of the \#include, is that you can use it almost +anywhere in the .ael file. It is possible to include the contents of +a file in a macro, context, or even extension. The \#include does not +have to occur at the beginning of a line. Included files can include +other files, up to 50 levels deep. If the path provided in quotes is a +relative path, the parser looks in the config file directory for the +file (usually /etc/asterisk). + + + +\subsection{Dialplan Switches} + +Switches are listed in their own block within a context. For clues as +to what these are used for, see Asterisk - dual servers, and Asterisk +config extensions.conf. + +\begin{verbatim} +context default { + switches { + DUNDi/e164; + IAX2/box5; + }; + eswitches { + IAX2/context@${CURSERVER}; + } +} +\end{verbatim} + + +\subsection{Ignorepat} + +ignorepat can be used to instruct channel drivers to not cancel +dialtone upon receipt of a particular pattern. The most commonly used +example is '9'. + +\begin{verbatim} +context outgoing { + ignorepat => 9; +} +\end{verbatim} + + +\subsection{Variables} + +Variables in Asterisk do not have a type, so to define a variable, it +just has to be specified with a value. + +Global variables are set in their own block. + +\begin{verbatim} +globals { + CONSOLE=Console/dsp; + TRUNK=Zap/g2; +} +\end{verbatim} + + +Variables can be set within extensions as well. + +\begin{verbatim} +context foo { + 555 => { + x=5; + y=blah; + divexample=10/2 + NoOp(x is ${x} and y is ${y} !); + } +} +\end{verbatim} + +NOTE: AEL wraps the right hand side of an assignment with \$[ ] to allow +expressions to be used If this is unwanted, you can protect the right hand +side from being wrapped by using the Set() application. +Read the README.variables about the requirements and behavior +of \$[ ] expressions. + +NOTE: These things are wrapped up in a \$[ ] expression: The while() test; +the if() test; the middle expression in the for( x; y; z) statement +(the y expression); Assignments - the right hand side, so a = b -> Set(a=\$[b]) + +Writing to a dialplan function is treated the same as writing to a variable. + +\begin{verbatim} +context blah { + s => { + CALLERID(name)=ChickenMan; + NoOp(My name is ${CALLERID(name)} !); + } +} +\end{verbatim} + + +\subsection{Loops} + +AEL has implementations of 'for' and 'while' loops. + +\begin{verbatim} +context loops { + 1 => { + for (x=0; ${x} < 3; x=${x} + 1) { + Verbose(x is ${x} !); + } + } + 2 => { + y=10; + while (${y} >= 0) { + Verbose(y is ${y} !); + y=${y}-1; + } + } +} +\end{verbatim} + +NOTE: The conditional expression (the "\${y} >= 0" above) is wrapped in + \$[ ] so it can be evaluated. NOTE: The for loop test expression + (the "\${x} < 3" above) is wrapped in \$[ ] so it can be evaluated. + + + +\subsection{Conditionals} + +AEL supports if and switch statements, like AEL, but adds ifTime, and +random. Unlike the original AEL, though, you do NOT need to put curly +braces around a single statement in the "true" branch of an if(), the +random(), or an ifTime() statement. The if(), ifTime(), and random() +statements allow optional else clause. + +\begin{verbatim} +context conditional { + _8XXX => { + Dial(SIP/${EXTEN}); + if ("${DIALSTATUS}" = "BUSY") + { + NoOp(yessir); + Voicemail(${EXTEN}|b); + } + else + Voicemail(${EXTEN}|u); + ifTime (14:00-25:00|sat-sun|*|*) + Voicemail(${EXTEN}|b); + else + { + Voicemail(${EXTEN}|u); + NoOp(hi, there!); + } + random(51) NoOp(This should appear 51% of the time); + + random( 60 ) + { + NoOp( This should appear 60% of the time ); + } + else + { + random(75) + { + NoOp( This should appear 30% of the time! ); + } + else + { + NoOp( This should appear 10% of the time! ); + } + } + } + _777X => { + switch (${EXTEN}) { + case 7771: + NoOp(You called 7771!); + break; + case 7772: + NoOp(You called 7772!); + break; + case 7773: + NoOp(You called 7773!); + // fall thru- + pattern 777[4-9]: + NoOp(You called 777 something!); + default: + NoOp(In the default clause!); + } + } +} +\end{verbatim} + +NOTE: The conditional expression in if() statements (the + "\${DIALSTATUS}" = "BUSY" above) is wrapped by the compiler in + \$[] for evaluation. + +NOTE: Neither the switch nor case values are wrapped in \$[ ]; they can + be constants, or \${var} type references only. + +NOTE: AEL generates each case as a separate extension. case clauses + with no terminating 'break', or 'goto', have a goto inserted, to + the next clause, which creates a 'fall thru' effect. + +NOTE: AEL introduces the ifTime keyword/statement, which works just + like the if() statement, but the expression is a time value, + exactly like that used by the application GotoIfTime(). See + Asterisk cmd GotoIfTime + +NOTE: The pattern statement makes sure the new extension that is + created has an '\_' preceding it to make sure asterisk recognizes + the extension name as a pattern. + +NOTE: Every character enclosed by the switch expression's parenthesis + are included verbatim in the labels generated. So watch out for + spaces! + +NOTE: NEW: Previous to version 0.13, the random statement used the + "Random()" application, which has been deprecated. It now uses + the RAND() function instead, in the GotoIf application. + + +\subsection{Break, Continue, and Return} + +Three keywords, break, continue, and return, are included in the +syntax to provide flow of control to loops, and switches. + +The break can be used in switches and loops, to jump to the end of the +loop or switch. + +The continue can be used in loops (while and for) to immediately jump +to the end of the loop. In the case of a for loop, the increment and +test will then be performed. In the case of the while loop, the +continue will jump to the test at the top of the loop. + +The return keyword will cause an immediate jump to the end of the +context, or macro, and can be used anywhere. + + + +\subsection{goto, jump, and labels} + +This is an example of how to do a goto in AEL. + +\begin{verbatim} +context gotoexample { + s => { +begin: + NoOp(Infinite Loop! yay!); + Wait(1); + goto begin; // go to label in same extension + } + 3 => { + goto s|begin; // go to label in different extension + } + 4 => { + goto gotoexample|s|begin; // overkill go to label in same context + } +} + +context gotoexample2 { + s => { + end: + goto gotoexample|s|begin; // go to label in different context + } +} +\end{verbatim} + +You can use the special label of "1" in the goto and jump +statements. It means the "first" statement in the extension. I would +not advise trying to use numeric labels other than "1" in goto's or +jumps, nor would I advise declaring a "1" label anywhere! As a matter +of fact, it would be bad form to declare a numeric label, and it might +conflict with the priority numbers used internally by asterisk. + +The syntax of the jump statement is: jump +extension[,priority][@context] If priority is absent, it defaults to +"1". If context is not present, it is assumed to be the same as that +which contains the "jump". + +\begin{verbatim} +context gotoexample { + s => { +begin: + NoOp(Infinite Loop! yay!); + Wait(1); + jump s; // go to first extension in same extension + } + 3 => { + jump s,begin; // go to label in different extension + } + 4 => { + jump s,begin@gotoexample; // overkill go to label in same context + } +} + +context gotoexample2 { + s => { + end: + jump s@gotoexample; // go to label in different context + } +} +\end{verbatim} + +NOTE: goto labels follow the same requirements as the Goto() + application, except the last value has to be a label. If the + label does not exist, you will have run-time errors. If the + label exists, but in a different extension, you have to specify + both the extension name and label in the goto, as in: goto s|z; + if the label is in a different context, you specify + context|extension|label. There is a note about using goto's in a + switch statement below... + +NOTE AEL introduces the special label "1", which is the beginning + context number for most extensions. + +NOTE: A NEW addition to AEL: you can now use ',' instead of '|' to + separate the items in the target address. You can't have a mix, + though, of '|' and ',' in the target. It's either one, or the other. + + + + +\subsection{Macros} + +A macro is defined in its own block like this. The arguments to the +macro are specified with the name of the macro. They are then referred +to by that same name. A catch block can be specified to catch special +extensions. + +\begin{verbatim} +macro std-exten( ext , dev ) { + Dial(${dev}/${ext},20); + switch(${DIALSTATUS) { + case BUSY: + Voicemail(b${ext}); + break; + default: + Voicemail(u${ext}); + + } + catch a { + VoiceMailMain(${ext}); + return; + } +} +\end{verbatim} + +A macro is then called by preceding the macro name with an +ampersand. Empty arguments can be passed simply with nothing between +comments(0.11). + +\begin{verbatim} +context example { + _5XXX => &std-exten(${EXTEN}, "IAX2"); + _6XXX => &std-exten(, "IAX2"); + _7XXX => &std-exten(${EXTEN},); + _8XXX => &std-exten(,); +} +\end{verbatim} + + +\section{Examples} + +\begin{verbatim} +context demo { + s => { + Wait(1); + Answer(); + TIMEOUT(digit)=5; + TIMEOUT(response)=10; +restart: + Background(demo-congrats); +instructions: + for (x=0; ${x} < 3; x=${x} + 1) { + Background(demo-instruct); + WaitExten(); + } + } + 2 => { + Background(demo-moreinfo); + goto s|instructions; + } + 3 => { + LANGUAGE()=fr; + goto s|restart; + } + + 500 => { + Playback(demo-abouttotry); + Dial(IAX2/guest@misery.digium.com); + Playback(demo-nogo); + goto s|instructions; + } + 600 => { + Playback(demo-echotest); + Echo(); + Playback(demo-echodone); + goto s|instructions; + } + # => { +hangup: + Playback(demo-thanks); + Hangup(); + } + t => goto #|hangup; + i => Playback(invalid); +} +\end{verbatim} + + +\section{Semantic Checks} + + +AEL, after parsing, but before compiling, traverses the dialplan +tree, and makes several checks: + +\begin{itemize} + \item Macro calls to non-existent macros. + \item Macro calls to contexts. + \item Macro calls with argument count not matching the definition. + \item application call to macro. (missing the '\&') + \item application calls to "GotoIf", "GotoIfTime", "while", + "endwhile", "Random", and "execIf", will generate a message to + consider converting the call to AEL goto, while, etc. constructs. + \item goto a label in an empty extension. + \item goto a non-existent label, either a within-extension, + within-context, or in a different context, or in any included + contexts. Will even check "sister" context references. + \item All the checks done on the time values in the dial plan, are + done on the time values in the ifTime() and includes times: + o the time range has to have two times separated by a dash; + o the times have to be in range of 0 to 24 hours. + o The weekdays have to match the internal list, if they are provided; + o the day of the month, if provided, must be in range of 1 to 31; + o the month name or names have to match those in the internal list. + \item (0.5) If an expression is wrapped in \$[ ... ], and the compiler + will wrap it again, a warning is issued. + \item (0.5) If an expression had operators (you know, + +,-,*,/,%,!,etc), but no \${ } variables, a warning is + issued. Maybe someone forgot to wrap a variable name? + \item (0.12) check for duplicate context names. + \item (0.12) check for abstract contexts that are not included by any context. + \item (0.13) Issue a warning if a label is a numeric value. +\end{itemize} + +There are a subset of checks that have been removed until the proposed +AAL (Asterisk Argument Language) is developed and incorporated into Asterisk. +These checks will be: + +\begin{itemize} + \item (if the application argument analyzer is working: the presence + of the 'j' option is reported as error. + \item if options are specified, that are not available in an + application. + \item if you specify too many arguments to an application. + \item a required argument is not present in an application call. + \item Switch-case using "known" variables that applications set, that + does not cover all the possible values. (a "default" case will + solve this problem. Each "unhandled" value is listed. + \item a Switch construct is used, which is uses a known variable, and + the application that would set that variable is not called in + the same extension. This is a warning only... + \item Calls to applications not in the "applist" database (installed + in /var/lib/asterisk/applist" on most systems). + \item In an assignment statement, if the assignment is to a function, + the function name used is checked to see if it one of the + currently known functions. A warning is issued if it is not. +\end{itemize} + + +Differences with the original version of AEL +============================================ + +\begin{enumerate} + \item The \$[...] expressions have been enhanced to include the ==, ||, + and \&\& operators. These operators are exactly equivalent to the + =, |, and \& operators, respectively. Why? So the C, Java, C++ + hackers feel at home here. + \item It is more free-form. The newline character means very little, + and is pulled out of the white-space only for line numbers in + error messages. + \item It generates more error messages -- by this I mean that any + difference between the input and the grammar are reported, by + file, line number, and column. + \item It checks the contents of \$[ ] expressions (or what will end up + being \$[ ] expressions!) for syntax errors. It also does + matching paren/bracket counts. + \item It runs several semantic checks after the parsing is over, but + before the compiling begins, see the list above. + \item It handles \#include "filepath" directives. -- ALMOST + anywhere, in fact. You could easily include a file in a context, + in an extension, or at the root level. Files can be included in + files that are included in files, down to 50 levels of hierarchy... + \item Local Goto's inside Switch statements automatically have the + extension of the location of the switch statement appended to them. + \item A pretty printer function is available within pbx\_ael.so. + \item In the utils directory, two standalone programs are supplied for + debugging AEL files. One is called "aelparse", and it reads in + the /etc/asterisk/extensions.ael file, and shows the results of + syntax and semantic checking on stdout, and also shows the + results of compilation to stdout. The other is "aelparse1", + which uses the original ael compiler to do the same work, + reading in "/etc/asterisk/extensions.ael", using the original + 'pbx\_ael.so' instead. + \item AEL supports the "jump" statement, and the "pattern" statement + in switch constructs. Hopefully these will be documented in the + AEL README. + \item Added the "return" keyword, which will jump to the end of an + extension/Macro. + \item Added the ifTime (