[asterisk-users] Asterisk dialplan best practices syntax

Ludovic Gasc gmludo at gmail.com
Sun Jun 28 08:40:58 CDT 2015


2015-06-26 17:11 GMT+02:00 Steve Edwards <asterisk.org at sedwards.com>:

> On Fri, 26 Jun 2015, Ludovic Gasc wrote:
>
>  1. What's the "official" notation of each line: "=>" or "=" ? In the wiki
>> of Asterisk, I see very often "=>", however, what's the reason for both
>> syntaxes authorized ? Historical ?
>>
>
> I'm not 'official,' but I have a strong preference for just '=.' Using
> '=>' seems clunky, ugly, and unnecessary.


It's interesting because from my point of view, I prefer to use '=>',
because, to me, '=' is for config files.
The dialplan is a programming language, not a config file.
If you like buzzwords, it's a Domain Specific Language.

However, it's completely a religious point of view, Asterisk will process
exactly the same dialplan with '=' or with '=>'.
I was interested in by the story that will explain to me why Asterisk
support both syntaxes, if somebody remembers.

Thank you Steve for your answers in point 2., any tips to improve
readability of dialplan is interesting to me.

 2. To write info in logs/console, you have two commands: NoOp and Verbose.
>> Verbose seems to be better, because you can define a log level. Are you
>> agree or another command fits better for logs ?
>>
>
> This is kind of a pet peeve of mine. Why use the misguided 'side effect'
> of an application when there is a specific, 'more featured,' application
> for that purpose? A 'noop' is a contraction of 'no operation' meaning it
> should do nothing but act as a placeholder.
>
> Two other areas of 'best practices' I'm a strong believer in are:
> alphabetize wherever possible, and use white space to improve readability.
>
> For example, here's a 'sanitized' sip.conf snippet from a popular
> provider's web site:
>
> [xxx-inbound]
> type=friend
> dtmfmode=auto
> host=xxx.yyy.zzz
> context=inbound
>
> username=xxx
> secret=yyy
>
> allow=all
> insecure=port,invite
> canreinvite=no
>
> [xxx-outbound]
> type=friend
> dtmfmode=auto
> host=xxx.yyy.zzz
> username=xxx
> fromuser=xxx
> secret=xxx
> trustrpid=yes
> sendrpid=yes
> allow=all
> canreinvite=no
>
> Pretty ugly and difficult to read. With a little whitespace and
> alphabetizing we get:
>
> [xxx-inbound]
>         allow                           = all
>         canreinvite                     = no
>         context                         = inbound
>         dtmfmode                        = auto
>         host                            = xxx.yyy.zzz
>         insecure                        = port,invite
>         secret                          = yyy
>         type                            = friend
>         username                        = xxx
>
> [xxx-outbound]
>         allow                           = all
>         canreinvite                     = no
>         dtmfmode                        = auto
>         fromuser                        = xxx
>         host                            = xxx.yyy.zzz
>         secret                          = xxx
>         sendrpid                        = yes
>         trustrpid                       = yes
>         type                            = friend
>         username                        = xxx
>
> Now, the major sections are easy to 'visually delineated.' Finding the
> 'secret' is much easier now. Comparing a 'working' extension with a
> 'broken' extension will be much easier as well.
>
> I use the same formatting in the dialplan. This snippet is from
> extensions.conf.sample:
>
> [outbound-freenum2]
> exten => _X!,1,Verbose(2,Performing ISN lookup for ${EXTEN})
> same => n,Set(SUFFIX=${CUT(EXTEN,*,2-)})
> same => n,GotoIf($["${FILTER(0-9,${SUFFIX})}" !=
> "${SUFFIX}"]?fn-CONGESTION,1)
> same => n,Set(TIMEOUT(absolute)=10800)
> same => n,Set(isnresult=${ENUMLOOKUP(${EXTEN},sip,,1,freenum.org)})
> same => n,GotoIf($["${isnresult}" != ""]?from)
> same => n,Set(DIALSTATUS=CONGESTION)
> same => n,Goto(fn-CONGESTION,1)
> same => n(from),Set(__SIPFROMUSER=${CALLERID(num)})
> same => n,GotoIf($["${GLOBAL(FREENUMDOMAIN)}" = ""]?dial)
> same => n,Set(__SIPFROMDOMAIN=${GLOBAL(FREENUMDOMAIN)})
> same => n(dial),Dial(SIP/${isnresult},40)
> same => n,Goto(fn-${DIALSTATUS},1)
>
> exten => fn-BUSY,1,Busy()
>
> exten => _f[n]-.,1,NoOp(ISN: ${DIALSTATUS})
> same => n,Congestion()
>
> With a little whitespace, this becomes much more readable:
>
> [outbound-freenum2]
>         exten = _X!,1,                  Verbose(2,Performing ISN lookup
> for ${EXTEN})
>         same = n,                       Set(SUFFIX=${CUT(EXTEN,*,2-)})
>         same = n,
>  GotoIf($["${FILTER(0-9,${SUFFIX})}" != "${SUFFIX}"]?fn-CONGESTION,1)
>         same = n,                       Set(TIMEOUT(absolute)=10800)
>         same = n,
>  Set(isnresult=${ENUMLOOKUP(${EXTEN},sip,,1,freenum.org)})
>         same = n,                       GotoIf($["${isnresult}" !=
> ""]?from)
>         same = n,                       Set(DIALSTATUS=CONGESTION)
>         same = n,                       Goto(fn-CONGESTION,1)
>         same = n(from),                 Set(__SIPFROMUSER=${CALLERID(num)})
>         same = n,
>  GotoIf($["${GLOBAL(FREENUMDOMAIN)}" = ""]?dial)
>         same = n,
>  Set(__SIPFROMDOMAIN=${GLOBAL(FREENUMDOMAIN)})
>         same = n(dial),                 Dial(SIP/${isnresult},40)
>         same = n,                       Goto(fn-${DIALSTATUS},1)
>
>         exten = fn-BUSY,1,              Busy()
>
>         exten = _f[n]-.,1,              NoOp(ISN: ${DIALSTATUS})
>         same = n,                       Congestion()
>
> Compare the effort to find where the 'dial' is in the 'before' and 'after.'
>
> --
> Thanks in advance,
> -------------------------------------------------------------------------
> Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
> Newline                                              Fax: +1-760-731-3000
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>               http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20150628/b0bea63e/attachment.html>


More information about the asterisk-users mailing list