try to avoid skipping hangup hook

This commit is contained in:
Anthony Minessale 2010-07-23 14:11:47 -05:00
parent c98b863181
commit 710376fbe8
2 changed files with 24 additions and 13 deletions

View File

@ -1608,7 +1608,7 @@ static jsval check_hangup_hook(struct js_session *jss, jsval * rp)
jsval ret = JS_TRUE; jsval ret = JS_TRUE;
char *resp; char *resp;
if (!jss->check_state && jss->on_hangup && (jss->hook_state == CS_HANGUP || jss->hook_state == CS_ROUTING)) { if (jss && !jss->check_state && jss->on_hangup && (jss->hook_state == CS_HANGUP || jss->hook_state == CS_ROUTING)) {
jss->check_state++; jss->check_state++;
argv[argc++] = OBJECT_TO_JSVAL(jss->obj); argv[argc++] = OBJECT_TO_JSVAL(jss->obj);
if (jss->hook_state == CS_HANGUP) { if (jss->hook_state == CS_HANGUP) {
@ -1637,6 +1637,9 @@ static switch_status_t hanguphook(switch_core_session_t *session)
if ((jss = switch_channel_get_private(channel, "jss"))) { if ((jss = switch_channel_get_private(channel, "jss"))) {
switch_channel_state_t state = switch_channel_get_state(channel); switch_channel_state_t state = switch_channel_get_state(channel);
if (state > CS_HANGUP) {
state = CS_HANGUP;
}
if (jss->hook_state != state) { if (jss->hook_state != state) {
jss->hook_state = state; jss->hook_state = state;
jss->check_state = 0; jss->check_state = 0;
@ -2375,21 +2378,24 @@ static JSBool session_hangup(JSContext * cx, JSObject * obj, uintN argc, jsval *
METHOD_SANITY_CHECK(); METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session); channel = switch_core_session_get_channel(jss->session);
CHANNEL_SANITY_CHECK(); //CHANNEL_SANITY_CHECK();
if (argc > 1) { if (switch_channel_up(channel)) {
if (JSVAL_IS_INT(argv[0])) { if (argc > 1) {
int32 i = 0; if (JSVAL_IS_INT(argv[0])) {
JS_ValueToInt32(cx, argv[0], &i); int32 i = 0;
cause = i; JS_ValueToInt32(cx, argv[0], &i);
} else { cause = i;
cause_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); } else {
cause = switch_channel_str2cause(cause_name); cause_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
cause = switch_channel_str2cause(cause_name);
}
} }
switch_channel_hangup(channel, cause);
switch_core_session_kill_channel(jss->session, SWITCH_SIG_KILL);
} }
switch_channel_hangup(channel, cause);
switch_core_session_kill_channel(jss->session, SWITCH_SIG_KILL);
return JS_TRUE; return JS_TRUE;
} }
@ -3051,6 +3057,10 @@ static void session_destroy(JSContext * cx, JSObject * obj)
if (cx && obj) { if (cx && obj) {
if ((jss = JS_GetPrivate(cx, obj))) { if ((jss = JS_GetPrivate(cx, obj))) {
jsval rval;
check_hangup_hook(jss, &rval);
JS_SetPrivate(cx, obj, NULL); JS_SetPrivate(cx, obj, NULL);
if (jss->speech && *jss->speech->sh.name) { if (jss->speech && *jss->speech->sh.name) {
destroy_speech_engine(jss); destroy_speech_engine(jss);
@ -3623,7 +3633,7 @@ static void js_parse_and_execute(switch_core_session_t *session, const char *inp
const char *script; const char *script;
int argc = 0, x = 0, y = 0; int argc = 0, x = 0, y = 0;
unsigned int flags = 0; unsigned int flags = 0;
struct js_session *jss; struct js_session *jss = NULL;
JSContext *cx = NULL; JSContext *cx = NULL;
jsval rval; jsval rval;

View File

@ -1235,6 +1235,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
runtime.max_dtmf_duration = SWITCH_MAX_DTMF_DURATION; runtime.max_dtmf_duration = SWITCH_MAX_DTMF_DURATION;
runtime.default_dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION; runtime.default_dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION;
runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION; runtime.min_dtmf_duration = SWITCH_MIN_DTMF_DURATION;
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
/* INIT APR and Create the pool context */ /* INIT APR and Create the pool context */
if (apr_initialize() != SWITCH_STATUS_SUCCESS) { if (apr_initialize() != SWITCH_STATUS_SUCCESS) {