Commit 64b18fb6 authored by deuce's avatar deuce
Browse files

Now sbbs links!

(Everything still broken)
parent 3b8981fb
......@@ -415,7 +415,7 @@ js_writeln(JSContext *cx, uintN argc, jsval *arglist)
if((fp=(FILE*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
js_write(cx,argc,arglist);
rc=JS_SUSPENDREQUEST(cx);
fprintf(fp,"\r\n");
JS_RESUMEREQUEST(cx, rc);
......
......@@ -598,6 +598,15 @@ static jsval get_value(JSContext *cx, char* value)
return(STRING_TO_JSVAL(JS_NewStringCopyZ(cx,value)));
}
static double js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj)
{
jsval rval;
if(!JS_CallFunctionName(cx, obj, "UTC", 0, NULL, &rval))
return ((double)time(NULL))*1000;
return JSVAL_TO_DOUBLE(rval);
}
static JSBool
js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -639,28 +648,21 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
switch(JSVAL_TAG(dflt)) {
case JSVAL_BOOLEAN:
JS_SET_RVAL(cx,arglist,BOOLEAN_TO_JSVAL(
iniReadBool(p->fp,section,key,JSVAL_TO_BOOLEAN(dflt))));
break;
case JSVAL_DOUBLE:
if(JSVAL_IS_BOOLEAN(dflt)) {
JS_SET_RVAL(cx,arglist,BOOLEAN_TO_JSVAL(
iniReadBool(p->fp,section,key,JSVAL_TO_BOOLEAN(dflt))));
}
else if(JSVAL_IS_OBJECT(dflt)) {
if((dflt_obj = JSVAL_TO_OBJECT(dflt))!=NULL && (strcmp("Date",JS_GetClass(cx, dflt_obj)->name)==0)) {
tt=(time_t)(js_DateGetMsecSinceEpoch(cx,dflt_obj)/1000.0);
rc=JS_SUSPENDREQUEST(cx);
dbl=iniReadFloat(p->fp,section,key,*JSVAL_TO_DOUBLE(dflt));
dbl=iniReadDateTime(p->fp,section,key,tt);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,DOUBLE_TO_JSVAL(dbl));
break;
case JSVAL_OBJECT:
if((dflt_obj = JSVAL_TO_OBJECT(dflt))!=NULL && js_DateIsValid(cx, dflt_obj)) {
tt=(time_t)(js_DateGetMsecSinceEpoch(cx,dflt_obj)/1000.0);
rc=JS_SUSPENDREQUEST(cx);
dbl=iniReadDateTime(p->fp,section,key,tt);
JS_RESUMEREQUEST(cx, rc);
date_obj = js_NewDateObjectMsec(cx, dbl);
if(date_obj!=NULL)
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(date_obj));
break;
}
date_obj = JS_NewDateObjectMsec(cx, DOUBLE_TO_JSVAL(dbl));
if(date_obj!=NULL)
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(date_obj));
}
else {
array = JS_NewArrayObject(cx, 0, NULL);
cstr=JS_GetStringBytes(JS_ValueToString(cx,dflt));
rc=JS_SUSPENDREQUEST(cx);
......@@ -675,33 +677,35 @@ js_iniGetValue(JSContext *cx, uintN argc, jsval *arglist)
iniFreeStringList(list);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(array));
break;
default:
if(JSVAL_IS_NUMBER(dflt)) {
if(!JS_ValueToInt32(cx,dflt,&i))
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
i=iniReadInteger(p->fp,section,key,i);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,INT_TO_JSVAL(i));
} else {
cstr=JS_GetStringBytes(JS_ValueToString(cx,dflt));
rc=JS_SUSPENDREQUEST(cx);
cstr2=iniReadString(p->fp,section,key,cstr,buf);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cstr2)));
}
break;
}
}
else if(JSVAL_IS_DOUBLE(dflt)) {
rc=JS_SUSPENDREQUEST(cx);
dbl=iniReadFloat(p->fp,section,key,JSVAL_TO_DOUBLE(dflt));
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,DOUBLE_TO_JSVAL(dbl));
}
else if(JSVAL_IS_NUMBER(dflt)) {
if(!JS_ValueToInt32(cx,dflt,&i))
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
i=iniReadInteger(p->fp,section,key,i);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,INT_TO_JSVAL(i));
} else {
cstr=JS_GetStringBytes(JS_ValueToString(cx,dflt));
rc=JS_SUSPENDREQUEST(cx);
cstr2=iniReadString(p->fp,section,key,cstr,buf);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cstr2)));
}
return(JS_TRUE);
}
static JSBool
js_iniSetValue(JSContext *cx, uintN argc, jsval *arglist)
js_iniSetValue_internal(JSContext *cx, JSObject *obj, uintN argc, jsval* argv, jsval *rval)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* section=ROOT_SECTION;
char* key;
char* result=NULL;
......@@ -714,7 +718,7 @@ js_iniSetValue(JSContext *cx, uintN argc, jsval *arglist)
char* cstr;
time_t tt;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
*rval = JSVAL_FALSE;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
......@@ -740,44 +744,35 @@ js_iniSetValue(JSContext *cx, uintN argc, jsval *arglist)
result = iniSetString(&list,section,key,"",NULL);
JS_RESUMEREQUEST(cx, rc);
}
else {
switch(JSVAL_TAG(value)) {
case JSVAL_BOOLEAN:
result = iniSetBool(&list,section,key,JSVAL_TO_BOOLEAN(value),NULL);
break;
case JSVAL_DOUBLE:
result = iniSetFloat(&list,section,key,JSVAL_TO_DOUBLE(value),NULL);
break;
default:
if(JSVAL_IS_NUMBER(value)) {
if(!JS_ValueToInt32(cx,value,&i))
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
result = iniSetInteger(&list,section,key,i,NULL);
JS_RESUMEREQUEST(cx, rc);
} else {
if(JSVAL_IS_OBJECT(value)
&& (value_obj = JSVAL_TO_OBJECT(value))!=NULL
&& js_DateIsValid(cx, value_obj)) {
tt=(time_t)(js_DateGetMsecSinceEpoch(cx,value_obj)/1000.0);
rc=JS_SUSPENDREQUEST(cx);
result = iniSetDateTime(&list,section,key,/* include_time */TRUE, tt,NULL);
JS_RESUMEREQUEST(cx, rc);
} else {
cstr=JS_GetStringBytes(JS_ValueToString(cx,value));
rc=JS_SUSPENDREQUEST(cx);
result = iniSetString(&list,section,key, cstr,NULL);
JS_RESUMEREQUEST(cx, rc);
}
}
break;
}
else if(JSVAL_IS_BOOLEAN(value)) {
result = iniSetBool(&list,section,key,JSVAL_TO_BOOLEAN(value),NULL);
}
else if(JSVAL_IS_DOUBLE(value)) {
result = iniSetFloat(&list,section,key,JSVAL_TO_DOUBLE(value),NULL);
}
else if(JSVAL_IS_NUMBER(value)) {
if(!JS_ValueToInt32(cx,value,&i))
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
result = iniSetInteger(&list,section,key,i,NULL);
JS_RESUMEREQUEST(cx, rc);
} else if(JSVAL_IS_OBJECT(value)
&& (value_obj = JSVAL_TO_OBJECT(value))!=NULL
&& (strcmp("Date",JS_GetClass(cx, value_obj)->name)==0)) {
tt=(time_t)(js_DateGetMsecSinceEpoch(cx,value_obj)/1000.0);
rc=JS_SUSPENDREQUEST(cx);
result = iniSetDateTime(&list,section,key,/* include_time */TRUE, tt,NULL);
JS_RESUMEREQUEST(cx, rc);
} else {
cstr=JS_GetStringBytes(JS_ValueToString(cx,value));
rc=JS_SUSPENDREQUEST(cx);
result = iniSetString(&list,section,key, cstr,NULL);
JS_RESUMEREQUEST(cx, rc);
}
rc=JS_SUSPENDREQUEST(cx);
if(result != NULL)
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list)));
*rval = BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list));
strListFree(&list);
JS_RESUMEREQUEST(cx, rc);
......@@ -785,6 +780,19 @@ js_iniSetValue(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
static JSBool
js_iniSetValue(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
jsval rval;
JSBool ret;
ret=js_iniSetValue_internal(cx, obj, argc, argv, &rval);
JS_SET_RVAL(cx, arglist, rval);
return ret;
}
static JSBool
js_iniRemoveKey(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1013,6 +1021,7 @@ js_iniSetObject(JSContext *cx, uintN argc, jsval *arglist)
JSObject* object;
JSIdArray* id_array;
jsval set_argv[3];
jsval rval;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
......@@ -1031,9 +1040,11 @@ js_iniSetObject(JSContext *cx, uintN argc, jsval *arglist)
JS_IdToValue(cx,id_array->vector[i],&set_argv[1]);
/* value */
JS_GetProperty(cx,object,JS_GetStringBytes(JSVAL_TO_STRING(set_argv[1])),&set_argv[2]);
if(!js_iniSetValue(cx,obj,3,set_argv,rval))
if(!js_iniSetValue_internal(cx,obj,3,set_argv,&rval))
break;
}
JS_SET_RVAL(cx, arglist, rval);
JS_DestroyIdArray(cx,id_array);
......@@ -1168,6 +1179,7 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
jsval oval;
jsval set_argv[3];
JSIdArray* id_array;
jsval rval;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
......@@ -1205,10 +1217,11 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
continue;
/* value */
JS_GetProperty(cx,object,JS_GetStringBytes(JSVAL_TO_STRING(set_argv[1])),&set_argv[2]);
if(!js_iniSetValue(cx,obj,3,set_argv,rval))
if(!js_iniSetValue_internal(cx,obj,3,set_argv,&rval))
break;
}
JS_SET_RVAL(cx, arglist, rval);
JS_DestroyIdArray(cx,id_array);
}
......@@ -1299,16 +1312,14 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
}
static JSBool
js_writeln(JSContext *cx, uintN argc, jsval *arglist)
js_writeln_internal(JSContext *cx, JSObject *obj, jsval *arg, jsval *rval)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* cp="";
JSString* str;
private_t* p;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
*rval = JSVAL_FALSE;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
......@@ -1318,8 +1329,8 @@ js_writeln(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc) {
if((str = JS_ValueToString(cx, argv[0]))==NULL) {
if(arg) {
if((str = JS_ValueToString(cx, *arg))==NULL) {
JS_ReportError(cx,"JS_ValueToString failed");
return(JS_FALSE);
}
......@@ -1331,12 +1342,31 @@ js_writeln(JSContext *cx, uintN argc, jsval *arglist)
rot13(cp);
if(fprintf(p->fp,"%s\n",cp)!=0)
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
*rval = JSVAL_TRUE;
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_writeln(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
jsval rval;
JSBool ret;
if(argc) {
ret=js_writeln_internal(cx, obj, &argv[0], &rval);
}
else {
ret=js_writeln_internal(cx, obj, NULL, &rval);
}
JS_SET_RVAL(cx, arglist, rval);
return(ret);
}
static JSBool
js_writebin(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1476,10 +1506,13 @@ js_writeall(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
for(i=0;i<limit;i++) {
jsval rval;
if(!JS_GetElement(cx, array, i, &elemval))
break;
js_writeln(cx, obj, 1, &elemval, rval);
if(*rval!=JSVAL_TRUE)
js_writeln_internal(cx, obj, &elemval, &rval);
JS_SET_RVAL(cx, arglist, rval);
if(rval!=JSVAL_TRUE)
break;
}
......
......@@ -322,6 +322,7 @@ js_load(JSContext *cx, uintN argc, jsval *arglist)
#endif
/* Save parent's 'log' function (for later use by our log function) */
#if TODO
if(JS_GetProperty(cx, obj, "log", &val)) {
JSFunction* func;
if((func=JS_ValueToFunction(cx, val))!=NULL && !(func->flags&JSFUN_INTERPRETED)) {
......@@ -330,6 +331,9 @@ js_load(JSContext *cx, uintN argc, jsval *arglist)
,"log", js_log, func->nargs, func->flags);
}
}
#else
#warning BACKGROUND LOG FUNCTION DEAD!
#endif
exec_cx = bg->cx;
exec_obj = bg->obj;
......@@ -468,8 +472,10 @@ js_load(JSContext *cx, uintN argc, jsval *arglist)
success = _beginthread(background_thread,0,bg)!=-1;
} else {
jsval rval;
success = JS_ExecuteScript(exec_cx, exec_obj, script, rval);
success = JS_ExecuteScript(exec_cx, exec_obj, script, &rval);
JS_SET_RVAL(cx, arglist, rval);
JS_DestroyScript(exec_cx, script);
}
......
......@@ -248,16 +248,15 @@ static queued_value_t* js_encode_value(JSContext *cx, jsval val, char* name
if(name!=NULL)
SAFECOPY(nv->name,name);
switch(JSVAL_TAG(val)) {
case JSVAL_TAG_BOOLEAN:
nv->type=JSTYPE_BOOLEAN;
nv->value.b=JSVAL_TO_BOOLEAN(val);
break;
case JSVAL_TAG_OBJECT:
if(JSVAL_IS_NULL(val)) {
nv->type=JSTYPE_NULL;
break;
}
if(JSVAL_IS_BOOLEAN(val)) {
nv->type=JSTYPE_BOOLEAN;
nv->value.b=JSVAL_TO_BOOLEAN(val);
}
else if(JSVAL_IS_OBJECT(val)) {
if(JSVAL_IS_NULL(val)) {
nv->type=JSTYPE_NULL;
}
else {
nv->type=JSTYPE_OBJECT;
obj = JSVAL_TO_OBJECT(val);
......@@ -284,18 +283,16 @@ static queued_value_t* js_encode_value(JSContext *cx, jsval val, char* name
}
v=js_encode_value(cx,JSVAL_VOID,NULL,v,count); /* terminate object */
JS_DestroyIdArray(cx,id_array);
break;
default:
if(JSVAL_IS_NUMBER(val)) {
nv->type = JSTYPE_NUMBER;
JS_ValueToNumber(cx,val,&nv->value.n);
} else if(JSVAL_IS_VOID(val)) {
nv->type = JSTYPE_VOID;
} else {
nv->type= JSTYPE_STRING;
nv->value.s = strdup(JS_GetStringBytes(JS_ValueToString(cx,val)));
}
break;
}
}
else if(JSVAL_IS_NUMBER(val)) {
nv->type = JSTYPE_NUMBER;
JS_ValueToNumber(cx,val,&nv->value.n);
} else if(JSVAL_IS_VOID(val)) {
nv->type = JSTYPE_VOID;
} else {
nv->type= JSTYPE_STRING;
nv->value.s = strdup(JS_GetStringBytes(JS_ValueToString(cx,val)));
}
return(v);
......
......@@ -116,7 +116,7 @@ extern int thread_suid_broken; /* NPTL is no longer broken */
#include <jsapi.h>
#if (JS_VERSION < 185) || (defined __cplusplus)
#include <jsprf.h> /* JS-safe sprintf functions */
#include <jsnum.h> /* JSDOUBLE_IS_NaN() */
#include <math.h> /* isnan() */
#endif
#if JS_VERSION >= 185
#define JS_DestroyScript(cx,script)
......@@ -1021,7 +1021,7 @@ extern "C" {
,const char* name, char* str[], uintN flags);
DLLEXPORT char* DLLCALL js_ValueToStringBytes(JSContext* cx, jsval val, size_t* len);
#define JSVAL_IS_NUM(v) (JSVAL_IS_NUMBER(v) && (!JSVAL_IS_DOUBLE(v) || !JSDOUBLE_IS_NaN(JSVAL_TO_DOUBLE(v))))
#define JSVAL_IS_NUM(v) (JSVAL_IS_NUMBER(v) && (!JSVAL_IS_DOUBLE(v) || !isnan(JSVAL_TO_DOUBLE(v))))
/* js_server.c */
DLLEXPORT JSObject* DLLCALL js_CreateServerObject(JSContext* cx, JSObject* parent
......
......@@ -390,7 +390,7 @@ js_writeln(JSContext *cx, uintN argc, jsval *arglist)
if((client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_write(cx,obj,argc,argv,rval);
js_write(cx,argc,arglist);
rc=JS_SUSPENDREQUEST(cx);
cp="\r\n";
......
......@@ -3957,8 +3957,10 @@ static void js_writebuf(http_session_t *session, const char *buf, size_t buflen)
}
static JSBool
js_writefunc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval, BOOL writeln)
js_writefunc(JSContext *cx, uintN argc, jsval *arglist, BOOL writeln)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
uintN i;
JSString* str=NULL;
http_session_t* session;
......@@ -4014,9 +4016,9 @@ js_writefunc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval,
}
if(str==NULL)
*rval = JSVAL_VOID;
JS_SET_RVAL(cx,arglist,JSVAL_VOID);
else
*rval = STRING_TO_JSVAL(str);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(str));
return(JS_TRUE);
}
......@@ -4024,14 +4026,12 @@ js_writefunc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval,
static JSBool
js_write(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
http_session_t* session;
if((session=(http_session_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_writefunc(cx, obj, argc, argv, rval,FALSE);
js_writefunc(cx, argc, arglist, FALSE);
return(JS_TRUE);
}
......@@ -4039,14 +4039,12 @@ js_write(JSContext *cx, uintN argc, jsval *arglist)
static JSBool
js_writeln(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
http_session_t* session;
if((session=(http_session_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
js_writefunc(cx, obj, argc, argv, rval,TRUE);
js_writefunc(cx, argc, arglist,TRUE);
return(JS_TRUE);
}
......@@ -4572,7 +4570,7 @@ static BOOL ssjs_send_headers(http_session_t* session,int chunked)
JS_GetProperty(session->js_cx,session->js_glob,"http_reply",&val);
reply = JSVAL_TO_OBJECT(val);
JS_GetProperty(session->js_cx,reply,"status",&val);
SAFECOPY(session->req.status,JS_GetStringBytes(JSVAL_TO_STRING(val)));
SAFECOPY(session->req.status,JS_GetStringBytes_dumbass(session->js_cx, JSVAL_TO_STRING(val)));
JS_GetProperty(session->js_cx,reply,"header",&val);
headers = JSVAL_TO_OBJECT(val);
heads=JS_Enumerate(session->js_cx,headers);
......@@ -4580,9 +4578,9 @@ static BOOL ssjs_send_headers(http_session_t* session,int chunked)
for(i=0;i<heads->length;i++) {
JS_IdToValue(session->js_cx,heads->vector[i],&val);
js_str=JSVAL_TO_STRING(val);
JS_GetProperty(session->js_cx,headers,JS_GetStringBytes(js_str),&val);
JS_GetProperty(session->js_cx,headers,JS_GetStringBytes_dumbass(session->js_cx, js_str),&val);
safe_snprintf(str,sizeof(str),"%s: %s"
,JS_GetStringBytes(js_str),JS_GetStringBytes(JSVAL_TO_STRING(val)));
,JS_GetStringBytes_dumbass(session->js_cx, js_str),JS_GetStringBytes_dumbass(session->js_cx, JSVAL_TO_STRING(val)));
strListPush(&session->req.dynamic_heads,str);
}
JS_ClearScope(session->js_cx, headers);
......
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