Posts Tagged ‘quicky’

[quicky] Asterisk and incoming cli manipulation

Thursday, January 15th, 2009

It is very common in professional VoIP that service providers put through CLIs transparently. If you are just a traffic routing party you usually don’t care about it, but for premium services however it can cause major issues. For example you have an application that matches the calling party’s CLI to an entry in a database. If you have built that application yourself it’s very easy to do some internal mangling, however some people buy products which are not suited to do the job properly.

So this article is about manipulating the calling party’s CLI, rather than the called number. Let’s take a look at the following call example. Person A (00123456789) calls service B(1223235325). Service B has a number in E.164 format, however person A does not. In this example person A is the calling party. However the service requires the calling number to be in E.164 format.

So what would we do in asterisk to fix that? Well, let’s say for example also the B-number has to zeros at the beginning of the number:

001223235325

In the asterisk configuration we could have the following example dial plan to strip the two zeros:

[example]
; match incoming 00xxxxxxx numbers and reformat
exten => 00X.,1,Goto(${EXTEN:2}, 1)
 
; normal dialplan
exten => _X.,1,Answer()
[...]

By using the ‘:2′ on the ‘EXTEN’ variable we get rid of the first ‘2′ digits, this is a substring operation.

So that was easy! However, when doing it for the incoming CLI it’s a totally different story. The incoming CLI is exposed by the CALLERID function. There is some regular expression support in Asterisk, so we can get going. Unfortunately it only supports matching. So no support for getting matched groups, which would be a lot easier. However after some twiddling I came up with the following:

[example]
; print cli as it came in
exten => _X.,1,Verbose(${CALLERID(num)})
 
; test if it matches 00XXX
exten => _X.,n,Set(STRIPCLI=${REGEX("^[0]\{2\}[1-9][0-9]+$" ${CALLERID(num)})})
 
; Depending if it is set to 0 or 1 goto continue or continue and format the cli
exten => _X.,n,GotoIf($["${STRIPCLI}" = "0"]?continue)
exten => _X.,n,Verbose(Formatting outbound CLI)
 
; format the CLI
exten => _X.,n,Set(CALLERID(num)=${CALLERID(num):2)})
 
; continue normal operation
exten => _X.,n(continue),Verbose(${CALLERID(num)})
exten => _X.,n,Dial(SIP/SOMESERVER/${EXTEN})
[..]

Let’s go back to our example now and how the dial plan handles it:

Verbose(00123456789)
Match on regular expression and put it a variable
if(STRIPCLI == false)
  continue normal dialplan
else
  format cli
 
normal dialplan:
 
Verbose(123456789)
Forward call to some service

As you can see the ‘00′ has been stripped of and the A number is now in E.164 format. I hope this will become useful for someone else as well :-)

[Quicky] Refactoring C++ in Microsoft Visual Studio

Saturday, January 10th, 2009

Yesterday I started a simple C++ project in Visual Studio and I got some class property which I wanted to rename. I’m used to Eclipse and Netbeans IDE which have in-built refactoring utilities. So I decided to select that property and right click on it to see if I would get some refactoring options. I was surprised I didn’t, so I looked up the menu and couldn’t find anything there as well. For my small rename operation I then went to the class view and renamed the property there. However, I will probably need some basic refactoring tools in the coming future, so I started investigating.

A quick search on the internet lead me to a question on stackoverflow. Apperently it’s too difficult for Microsoft to implement refactoring for C++. Which on itself is sad, because Visual Studio is an expensive product to buy and I’d at least expect some refactoring support.

One of the replies to the question on stackoverflow mentions Refactor! for C++. Although the free version only provides some basic functionality, it does meet the expectations I have. In other words, it offers enough for me to do the job.

[Quicky] Shorewall and opening port ranges

Saturday, December 6th, 2008

Imagine you want to open up a port range to your host ($FW) in your shorewall’s ‘rules’ file. So let’s say we run an Asterisk machine and we want to open RTP ports 10000 to 20000 to your machine, you would have to do something like:

ACCEPT  net  $FW  udp  10000:20000

For more reference on Asterisk’s firewall rules, click here.

[Quicky] JSTL and comparing strings

Saturday, November 29th, 2008

This is the first article in a series of really short articles with problems I come across in my day to day development life. You can recognize these articles by the ‘[Quicky]‘ reference in the title and of course a ‘quicky’ tag is supplied. These ‘quickies’ don’t supply much explanation on why the problem exists, but more how to solve it.

Today I had to compare a variable with a string value using JSTL. Something like:

<c:choose>
  <c:when test="${variable eq "expected value"}">
    something
  </c:when>
</c:choose>

will obviously not work, because the XML becomes invalid. The way to do it however is:

<c:choose>
  <c:when test="${variable eq 'expected value'}">
    something
  </c:when>
</c:choose>

Replacing the double quotes surrounding the string value by single quotes does the trick.