Solved

asterisk cmd Case or Switch statment

Posted on 2011-03-22
7
2,172 Views
Last Modified: 2013-11-12
Trying to write something in the macro language. or Asterisk, in the .conf files

is there a case or switch statement for this ?

can you show me a good lanuage reference
http://www.voip-info.org/wiki/view/Asterisk+cmd+Goto
this site is ok, but the search engine not smart.

What I want to do is somethign like

 IF extension = 300
         if arg2:2:5 = "505   set flag =1
         if arg2:2:5 = "533   set flag =2
         if arg2:2:5 = "544   set flag =3
 end if

or as a case
if extension = 300
switch(arg2:2:5)
     case 505 : set flag =1 break
     case 533 : set flag =2 break
     case 544 : set flag =3 break
else
     set flag=3
end

Will accept suggestions. how to do it better

The Lanuage looks like this
exten => a,n,Set(FLAG1=1})
exten => a,n,GotoIf($ARG2}" = "1"]?acontext)
BLA BLA BLA

0
Comment
Question by:yahoolane
7 Comments
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35195021
Dialplan has no switch or case statements.

Alternatively, you can use AGI with PHP and get the job done quite easily.

I use this:
http://phpagi.sourceforge.net/
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35220649
Have you tried this? Do you understand my solution?
0
 
LVL 25

Accepted Solution

by:
Ron M earned 300 total points
ID: 35235894
Something like this maybe...

exten => s,n,ExecIf($[${ARG2:1:3} = 500]?Set(FLAG=0))
exten => s,n,ExecIf($[${ARG2:1:3} = 501]?Set(FLAG=1))
exten => s,n,ExecIf($[${ARG2:1:3} = 502]?Set(FLAG=2))

exten => s,n,GotoIf($[${FLAG} = 0]?label0)
exten => s,n,GotoIf($[${FLAG} = 1]?label1)
exten => s,n,GotoIf($[${FLAG} = 2]?label2)
exten => s,n,NoOp(Condition not met.  Hangup!)
exten => s,n,MacroExit()

exten => s,n(lable0),........
exten => s,n,MacroExit()
exten => s,n(lable1),........
exten => s,n,MacroExit()
exten => s,n(lable2),........
exten => s,n,MacroExit()


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 32

Expert Comment

by:DrDamnit
ID: 35236947
Ooooooooo. Nice post xuser... That should do the trick...
0
 
LVL 19

Expert Comment

by:feptias
ID: 35378018
Here is yet another approach that I use sometimes:

[globals]
CASE505=1
CASE533=2
CASE544=3

[acontext]
..
exten => s,n,Set(flag=${CASE${ARG2:2:3}})

It is a very compact way of doing multiple cases, but is weak regarding default values where, say, ARG2 doesn't match any of the expected cases. I'm sure that extra code could be added to assign a default value to flag if needed.

I notice that the question also asks how to construct an if-then-else block. I would do it like this:

[acontext]
..
exten => _X.,n,Gotoif($[${EXTEN} = 300] ? match)
; Is not 300
exten => _X.,n,Noop(Extension does not equal 300)
exten => _X.,n,...
exten => _X.,n,Goto(done)
; Is 300
exten => _X.,n(match),Noop(Extension does equal 300)
exten => _X.,n,...
;
exten => _X.,n(done),...
0
 
LVL 25

Assisted Solution

by:Ron M
Ron M earned 300 total points
ID: 35730279
[selectcase]

exten => s,1(select case),NoOp(Case ${ARG2:1:3})
exten => s,n,GotoIf($[${ARG2:1:3} <> ""]?case${ARG2:1:3}:select case)
exten => s,n,Hangup()

exten => s,n(case500),NoOp(500)
exten => s,n,Hangup()

exten => s,n(case550),NoOp(550)
exten => s,n,Hangup()

exten => s,n(case580),NoOp(580)
exten => s,n,Hangup()

0
 
LVL 1

Author Closing Comment

by:yahoolane
ID: 35985137
I did not try the
[selectcase]

But Looked great,

I did more of flags and big IF statments
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The point of this post is to give you a copy/paste installation solution to setting up Asterisk 1.6 on Ubuntu 9.04 (or similar) server. # Setup the system apt-get install subversion apt-get install make apt-get install linux-source kernel-p…
As companies replace their old PBX phone systems with Unified IP Communications, many are finding out that legacy applications such as fax do not work well with VoIP. Fortunately, Cloud Faxing provides a cost-effective alternative that works over an…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now