提交 4e1d518c authored 作者: Anthony Minessale's avatar Anthony Minessale

spidermonkey has it's own loadable modules now good luck

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3307 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 964aec99
...@@ -75,6 +75,13 @@ ...@@ -75,6 +75,13 @@
</modules> </modules>
</configuration> </configuration>
<configuration name="spidermonkey.conf" description="Spider Monkey JavaScript Plug-Ins">
<modules>
<load module="mod_spidermonkey_teletone"/>
<load module="mod_spidermonkey_core_db"/>
</modules>
</configuration>
<configuration name="event_multicast.conf" description="Multicast Event"> <configuration name="event_multicast.conf" description="Multicast Event">
<settings> <settings>
<param name="address" value="225.1.1.1"/> <param name="address" value="225.1.1.1"/>
......
...@@ -41,5 +41,7 @@ formats/mod_native_file ...@@ -41,5 +41,7 @@ formats/mod_native_file
formats/mod_sndfile formats/mod_sndfile
#languages/mod_perl #languages/mod_perl
#languages/mod_spidermonkey #languages/mod_spidermonkey
#languages/mod_spidermonkey_teletone
#languages/mod_spidermonkey_core_db
timers/mod_softtimer timers/mod_softtimer
#xml_int/mod_xml_rpc #xml_int/mod_xml_rpc
# This is all used to make sure we use the right options during build and link. include sm.mak
OS_ARCH := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
#VER=DBG
#BO=0
VER=OPT
BO=1
# Attempt to differentiate between SunOS 5.4 and x86 5.4
OS_CPUARCH := $(shell uname -m)
ifeq ($(OS_CPUARCH),i86pc)
OS_RELEASE := $(shell uname -r)_$(OS_CPUARCH)
else
ifeq ($(OS_ARCH),AIX)
OS_RELEASE := $(shell uname -v).$(shell uname -r)
else
OS_RELEASE := $(shell uname -r)
endif
endif
ifeq ($(OS_ARCH),IRIX64)
OS_ARCH := IRIX
endif
# Handle output from win32 unames other than Netscape's version
ifeq (,$(filter-out Windows_95 Windows_98 CYGWIN_95-4.0 CYGWIN_98-4.10, $(OS_ARCH)))
OS_ARCH := WIN95
endif
ifeq ($(OS_ARCH),WIN95)
OS_ARCH := WINNT
OS_RELEASE := 4.0
endif
ifeq ($(OS_ARCH), Windows_NT)
OS_ARCH := WINNT
OS_MINOR_RELEASE := $(shell uname -v)
ifeq ($(OS_MINOR_RELEASE),00)
OS_MINOR_RELEASE = 0
endif
OS_RELEASE := $(OS_RELEASE).$(OS_MINOR_RELEASE)
endif
ifeq (CYGWIN_NT,$(findstring CYGWIN_NT,$(OS_ARCH)))
OS_RELEASE := $(patsubst CYGWIN_NT-%,%,$(OS_ARCH))
OS_ARCH := WINNT
endif
ifeq ($(OS_ARCH), CYGWIN32_NT)
OS_ARCH := WINNT
endif
ifeq (MINGW32_NT,$(findstring MINGW32_NT,$(OS_ARCH)))
OS_RELEASE := $(patsubst MINGW32_NT-%,%,$(OS_ARCH))
OS_ARCH := WINNT
endif
ifeq ($(OS_ARCH),Linux)
OS_CONFIG := Linux_All
else
ifeq ($(OS_ARCH),dgux)
OS_CONFIG := dgux
else
ifeq ($(OS_ARCH),Darwin)
OS_CONFIG := Darwin
else
OS_CONFIG := $(OS_ARCH)$(OS_OBJTYPE)$(OS_RELEASE)
endif
endif
endif
CFLAGS += -I$(BASE)/libs/mozilla/js/src -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/js/src -I$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -I$(OS_CONFIG)_$(VER).OBJ
LDFLAGS +=-DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -lteletone
OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a -lcurl -letpan OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a -lcurl -letpan
LINKER=$(CC) LINKER=$(CC)
......
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_spidermonkey.h -- Javascript Module
*
*/
#ifndef SWITCH_MOD_SPIDERMONKEY_H
#define SWITCH_MOD_SPIDERMONKEY_H
#include <switch.h>
#include "jstypes.h"
#include "jsarena.h"
#include "jsutil.h"
#include "jsprf.h"
#include "jsapi.h"
#include "jsatom.h"
#include "jscntxt.h"
#include "jsdbgapi.h"
#include "jsemit.h"
#include "jsfun.h"
#include "jsgc.h"
#include "jslock.h"
#include "jsobj.h"
#include "jsparse.h"
#include "jsscope.h"
#include "jsscript.h"
#include <libteletone.h>
SWITCH_BEGIN_EXTERN_C
#define JS_BUFFER_SIZE 1024 * 32
#define JS_BLOCK_SIZE JS_BUFFER_SIZE
#ifdef __ICC
#pragma warning (disable:310 193 1418)
#endif
SWITCH_DECLARE(int) eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval);
typedef switch_status_t(*spidermonkey_load_t)(JSContext *cx, JSObject *obj);
struct sm_module_interface {
const char *name;
spidermonkey_load_t spidermonkey_load;
const struct sm_module_interface *next;
};
typedef struct sm_module_interface sm_module_interface_t;
typedef switch_status_t(*spidermonkey_init_t)(const sm_module_interface_t **module_interface);
struct js_session {
switch_core_session_t *session;
JSContext *cx;
JSObject *obj;
unsigned int flags;
};
SWITCH_END_EXTERN_C
#endif
# This is all used to make sure we use the right options during build and link.
OS_ARCH := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
#VER=DBG
#BO=0
VER=OPT
BO=1
# Attempt to differentiate between SunOS 5.4 and x86 5.4
OS_CPUARCH := $(shell uname -m)
ifeq ($(OS_CPUARCH),i86pc)
OS_RELEASE := $(shell uname -r)_$(OS_CPUARCH)
else
ifeq ($(OS_ARCH),AIX)
OS_RELEASE := $(shell uname -v).$(shell uname -r)
else
OS_RELEASE := $(shell uname -r)
endif
endif
ifeq ($(OS_ARCH),IRIX64)
OS_ARCH := IRIX
endif
# Handle output from win32 unames other than Netscape's version
ifeq (,$(filter-out Windows_95 Windows_98 CYGWIN_95-4.0 CYGWIN_98-4.10, $(OS_ARCH)))
OS_ARCH := WIN95
endif
ifeq ($(OS_ARCH),WIN95)
OS_ARCH := WINNT
OS_RELEASE := 4.0
endif
ifeq ($(OS_ARCH), Windows_NT)
OS_ARCH := WINNT
OS_MINOR_RELEASE := $(shell uname -v)
ifeq ($(OS_MINOR_RELEASE),00)
OS_MINOR_RELEASE = 0
endif
OS_RELEASE := $(OS_RELEASE).$(OS_MINOR_RELEASE)
endif
ifeq (CYGWIN_NT,$(findstring CYGWIN_NT,$(OS_ARCH)))
OS_RELEASE := $(patsubst CYGWIN_NT-%,%,$(OS_ARCH))
OS_ARCH := WINNT
endif
ifeq ($(OS_ARCH), CYGWIN32_NT)
OS_ARCH := WINNT
endif
ifeq (MINGW32_NT,$(findstring MINGW32_NT,$(OS_ARCH)))
OS_RELEASE := $(patsubst MINGW32_NT-%,%,$(OS_ARCH))
OS_ARCH := WINNT
endif
ifeq ($(OS_ARCH),Linux)
OS_CONFIG := Linux_All
else
ifeq ($(OS_ARCH),dgux)
OS_CONFIG := dgux
else
ifeq ($(OS_ARCH),Darwin)
OS_CONFIG := Darwin
else
OS_CONFIG := $(OS_ARCH)$(OS_OBJTYPE)$(OS_RELEASE)
endif
endif
endif
CFLAGS += -I../mod_spidermonkey -I$(BASE)/libs/mozilla/js/src -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/js/src -I$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -I$(OS_CONFIG)_$(VER).OBJ
LDFLAGS +=-DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -lteletone
include ../mod_spidermonkey/sm.mak
OBJS=#$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
LINKER=$(CC)
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
$(CC) $(CFLAGS) -fPIC -c $(MODNAME).c -o $(MODNAME).o
$(LINKER) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS)
clean:
rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~
install:
cp -f $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PREFIX)/mod
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_spidermonkey_DB.c -- DB Javascript Module
*
*/
#include "mod_spidermonkey.h"
static const char modname[] = "DB";
struct db_obj {
switch_memory_pool_t *pool;
switch_core_db_t *db;
switch_core_db_stmt_t *stmt;
char *dbname;
char code_buffer[2048];
JSContext *cx;
JSObject *obj;
};
/* DB Object */
/*********************************************************************************/
static JSBool db_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
switch_memory_pool_t *pool;
switch_core_db_t *db;
struct db_obj *dbo;
if (argc > 0) {
char *dbname = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
switch_core_new_memory_pool(&pool);
if (! (db = switch_core_db_open_file(dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open DB!\n");
switch_core_destroy_memory_pool(&pool);
return JS_FALSE;
}
dbo = switch_core_alloc(pool, sizeof(*dbo));
dbo->pool = pool;
dbo->dbname = switch_core_strdup(pool, dbname);
dbo->cx = cx;
dbo->obj = obj;
dbo->db = db;
JS_SetPrivate(cx, obj, dbo);
return JS_TRUE;
}
return JS_FALSE;
}
static void db_destroy(JSContext *cx, JSObject *obj)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
if (dbo) {
switch_memory_pool_t *pool = dbo->pool;
if (dbo->stmt) {
switch_core_db_finalize(dbo->stmt);
dbo->stmt = NULL;
}
switch_core_db_close(dbo->db);
switch_core_destroy_memory_pool(&pool);
pool = NULL;
}
}
static int db_callback(void *pArg, int argc, char **argv, char **columnNames)
{
struct db_obj *dbo = pArg;
char code[1024];
jsval rval;
int x = 0;
snprintf(code, sizeof(code), "~var _Db_RoW_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
for(x=0; x < argc; x++) {
snprintf(code, sizeof(code), "~_Db_RoW_[\"%s\"] = \"%s\"", columnNames[x], argv[x]);
eval_some_js(code, dbo->cx, dbo->obj, &rval);
}
snprintf(code, sizeof(code), "~%s(_Db_RoW_)", dbo->code_buffer);
eval_some_js(code, dbo->cx, dbo->obj, &rval);
snprintf(code, sizeof(code), "~delete _Db_RoW_");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
return 0;
}
static JSBool db_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *err = NULL;
void *arg = NULL;
switch_core_db_callback_func_t cb_func = NULL;
if (argc > 1) {
char *js_func = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_copy_string(dbo->code_buffer, js_func, sizeof(dbo->code_buffer));
cb_func = db_callback;
arg = dbo;
}
switch_core_db_exec(dbo->db, sql, cb_func, arg, &err);
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
switch_core_db_free(err);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
}
}
return JS_TRUE;
}
static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
if (dbo->stmt) {
int running = 1;
while (running < 5000) {
int result = switch_core_db_step(dbo->stmt);
if (result == SQLITE_ROW) {
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
break;
} else if (result == SQLITE_BUSY) {
running++;
continue;
}
switch_core_db_finalize(dbo->stmt);
dbo->stmt = NULL;
break;
}
}
return JS_TRUE;
}
static JSBool db_fetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
int colcount = switch_core_db_column_count(dbo->stmt);
char code[1024];
int x;
snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
for (x = 0; x < colcount; x++) {
snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
(char *) switch_core_db_column_name(dbo->stmt, x),
(char *) switch_core_db_column_text(dbo->stmt, x));
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
}
JS_GetProperty(cx, obj, "_dB_RoW_DaTa_", rval);
return JS_TRUE;
}
static JSBool db_prepare(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
if (dbo->stmt) {
switch_core_db_finalize(dbo->stmt);
dbo->stmt = NULL;
}
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if(switch_core_db_prepare(dbo->db, sql, 0, &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 );
}
}
return JS_TRUE;
}
enum db_tinyid {
DB_NAME
};
static JSFunctionSpec db_methods[] = {
{"exec", db_exec, 1},
{"next", db_next, 0},
{"fetch", db_fetch, 1},
{"prepare", db_prepare, 0},
{0}
};
static JSPropertySpec db_props[] = {
{"path", DB_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{0}
};
static JSBool db_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSBool res = JS_TRUE;
struct db_obj *dbo = JS_GetPrivate(cx, obj);
char *name;
int param = 0;
name = JS_GetStringBytes(JS_ValueToString(cx, id));
/* numbers are our props anything else is a method */
if (name[0] >= 48 && name[0] <= 57) {
param = atoi(name);
} else {
return JS_TRUE;
}
switch(param) {
case DB_NAME:
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dbo->dbname));
break;
}
return res;
}
JSClass db_class = {
"DB", 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)
{
JS_InitClass(cx,
obj,
NULL,
&db_class,
db_construct,
3,
db_props,
db_methods,
db_props,
db_methods
);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t DB_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ spidermonkey_load,
/*.next*/ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &DB_module_interface;
return SWITCH_STATUS_SUCCESS;
}
include ../mod_spidermonkey/sm.mak
OBJS=#$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
LINKER=$(CC)
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
$(CC) $(CFLAGS) -fPIC -c $(MODNAME).c -o $(MODNAME).o
$(LINKER) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS)
clean:
rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~
install:
cp -f $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PREFIX)/mod
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* mod_spidermonkey_skel.c -- Skel Javascript Module
*
*/
#include "mod_spidermonkey.h"
static const char modname[] = "Skel";
/* Skel Object */
/*********************************************************************************/
static JSBool skel_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
static void skel_destroy(JSContext *cx, JSObject *obj)
{
}
static JSBool skel_my_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
enum skel_tinyid {
SKEL_NAME
};
static JSFunctionSpec skel_methods[] = {
{"myMethod", skel_my_method, 1},
{0}
};
static JSPropertySpec skel_props[] = {
{"name", SKEL_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{0}
};
static JSBool skel_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
JSBool res = JS_TRUE;
return res;
}
JSClass skel_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, skel_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, skel_destroy, NULL, NULL, NULL,
skel_construct
};
switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
{
JS_InitClass(cx,
obj,
NULL,
&skel_class,
skel_construct,
3,
skel_props,
skel_methods,
skel_props,
skel_methods
);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t skel_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ spidermonkey_load,
/*.next*/ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
{
*module_interface = &skel_module_interface;
return SWITCH_STATUS_SUCCESS;
}
include ../mod_spidermonkey/sm.mak
OBJS=#$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_$(VER).OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
LINKER=$(CC)
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN)
depends:
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
$(CC) $(CFLAGS) -fPIC -c $(MODNAME).c -o $(MODNAME).o
$(LINKER) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS)
clean:
rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~
install:
cp -f $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PREFIX)/mod
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论