summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-11-02 01:04:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:39 -0500
commit783851099b43236666b2fc0cc866834773d6e7b7 (patch)
tree277745750144e4e326ae1ad6e246daba042c332c /source4/scripting/ejs
parente8c23e4e2d9aab7fcf0e7653756c84ef6cf34ed6 (diff)
downloadsamba-783851099b43236666b2fc0cc866834773d6e7b7.tar.gz
samba-783851099b43236666b2fc0cc866834773d6e7b7.tar.bz2
samba-783851099b43236666b2fc0cc866834773d6e7b7.zip
r11458: fixed our ejs smbscript interfaces to use arrays where appropriate. In
js arrays are a special type of object where the length property is automatic, and cannot be modified manually. Our code was manually setting length, which made it abort when someone passed in a real ejs array. To fix this we need to create real arrays instead of objects, and remove the code that manually sets the length (This used to be commit ebdd1393fde44a0a35446d1a922d29a7c1769ba7)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/mprutil.c27
-rw-r--r--source4/scripting/ejs/smbcalls_data.c2
-rw-r--r--source4/scripting/ejs/smbcalls_samba3.c28
-rw-r--r--source4/scripting/ejs/smbcalls_string.c2
-rw-r--r--source4/scripting/ejs/smbcalls_sys.c2
5 files changed, 34 insertions, 27 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index 9634c9bf42..91683db6bd 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -33,6 +33,14 @@ struct MprVar mprObject(const char *name)
}
/*
+ return a empty mpr array
+*/
+struct MprVar mprArray(const char *name)
+{
+ return ejsCreateArray(name && *name?name:"(NULL)", 0);
+}
+
+/*
find a mpr component, allowing for sub objects, using the '.' convention
*/
NTSTATUS mprGetVar(struct MprVar **v, const char *name)
@@ -101,7 +109,6 @@ struct MprVar mprObject(const char *name)
char idx[16];
mprItoa(i, idx, sizeof(idx));
mprSetVar(var, idx, v);
- mprSetVar(var, "length", mprCreateIntegerVar(i+1));
}
/*
@@ -112,13 +119,10 @@ struct MprVar mprList(const char *name, const char **list)
struct MprVar var;
int i;
- var = mprObject(name);
+ var = mprArray(name);
for (i=0;list && list[i];i++) {
mprAddArray(&var, i, mprString(list[i]));
}
- if (i==0) {
- mprSetVar(&var, "length", mprCreateIntegerVar(i));
- }
return var;
}
@@ -182,7 +186,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
val = mprData(v.data, v.length);
} else {
int j;
- val = mprObject(el->name);
+ val = mprArray(el->name);
for (j=0;j<el->num_values;j++) {
if (attr->ldif_write_fn(ldb, msg,
&el->values[j], &v) != 0) {
@@ -214,13 +218,10 @@ struct MprVar mprLdbArray(struct ldb_context *ldb,
struct MprVar res;
int i;
- res = mprObject(name);
+ res = mprArray(name);
for (i=0;i<count;i++) {
mprAddArray(&res, i, mprLdbMessage(ldb, msg[i]));
}
- if (i==0) {
- mprSetVar(&res, "length", mprCreateIntegerVar(0));
- }
return res;
}
@@ -230,6 +231,9 @@ struct MprVar mprLdbArray(struct ldb_context *ldb,
*/
const char *mprToString(const struct MprVar *v)
{
+ if (v->trigger) {
+ mprReadProperty(v, 0);
+ }
if (!mprVarIsString(v->type)) return NULL;
return v->string;
}
@@ -239,6 +243,9 @@ const char *mprToString(const struct MprVar *v)
*/
int mprToInt(const struct MprVar *v)
{
+ if (v->trigger) {
+ mprReadProperty(v, 0);
+ }
if (!mprVarIsNumber(v->type)) return 0;
return mprVarToNumber(v);
}
diff --git a/source4/scripting/ejs/smbcalls_data.c b/source4/scripting/ejs/smbcalls_data.c
index 4859de94d7..54e496ea57 100644
--- a/source4/scripting/ejs/smbcalls_data.c
+++ b/source4/scripting/ejs/smbcalls_data.c
@@ -88,7 +88,7 @@ static int ejs_blobToArray(MprVarHandle eid, int argc, struct MprVar **argv)
goto failed;
}
- array = mprObject("array");
+ array = mprArray("array");
for (i=0;i<blob->length;i++) {
mprAddArray(&array, i, mprCreateNumberVar(blob->data[i]));
diff --git a/source4/scripting/ejs/smbcalls_samba3.c b/source4/scripting/ejs/smbcalls_samba3.c
index 4a4977be60..0a05e4584f 100644
--- a/source4/scripting/ejs/smbcalls_samba3.c
+++ b/source4/scripting/ejs/smbcalls_samba3.c
@@ -31,14 +31,14 @@ static struct MprVar mprRegistry(struct samba3_regdb *reg)
struct MprVar mpv = mprObject("registry"), ks, vs, k, v;
int i, j;
- ks = mprObject("array");
+ ks = mprArray("array");
for (i = 0; i < reg->key_count; i++) {
k = mprObject("regkey");
mprSetVar(&k, "name", mprString(reg->keys[i].name));
- vs = mprObject("array");
+ vs = mprArray("array");
for (j = 0; j < reg->keys[i].value_count; j++) {
v = mprObject("regval");
@@ -90,7 +90,7 @@ static struct MprVar mprIdmapDb(struct samba3_idmapdb *db)
mprSetVar(&mpv, "user_hwm", mprCreateIntegerVar(db->user_hwm));
mprSetVar(&mpv, "group_hwm", mprCreateIntegerVar(db->group_hwm));
- mps = mprObject("array");
+ mps = mprArray("array");
for (i = 0; i < db->mapping_count; i++) {
char *tmp;
@@ -120,7 +120,7 @@ static struct MprVar mprIdmapDb(struct samba3_idmapdb *db)
static struct MprVar mprGroupMappings(struct samba3_groupdb *db)
{
- struct MprVar mpv = mprObject("array"), g;
+ struct MprVar mpv = mprArray("array"), g;
int i;
for (i = 0; i < db->groupmap_count; i++) {
@@ -161,7 +161,7 @@ static struct MprVar mprAliases(struct samba3_groupdb *db)
mprSetVar(&a, "sid", mprString(tmp));
talloc_free(tmp);
- am = mprObject("array");
+ am = mprArray("array");
for (j = 0; j < db->aliases[i].member_count; j++) {
tmp = dom_sid_string(NULL, db->aliases[i].members[j]);
@@ -218,7 +218,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
struct MprVar mpv = mprObject("samba3_secrets"), es, e;
int i;
- es = mprObject("array");
+ es = mprArray("array");
for (i = 0; i < sec->ldappw_count; i++) {
e = mprObject("ldappw");
@@ -231,7 +231,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
mprSetVar(&mpv, "ldappws", es);
- es = mprObject("array");
+ es = mprArray("array");
for (i = 0; i < sec->domain_count; i++) {
mprAddArray(&es, i, mprDomainSecrets(&sec->domains[i]));
@@ -243,7 +243,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
mprSetVar(&mpv, "domains", es);
- es = mprObject("trusted_domains");
+ es = mprArray("trusted_domains");
for (i = 0; i < sec->trusted_domain_count; i++) {
struct MprVar ns;
@@ -251,7 +251,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
int j;
e = mprObject("trusted_domain");
- ns = mprObject("array");
+ ns = mprArray("array");
for (j = 0; j < sec->trusted_domains[i].uni_name_len; j++) {
mprAddArray(&ns, j, mprString(sec->trusted_domains[i].uni_name[j]));
@@ -275,7 +275,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
mprSetVar(&mpv, "trusted_domains", es);
- es = mprObject("array");
+ es = mprArray("array");
for (i = 0; i < sec->afs_keyfile_count; i++) {
struct MprVar ks;
@@ -284,7 +284,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
mprSetVar(&e, "cell", mprString(sec->afs_keyfiles[i].cell));
- ks = mprObject("array");
+ ks = mprArray("array");
for (j = 0; j < 8; j++) {
struct MprVar k = mprObject("entry");
@@ -318,7 +318,7 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
static struct MprVar mprShares(struct samba3 *samba3)
{
- struct MprVar mpv = mprObject("array"), s;
+ struct MprVar mpv = mprArray("array"), s;
int i;
for (i = 0; i < samba3->share_count; i++) {
@@ -340,7 +340,7 @@ static struct MprVar mprShares(struct samba3 *samba3)
static struct MprVar mprSamAccounts(struct samba3 *samba3)
{
- struct MprVar mpv = mprObject("array"), m;
+ struct MprVar mpv = mprArray("array"), m;
int i;
for (i = 0; i < samba3->samaccount_count; i++) {
@@ -391,7 +391,7 @@ static struct MprVar mprSamAccounts(struct samba3 *samba3)
static struct MprVar mprWinsEntries(struct samba3 *samba3)
{
- struct MprVar mpv = mprObject("array");
+ struct MprVar mpv = mprArray("array");
int i, j;
for (i = 0; i < samba3->winsdb_count; i++) {
diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c
index 5976e42251..e9e6e148d1 100644
--- a/source4/scripting/ejs/smbcalls_string.c
+++ b/source4/scripting/ejs/smbcalls_string.c
@@ -109,7 +109,7 @@ static int ejs_split(MprVarHandle eid, int argc, char **argv)
separator = argv[0];
s = argv[1];
- ret = mprObject("list");
+ ret = mprArray("list");
while ((p = strstr(s, separator))) {
char *s2 = talloc_strndup(tmp_ctx, s, (int)(p-s));
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c
index f39d5cbddc..1a876c9e87 100644
--- a/source4/scripting/ejs/smbcalls_sys.c
+++ b/source4/scripting/ejs/smbcalls_sys.c
@@ -32,7 +32,7 @@
static int ejs_sys_interfaces(MprVarHandle eid, int argc, struct MprVar **argv)
{
int i, count = iface_count();
- struct MprVar ret = mprObject("interfaces");
+ struct MprVar ret = mprArray("interfaces");
for (i=0;i<count;i++) {
mprAddArray(&ret, i, mprString(iface_n_ip(i)));
}