summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-11-02 06:41:11 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:41 -0500
commitc845ab1e60f2c97410fa4d530aa594f1f3d5fe55 (patch)
tree684ba0b1cb4859846ec4304ce32329823782972d /source4/scripting/ejs
parent66d3ee9ccb9807ca443962ef2a887627505c537c (diff)
downloadsamba-c845ab1e60f2c97410fa4d530aa594f1f3d5fe55.tar.gz
samba-c845ab1e60f2c97410fa4d530aa594f1f3d5fe55.tar.bz2
samba-c845ab1e60f2c97410fa4d530aa594f1f3d5fe55.zip
r11474: - enable ldb transactions from ejs
- speed up provisioning a bit using a ldb transaction (also means you can't end up with a ldb being half done) (This used to be commit 91dfe304cf688bb81b69ff3192ac84b78b34b311)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 83d5f1ae44..b77736dc36 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -397,6 +397,84 @@ static int ejs_ldbClose(MprVarHandle eid, int argc, struct MprVar **argv)
/*
+ start a ldb transaction
+ usage:
+ ok = ldb.transaction_start();
+*/
+static int ejs_ldbTransactionStart(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct ldb_context *ldb;
+ int ret;
+
+ if (argc != 0) {
+ ejsSetErrorMsg(eid, "ldb.transaction_start invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ ret = ldb_transaction_start(ldb);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ return 0;
+}
+
+/*
+ cancel a ldb transaction
+ usage:
+ ok = ldb.transaction_cancel();
+*/
+static int ejs_ldbTransactionCancel(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct ldb_context *ldb;
+ int ret;
+
+ if (argc != 0) {
+ ejsSetErrorMsg(eid, "ldb.transaction_cancel invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ ret = ldb_transaction_cancel(ldb);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ return 0;
+}
+
+/*
+ commit a ldb transaction
+ usage:
+ ok = ldb.transaction_commit();
+*/
+static int ejs_ldbTransactionCommit(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct ldb_context *ldb;
+ int ret;
+
+ if (argc != 0) {
+ ejsSetErrorMsg(eid, "ldb.transaction_commit invalid arguments");
+ return -1;
+ }
+
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
+ return -1;
+ }
+
+ ret = ldb_transaction_commit(ldb);
+
+ mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ return 0;
+}
+
+/*
initialise ldb ejs subsystem
*/
static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -413,6 +491,9 @@ static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
mprSetCFunction(ldb, "encode", ejs_base64encode);
mprSetCFunction(ldb, "decode", ejs_base64decode);
mprSetCFunction(ldb, "close", ejs_ldbClose);
+ mprSetCFunction(ldb, "transaction_start", ejs_ldbTransactionStart);
+ mprSetCFunction(ldb, "transaction_cancel", ejs_ldbTransactionCancel);
+ mprSetCFunction(ldb, "transaction_commit", ejs_ldbTransactionCommit);
mprSetVar(ldb, "SCOPE_BASE", mprCreateNumberVar(LDB_SCOPE_BASE));
mprSetVar(ldb, "SCOPE_ONE", mprCreateNumberVar(LDB_SCOPE_ONELEVEL));
mprSetVar(ldb, "SCOPE_SUBTREE", mprCreateNumberVar(LDB_SCOPE_SUBTREE));