diff --git a/src/sbbs3/js_msgbase.c b/src/sbbs3/js_msgbase.c index 508aa678a153fca78b2c302c1223c5476c8b0da2..0b096ba90517ed5b127d29009f675ed1665c2416 100644 --- a/src/sbbs3/js_msgbase.c +++ b/src/sbbs3/js_msgbase.c @@ -2100,6 +2100,15 @@ js_save_msg(JSContext *cx, uintN argc, jsval *arglist) } } + // Find and use the global client object if possible... + if(client==NULL) { + if(JS_GetProperty(cx, JS_GetGlobalObject(cx), "client", &val) && !JSVAL_NULL_OR_VOID(val)) { + objarg = JSVAL_TO_OBJECT(val); + if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) + client=JS_GetPrivate(cx,objarg); + } + } + if(hdr==NULL) return(JS_TRUE); if(body==NULL) @@ -2465,7 +2474,8 @@ static jsSyncMethodSpec js_msgbase_functions[] = { "</table>" "<br><i>New in v3.12:</i> " "The optional <i>client</i> argument is an instance of the <i>Client</i> class to be used for the " - "security log header fields (e.g. sender IP address, hostname, protocol, and port). " + "security log header fields (e.g. sender IP address, hostname, protocol, and port). As of version 3.16c, the " + "global client object will be used if this is omitted." "<br><br><i>New in v3.12:</i> " "The optional <i>rcpt_list</i> is an array of objects that specifies multiple recipients " "for a single message (e.g. bulk e-mail). Each object in the array may include the following header properties " diff --git a/src/sbbs3/js_system.c b/src/sbbs3/js_system.c index ad1c6b45034a247c08bf995ec35057aa2fe4df32..109ea5945d6099e074b227f9a49ed03392d58980 100644 --- a/src/sbbs3/js_system.c +++ b/src/sbbs3/js_system.c @@ -1504,8 +1504,11 @@ js_new_user(JSContext *cx, uintN argc, jsval *arglist) scfg_t* cfg; user_t user; JSObject* userobj; + JSObject* objarg; + JSClass* cl; jsrefcount rc; client_t* client=NULL; + jsval val; JS_SET_RVAL(cx, arglist, JSVAL_VOID); @@ -1529,14 +1532,21 @@ js_new_user(JSContext *cx, uintN argc, jsval *arglist) memset(&user,0,sizeof(user)); for(n=0;n<argc;n++) { if(JSVAL_IS_OBJECT(argv[n])) { - JSClass* cl; - JSObject* objarg = JSVAL_TO_OBJECT(argv[n]); + objarg = JSVAL_TO_OBJECT(argv[n]); if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) { client=JS_GetPrivate(cx,objarg); continue; } } } + // Find and use the global client object if possible... + if(client==NULL) { + if(JS_GetProperty(cx, JS_GetGlobalObject(cx), "client", &val) && !JSVAL_NULL_OR_VOID(val)) { + objarg = JSVAL_TO_OBJECT(val); + if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) + client=JS_GetPrivate(cx,objarg); + } + } if(client!=NULL) { SAFECOPY(user.modem,client->protocol); SAFECOPY(user.comp,client->host); @@ -1865,7 +1875,8 @@ static jsSyncMethodSpec js_system_functions[] = { {"newuser", js_new_user, 1, JSTYPE_ALIAS }, {"new_user", js_new_user, 1, JSTYPE_OBJECT, JSDOCSTR("name/alias [,client object]") ,JSDOCSTR("creates a new user record, returns a new <a href=#User>User</a> object representing the new user account, on success.<br>" - "returns an numeric error code on failure (optional <i>client</i> object argument added in v3.15a)") + "returns an numeric error code on failure (optional <i>client</i> object argument added in v3.15a. As of 3.16c, the global " + "client object is used if the argument is omitted)") ,310 }, {"del_user", js_del_user, 1, JSTYPE_BOOLEAN, JSDOCSTR("number")