Skip to content
Snippets Groups Projects
Commit 20fa7014 authored by deuce's avatar deuce
Browse files

For system.new_user() and MsgBase.save_msg(), use the global client object

if one isn't specified.

For backward compatability with versions before 3.16c, this argument should
still be provided.
parent 8db54c47
No related branches found
No related tags found
No related merge requests found
......@@ -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 "
......
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment