diff --git a/libs/js/src/jspubtd.h b/libs/js/src/jspubtd.h index 05d7282fdf..02a9c1e574 100644 --- a/libs/js/src/jspubtd.h +++ b/libs/js/src/jspubtd.h @@ -552,7 +552,7 @@ typedef void * JSEXN_NONE marks an unthrowable error. */ typedef enum JSExnType { - JSEXN_NONE = -1, + JSEXN_NONE, JSEXN_ERR, JSEXN_INTERNALERR, JSEXN_EVALERR, diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index 88d01e11ce..ccf995e495 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -733,7 +733,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void * */ SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes); -SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename); +SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool); /** @} */ diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index a9cc48d610..8e499c6ca6 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -2771,7 +2771,7 @@ static void message_query_handler(switch_event_t *event) path = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR); assert(path != NULL); - if (switch_file_exists(path) == SWITCH_STATUS_SUCCESS) { + if (switch_file_exists(path, NULL) == SWITCH_STATUS_SUCCESS) { cmd = switch_mprintf("%s %s", path, account); assert(cmd != NULL); js_thread_launch(cmd); diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h index 24486d8339..323d8bbb44 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h @@ -91,7 +91,7 @@ int eval_some_js(char *code, JSContext * cx, JSObject * obj, jsval * rval) script_name = path; } if (script_name) { - if (switch_file_exists(script_name) == SWITCH_STATUS_SUCCESS) { + if (switch_file_exists(script_name, NULL) == SWITCH_STATUS_SUCCESS) { script = JS_CompileFile(cx, obj, script_name); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name); diff --git a/src/switch_apr.c b/src/switch_apr.c index 7a25a9a327..076344bb3a 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -335,17 +335,31 @@ SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const return apr_file_write(thefile, buf, nbytes); } -SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename) +SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool) { int32_t wanted = APR_FINFO_TYPE; + switch_memory_pool_t *our_pool = NULL; + switch_status_t status = SWITCH_STATUS_FALSE; apr_finfo_t info = { 0 }; - if (filename) { - apr_stat(&info, filename, wanted, NULL); - if (info.filetype != APR_NOFILE) { - return SWITCH_STATUS_SUCCESS; + + if (!pool) { + if ((apr_pool_create(&our_pool, NULL)) != SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_MEMERR; } } - return SWITCH_STATUS_FALSE; + + if (filename) { + apr_stat(&info, filename, wanted, pool ? pool : our_pool); + if (info.filetype != APR_NOFILE) { + status = SWITCH_STATUS_SUCCESS; + } + } + + if (our_pool) { + apr_pool_destroy(our_pool); + } + + return status; } /* thread stubs */