summaryrefslogtreecommitdiffstats
path: root/source4/scripting/ejs/smbcalls_ldb.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-15 11:10:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:23:08 -0500
commit94d99612b9093ca83da3b6b66f875915eeabb389 (patch)
tree17aad583cb4a7bfc7f2ee384f680b7264e035120 /source4/scripting/ejs/smbcalls_ldb.c
parent2bb9fa28754b8575c5926646c1a6221475d24dcc (diff)
downloadsamba-94d99612b9093ca83da3b6b66f875915eeabb389.tar.gz
samba-94d99612b9093ca83da3b6b66f875915eeabb389.tar.xz
samba-94d99612b9093ca83da3b6b66f875915eeabb389.zip
r8488: after discussions with simo, moved to a full OO interface, so you don't need to keep
a 'db' variable around. The ldb object knows what it is connected to. Added a simple ldb testsuite in testprogs/ldb.js (This used to be commit cf35818648b5b649d0cd25f115a04b7b5b5311aa)
Diffstat (limited to 'source4/scripting/ejs/smbcalls_ldb.c')
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index be54ac79ac..924a9665b3 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -28,9 +28,10 @@
/*
get the connected db
*/
-static struct ldb_context *ejs_ldb_db(int eid, struct MprVar *v)
+static struct ldb_context *ejs_ldb_db(int eid)
{
- struct ldb_context *ldb = mprGetPtr(v, "ldb");
+ struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
+ struct ldb_context *ldb = mprGetPtr(this, "db");
if (ldb == NULL) {
ejsSetErrorMsg(eid, "invalid ldb connection");
}
@@ -41,9 +42,9 @@ static struct ldb_context *ejs_ldb_db(int eid, struct MprVar *v)
perform an ldb search, returning an array of results
syntax:
- res = ldb.search(db, "expression");
+ res = ldb.search("expression");
var attrs = new Array("attr1", "attr2", "attr3");
- ldb.search(db, "expression", attrs);
+ ldb.search("expression", attrs);
*/
static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -55,27 +56,27 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
struct ldb_message **res;
/* validate arguments */
- if (argc < 2 || argc > 3) {
+ if (argc < 1 || argc > 2) {
ejsSetErrorMsg(eid, "ldb.search invalid arguments");
goto failed;
}
- if (argc == 3 && argv[2]->type != MPR_TYPE_OBJECT) {
+ if (argc == 2 && argv[1]->type != MPR_TYPE_OBJECT) {
ejsSetErrorMsg(eid, "ldb.search attributes must be an object");
goto failed;
}
- ldb = ejs_ldb_db(eid, argv[0]);
+ ldb = ejs_ldb_db(eid);
if (ldb == NULL) {
return -1;
}
- expression = mprToString(argv[1]);
+ expression = mprToString(argv[0]);
if (expression == NULL) {
ejsSetErrorMsg(eid, "ldb.search invalid arguments");
goto failed;
}
- if (argc > 2) {
- attrs = mprToList(tmp_ctx, argv[2]);
+ if (argc == 2) {
+ attrs = mprToList(tmp_ctx, argv[1]);
}
ret = ldb_search(ldb, NULL, LDB_SCOPE_DEFAULT, expression, attrs, &res);
@@ -106,18 +107,18 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
struct ldb_ldif *ldif;
int ret;
- if (argc != 2) {
+ if (argc != 1) {
ejsSetErrorMsg(eid, "ldb.add/modify invalid arguments");
return -1;
}
- ldifstring = mprToString(argv[1]);
+ ldifstring = mprToString(argv[0]);
if (ldifstring == NULL) {
ejsSetErrorMsg(eid, "ldb.add/modify invalid arguments");
return -1;
}
- ldb = ejs_ldb_db(eid, argv[0]);
+ ldb = ejs_ldb_db(eid);
if (ldb == NULL) {
return -1;
}
@@ -136,7 +137,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
/*
perform an ldb delete
usage:
- ok = ldb.delete(db, dn);
+ ok = ldb.delete(dn);
*/
static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -144,14 +145,14 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
struct ldb_context *ldb;
int ret;
- if (argc != 2) {
+ if (argc != 1) {
ejsSetErrorMsg(eid, "ldb.delete invalid arguments");
return -1;
}
- dn = mprToString(argv[1]);
+ dn = mprToString(argv[0]);
- ldb = ejs_ldb_db(eid, argv[0]);
+ ldb = ejs_ldb_db(eid);
if (ldb == NULL) {
return -1;
}
@@ -164,7 +165,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
/*
perform an ldb rename
usage:
- ok = ldb.rename(db, dn1, dn2);
+ ok = ldb.rename(dn1, dn2);
*/
static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -172,19 +173,19 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
struct ldb_context *ldb;
int ret;
- if (argc != 3) {
+ if (argc != 2) {
ejsSetErrorMsg(eid, "ldb.rename invalid arguments");
return -1;
}
- dn1 = mprToString(argv[1]);
- dn2 = mprToString(argv[2]);
+ dn1 = mprToString(argv[0]);
+ dn2 = mprToString(argv[1]);
if (dn1 == NULL || dn2 == NULL) {
ejsSetErrorMsg(eid, "ldb.rename invalid arguments");
return -1;
}
- ldb = ejs_ldb_db(eid, argv[0]);
+ ldb = ejs_ldb_db(eid);
if (ldb == NULL) {
return -1;
}
@@ -199,7 +200,7 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
perform an ldb modify
syntax:
- ok = ldb.modify(db, ldifstring);
+ ok = ldb.modify(ldifstring);
*/
static int ejs_ldbAdd(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -210,7 +211,7 @@ static int ejs_ldbAdd(MprVarHandle eid, int argc, struct MprVar **argv)
perform an ldb add
syntax:
- ok = ldb.add(db, ldifstring);
+ ok = ldb.add(ldifstring);
*/
static int ejs_ldbModify(MprVarHandle eid, int argc, struct MprVar **argv)
{
@@ -220,13 +221,13 @@ static int ejs_ldbModify(MprVarHandle eid, int argc, struct MprVar **argv)
/*
connect to a database
usage:
- db = ldb.connect(dbfile);
+ ok = ldb.connect(dbfile);
*/
static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
{
struct ldb_context *ldb;
const char *dbfile;
- struct MprVar v;
+ struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
if (argc != 1) {
ejsSetErrorMsg(eid, "ldb.connect invalid arguments");
@@ -238,13 +239,10 @@ static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, NULL);
if (ldb == NULL) {
ejsSetErrorMsg(eid, "ldb.connect failed to open %s", dbfile);
- mpr_Return(eid, mprCreateUndefinedVar());
}
- v = mprObject("db");
- mprSetPtrChild(&v, "ldb", ldb);
-
- mpr_Return(eid, v);
+ mprSetPtrChild(this, "db", ldb);
+ mpr_Return(eid, mprCreateBoolVar(ldb != NULL));
return 0;
}
@@ -254,16 +252,18 @@ 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 = mprObject("ldb");
+ struct MprVar *ldb;
+ mpr_Return(eid, mprObject("ldb"));
+
+ ldb = ejsGetReturnValue(eid);
- mprSetStringCFunction(&ldb, "connect", ejs_ldbConnect);
- mprSetCFunction(&ldb, "search", ejs_ldbSearch);
- mprSetCFunction(&ldb, "add", ejs_ldbAdd);
- mprSetCFunction(&ldb, "modify", ejs_ldbModify);
- mprSetCFunction(&ldb, "delete", ejs_ldbDelete);
- mprSetCFunction(&ldb, "rename", ejs_ldbRename);
+ mprSetStringCFunction(ldb, "connect", ejs_ldbConnect);
+ mprSetCFunction(ldb, "search", ejs_ldbSearch);
+ mprSetCFunction(ldb, "add", ejs_ldbAdd);
+ mprSetCFunction(ldb, "modify", ejs_ldbModify);
+ mprSetCFunction(ldb, "delete", ejs_ldbDelete);
+ mprSetCFunction(ldb, "rename", ejs_ldbRename);
- mpr_Return(eid, ldb);
return 0;
}