fix a few js issues

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3472 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-11-28 20:52:04 +00:00
parent a85ec77f99
commit d3758afbae
3 changed files with 24 additions and 27 deletions

View File

@ -409,7 +409,7 @@ static void js_error(JSContext *cx, const char *message, JSErrorReport *report)
}
static switch_status_t sm_load_file(char *filename, sm_loadable_module_t **new_module)
static switch_status_t sm_load_file(char *filename)
{
sm_loadable_module_t *module = NULL;
apr_dso_handle_t *dso = NULL;
@ -424,7 +424,6 @@ static switch_status_t sm_load_file(char *filename, sm_loadable_module_t **new_m
assert(filename != NULL);
*new_module = NULL;
status = apr_dso_load(&dso, filename, module_manager.pool);
while (loading) {
@ -447,7 +446,7 @@ static switch_status_t sm_load_file(char *filename, sm_loadable_module_t **new_m
break;
}
if ((module = switch_core_permanent_alloc(sizeof(sm_loadable_module_t))) == 0) {
if (!(module = (sm_loadable_module_t *) switch_core_permanent_alloc(sizeof(*module)))) {
err = "Could not allocate memory\n";
break;
}
@ -465,11 +464,10 @@ static switch_status_t sm_load_file(char *filename, sm_loadable_module_t **new_m
module->module_interface = module_interface;
module->lib = dso;
*new_module = module;
switch_core_hash_insert(module_manager.mod_hash, (char *) module->filename, (void *) module);
for (mp = module_interface; mp; mp = mp->next) {
for (mp = module->module_interface; mp; mp = mp->next) {
switch_core_hash_insert(module_manager.load_hash, (char *)mp->name, (void *) mp);
}
@ -484,7 +482,6 @@ static switch_status_t sm_load_module(char *dir, char *fname)
switch_size_t len = 0;
char *path;
char *file;
sm_loadable_module_t *new_module = NULL;
#ifdef WIN32
const char *ext = ".dll";
@ -517,7 +514,7 @@ static switch_status_t sm_load_module(char *dir, char *fname)
}
}
return sm_load_file(path, &new_module);
return sm_load_file(path);
}
static switch_status_t load_modules(void)
@ -961,6 +958,13 @@ static JSBool session_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval
}
}
if (argc > 4) {
int32 samps;
uint32_t pos = 0;
JS_ValueToInt32(cx, argv[4], &samps);
switch_core_file_seek(&fh, &pos, samps, SEEK_CUR);
}
memset(&fh, 0, sizeof(fh));
cb_state.extra = &fh;
cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
@ -1214,13 +1218,13 @@ static JSBool session_execute(JSContext *cx, JSObject *obj, uintN argc, jsval *a
char *app_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *app_arg = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
struct js_session *jss = JS_GetPrivate(cx, obj);
jsrefcount saveDepth;
//jsrefcount saveDepth;
if ((application_interface = switch_loadable_module_get_application_interface(app_name))) {
if (application_interface->application_function) {
saveDepth = JS_SuspendRequest(cx);
//saveDepth = JS_SuspendRequest(cx);
application_interface->application_function(jss->session, app_arg);
JS_ResumeRequest(cx, saveDepth);
//JS_ResumeRequest(cx, saveDepth);
retval = JS_TRUE;
}
}

View File

@ -31,7 +31,7 @@
*/
#include "mod_spidermonkey.h"
static const char modname[] = "DB";
static const char modname[] = "CoreDB";
struct db_obj {
switch_memory_pool_t *pool;
@ -148,10 +148,9 @@ static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
if (dbo->stmt) {
int running = 1;
if (dbo->stmt) {
int running = 1;
while (running < 5000) {
int result = switch_core_db_step(dbo->stmt);
if (result == SQLITE_ROW) {
@ -210,10 +209,9 @@ static JSBool db_prepare(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
dbo->stmt = NULL;
}
if (argc > 0) {
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if(switch_core_db_prepare(dbo->db, sql, 0, &dbo->stmt, 0)) {
if(switch_core_db_prepare(dbo->db, sql, -1, &dbo->stmt, 0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(dbo->db));
} else {
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
@ -266,18 +264,14 @@ static JSBool db_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
JSClass db_class = {
"DB", JSCLASS_HAS_PRIVATE,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, db_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, db_destroy, NULL, NULL, NULL,
db_construct
};
switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
switch_status_t db_load(JSContext *cx, JSObject *obj)
{
JS_InitClass(cx,
@ -291,14 +285,13 @@ switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
db_props,
db_methods
);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t DB_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ spidermonkey_load,
/*.spidermonkey_load*/ db_load,
/*.next*/ NULL
};

View File

@ -357,7 +357,7 @@ JSClass teletone_class = {
};
switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
switch_status_t teletone_load(JSContext *cx, JSObject *obj)
{
JS_InitClass(cx,
obj,
@ -376,7 +376,7 @@ switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
const sm_module_interface_t teletone_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ spidermonkey_load,
/*.spidermonkey_load*/ teletone_load,
/*.next*/ NULL
};