Gosub error in macro-dial-one

Hi all. First of all, I’m comfortable with stock asterisk using it since 1.2 but not with FreePBX.

I want to check how I could add my dialplan rules for various scenario. So I try to add my own PJSIP_HEADERS and saw that I could do it in macro-dial-one just before the dial. I also add a channel variable for incoming calls from trunk, which is called DIALEDNUMBER. In macro-dial-one I set

exten => s,n,ExecIf($[“${ivrreturn}” = “1”]?Set(D_OPTIONS=${D_OPTIONS}g))
same = n,NoOp(DIALEDNUMBER=${DIALEDNUMBER})
same = n,ExecIf($[“x${DIALEDNUMBER:-4}” = “x0089”]?Gosub(func-set-sipheader,s,1(Alert-Info,blabla;info=Private-DH;x-line-id=0)))
exten => s,n(dial),Dial(${DSTRING},${ARG1},${D_OPTIONS}${CWRING}b(func-apply-sipheaders^s^1))

With result being

-- Executing [[email protected]:55] ExecIf("Local/[email protected];2", "0?Set(D_OPTIONS=HhTtrM(auto-blkvm)g)") in new stack
-- Executing [[email protected]:56] NoOp("Local/[email protected];2", "DIALEDNUMBER=XXXXXX0089") in new stack
-- Executing [[email protected]:57] ExecIf("Local/[email protected];2", "1?Gosub(func-set-sipheader,s,1(Alert-Info,blabla;info=Private-DH;x-line-id=0))") in new stack

== Channel ‘Local/[email protected];2’ jumping out of macro ‘dial-one’
== Channel ‘Local/[email protected];2’ jumping out of macro ‘exten-vm’
– Executing [[email protected]:1] NoOp(“Local/[email protected];2”, “Sip Add Header function called. Adding = HhTtrM(auto-blkvm)”) in new stack
– Executing [[email protected]:2] Set(“Local/[email protected];2”, “HASH(__SIPHEADERS,)=HhTtrM(auto-blkvm)”) in new stack
– Executing [[email protected]:3] Return(“Local/[email protected];2”, “”) in new stack

So jumping out of queue twice and adding Sip Header HhTtrM(auto-blkvm) !!!

Now I remove the ExecIf($[“x${DIALEDNUMBER:-4}” = “x0089”]? which now looks like

same = n,Gosub(func-set-sipheader,s,1(Alert-Info,blabla;info=Private-DH;x-line-id=0))

and get

-- Executing [[email protected]:55] ExecIf("Local/[email protected];2", "0?Set(D_OPTIONS=HhTtrM(auto-blkvm)g)") in new stack
-- Executing [[email protected]:56] NoOp("Local/[email protected];2", "DIALEDNUMBER=XXXXXX0089") in new stack
-- Executing [[email protected]:57] Gosub("Local/[email protected];2", "func-set-sipheader,s,1(Alert-Info,blabla;info=Private-DH;x-line-id=0)") in new stack
-- Executing [[email protected]:1] NoOp("Local/[email protected];2", "Sip Add Header function called. Adding Alert-Info = blabla;info=Private-DH;x-line-id=0") in new stack

which is the right result.

Anyone has an idea on this ? Should I open an issue ?

Daniel

You’re on the right track as far as using the func-set-sipheader gosub to add headers, but it’s not clear how exactly you’re editing the macro-dial-one context. That context is not intended to be edited directly. Check out this post on using the dialplan hooks:

Hi Lorne. Please take a look in original message, I eplain where I insert the Gosub, just before the Dial. Any way, that’s not the problem as it’s OK without the ExecIf and NOK with. Why ?

Thanks for your help

Hi Igaetz. I follow th dialplan hooks tips and get same result NOK:

[macro-dialout-one-predial-hook]
;
exten = s,1,NoOp(DIALEDNUMBER=${DIALEDNUMBER})
same = n,ExecIf($[“x${DIALEDNUMBER:-9}” = “x368460089”]?Gosub(func-set-sipheader,s,1(Alert-Info,http://www.notused.com;info=Private-DH;x-line-id=0)))
same = n,MacroExit

Channel ‘Local/[email protected];2’ jumping out of macro ‘dialout-one-predial-hook’
== Channel ‘Local/[email protected];2’ jumping out of macro ‘dial-one’
== Channel ‘Local/[email protected];2’ jumping out of macro ‘exten-vm’
– Executing [[email protected]:1] NoOp(“Local/[email protected];2”, “Sip Add Header function called. Adding = HhTtrM(auto-blkvm)”) in new stack
– Executing [[email protected]:2] Set(“Local/[email protected];2”, “HASH(__SIPHEADERS,)=HhTtrM(auto-blkvm)”) in new stack
– Executing [[email protected]:3] Return(“Local/[email protected];2”, “”) in new stack

Replacing
same = n,ExecIf($[“x${DIALEDNUMBER:-9}” = “x368460089”]?Gosub(func-set-sipheader,s,1(Alert-Info,http://www.notused.com;info=Private-DH;x-line-id=0)))

with

same = n,Gosub(func-set-sipheader,s,1(Alert-Info,http://www.notused.com;info=Private-DH;x-line-id=0))

make it work.

BTW, dialplan hooks is not a viable solution, I trie it on incoming calls, context from-pstn, didn’t find any hook for a FROM_DID I had to create

[from-trunk]
…my stuff…
same = n,Goto(from-pstn,1)

Not really flexible :frowning:

I’m surprised no one as caught this but in Asterisk the ; indicates a comment such as [test-context] ;Testing Context therefore when you do auto answer or other headers that have ; in them you need to escape them. Such as:

same = n,Gosub(func-set-sipheader,s,1(Alert-Info,[http://www.notused.com](http://www.notused.com/)\;info=Private-DH\;x-line-id=0)) otherwise everything after the first ; is considered a comment in the dialplan.

It would also be more helpful to have the full call from the logs and not just snippets of it. That way we can see exactly what is happening and when. Including if your header is being accepted properly.

; are escaped by \ in the dialplan as you explain, the shown logs are those from cli output. And yes, headers are applied (changing ringer), I can hear the result :wink:

Then why am I quoting dialplan that you posted which shows no escaping?

As said above, I copy the CLI logs output -which remove the escape caracter- to show the result of the execution of the dialplan

You’ll have to excuse me but this doesn’t look like CLI output to me. It looks like raw dialplan that has ; that aren’t escaped.

THIS is dialplan execution from the CLI. Totally different things.

I don’t know what is your goal but as said, semi-colon are escaped in dialplan. And the Gosub(my command) is exactly the same spelling in both cases, one work the other one not. Spelling is NOT open to question.

Instead of using execif ... gosub, do you get a different result by using gosubif?

You got it, it works with gosubif !

Thanks for your support

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.