Solved

asterisk cmd Case or Switch statment

Posted on 2011-03-22
7
2,235 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Implementing Avaya's One-X portal is pretty painless, until you want to deploy this to the Android and iPhone clients when these clients are outside of your network. The clients will also work within your local network. Here is our experience and so…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

17 Experts available now in Live!

Get 1:1 Help Now