diff options
author | Simo Sorce <idra@samba.org> | 2007-02-14 21:55:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:48:18 -0500 |
commit | 7ca399c0755e186508a4ed9796cbbbe6f50181e9 (patch) | |
tree | 50c7ce84b894bfdd46a773c16a890401afe751c1 /source4/scripting/ejs | |
parent | bd7df755f326e9c601439c0aa727961c4a4f4518 (diff) | |
download | samba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.tar.gz samba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.tar.bz2 samba-7ca399c0755e186508a4ed9796cbbbe6f50181e9.zip |
r21351: Change ldb ejs bindings return codes.
We were returning just true/false and discarding error number and string.
This checking probably breaks swat, will fix it in next round as swat
is what made me look into this as I had no way to get back error messages
to show to the users.
Simo.
(This used to be commit 35886b4ae68be475b0fc8b2689ca04d766661261)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/mprutil.c | 31 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls.h | 1 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_ldb.c | 10 |
3 files changed, 28 insertions, 14 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c index cfed69dbe0..459f198dca 100644 --- a/source4/scripting/ejs/mprutil.c +++ b/source4/scripting/ejs/mprutil.c @@ -223,19 +223,32 @@ failed: /* - turn an array of ldb_messages into a ejs object variable + build a MprVar result object for ldb operations with lots of funky properties */ -struct MprVar mprLdbArray(struct ldb_context *ldb, - struct ldb_message **msg, int count, const char *name) +struct MprVar mprLdbResult(struct ldb_context *ldb, int err, struct ldb_result *result) { - struct MprVar res; - int i; + struct MprVar ret; + struct MprVar ary; + + ret = mprObject("ldbret"); + + mprSetVar(&ret, "error", mprCreateIntegerVar(err)); + mprSetVar(&ret, "errstr", mprString(ldb_errstring(ldb))); + + ary = mprArray("ldb_message"); + if (result) { + int i; - res = mprArray(name); - for (i=0;i<count;i++) { - mprAddArray(&res, i, mprLdbMessage(ldb, msg[i])); + for (i = 0; i < result->count; i++) { + mprAddArray(&ary, i, mprLdbMessage(ldb, result->msgs[i])); + } } - return res; + + mprSetVar(&ret, "msgs", ary); + + /* TODO: add referrals, exteded ops, and controls */ + + return ret; } diff --git a/source4/scripting/ejs/smbcalls.h b/source4/scripting/ejs/smbcalls.h index 9fa9100276..a525403493 100644 --- a/source4/scripting/ejs/smbcalls.h +++ b/source4/scripting/ejs/smbcalls.h @@ -21,6 +21,7 @@ */ #include "lib/appweb/ejs/ejs.h" +#include "lib/ldb/include/ldb.h" void mpr_Return(int eid, struct MprVar); NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val); diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c index 3c368bba4f..fc44862985 100644 --- a/source4/scripting/ejs/smbcalls_ldb.c +++ b/source4/scripting/ejs/smbcalls_ldb.c @@ -108,9 +108,9 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) ret = ldb_search(ldb, basedn, scope, expression, attrs, &res); if (ret != LDB_SUCCESS) { ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb)); - mpr_Return(eid, mprCreateUndefinedVar()); + mpr_Return(eid, mprLdbResult(ldb, ret, NULL)); } else { - mpr_Return(eid, mprLdbArray(ldb, res->msgs, res->count, "ldb_message")); + mpr_Return(eid, mprLdbResult(ldb, ret, res)); talloc_free(res); } talloc_free(tmp_ctx); @@ -161,7 +161,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv, return -1; } - mpr_Return(eid, mprCreateBoolVar(ret == 0)); + mpr_Return(eid, mprLdbResult(ldb, ret, NULL)); return 0; } @@ -197,7 +197,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv) talloc_free(dn); - mpr_Return(eid, mprCreateBoolVar(ret == 0)); + mpr_Return(eid, mprLdbResult(ldb, ret, NULL)); return 0; } @@ -234,7 +234,7 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv) talloc_free(dn1); talloc_free(dn2); - mpr_Return(eid, mprCreateBoolVar(ret == 0)); + mpr_Return(eid, mprLdbResult(ldb, ret, NULL)); return 0; } |