--- pbx.old.c 2009-02-21 00:04:33.000000000 +0100 +++ pbx.c 2009-07-31 14:39:26.000000000 +0200 @@ -3661,6 +3661,7 @@ int res = 0; int autoloopflag; int error = 0; /* set an error conditions */ + const char *emc; /* A little initial setup here */ if (c->pbx) { @@ -3857,9 +3858,16 @@ ast_softhangup(c, c->hangupcause ? c->hangupcause : AST_CAUSE_NORMAL_CLEARING); } + if ((emc = pbx_builtin_getvar_helper(c, "EXIT_MACRO_CONTEXT"))) { + emc = ast_strdupa(emc); + } + if ((!args || !args->no_hangup_chan) && !ast_test_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN) && - ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) { + ((emc && ast_exists_extension(c, emc, "h", 1, c->cid.cid_num)) || + (ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num) && (emc = c->context))) + ) { + ast_copy_string(c->context, emc, sizeof(c->context)); set_ext_pri(c, "h", 1); if (c->cdr && ast_opt_end_cdr_before_h_exten) { ast_cdr_end(c->cdr);