Gotoif multiple matches

I’m trying to reduce the number of gotoif lines I have.

Currently the macro looks like this but with many more similar lines
same =>n,GotoIf($["${pin}" = “11”]?badpin:)
same =>n,GotoIf($["${pin}" = “22”]?badpin:)
same =>n,GotoIf($["${pin}" = “33”]?badpin:)

I can consilidate the first two linesto look like this
same =>n,GotoIf($["${pin}" = “11” | $["${pin}" = “22”]]?badpin:)

But again this is little long and dificult to maintain when there are lots of numbers to match.

I could store all the numbers in a test file and set this in as a varaible like this
same =>n,Set(bad-pins=${FILE(/etc/asterisk/bad-pins.txt)})
same =>n,GotoIf($["${pin}" = ${bad-pins}]?badpin:)


the varible is read in but doesn’t match ${pin}

Does anyone have a good method of maintaining a blacklist in a few lines of code?

Store them in astdb (or a compatible RDBMS) and look them up.

alternatively make them extensions in a subroutine (macros are deprecated).


As David said store them in a DB, but also to save code and make it cleaner why aren’t you just checking the good pins and the anything else is bad.

Thanks for the reply’s. It looks like I will have to read up about sub routines, and just as I was getting used to using macros. The books I have maybe out of date.

I was trying to avoid storing these in ast database because I may wish to have a simple script update the list and storing the list in mysql felt over kill.

In the macro, bad pins are checked first and then a minimum length is checked.

There are approximately 25 bad pins and an unlimited number of good pins. The idea is users would select their own pin but nothing simple like 1234 or 1111 etc. … +db_exists

then just sore them in the astdb , then its just a couple of lines to check all of them

Astdb isn’t very user friendly.

Unless I a wrong, and I could be, I can’t see a way of listing whats in a particular family.
I can check to se if a record is aready in there but not list out what is aready there.

Adding entris to the list externaly apears to be possible via the asterisk command line which would work.

Would prefer to have a asterisk check if a number is listed in a simple text file. Any thoughts on how this maybe possible?

Do we think there is a performance benefit by using astdb?


yep you are wrong :wink:

database show DEVICE 3301 shows teh setting for device 3301
database show DEVICE shows the settings for all devices
database show shows the whole database

it can be manipulated from the command line or via AMI, Its fast and doenst suffer from timeouts that can occure on mysql connections

Is there any sensible limitation to the maximum numbers of entrys in the AstDB? Does anybody have any experience with that?

I did use the astdb in the end and DB_EXISTS.

I wrote a script to help me manage the databse.

Thanks for the advice

Glad the pointer helped. sometimes a fresh look at a problem can show a better way, As Helen Keller said “we look so long at the closed door that we do not see the one which has been opened for us”