VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
gmludo at gmail.com Guest
|
Posted: Fri Jun 26, 2015 4:22 am Post subject: [asterisk-users] Asterisk dialplan best practices syntax |
|
|
Hi,
I've two yocto questions about the syntax of dialplan:
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 ?
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 ?
Thanks for your responses.
Regards.
--
Ludovic Gasc (GMLudo)
http://www.gmludo.eu/ |
|
Back to top |
|
|
asterisk.org at sedwar... Guest
|
Posted: Fri Jun 26, 2015 10:12 am Post subject: [asterisk-users] Asterisk dialplan best practices syntax |
|
|
On Fri, 26 Jun 2015, Ludovic Gasc wrote:
Quote: | 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.
Quote: | 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@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 |
|
Back to top |
|
|
gmludo at gmail.com Guest
|
Posted: Sun Jun 28, 2015 8:41 am Post subject: [asterisk-users] Asterisk dialplan best practices syntax |
|
|
2015-06-26 17:11 GMT+02:00 Steve Edwards <asterisk.org@sedwards.com (asterisk.org@sedwards.com)>:
Quote: | On Fri, 26 Jun 2015, Ludovic Gasc wrote:
Quote: | 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.
Quote: | Quote: | 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@sedwards.com (sedwards@sedwards.com) Voice: [url=tel:%2B1-760-468-3867]+1-760-468-3867[/url] PST
Newline Fax: [url=tel:%2B1-760-731-3000]+1-760-731-3000[/url]
--
_____________________________________________________________________
-- 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
|
|
|
Back to top |
|
|
asterisk.org at sedwar... Guest
|
Posted: Sun Jun 28, 2015 10:08 am Post subject: [asterisk-users] Asterisk dialplan best practices syntax |
|
|
On Sun, 28 Jun 2015, Ludovic Gasc wrote:
Quote: | 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.
|
The only language I'm familiar with (I'm primarily a 'c' guy) that uses
'=>' is PHP. In PHP, '=>' is used with associative arrays.
I tend to think of a dialplan as a group of one dimensional linear arrays
with the name of the array being the context concatenated with the exten
so for me, a simple assignment makes sense.
--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards sedwards@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 |
|
Back to top |
|
|
asterisk at voipbusine... Guest
|
Posted: Sun Jun 28, 2015 11:11 am Post subject: [asterisk-users] Asterisk dialplan best practices syntax |
|
|
Hey;
Don't forget Perl. I'm not sure what everyone else calls it, but most
Perl programmers call it a "fat comma".
From Chromatic's "Modern Perl" book: One of the simplest but most useful
examples of TIMTOWTDI in the design of Perl is the fat comma operator (=>),
which acts like a regular comma except that it automatically quotes
barewords used as its left operands. It also looks like an arrow, so it
leads from left to right and implies a stronger association between its
operands than the normal comma does.
You can see this in hash initializers:
my %dogs = (
alpha => 'Rodney',
clown => 'Lucky',
puppy => 'Rosie',
);
Regards;
John V.
-----Original Message-----
From: asterisk-users-bounces@lists.digium.com
[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Steve Edwards
Sent: Sunday, June 28, 2015 11:08 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk dialplan best practices syntax
On Sun, 28 Jun 2015, Ludovic Gasc wrote:
Quote: | 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.
|
The only language I'm familiar with (I'm primarily a 'c' guy) that uses '=>'
is PHP. In PHP, '=>' is used with associative arrays.
I tend to think of a dialplan as a group of one dimensional linear arrays
with the name of the array being the context concatenated with the exten so
for me, a simple assignment makes sense.
--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards sedwards@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
--
_____________________________________________________________________
-- 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 |
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|