How to work with ExecIF command

Hi,

I am trying to configure a dialplan. When call are incoming I answer it, then read DTMF for login and password, after that I validate value if correct then I mark it with ODBC as used (pair login/pass are one time only), and finally place a call to internal extension.

To this moment all works as I want.

Problem is with h extension. I dont know, why dialplan execute {ODBC_ODBLOKUJKOD} each time instead only when {DIALSTATUS} != Answer

exten => h,1,Noop(Rozlaczenie kanalu)
same => n,DumpChan()
same => n,ExecIf([{DIALSTATUS}!=ANSWER]?Set(x={ODBC_ODBLOKUJKOD({ID})}))

All your $'s are missing, or you styled the text rather than marking it as pre-formatted.

They are in my dialplan, they must mised when i ctrl+c ctrl+v

exten => h,1,Noop(Rozlaczenie kanalu)
        same => n,DumpChan()
        same => n,ExecIf($[${DIALSTATUS}!=ANSWER]?Set(x=${ODBC_ODBLOKUJKOD(${ID})}))

You can’t do a DumpChan() in the h extension, that is hangup. Once the call hits h all the channel variables are gone.

I see you are new in Asterisk.

No, my statement doesn’t change. The h extension happens when a channel is hungup, no matter how that is. The call is over, in fact if you want to continue in the dialplan you have to flag the Dial() with the g option, otherwise it goes to h. Since the channel doesn’t exist any more at that point, how can it’s variables?

Why don’t you show a call and the results of this DumpChan() after the hangup that shows what the DIALSTATUS var really is at the time of the call.

And this is a ponit. DumpChan on h extension shows to me all variables. Additionally, dialstatus are show good valie depends if call was answer or not.
So, each variables used in exeif are set properly, the problem is, why odbc_odblokujkod are exec always

Show a debug of what is happening. Actual proof and data of a call this is happening on.

  == Using SIP RTP Audio CoS mark 5
    -- PJSIP/9001-00000031 is ringing
    -- PJSIP/9001-00000031 is ringing
    -- PJSIP/9001-00000031 answered PJSIP/freephone-00000030
    -- Channel PJSIP/9001-00000031 joined 'simple_bridge' basic-bridge <5adeecae-0bc5-4874-814f-56c9b7bf4484>
    -- Channel PJSIP/freephone-00000030 joined 'simple_bridge' basic-bridge <5adeecae-0bc5-4874-814f-56c9b7bf4484>
    -- Channel PJSIP/freephone-00000030 left 'simple_bridge' basic-bridge <5adeecae-0bc5-4874-814f-56c9b7bf4484>
    -- Channel PJSIP/9001-00000031 left 'simple_bridge' basic-bridge <5adeecae-0bc5-4874-814f-56c9b7bf4484>
  == Spawn extension (SUB-POBIERZDANE, s, 13) exited non-zero on 'PJSIP/freephone-00000030'
    -- Executing [h@SUB-POBIERZDANE:1] NoOp("PJSIP/freephone-00000030", "Rozlaczenie kanalu") in new stack
    -- Executing [h@SUB-POBIERZDANE:2] DumpChan("PJSIP/freephone-00000030", "") in new stack

Dumping Info For Channel: PJSIP/freephone-00000030:
================================================================================
Info:
Name=               PJSIP/freephone-00000030
Type=               PJSIP
UniqueID=           1548590683.93
LinkedID=           1548590683.93
CallerIDNum=        MYNUMBER
CallerIDName=       MYNUMBER
ConnectedLineIDNum= s
ConnectedLineIDName=(N/A)
DNIDDigits=         s
RDNIS=              (N/A)
Parkinglot=
Language=           en
State=              Up (6)
Rings=              1
NativeFormat=       (alaw)
WriteFormat=        alaw
ReadFormat=         alaw
RawWriteFormat=     alaw
RawReadFormat=      alaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  -1
Framesin=           830
Framesout=          556
TimetoHangup=       0
ElapsedTime=        0h0m19s
BridgeID=           (Not bridged)
Context=            SUB-POBIERZDANE
Extension=          h
Priority=           2
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
DIALSTATUS=ANSWER
DIALEDTIME=19
ANSWEREDTIME=19
DIALEDPEERNUMBER=9001
DIALEDPEERNAME=PJSIP/9001-00000031
x=
ODBCSTATUS=NODATA
ODBCROWS=0
DEVICESTATE=1
~ODBCFIELDS~=count(endpoint)
NRTEL=MYNUMER
NRWEW=9001
IDUSER=2
ARGC=0
RESULT=1
ID=7
READSTATUS=OK
KOD=112233
LOGIN=9001
ARGC=0
================================================================================
    -- Executing [h@SUB-POBIERZDANE:3] ExecIf("PJSIP/freephone-00000030", "1?Noop(Rozmowa odebrana):Set(x=)") in new stack
    -- Executing [h@SUB-POBIERZDANE:4] NoOp("PJSIP/freephone-00000030", "ANSWER") in new stack
    -- Executing [h@SUB-POBIERZDANE:5] NoOp("PJSIP/freephone-00000030", "7") in new stack
    -- Executing [h@SUB-POBIERZDANE:6] Hangup("PJSIP/freephone-00000030", "") in new stack
  == Spawn extension (SUB-POBIERZDANE, h, 6) exited non-zero on 'PJSIP/freephone-00000030'
psycholog*CLI>

Try this:

same => n,ExecIf($["${DIALSTATUS}"!="ANSWER"]?Set(x=${ODBC_ODBLOKUJKOD(${ID})}))

I modified dialplan as you seggest but problem still exist. Why I think i still not work properly? As I wrote before login and code are one-time code only, so before I placed a call to internal i exec {ODBC_ZABLOKUJKOD}. This make query on my database to inform system in future is this code are used. But if exists any reason i can't place a call i need to unlock that code - this is a role {ODBC_ODBLOKUJKOD}.
When call are established I see changes in my DB, and when I hangup a call DB again are changed.

Here is output

 == Using SIP RTP Audio CoS mark 5
    -- PJSIP/9001-0000003f is ringing
    -- PJSIP/9001-0000003f is ringing
    -- PJSIP/9001-0000003f answered PJSIP/freephone-0000003e
    -- Channel PJSIP/9001-0000003f joined 'simple_bridge' basic-bridge <3de7                                       54dd-2548-484f-a3fd-aab4a255968d>
    -- Channel PJSIP/freephone-0000003e joined 'simple_bridge' basic-bridge                                        <3de754dd-2548-484f-a3fd-aab4a255968d>
    -- Channel PJSIP/freephone-0000003e left 'simple_bridge' basic-bridge <3de754dd-2548-484f-a3fd-aab4a255968d>
  == Spawn extension (SUB-POBIERZDANE, s, 13) exited non-zero on 'PJSIP/freephone-0000003e'
    -- Executing [h@SUB-POBIERZDANE:1] NoOp("PJSIP/freephone-0000003e", "Rozlaczenie kanalu") in new stack
    -- Executing [h@SUB-POBIERZDANE:2] DumpChan("PJSIP/freephone-0000003e", "") in new stack
    -- Channel PJSIP/9001-0000003f left 'simple_bridge' basic-bridge <3de754dd-2548-484f-a3fd-aab4a255968d>

Dumping Info For Channel: PJSIP/freephone-0000003e:
================================================================================
Info:
Name=               PJSIP/freephone-0000003e
Type=               PJSIP
UniqueID=           1548691901.122
LinkedID=           1548691901.122
CallerIDNum=        number
CallerIDName=       number
ConnectedLineIDNum= s
ConnectedLineIDName=(N/A)
DNIDDigits=         s
RDNIS=              (N/A)
Parkinglot=
Language=           en
State=              Up (6)
Rings=              1
NativeFormat=       (alaw)
WriteFormat=        alaw
ReadFormat=         alaw
RawWriteFormat=     alaw
RawReadFormat=      alaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  -1
Framesin=           1339
Framesout=          1151
TimetoHangup=       0
ElapsedTime=        0h0m30s
BridgeID=           (Not bridged)
Context=            SUB-POBIERZDANE
Extension=          h
Priority=           2
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
DIALSTATUS=ANSWER
DIALEDTIME=30
ANSWEREDTIME=30
DIALEDPEERNUMBER=9001
DIALEDPEERNAME=PJSIP/9001-0000003f
x=
ODBCSTATUS=NODATA
ODBCROWS=0
DEVICESTATE=1
~ODBCFIELDS~=count(endpoint)
NRTEL=number
NRWEW=9001
IDUSER=2
ARGC=0
RESULT=1
ID=7
READSTATUS=OK
KOD=112233
LOGIN=9001
ARGC=0
================================================================================
    -- Executing [h@SUB-POBIERZDANE:3] NoOp("PJSIP/freephone-0000003e", "ANSWER") in new stack
    -- Executing [h@SUB-POBIERZDANE:4] ExecIf("PJSIP/freephone-0000003e", "0?Set(x=)") in new stack
    -- Executing [h@SUB-POBIERZDANE:5] NoOp("PJSIP/freephone-0000003e", "7") in new stack
    -- Executing [h@SUB-POBIERZDANE:6] Hangup("PJSIP/freephone-0000003e", "") in new stack
  == Spawn extension (SUB-POBIERZDANE, h, 6) exited non-zero on 'PJSIP/freephone-0000003e'

– Executing [h@SUB-POBIERZDANE:3] ExecIf(“PJSIP/freephone-00000030”, “1?Noop(Rozmowa odebrana):Set(x=)”) in new stack

OK so this is your original debug. The 1 before the ? means that your ExecIf was true. Since you ExecIf should return turn only if the DIALSTATUS is not ANSWER and in this case it is, that is incorrect. It should not be true it should be false.

– Executing [h@SUB-POBIERZDANE:4] ExecIf(“PJSIP/freephone-0000003e”, “0?Set(x=)”) in new stack

This is the debug after my suggested changes. Notice the 0 this time before the ?. This means the ExecIf returned false. So it does not execute the Set command.

These are going to show up in your log the difference is in the 1 or 0 before the ? because that tells you the result. 1 = true and 0 = false.

Dosent matter. It was execute always. If 0 or 1 i think this is a bug

OK so if you are still getting DB hits regardless of true or false the only other thing I can think of is that you’re not offering up a false option. By that I mean there is no : at the end of your ExecIf so it may be treating your Set() to run on either result.

Try this. Note the : at the end now. same => n,ExecIf($["${DIALSTATUS}"!="ANSWER"]?Set(x=${ODBC_ODBLOKUJKOD(${ID})}):)

Ok, I’am back. I modified my dialplan to this

exten => h,1,Noop(Rozlaczenie kanalu)
        same => n,DumpChan()
;       same => n,ExecIF($[${DIALSTATUS}=ANSWER]?Noop(Rozmowa odebrana):Set(x=${ODBC_ODBLOKUJKOD(${ID})}))
        same => n,Noop(${DIALSTATUS})
        same => n,ExecIf($["${DIALSTATUS}"!="ANSWER"]?Set(x=${ODBC_ODBLOKUJKOD(${ID})}):Noop(FALSE))
        same => n,Noop(${ID})
        same => n,Hangup

But database are still modified

    -- PJSIP/9001-00000042 is ringing
    -- PJSIP/9001-00000042 is ringing
    -- PJSIP/9001-00000042 answered PJSIP/freephone-00000041
    -- Channel PJSIP/9001-00000042 joined 'simple_bridge' basic-bridge <9d9deb07-7554-4a4c-84de-08e5099f65e2>
    -- Channel PJSIP/freephone-00000041 joined 'simple_bridge' basic-bridge <9d9deb07-7554-4a4c-84de-08e5099f65e2>
    -- Channel PJSIP/freephone-00000041 left 'simple_bridge' basic-bridge <9d9deb07-7554-4a4c-84de-08e5099f65e2>
    -- Channel PJSIP/9001-00000042 left 'simple_bridge' basic-bridge <9d9deb07-7554-4a4c-84de-08e5099f65e2>
  == Spawn extension (SUB-POBIERZDANE, s, 13) exited non-zero on 'PJSIP/freephone-00000041'
    -- Executing [h@SUB-POBIERZDANE:1] NoOp("PJSIP/freephone-00000041", "Rozlaczenie kanalu") in new stack
    -- Executing [h@SUB-POBIERZDANE:2] DumpChan("PJSIP/freephone-00000041", "") in new stack

Dumping Info For Channel: PJSIP/freephone-00000041:
================================================================================
Info:
Name=               PJSIP/freephone-00000041
Type=               PJSIP
UniqueID=           1548698782.129
LinkedID=           1548698782.129
CallerIDNum=        x
CallerIDName=       x
ConnectedLineIDNum= s
ConnectedLineIDName=(N/A)
DNIDDigits=         s
RDNIS=              (N/A)
Parkinglot=
Language=           en
State=              Up (6)
Rings=              1
NativeFormat=       (alaw)
WriteFormat=        alaw
ReadFormat=         alaw
RawWriteFormat=     alaw
RawReadFormat=      alaw
WriteTranscode=     No
ReadTranscode=      No
1stFileDescriptor=  -1
Framesin=           2044
Framesout=          1790
TimetoHangup=       0
ElapsedTime=        0h0m43s
BridgeID=           (Not bridged)
Context=            SUB-POBIERZDANE
Extension=          h
Priority=           2
CallGroup=
PickupGroup=
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
DIALSTATUS=ANSWER
DIALEDTIME=43
ANSWEREDTIME=43
DIALEDPEERNUMBER=9001
DIALEDPEERNAME=PJSIP/9001-00000042
x=
ODBCSTATUS=NODATA
ODBCROWS=0
DEVICESTATE=1
~ODBCFIELDS~=count(endpoint)
NRTEL=x
NRWEW=9001
IDUSER=2
ARGC=0
RESULT=1
ID=7
READSTATUS=OK
KOD=112233
LOGIN=9001
ARGC=0
================================================================================
    -- Executing [h@SUB-POBIERZDANE:3] NoOp("PJSIP/freephone-00000041", "ANSWER") in new stack
    -- Executing [h@SUB-POBIERZDANE:4] ExecIf("PJSIP/freephone-00000041", "0?Set(x=):Noop(FALSE)") in new stack
    -- Executing [h@SUB-POBIERZDANE:5] NoOp("PJSIP/freephone-00000041", "7") in new stack
    -- Executing [h@SUB-POBIERZDANE:6] Hangup("PJSIP/freephone-00000041", "") in new stack
  == Spawn extension (SUB-POBIERZDANE, h, 6) exited non-zero on 'PJSIP/freephone-00000041'

Variables and functions are basically processed as text macros. That means that functions which are not pure functions will have their side effects, even in the branch that is not executed.

1 Like

I found an workaround.

exten => h,1,Noop(Rozlaczenie kanalu)
        same => n,DumpChan()
        same => n,Noop(${ID})
        same => n,GotoIf($["${DIALSTATUS}"="ANSWER"]?END)
        same => n,Set(x=${ODBC_ODBLOKUJKOD(${ID})})
        same => n(END),Hangup
1 Like