Commit d1a31307 authored by deuce's avatar deuce
Browse files

More work towards a shared runtime... there's now a mechanism in place to

test shared runtimes (which still crashes)

I suspect this is due to the script compilation/startup not being inside
a BeginRequest() block.
parent 9c5d941e
......@@ -387,6 +387,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
uintN i;
JSString* str=NULL;
FILE* fp;
jsrefcount rc;
if((fp=(FILE*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -395,7 +396,9 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
str = JS_ValueToString(cx, argv[i]);
if (!str)
return JS_FALSE;
rc=JS_SuspendRequest(cx);
fprintf(fp,"%s",JS_GetStringBytes(str));
JS_ResumeRequest(cx, rc);
}
if(str==NULL)
......@@ -409,12 +412,15 @@ static JSBool
js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
FILE* fp;
jsrefcount rc;
if((fp=(FILE*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
rc=JS_SuspendRequest(cx);
fprintf(fp,"\r\n");
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
......@@ -626,6 +632,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
JSScript* js_script=NULL;
JSString* js_str;
long double start=xp_timer();
jsrefcount rc;
lprintf(LOG_DEBUG,"%04d JavaScript: Generating HTML Index for %s"
,sock, genvpath(lib,dir,str));
......@@ -658,6 +665,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
break;
}
rc=JS_SuspendRequest(js_cx);
if(strcspn(startup->html_index_script,"/\\")==strlen(startup->html_index_script)) {
sprintf(spath,"%s%s",scfg.mods_dir,startup->html_index_script);
if(scfg.mods_dir[0]==0 || !fexist(spath))
......@@ -672,6 +680,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
lprintf(LOG_ERR,"%04d !HTML JavaScript (%s) doesn't exist",sock,spath);
break;
}
JS_ResumeRequest(js_cx, rc);
if((js_str=JS_NewStringCopyZ(js_cx, startup->html_index_file))==NULL)
break;
......@@ -774,6 +783,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
if(lib<0) { /* root dir */
rc=JS_SuspendRequest(js_cx);
/* File Aliases */
sprintf(path,"%sftpalias.cfg",scfg.ctrl_dir);
if((alias_fp=fopen(path,"r"))!=NULL) {
......@@ -833,6 +843,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
SAFEPRINTF2(vpath,"/%s/%s",p,startup->html_index_file);
} else
SAFECOPY(vpath,p);
JS_ResumeRequest(js_cx, rc);
js_add_file(js_cx
,alias_dir ? dir_array : file_array
,p /* filename */
......@@ -848,10 +859,12 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
,scfg.sys_id /* uploader */
,vpath /* link */
);
rc=JS_SuspendRequest(js_cx);
}
fclose(alias_fp);
}
JS_ResumeRequest(js_cx, rc);
/* QWK Packet */
if(startup->options&FTP_OPT_ALLOW_QWK /* && fexist(qwkfile) */) {
......@@ -916,6 +929,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
}
} else if(chk_ar(&scfg,scfg.dir[dir]->ar,user)){
SAFEPRINTF(path,"%s*",scfg.dir[dir]->path);
rc=JS_SuspendRequest(js_cx);
glob(path,0,NULL,&g);
for(i=0;i<(int)g.gl_pathc;i++) {
if(isdir(g.gl_pathv[i]))
......@@ -940,6 +954,7 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
,scfg.lib[scfg.dir[dir]->lib]->sname
,scfg.dir[dir]->code_suffix
,getfname(g.gl_pathv[i]));
JS_ResumeRequest(js_cx, rc);
js_add_file(js_cx
,file_array
,getfname(g.gl_pathv[i]) /* filename */
......@@ -955,10 +970,12 @@ BOOL js_generate_index(JSContext* js_cx, JSObject* parent,
,f.uler /* uploader */
,getfname(g.gl_pathv[i]) /* link */
);
rc=JS_SuspendRequest(js_cx);
}
}
globfree(&g);
}
JS_ResumeRequest(js_cx, rc);
/* RUN SCRIPT */
......@@ -3859,7 +3876,7 @@ static void ctrl_thread(void* arg)
lprintf(LOG_DEBUG,"%04d JavaScript: Creating runtime: %lu bytes"
,sock,startup->js.max_bytes);
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000))==NULL) {
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000, __FILE__, __LINE__))==NULL) {
lprintf(LOG_ERR,"%04d !ERROR creating JavaScript runtime",sock);
sockprintf(sock,"451 Error creating JavaScript runtime");
filepos=0;
......
......@@ -257,7 +257,7 @@ js_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
bg->branch.counter=0;
bg->branch.gc_attempts=0;
if((bg->runtime = jsrt_GetNew(JAVASCRIPT_MAX_BYTES, 1000))==NULL)
if((bg->runtime = jsrt_GetNew(JAVASCRIPT_MAX_BYTES, 1000, __FILE__, __LINE__))==NULL)
return(JS_FALSE);
if((bg->cx = JS_NewContext(bg->runtime, JAVASCRIPT_CONTEXT_STACK))==NULL)
......
......@@ -3,21 +3,57 @@
#include "js_rtpool.h"
#include <threadwrap.h>
//#define SHARED_RUNTIMES
struct jsrt_queue {
JSRuntime *rt;
int maxbytes;
int used;
int created;
JSRuntime *rt;
int created;
#ifdef SHARED_RUNTIMES
const char* file;
long line;
#else
int maxbytes;
int used;
#endif
};
#define JSRT_QUEUE_SIZE 128
struct jsrt_queue jsrt_queue[JSRT_QUEUE_SIZE];
static pthread_mutex_t jsrt_mutex;
static int initialized=0;
#ifndef SHARED_RUNTIMES
static sem_t jsrt_sem;
#endif
JSRuntime *jsrt_GetNew(int maxbytes, unsigned long timeout)
JSRuntime *jsrt_GetNew(int maxbytes, unsigned long timeout, const char *filename, long line)
{
#ifdef SHARED_RUNTIMES
int i;
if(!initialized) {
pthread_mutex_init(&jsrt_mutex, NULL);
initialized=TRUE;
}
pthread_mutex_lock(&jsrt_mutex);
for(i=0; i<JSRT_QUEUE_SIZE; i++) {
if(!jsrt_queue[i].created) {
jsrt_queue[i].rt=JS_NewRuntime(maxbytes);
if(jsrt_queue[i].rt != NULL) {
jsrt_queue[i].file=filename;
jsrt_queue[i].line=line;
jsrt_queue[i].created=1;
}
}
if(jsrt_queue[i].created && jsrt_queue[i].file == filename && jsrt_queue[i].line == line) {
pthread_mutex_unlock(&jsrt_mutex);
return(jsrt_queue[i].rt);
}
}
pthread_mutex_unlock(&jsrt_mutex);
return(NULL);
#else
int i;
int last_unused=-1;
......@@ -57,10 +93,13 @@ JSRuntime *jsrt_GetNew(int maxbytes, unsigned long timeout)
}
return(NULL);
#endif
}
void jsrt_Release(JSRuntime *rt)
{
#ifdef SHARED_RUNTIMES
#else
int i;
for(i=0; i<JSRT_QUEUE_SIZE; i++) {
......@@ -72,4 +111,5 @@ void jsrt_Release(JSRuntime *rt)
sem_post(&jsrt_sem);
}
}
#endif
}
......@@ -36,7 +36,7 @@
#if defined(__cplusplus)
extern "C" {
#endif
DLLEXPORT JSRuntime * DLLCALL jsrt_GetNew(int maxbytes, unsigned long timeout);
DLLEXPORT JSRuntime * DLLCALL jsrt_GetNew(int maxbytes, unsigned long timeout, const char *filename, long line);
DLLEXPORT void DLLCALL jsrt_Release(JSRuntime *);
#if defined(__cplusplus)
}
......
......@@ -610,7 +610,7 @@ static BOOL js_init(char** environ)
fprintf(statfp,"JavaScript: Creating runtime: %lu bytes\n"
,js_max_bytes);
if((js_runtime = jsrt_GetNew(js_max_bytes, 5000))==NULL)
if((js_runtime = jsrt_GetNew(js_max_bytes, 5000, __FILE__, __LINE__))==NULL)
return(FALSE);
fprintf(statfp,"JavaScript: Initializing context (stack: %lu bytes)\n"
......
......@@ -1503,6 +1503,7 @@ js_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
char file[MAX_PATH+1];
char* warning;
SOCKET* sock;
jsrefcount rc;
if((sock=(SOCKET*)JS_GetContextPrivate(cx))==NULL)
return;
......@@ -1530,8 +1531,10 @@ js_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
} else
warning="";
rc=JS_SuspendRequest(cx);
lprintf(LOG_ERR,"%04d !JavaScript %s%s%s: %s"
,*sock, warning ,file, line, message);
JS_ResumeRequest(cx, rc);
}
static JSBool
......@@ -1541,6 +1544,7 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int32 level=LOG_INFO;
JSString* str=NULL;
SOCKET* sock;
jsrefcount rc;
if((sock=(SOCKET*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -1551,7 +1555,9 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
for(; i<argc; i++) {
if((str=JS_ValueToString(cx, argv[i]))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
lprintf(level,"%04d JavaScript: %s",*sock,JS_GetStringBytes(str));
JS_ResumeRequest(cx, rc);
}
if(str==NULL)
......@@ -1610,7 +1616,7 @@ js_mailproc(SOCKET sock, client_t* client, user_t* user
lprintf(LOG_DEBUG,"%04d JavaScript: Creating runtime: %lu bytes\n"
,sock, startup->js.max_bytes);
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000))==NULL)
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000, __FILE__, __LINE__))==NULL)
break;
lprintf(LOG_DEBUG,"%04d JavaScript: Initializing context (stack: %lu bytes)\n"
......
......@@ -643,6 +643,7 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int32 level=LOG_INFO;
JSString* str=NULL;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -651,13 +652,17 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JS_ValueToInt32(cx,argv[i++],&level);
for(; i<argc; i++) {
if((str=JS_ValueToString(cx, argv[i]))==NULL)
if((str=JS_ValueToString(cx, argv[i]))==NULL) {
JS_ResumeRequest(cx, rc);
return(JS_FALSE);
}
rc=JS_SuspendRequest(cx);
if(sbbs->online==ON_LOCAL) {
if(startup!=NULL && startup->event_lputs!=NULL)
startup->event_lputs(level,JS_GetStringBytes(str));
} else
lputs(level,JS_GetStringBytes(str));
JS_ResumeRequest(cx, rc);
}
if(str==NULL)
......@@ -673,6 +678,7 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
uchar* buf;
int32 len=128;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -683,7 +689,9 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((buf=(uchar*)malloc(len))==NULL)
return(JS_TRUE);
rc=JS_SuspendRequest(cx);
len=RingBufRead(&sbbs->inbuf,buf,len);
JS_ResumeRequest(cx, rc);
if(len>0)
*rval = STRING_TO_JSVAL(JS_NewStringCopyN(cx,(char*)buf,len));
......@@ -698,6 +706,7 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* buf;
int32 len=128;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -708,7 +717,9 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((buf=(char*)malloc(len))==NULL)
return(JS_TRUE);
rc=JS_SuspendRequest(cx);
len=sbbs->getstr(buf,len,K_NONE);
JS_ResumeRequest(cx, rc);
if(len>0)
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,buf));
......@@ -723,6 +734,8 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
uintN i;
JSString* str=NULL;
sbbs_t* sbbs;
jsrefcount rc;
rc=JS_SuspendRequest(cx);
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -730,10 +743,12 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
for (i = 0; i < argc; i++) {
if((str=JS_ValueToString(cx, argv[i]))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
if(sbbs->online==ON_LOCAL)
eprintf(LOG_INFO,"%s",JS_GetStringBytes(str));
else
sbbs->bputs(JS_GetStringBytes(str));
JS_ResumeRequest(cx, rc);
}
if(str==NULL)
......@@ -750,6 +765,7 @@ js_write_raw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* str=NULL;
size_t len;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -757,7 +773,9 @@ js_write_raw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
for (i = 0; i < argc; i++) {
if((str=js_ValueToStringBytes(cx, argv[i], &len))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
sbbs->putcom(str, len);
JS_ResumeRequest(cx, rc);
}
return(JS_TRUE);
......@@ -767,13 +785,16 @@ static JSBool
js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
rc=JS_SuspendRequest(cx);
if(sbbs->online==ON_REMOTE)
sbbs->bputs(crlf);
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
......@@ -783,6 +804,7 @@ js_printf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* p;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -792,10 +814,12 @@ js_printf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return(JS_FALSE);
}
rc=JS_SuspendRequest(cx);
if(sbbs->online==ON_LOCAL)
eprintf(LOG_INFO,"%s",p);
else
sbbs->bputs(p);
JS_ResumeRequest(cx, rc);
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, p));
......@@ -809,6 +833,7 @@ js_alert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString * str;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -816,10 +841,12 @@ js_alert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
sbbs->attr(sbbs->cfg.color[clr_err]);
sbbs->bputs(JS_GetStringBytes(str));
sbbs->attr(LIGHTGRAY);
sbbs->bputs(crlf);
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
......@@ -829,6 +856,7 @@ js_confirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString * str;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -836,7 +864,9 @@ js_confirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
*rval = BOOLEAN_TO_JSVAL(sbbs->yesno(JS_GetStringBytes(str)));
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
......@@ -847,6 +877,7 @@ js_prompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSString * prompt;
JSString * str;
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -861,12 +892,15 @@ js_prompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
} else
instr[0]=0;
rc=JS_SuspendRequest(cx);
sbbs->bprintf("\1n\1y\1h%s\1w: ",JS_GetStringBytes(prompt));
if(!sbbs->getstr(instr,sizeof(instr)-1,K_EDIT)) {
*rval = JSVAL_NULL;
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
JS_ResumeRequest(cx, rc);
if((str=JS_NewStringCopyZ(cx, instr))==NULL)
return(JS_FALSE);
......@@ -931,6 +965,7 @@ js_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
char file[MAX_PATH+1];
sbbs_t* sbbs;
const char* warning;
jsrefcount rc;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return;
......@@ -958,12 +993,14 @@ js_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
} else
warning=nulstr;
rc=JS_SuspendRequest(cx);
if(sbbs->online==ON_LOCAL)
eprintf(LOG_ERR,"!JavaScript %s%s%s: %s",warning,file,line,message);
else {
lprintf(LOG_ERR,"!JavaScript %s%s%s: %s",warning,file,line,message);
sbbs->bprintf("!JavaScript %s%s%s: %s\r\n",warning,file,line,message);
}
JS_ResumeRequest(cx, rc);
}
bool sbbs_t::js_init(ulong* stack_frame)
......@@ -981,7 +1018,7 @@ bool sbbs_t::js_init(ulong* stack_frame)
lprintf(LOG_DEBUG,"%s JavaScript: Creating runtime: %lu bytes"
,node,startup->js.max_bytes);
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000))==NULL)
if((js_runtime = jsrt_GetNew(startup->js.max_bytes, 1000, __FILE__, __LINE__))==NULL)
return(false);
lprintf(LOG_DEBUG,"%s JavaScript: Initializing context (stack: %lu bytes)"
......
......@@ -259,6 +259,7 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* buf;
int32 len=512;
service_client_t* client;
jsrefcount rc;
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -269,7 +270,9 @@ js_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((buf=alloca(len))==NULL)
return(JS_TRUE);
rc=JS_SuspendRequest(cx);
len=recv(client->socket,buf,len,0);
JS_ResumeRequest(cx, rc);
if(len>0)
*rval = STRING_TO_JSVAL(JS_NewStringCopyN(cx,buf,len));
......@@ -289,6 +292,7 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int32 timeout=30; /* seconds */
JSString* str;
service_client_t* client;
jsrefcount rc;
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -304,6 +308,7 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(argc>1)
JS_ValueToInt32(cx,argv[1],(int32*)&timeout);
rc=JS_SuspendRequest(cx);
start=time(NULL);
for(i=0;i<len;) {
......@@ -313,6 +318,7 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(!rd) {
if(time(NULL)-start>timeout) {
*rval = JSVAL_NULL;
JS_ResumeRequest(cx, rc);
return(JS_TRUE); /* time-out */
}
continue; /* no data */
......@@ -330,6 +336,7 @@ js_readln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
buf[i-1]=0;
else
buf[i]=0;
JS_ResumeRequest(cx, rc);
str = JS_NewStringCopyZ(cx, buf);
if(str==NULL)
......@@ -347,6 +354,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
char* cp;
JSString* str;
service_client_t* client;
jsrefcount rc;
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -358,7 +366,9 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
continue;
if((cp=JS_GetStringBytes(str))==NULL)
continue;
rc=JS_SuspendRequest(cx);
sendsocket(client->socket,cp,strlen(cp));
JS_ResumeRequest(cx, rc);
}
return(JS_TRUE);
......@@ -369,14 +379,17 @@ js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* cp;
service_client_t* client;
jsrefcount rc;
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
rc=JS_SuspendRequest(cx);
cp="\r\n";
sendsocket(client->socket,cp,2);
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
......@@ -389,6 +402,7 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int32 level=LOG_INFO;
JSString* js_str;
service_client_t* client;
jsrefcount rc;
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
......@@ -407,10 +421,12 @@ js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
strcat(str," ");
}
rc=JS_SuspendRequest(cx);
if(service==NULL)
lprintf(level,"%04d %s",client->socket,str);
else if(level <= client->service->log_level)
lprintf(level,"%04d %s %s",client->socket,client->service->protocol,str);
JS_ResumeRequest(cx, rc);
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, str));
......@@ -426,6 +442,7 @@ js_login(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
jsval val;
JSString* js_str;
service_client_t* client;
jsrefcount rc;
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
......@@ -439,6 +456,7 @@ js_login(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((p=JS_GetStringBytes(js_str))==NULL)
return(JS_FALSE);
rc=JS_SuspendRequest(cx);
memset(&user,0,sizeof(user));
if(isdigit(*p))
......@@ -449,33 +467,42 @@ js_login(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(getuserdat(&scfg,&user)!=0) {
lprintf(LOG_NOTICE,"%04d %s !USER NOT FOUND: '%s'"
,client->socket,client->service->protocol,p);
JS_ResumeRequest(cx, rc);
return(JS_TRUE);
}
if(user.misc&(DELETED|INACTIVE)) {
lprintf(LOG_WARNING,"%04d %s !DELETED OR INACTIVE USER #%d: %s"
,client->socket,client->service->protocol,user.number,p);
JS_ResumeRequest(cx, rc);