[Home]

Summary:ASTERISK-13519: calling Gosub in macro does not work if the invalid extension is triggered
Reporter:klaus3000 (klaus3000)Labels:
Date Opened:2009-02-05 05:39:26.000-0600Date Closed:2011-06-07 14:08:26
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Applications/app_macro
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20090206__bug14411.diff.txt
Description:Hi!

Consider the following example:

macro blacklistMakro() {
 Gosub(blacklist_${BLACKLIST}|${MACRO_EXTEN}|1);
 return;
}

context blacklist_SIMPLE {
 _+49. => Hangup();
 i =>Return();
}

If the Gosub call inside the macro triggers the i extension, MACRO_DEPTH is set to 0, the macro "forgets" that it is a macrom, and does not return (auto fallthrough happens)

Comments:By: klaus3000 (klaus3000) 2009-02-05 05:47:54.000-0600

Severity should be minor

By: Tilghman Lesher (tilghman) 2009-02-05 10:07:35.000-0600

This isn't a case of the i extension being triggered.  This is a case of you trying to go to an extension which does not exist and so the Macro exits.  You CANNOT trigger the i extension without using a WaitExten or Background.

By: klaus3000 (klaus3000) 2009-02-05 13:14:14.000-0600

So why does Gosub behave different if called from within a macro or called from another context?

By: klaus3000 (klaus3000) 2009-02-05 13:36:17.000-0600

> This is a case of you trying to go to an extension which does not exist and so the Macro exits.

But all my priorities in the i extension are executed fine. Thus, the i extension IS triggered.

By: Tilghman Lesher (tilghman) 2009-02-05 14:15:21.000-0600

No, you attempted to go to an extension which didn't exist, the Gosub failed, it continued onto the next priority, and the Macro exited.

By: klaus3000 (klaus3000) 2009-02-05 15:01:31.000-0600

If I have this one:

context blacklist_SIMPLE {
 _+49. => Hangup();
 i => {
   Wait(30);
   Return();
 }
}

The Wait() is executed. So what failed here? Nothing. The i extension is executed.



By: klaus3000 (klaus3000) 2009-02-05 15:07:03.000-0600

> This is a case of you trying to go to an extension which does not exist and so the Macro exits.

Maybe this is the behavior - but IMO this should not be the behavior.

The macro gosubs in another context - whatever in the context happens should not break the macro. The macro should be stopped with a "return" or with an explicit jump/goto.

By: Tilghman Lesher (tilghman) 2009-02-05 16:54:25.000-0600

Show me your dialplan output where this works.  I just mocked it up, and it behaves the way I documented:

   -- Executing [8144@digium:1] Gosub("SIP/103-084a0240", "invalid_wont_work,200,1") in new stack
[Feb  5 16:52:46] ERROR[25454]: app_stack.c:387 gosub_exec: Attempt to reach a non-existent destination for gosub: (Context:invalid_wont_work, Extension:200, Priority:0)
 == Spawn extension (digium, 8144, 2) exited non-zero on 'SIP/103-084a0240'

By: klaus3000 (klaus3000) 2009-02-05 23:23:50.000-0600

No problem: (I am using Asterisk 1.4.23)

context fromPhone {
       _+. => {
               NoOp(fromPhone: Calling test1 (valid extension) ...);
               Gosub(test1,${EXTEN},1);
               NoOp(fromPhone: Returned from test1 ...);

               NoOp(fromPhone: Calling test2 (invalid extension) ...);
               Gosub(test2,${EXTEN},1);
               NoOp(fromPhone: Returned from test2 ...);

               NoOp(fromPhone: Calling macro1 ...);
               &testMacro1();
               NoOp(fromPhone: Returned from macro1 ...);

               NoOp(fromPhone: Calling macro2 ...);
               &testMacro2();
               NoOp(fromPhone: Returned from macro2 ...);
       }
}

macro testMacro1() {
       NoOp(testMacro1: Calling test1 (valid extension) ...);
       Gosub(test1,${MACRO_EXTEN},1);
       NoOp(testMacro1: Returned from test1 ...);

       return;
}

macro testMacro2() {
       NoOp(testMacro2: Calling test2 (invalid extension) ...);
       Gosub(test2,${MACRO_EXTEN},1);
       NoOp(testMacro2: Returned from test2 ...);

       return;
}

context test1 {
       _+. => {
               NoOp(test1: test1 entered (valid extension) ...);
               Return();
       }
}
context test2 {
       i => {
               NoOp(test2: test2 entered (invalid extension) ...);
               Return();
       }
}



 -- Executing [+12345@fromPhone:1] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Calling test1 (valid extension) ...") in new stack
 -- Executing [+12345@fromPhone:2] Gosub("SIP/u+437206200730151-b58028b8", "test1|+12345|1") in new stack
 -- Executing [+12345@test1:1] NoOp("SIP/u+437206200730151-b58028b8", "test1: test1 entered (valid extension) ...") in new stack
 -- Executing [+12345@test1:2] Return("SIP/u+437206200730151-b58028b8", "") in new stack
 -- Executing [+12345@fromPhone:3] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Returned from test1 ...") in new stack
 -- Executing [+12345@fromPhone:4] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Calling test2 (invalid extension) ...") in new stack
 -- Executing [+12345@fromPhone:5] Gosub("SIP/u+437206200730151-b58028b8", "test2|+12345|1") in new stack
 -- Sent into invalid extension '+12345' in context 'test2' on SIP/u+437206200730151-b58028b8
 -- Executing [i@test2:1] NoOp("SIP/u+437206200730151-b58028b8", "test2: test2 entered (invalid extension) ...") in new stack
 -- Executing [i@test2:2] Return("SIP/u+437206200730151-b58028b8", "") in new stack
 -- Executing [+12345@fromPhone:6] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Returned from test2 ...") in new stack
 -- Executing [+12345@fromPhone:7] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Calling macro1 ...") in new stack
 -- Executing [+12345@fromPhone:8] Macro("SIP/u+437206200730151-b58028b8", "testMacro1") in new stack
 -- Executing [s@macro-testMacro1:1] NoOp("SIP/u+437206200730151-b58028b8", "testMacro1: Calling test1 (valid extension) ...") in new stack
 -- Executing [s@macro-testMacro1:2] Gosub("SIP/u+437206200730151-b58028b8", "test1|+12345|1") in new stack
 -- Executing [+12345@test1:1] NoOp("SIP/u+437206200730151-b58028b8", "test1: test1 entered (valid extension) ...") in new stack
 -- Executing [+12345@test1:2] Return("SIP/u+437206200730151-b58028b8", "") in new stack
 -- Executing [s@macro-testMacro1:3] NoOp("SIP/u+437206200730151-b58028b8", "testMacro1: Returned from test1 ...") in new stack
 -- Executing [s@macro-testMacro1:4] Goto("SIP/u+437206200730151-b58028b8", "5") in new stack
 -- Goto (macro-testMacro1,s,5)
 -- Executing [s@macro-testMacro1:5] NoOp("SIP/u+437206200730151-b58028b8", "End of Macro testMacro1-s") in new stack
 -- Executing [+12345@fromPhone:9] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Returned from macro1 ...") in new stack
 -- Executing [+12345@fromPhone:10] NoOp("SIP/u+437206200730151-b58028b8", "fromPhone: Calling macro2 ...") in new stack
 -- Executing [+12345@fromPhone:11] Macro("SIP/u+437206200730151-b58028b8", "testMacro2") in new stack
 -- Executing [s@macro-testMacro2:1] NoOp("SIP/u+437206200730151-b58028b8", "testMacro2: Calling test2 (invalid extension) ...") in new stack
 -- Executing [s@macro-testMacro2:2] Gosub("SIP/u+437206200730151-b58028b8", "test2|+12345|1") in new stack
 -- Sent into invalid extension '+12345' in context 'test2' on SIP/u+437206200730151-b58028b8
 -- Executing [i@test2:1] NoOp("SIP/u+437206200730151-b58028b8", "test2: test2 entered (invalid extension) ...") in new stack
 -- Executing [i@test2:2] Return("SIP/u+437206200730151-b58028b8", "") in new stack
 -- Executing [s@macro-testMacro2:3] NoOp("SIP/u+437206200730151-b58028b8", "testMacro2: Returned from test2 ...") in new stack
 -- Executing [s@macro-testMacro2:4] Goto("SIP/u+437206200730151-b58028b8", "5") in new stack
 -- Goto (macro-testMacro2,s,5)
 -- Executing [s@macro-testMacro2:5] NoOp("SIP/u+437206200730151-b58028b8", "End of Macro testMacro2-s") in new stack
== Auto fallthrough, channel 'SIP/u+437206200730151-b58028b8' status is 'UNKNOWN'

By: klaus3000 (klaus3000) 2009-02-06 17:52:20.000-0600

will test in a week - going on holidays

By: Leif Madsen (lmadsen) 2009-04-15 18:38:31

Pinging this issue?

By: klaus3000 (klaus3000) 2009-04-16 02:28:54

there was lots of discussion on the mailing lists about 'i' extension in Gosub(). IIRC the final decision was that the i extension should not trigger. Thus, this bug report became invalid.

By: Leif Madsen (lmadsen) 2009-04-16 08:04:04

Closed due to comments by klaus3000