summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/EJS.pm9
-rw-r--r--source4/scripting/ejs/mprutil.c14
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c7
-rw-r--r--source4/scripting/ejs/smbcalls_nss.c5
-rw-r--r--source4/scripting/ejs/smbcalls_sys.c25
5 files changed, 33 insertions, 27 deletions
diff --git a/source4/build/pidl/Parse/Pidl/Samba/EJS.pm b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm
index 0aa8de7c93..370db6d0e4 100644
--- a/source4/build/pidl/Parse/Pidl/Samba/EJS.pm
+++ b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm
@@ -692,19 +692,18 @@ sub EjsInterface($$)
pidl "static int ejs_$name\_init(int eid, int argc, struct MprVar **argv)";
pidl "{";
indent;
- pidl "struct MprVar obj = mprObject(\"$name\");";
+ pidl "struct MprVar *obj = mprInitObject(eid, \"$name\", argc, argv);";
foreach (@fns) {
- pidl "mprSetCFunction(&obj, \"$_\", ejs_$_);";
+ pidl "mprSetCFunction(obj, \"$_\", ejs_$_);";
}
foreach my $v (keys %constants) {
my $value = $constants{$v};
if (substr($value, 0, 1) eq "\"") {
- pidl "mprSetVar(&obj, \"$v\", mprString($value));";
+ pidl "mprSetVar(obj, \"$v\", mprString($value));";
} else {
- pidl "mprSetVar(&obj, \"$v\", mprCreateNumberVar($value));";
+ pidl "mprSetVar(obj, \"$v\", mprCreateNumberVar($value));";
}
}
- pidl "mpr_Return(eid, obj);";
pidl "return 0;";
deindent;
pidl "}\n";
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index f9813f2597..14d120c45a 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -403,3 +403,17 @@ void mprSetThisPtr(int eid, const char *name, void *ptr)
struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
mprSetPtrChild(this, name, ptr);
}
+
+/*
+ used by object xxx_init() routines to allow for the caller
+ to supply a pre-existing object to add properties to,
+ or create a new object. This makes inheritance easy
+*/
+struct MprVar *mprInitObject(int eid, const char *name, int argc, struct MprVar **argv)
+{
+ if (argc > 0 && mprVarIsObject(argv[0]->type)) {
+ return argv[0];
+ }
+ mpr_Return(eid, mprObject(name));
+ return ejsGetReturnValue(eid);
+}
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 0795db9018..f09039731f 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -273,7 +273,7 @@ static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
dbfile = argv[0];
- ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, argv+1);
+ ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, (const char **)(argv+1));
if (ldb == NULL) {
ejsSetErrorMsg(eid, "ldb.connect failed to open %s", dbfile);
}
@@ -289,10 +289,7 @@ static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
*/
static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
{
- struct MprVar *ldb;
- mpr_Return(eid, mprObject("ldb"));
-
- ldb = ejsGetReturnValue(eid);
+ struct MprVar *ldb = mprInitObject(eid, "ldb", argc, argv);
mprSetStringCFunction(ldb, "connect", ejs_ldbConnect);
mprSetCFunction(ldb, "search", ejs_ldbSearch);
diff --git a/source4/scripting/ejs/smbcalls_nss.c b/source4/scripting/ejs/smbcalls_nss.c
index a804c14b7f..6111ed57c2 100644
--- a/source4/scripting/ejs/smbcalls_nss.c
+++ b/source4/scripting/ejs/smbcalls_nss.c
@@ -141,10 +141,7 @@ static int ejs_getgrgid(MprVarHandle eid, int argc, struct MprVar **argv)
*/
static int ejs_nss_init(MprVarHandle eid, int argc, struct MprVar **argv)
{
- struct MprVar *nss;
- mpr_Return(eid, mprObject("nss"));
-
- nss = ejsGetReturnValue(eid);
+ struct MprVar *nss = mprInitObject(eid, "nss", argc, argv);
mprSetCFunction(nss, "getpwnam", ejs_getpwnam);
mprSetCFunction(nss, "getpwuid", ejs_getpwuid);
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c
index b1fb854dfb..61b89843dc 100644
--- a/source4/scripting/ejs/smbcalls_sys.c
+++ b/source4/scripting/ejs/smbcalls_sys.c
@@ -193,19 +193,18 @@ static int ejs_sys_file_save(MprVarHandle eid, int argc, char **argv)
*/
static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv)
{
- struct MprVar obj = mprObject("sys");
-
- mprSetCFunction(&obj, "interfaces", ejs_sys_interfaces);
- mprSetCFunction(&obj, "hostname", ejs_sys_hostname);
- mprSetCFunction(&obj, "nttime", ejs_sys_nttime);
- mprSetCFunction(&obj, "gmtime", ejs_sys_gmtime);
- mprSetCFunction(&obj, "ldaptime", ejs_sys_ldaptime);
- mprSetCFunction(&obj, "httptime", ejs_sys_httptime);
- mprSetStringCFunction(&obj, "unlink", ejs_sys_unlink);
- mprSetStringCFunction(&obj, "file_load", ejs_sys_file_load);
- mprSetStringCFunction(&obj, "file_save", ejs_sys_file_save);
-
- mpr_Return(eid, obj);
+ struct MprVar *obj = mprInitObject(eid, "sys", argc, argv);
+
+ mprSetCFunction(obj, "interfaces", ejs_sys_interfaces);
+ mprSetCFunction(obj, "hostname", ejs_sys_hostname);
+ mprSetCFunction(obj, "nttime", ejs_sys_nttime);
+ mprSetCFunction(obj, "gmtime", ejs_sys_gmtime);
+ mprSetCFunction(obj, "ldaptime", ejs_sys_ldaptime);
+ mprSetCFunction(obj, "httptime", ejs_sys_httptime);
+ mprSetStringCFunction(obj, "unlink", ejs_sys_unlink);
+ mprSetStringCFunction(obj, "file_load", ejs_sys_file_load);
+ mprSetStringCFunction(obj, "file_save", ejs_sys_file_save);
+
return 0;
}