summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/mprutil.c7
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c78
2 files changed, 44 insertions, 41 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index 247cea0b06..f25064f245 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -202,6 +202,9 @@ struct MprVar mprLdbArray(struct ldb_message **msg, int count, const char *name)
for (i=0;i<count;i++) {
mprAddArray(&res, i, mprLdbMessage(msg[i]));
}
+ if (i==0) {
+ mprSetVar(&res, "length", mprCreateIntegerVar(0));
+ }
return res;
}
@@ -372,7 +375,7 @@ void mpr_ReturnString(int eid, const char *s)
*/
void mprSetCFunction(struct MprVar *obj, const char *name, MprCFunction fn)
{
- mprSetVar(obj, name, mprCreateCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE));
+ mprSetVar(obj, name, mprCreateCFunctionVar(fn, obj, MPR_VAR_SCRIPT_HANDLE));
}
/*
@@ -380,5 +383,5 @@ void mpr_ReturnString(int eid, const char *s)
*/
void mprSetStringCFunction(struct MprVar *obj, const char *name, MprStringCFunction fn)
{
- mprSetVar(obj, name, mprCreateStringCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE));
+ mprSetVar(obj, name, mprCreateStringCFunctionVar(fn, obj, MPR_VAR_SCRIPT_HANDLE));
}
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;
}