Commit c8c921fa authored by deuce's avatar deuce
Browse files

More JSDoor stuff... create a minimal system object, populate all dirs except

node_dir.
parent f09babf5
......@@ -130,6 +130,7 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
#ifndef JSDOOR
case SYS_PROP_NAME:
p=cfg->sys_name;
break;
......@@ -176,6 +177,7 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
case SYS_PROP_LASTUSERON:
p=lastuseron;
break;
#endif
case SYS_PROP_FREEDISKSPACE:
case SYS_PROP_FREEDISKSPACEK:
rc=JS_SUSPENDREQUEST(cx);
......@@ -186,7 +188,7 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
JS_RESUMEREQUEST(cx, rc);
*vp=DOUBLE_TO_JSVAL((double)val);
break;
#ifndef JSDOOR
case SYS_PROP_NEW_PASS:
p=cfg->new_pass;
break;
......@@ -265,6 +267,7 @@ static JSBool js_system_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
case SYS_PROP_NODE_DIR:
p=cfg->node_dir;
break;
#endif
case SYS_PROP_CTRL_DIR:
p=cfg->ctrl_dir;
break;
......@@ -339,11 +342,13 @@ static JSBool js_system_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
#ifndef JSDOOR
switch(tiny) {
case SYS_PROP_MISC:
JS_ValueToInt32(cx, *vp, &cfg->sys_misc);
break;
}
#endif
return(TRUE);
}
......@@ -354,6 +359,7 @@ static JSBool js_system_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict
static jsSyncPropertySpec js_system_properties[] = {
/* name, tinyid, flags, ver */
#ifndef JSDOOR
{ "name", SYS_PROP_NAME, SYSOBJ_FLAGS, 310 },
{ "operator", SYS_PROP_OP, SYSOBJ_FLAGS, 310 },
{ "qwk_id", SYS_PROP_ID, SYSOBJ_FLAGS, 310 },
......@@ -369,9 +375,11 @@ static jsSyncPropertySpec js_system_properties[] = {
{ "lastuser", SYS_PROP_LASTUSER ,SYSOBJ_FLAGS, 311 },
{ "lastuseron", SYS_PROP_LASTUSERON ,SYSOBJ_FLAGS, 310 },
#endif
{ "freediskspace", SYS_PROP_FREEDISKSPACE ,SYSOBJ_FLAGS, 310 },
{ "freediskspacek", SYS_PROP_FREEDISKSPACEK ,SYSOBJ_FLAGS, 310 },
#ifndef JSDOOR
{ "nodes", SYS_PROP_NODES, SYSOBJ_FLAGS, 310 },
{ "lastnode", SYS_PROP_LASTNODE, SYSOBJ_FLAGS, 310 },
......@@ -403,6 +411,7 @@ static jsSyncPropertySpec js_system_properties[] = {
/* directories */
{ "node_dir", SYS_PROP_NODE_DIR ,SYSOBJ_FLAGS, 310 },
#endif
{ "ctrl_dir", SYS_PROP_CTRL_DIR ,SYSOBJ_FLAGS, 310 },
{ "data_dir", SYS_PROP_DATA_DIR ,SYSOBJ_FLAGS, 310 },
{ "text_dir", SYS_PROP_TEXT_DIR ,SYSOBJ_FLAGS, 310 },
......@@ -544,6 +553,7 @@ enum {
,SYSSTAT_PROP_FEEDBACK
};
#ifndef JSDOOR
static JSBool js_sysstats_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
......@@ -666,7 +676,7 @@ static jsSyncPropertySpec js_sysstats_properties[] = {
{0}
};
#ifdef BUILD_JSDOCS
#if !defined(JSDOOR) && defined(BUILD_JSDOCS)
static char* sysstat_prop_desc[] = {
"total logons"
,"logons today"
......@@ -882,6 +892,7 @@ js_matchuserdata(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
#endif
static JSBool
js_trashcan(JSContext *cx, uintN argc, jsval *arglist)
......@@ -1108,6 +1119,7 @@ js_secondstr(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
#ifndef JSDOOR
static JSBool
js_spamlog(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1632,9 +1644,10 @@ js_del_user(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
#endif
static JSBool
js_exec(JSContext *cx, uintN argc, jsval *arglist)
js_sys_exec(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
jsrefcount rc;
......@@ -1713,6 +1726,7 @@ js_popen(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
#ifndef JSDOOR
static JSBool
js_chksyspass(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1753,6 +1767,7 @@ js_chkname(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
#endif
static JSBool
js_chkpid(JSContext *cx, uintN argc, jsval *arglist)
......@@ -1798,6 +1813,7 @@ js_killpid(JSContext *cx, uintN argc, jsval *arglist)
static jsSyncMethodSpec js_system_functions[] = {
#ifndef JSDOOR
{"username", js_username, 1, JSTYPE_STRING, JSDOCSTR("number")
,JSDOCSTR("returns name of user in specified user record <i>number</i>, or empty string if not found")
,311
......@@ -1817,6 +1833,7 @@ static jsSyncMethodSpec js_system_functions[] = {
"or record at which to begin searching if optional <i>match_next</i> is <tt>true</tt>")
,310
},
#endif
{"trashcan", js_trashcan, 2, JSTYPE_BOOLEAN, JSDOCSTR("basename, find_string")
,JSDOCSTR("search <tt>text/<i>basename</i>.can</tt> for pseudo-regexp")
,310
......@@ -1844,6 +1861,7 @@ static jsSyncMethodSpec js_system_functions[] = {
,JSDOCSTR("convert elapsed time in seconds into a string in <tt>hh:mm:ss</tt> format")
,310
},
#ifndef JSDOOR
{"spamlog", js_spamlog, 6, JSTYPE_BOOLEAN, JSDOCSTR("[protocol, action, reason, host, ip, to, from]")
,JSDOCSTR("log a suspected SPAM attempt")
,310
......@@ -1883,7 +1901,8 @@ static jsSyncMethodSpec js_system_functions[] = {
,JSDOCSTR("delete the specified user account")
,316
},
{"exec", js_exec, 1, JSTYPE_NUMBER, JSDOCSTR("command-line")
#endif
{"exec", js_sys_exec, 1, JSTYPE_NUMBER, JSDOCSTR("command-line")
,JSDOCSTR("executes a native system/shell command-line, returns <i>0</i> on success")
,311
},
......@@ -1892,6 +1911,7 @@ static jsSyncMethodSpec js_system_functions[] = {
"(<b>only functional on UNIX systems</b>)")
,311
},
#ifndef JSDOOR
{"check_syspass", js_chksyspass, 1, JSTYPE_BOOLEAN, JSDOCSTR("password")
,JSDOCSTR("compares the supplied <i>password</i> against the system password and returns <i>true</i> if it matches")
,311
......@@ -1901,6 +1921,7 @@ static jsSyncMethodSpec js_system_functions[] = {
"returns <i>true</i> if it is valid")
,315
},
#endif
{"check_pid", js_chkpid, 1, JSTYPE_BOOLEAN, JSDOCSTR("process-ID")
,JSDOCSTR("checks that the provided process ID is a valid executing process on the system, "
"returns <i>true</i> if it is valid")
......@@ -2202,11 +2223,13 @@ static JSBool js_system_resolve(JSContext *cx, JSObject *obj, jsid id)
jsval val;
char str[256];
JSString* js_str;
JSBool ret;
#ifndef JSDOOR
JSObject* newobj;
JSObject* nodeobj;
scfg_t* cfg;
uint i;
JSBool ret;
#endif
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
......@@ -2254,6 +2277,7 @@ static JSBool js_system_resolve(JSContext *cx, JSObject *obj, jsid id)
LAZY_STRING("js_version", (char *)JS_GetImplementationVersion());
LAZY_STRING("os_version", os_version(str));
#ifndef JSDOOR
/* fido_addr_list property */
if(name==NULL || strcmp(name, "fido_addr_list")==0) {
if(name) free(name);
......@@ -2340,6 +2364,7 @@ static JSBool js_system_resolve(JSContext *cx, JSObject *obj, jsid id)
}
if(name) return(JS_TRUE);
}
#endif
ret = js_SyncResolve(cx, obj, name, js_system_properties, js_system_functions, NULL, 0);
if(name) free(name);
......@@ -2383,11 +2408,13 @@ JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
/****************************/
/* static string properties */
#ifndef JSDOOR
if((js_str=JS_NewStringCopyZ(cx, host_name))==NULL)
return(NULL);
val = STRING_TO_JSVAL(js_str);
if(!JS_SetProperty(cx, sysobj, "host_name", &val))
return(NULL);
#endif
if((js_str=JS_NewStringCopyZ(cx, socklib_version(str, socklib_desc)))==NULL)
return(NULL);
......@@ -2397,9 +2424,11 @@ JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
/***********************/
#ifndef JSDOOR
val=DOUBLE_TO_JSVAL((double)uptime);
if(!JS_SetProperty(cx, sysobj, "uptime", &val))
return(NULL);
#endif
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,sysobj,"Global system-related properties and methods",310);
......
......@@ -182,6 +182,16 @@ DLLCALL js_SyncResolve(JSContext* cx, JSObject* obj, char *name, jsSyncPropertyS
return(JS_TRUE);
}
// Needed for load()
JSObject* js_CreateBbsObject(JSContext* cx, JSObject* parent)
{
return NULL;
}
JSObject* js_CreateConsoleObject(JSContext* cx, JSObject* parent)
{
return NULL;
}
BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
,scfg_t *unused1
,scfg_t *unused2
......@@ -204,6 +214,10 @@ BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
return(FALSE);
do {
/* System Object */
if(js_CreateSystemObject(js_cx, *glob, &scfg, uptime, host_name, socklib_desc)==NULL)
break;
/* Internal JS Object */
if(cb!=NULL
&& js_CreateInternalJsObject(js_cx, *glob, cb, js_startup)==NULL)
......@@ -253,3 +267,5 @@ BOOL DLLCALL js_CreateCommonObjects(JSContext* js_cx
#define JSDOOR
#include "jsexec.c"
#include "js_system.c"
#include "ver.cpp"
......@@ -115,7 +115,9 @@ void usage(FILE* fp)
fprintf(fp,"\nusage: " PROG_NAME_LC " [-opts] [path]module[.js] [args]\n"
"\navailable opts:\n\n"
#ifndef JSDOOR
#ifdef JSDOOR
"\t-c<ctrl_dir> specify path to CTRL directory\n"
#else
"\t-c<ctrl_dir> specify path to Synchronet CTRL directory\n"
#endif
#if defined(__unix__)
......@@ -1090,8 +1092,18 @@ int main(int argc, char **argv, char** environ)
getcwd(orig_cwd, sizeof(orig_cwd));
backslash(orig_cwd);
#ifdef JSDOOR
SAFECOPY(scfg.ctrl_dir, orig_cwd);
prep_dir("", scfg.ctrl_dir, sizeof(scfg.ctrl_dir));
SAFECOPY(scfg.exec_dir, orig_cwd);
prep_dir(scfg.ctrl_dir, scfg.exec_dir, sizeof(scfg.exec_dir));
SAFECOPY(scfg.mods_dir, orig_cwd);
prep_dir(scfg.ctrl_dir, scfg.mods_dir, sizeof(scfg.mods_dir));
SAFECOPY(scfg.data_dir, orig_cwd);
prep_dir(scfg.ctrl_dir, scfg.data_dir, sizeof(scfg.data_dir));
SAFECOPY(scfg.text_dir, orig_cwd);
prep_dir(scfg.ctrl_dir, scfg.text_dir, sizeof(scfg.text_dir));
SAFECOPY(scfg.logs_dir, orig_cwd);
prep_dir(scfg.ctrl_dir, scfg.text_dir, sizeof(scfg.text_dir));
scfg.sys_misc = 0; /* SM_EURODATE and SM_MILITARY are used */
#endif
......@@ -1102,12 +1114,10 @@ int main(int argc, char **argv, char** environ)
case 'a':
omode="a";
break;
#ifndef JSDOOR
case 'c':
if(*p==0) p=argv[++argn];
SAFECOPY(scfg.ctrl_dir,p);
break;
#endif
#if defined(__unix__)
case 'd':
daemonize=TRUE;
......
......@@ -69,6 +69,7 @@ char* socklib_version(char* str, char* winsock_ver)
return(str);
}
#ifndef JSDOOR
void sbbs_t::ver()
{
char str[128],compiler[32];
......@@ -109,4 +110,4 @@ void sbbs_t::ver()
center(os_version(str));
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment