C programming - Get dial result from dialplan?

Hi

I’m writing a little special addition to chan_sip.
When a INVITE comes I want to take the ‘To’ field,
call some function that parses the dial plan and returns which
channel that will be called. I have tried to find this magical
function i the Asterisk source without luck. But somewhere
this must be done by asterisk.

This is what I’m looking for:
int MagicalParse( const char* sip_to, char* dialinfo, size_t maxinfo ) ;

In dialplan:

exten => _X,1,Dial(Zap/g1/w${EXTEN})
exten => _X,2,Hangup()

char info[100] ;
MagicalParse( “5”, info, sizeof(info) ) ;
would the write “Zap/g1” to infobuffer.

Of course there is no such function but
there may be another that produces same result.

Does anyone know how to do this from C.

Thanks
roland

Can you give more details as to what you are trying to do?

From the dialplan you can already access the values in the sip header. See the SIP_HEADER and SIPCHANINFO functions.

Here is the background.

When a SIP_MESSAGE comes in
I will make a analog ZAP call to the number
that’s specified in the SIP_HEADER To field.

But depending of the number I will call
the Zap channel or group that’s specified in
the DialPlan.

I have written a hook in chan_sip.c which is
called when a SIP_MESSAGE arrives.

I can get all SIP_HEADER info from sip_pvt and sip_req,
that’s no problem. I can also make my call to a Zap channel
or group from my little C-hook. My problem is that I need to know
which Zap channels or group to call according to the dial-plan.

Pseudo code:

When I come here no call has been made yet
on-sip-message( )
{
from = get from SIP_HEADER( to )
zap = get from dial-plan giving ‘to’ as parameter
call zap, to
}

my problem is how to find out which zap group to call.
I need to get that info from dial-plan before making the call.
Its because my application will ‘talk’ different protocols
on different zap channels/groups

so … my dream function would be

zap = get_zapgroup( from ) ;

I may be wrong, but I think you are over thinking your problem. If you have different zap groups etc which are used based on the number called, why can’t you do it directly from the dialplan?

Lets say for instance, you accept different SIP calls from different sources. In sip.conf you can specify a default context for the calls to go into. In this example we’ll use context=incoming in the general section of sip.conf. (Note: this example is pretty insecure as it allows anyone to make calls to the matches) Then in the dialplan you can do something like this:

[incoming]
; Default route
exten => _NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN})

; Specific route for this number
exten => 8005551212,1,Dial(Zap/g2/${EXTEN})

; Specific route for this area code.
exten => _212NXXXXXX,1,Dial(Zap/g3/${EXTEN})

etc…

Hi davevg and thanks for you answer.

This is exactly how I do it, and for
SIP_INVITES there is no problem as
in that case asterisk will make the Zap call
using the dialplan.

But in my case there is no SIP_INVITE.
There is only a SIP_MESSAGE coming in
so asterisk wont do any call.

My task is to handle the SIP_MESSAGE,
call a Zap group according to what’s said
in the dialplan and send some DTMF info
to the called Zap channel.

So I have to make the call my self.
I’m using ast_request_and_dial for this
but that function need to know the Zap-channel-or-group
That’s why I need that info before calling.

Maybe I’m doing my own call the wrong way when
using ast_request_and_dial, but that’s the only way
I fond to make an own analog call from my routine.

Is there a better way to make this call so asterisk
will make the call using the dialplan info. I have
tried some other ways to make the call but have failed
as I don’t have any Sip-channel active when a make
the call. Remember that I only get a SIP_MESSAGE.

The whole idea is that when I get a SIP_MESSAGE (not inside a dialog)
I will call an analog device and send some DTMF info parsed
from the SIP_MESSAGE.

Cheers
roland

Ahh ok, I understand now.

Maybe something like this?

ast_goto_if_exists(chan, chan->context, to, 1);

Not entirely sure this is what you need but hope it helps, or maybe someone else has answers.

Thanks for the tip.
I’ll look into that suggestion

Edit:
That did not work either. But I solved the problem
now. I wrote an own extension parser which gets
the information from the extensions.conf and now
it works as I want it to.

Thanks for you help anyway.
Roland

hi
how i can make call by using asterisk ???