Gosub and ‘h’ (again?)

Home » Asterisk Users » Gosub and ‘h’ (again?)
Asterisk Users 2 Comments

Problem as follows:

exten => 777,1,Gosub(sub,1,1)
exten => 777,n,Hangup()
exten => h,1,NoOp(hung up in ‘default’ context)

exten => 1,1,NoOp(in sub)
exten => 1,n,Playback(tt-monkeys)
exten => 1,n,Return()
exten => h,1,NoOp(hung up in ‘sub’ context)

This works fine if the caller listens to all the ‘tt-monkeys’ and let’s
the system hangup. You get the hang up in the ‘default’ context.

But, if the caller hangs up BEFORE the end of ‘tt-monkeys’ – the hang up
occurs in the ‘sub’ context. This means that I have to force each sub
routine to go to the main contexts ‘h’ extension (‘exten =>
h,1,Goto(default,h,1)’ in this case).

Is there a way to tell * to use the default ‘h’ extension on a hang up –
rather than having to put a ‘h’ in to every separate sub routine?

I know Tilghman said “…Gosub, on the other hand, isn’t really even
executing at that point, so there isn’t a code path that exists whereby
the Gosub can empty the return stack and return to the original
place….” [see

But what does that mean in English ;)?


If you have received this communication in error we would appreciate
you advising us either by telephone or return of e-mail. The contents
of this message, and any attachments, are the property of DataVox,
and are intended for the confidential use of the named recipient only.
If you are not the intended recipient, employee or agent responsible
for delivery of this message to the intended recipient, take note that
any dissemination, distribution or copying of this communication and
its attachments is strictly prohibited, and may be subject to civil or
criminal action for which you may be liable.
Every effort has been made to ensure that this e-mail or any attachments
are free from viruses. While the company has taken every reasonable
precaution to minimise this risk, neither company, nor the sender can
accept liability for any damage which you sustain as a result of viruses.
It is recommended that you should carry out your own virus checks
before opening any attachments.

Registered in England. No. 27459085.

2 thoughts on - Gosub and ‘h’ (again?)

  • Well a solution for you to put original context name in variable and then
    use that variable in goto statement on h.

  • Thanks for your reply – but I did it a slightly different way:

    “Nevermind – I’ve re-written my dialplan so that all subs are in one
    context. Now I only need 1 more line of code.”

    Thanks anyway 🙂