diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-07-15 05:40:34 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:23:07 -0500 |
commit | 63535f566e2fbe9244fd3e50b9c8d1281b822fc0 (patch) | |
tree | e14f9101f03c29c7a076576efd36d3ac7a8e381f /source4/scripting/ejs | |
parent | 970ff9ba8d0b47fce6760e6adf9458820c5084b9 (diff) | |
download | samba-63535f566e2fbe9244fd3e50b9c8d1281b822fc0.tar.gz samba-63535f566e2fbe9244fd3e50b9c8d1281b822fc0.tar.bz2 samba-63535f566e2fbe9244fd3e50b9c8d1281b822fc0.zip |
r8481: switched ldb ejs called over to an OO interface, so you do:
var ldb = ldb_init();
res = ldb.search(dbfile, "(objectClass=user)");
you can also do:
ldbSearch = ldb.search;
res = ldbSearch(dbfile, "(objectClass=user)");
if you want the old interface (ie. you can use this to import
functions into the global or local namespace).
(This used to be commit 3093057d9735cbb62f57e7159264d5a28b85320f)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/mprutil.c | 15 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls.h | 3 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_ldb.c | 22 |
3 files changed, 35 insertions, 5 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c index 49c4f74cd6..247cea0b06 100644 --- a/source4/scripting/ejs/mprutil.c +++ b/source4/scripting/ejs/mprutil.c @@ -367,3 +367,18 @@ void mpr_ReturnString(int eid, const char *s) } +/* + set a C function in a variable +*/ + void mprSetCFunction(struct MprVar *obj, const char *name, MprCFunction fn) +{ + mprSetVar(obj, name, mprCreateCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE)); +} + +/* + set a string C function in a variable +*/ + void mprSetStringCFunction(struct MprVar *obj, const char *name, MprStringCFunction fn) +{ + mprSetVar(obj, name, mprCreateStringCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE)); +} diff --git a/source4/scripting/ejs/smbcalls.h b/source4/scripting/ejs/smbcalls.h index 8002e3d8bb..aa5c27b4f5 100644 --- a/source4/scripting/ejs/smbcalls.h +++ b/source4/scripting/ejs/smbcalls.h @@ -26,3 +26,6 @@ void mpr_Return(int eid, struct MprVar); NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val); NTSTATUS mprGetVar(struct MprVar **v, const char *name); void mprAddArray(struct MprVar *var, int i, struct MprVar v); +void mprSetCFunction(struct MprVar *obj, const char *name, MprCFunction fn); +void mprSetStringCFunction(struct MprVar *obj, const char *name, MprStringCFunction fn); + diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c index 2df53ace4f..659ac11b1b 100644 --- a/source4/scripting/ejs/smbcalls_ldb.c +++ b/source4/scripting/ejs/smbcalls_ldb.c @@ -222,6 +222,22 @@ static int ejs_ldbModify(MprVarHandle eid, int argc, char **argv) return ejs_ldbAddModify(eid, argc, argv, ldb_modify); } +/* + initialise ldb ejs subsystem +*/ +static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct MprVar ldb = mprObject("ldb"); + + mprSetCFunction(&ldb, "search", ejs_ldbSearch); + mprSetStringCFunction(&ldb, "add", ejs_ldbAdd); + mprSetStringCFunction(&ldb, "modify", ejs_ldbModify); + mprSetStringCFunction(&ldb, "delete", ejs_ldbDelete); + mprSetStringCFunction(&ldb, "rename", ejs_ldbRename); + + mpr_Return(eid, ldb); + return 0; +} /* @@ -229,9 +245,5 @@ static int ejs_ldbModify(MprVarHandle eid, int argc, char **argv) */ void smb_setup_ejs_ldb(void) { - ejsDefineCFunction(-1, "ldbSearch", ejs_ldbSearch, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineStringCFunction(-1, "ldbAdd", ejs_ldbAdd, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineStringCFunction(-1, "ldbModify", ejs_ldbModify, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineStringCFunction(-1, "ldbDelete", ejs_ldbDelete, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineStringCFunction(-1, "ldbRename", ejs_ldbRename, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineCFunction(-1, "ldb_init", ejs_ldb_init, NULL, MPR_VAR_SCRIPT_HANDLE); } |