diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-08-30 16:09:38 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:35:03 -0500 |
commit | cf016f972b931b54c155ca8e6df485e05c37b034 (patch) | |
tree | 61a716f6c30ec08f01d22a0d68dcef951132f5c0 /source4/scripting/ejs | |
parent | 9f4b32996c1c97122b198a13216c35ad40f6ea2d (diff) | |
download | samba-cf016f972b931b54c155ca8e6df485e05c37b034.tar.gz samba-cf016f972b931b54c155ca8e6df485e05c37b034.tar.bz2 samba-cf016f972b931b54c155ca8e6df485e05c37b034.zip |
r9805: Add 'data' property to param EJS object
Write out new smb.conf file. Parameters that have disappeared
between Samba 3 and 4 will optionally be prefixed with 'samba3:'
(This used to be commit 27eefbd9059fe0a3daca15a71da7b4cb88ed22ec)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/smbcalls_param.c | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c index e5553cac0b..ddd2b44c82 100644 --- a/source4/scripting/ejs/smbcalls_param.c +++ b/source4/scripting/ejs/smbcalls_param.c @@ -97,9 +97,12 @@ static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv) ok = param.set("name", "value"); ok = param.set("section", "name", "value"); */ -static int ejs_param_set(MprVarHandle eid, int argc, char **argv) +static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv) { struct param_context *ctx; + const char **list; + const char *section, *paramname; + struct MprVar *value; bool ret; if (argc != 2 && argc != 3) { ejsSetErrorMsg(eid, "param.set invalid argument count"); @@ -108,17 +111,66 @@ static int ejs_param_set(MprVarHandle eid, int argc, char **argv) ctx = mprGetThisPtr(eid, "param"); mprAssert(ctx); + if (argc == 3) { - ret = param_set_string(ctx, argv[0], argv[1], argv[2]); + section = mprToString(argv[0]); + paramname = mprToString(argv[1]); + value = argv[2]; + } else { + section = NULL; + paramname = mprToString(argv[0]); + value = argv[1]; + } + + list = mprToList(mprMemCtx(), value); + if (list) { + ret = param_set_string_list(ctx, section, paramname, list); } else { - ret = param_set_string(ctx, NULL, argv[0], argv[2]); + ret = param_set_string(ctx, section, paramname, mprToString(value)); } mpr_Return(eid, mprCreateBoolVar(ret)); return 0; } +/* + param data as a two-level array + + data = param.data; + */ +static int ejs_param_data(MprVarHandle eid, int argc, char **argv) +{ + struct param_context *ctx; + struct MprVar ret; + struct param_section *sec; + + if (argc != 0) { + ejsSetErrorMsg(eid, "param.data does not take arguments"); + return -1; + } + + ctx = mprGetThisPtr(eid, "param"); + mprAssert(ctx); + + ret = mprObject("array"); + + for (sec = ctx->sections; sec; sec = sec->next) { + struct MprVar ps = mprObject("array"); + struct param *p; + + for (p = sec->parameters; p; p = p->next) { + mprSetVar(&ps, p->name, mprString(p->value)); + } + + mprSetVar(&ret, sec->name, ps); + } + + mpr_Return(eid, ret); + + return 0; +} + /* load file @@ -143,6 +195,7 @@ static int ejs_param_load(MprVarHandle eid, int argc, char **argv) return 0; } + /* save file @@ -171,9 +224,10 @@ static void param_add_members(struct MprVar *obj) { mprSetStringCFunction(obj, "get", ejs_param_get); mprSetStringCFunction(obj, "get_list", ejs_param_get_list); - mprSetStringCFunction(obj, "set", ejs_param_set); + mprSetCFunction(obj, "set", ejs_param_set); mprSetStringCFunction(obj, "load", ejs_param_load); mprSetStringCFunction(obj, "save", ejs_param_save); + mprSetStringCFunction(obj, "data", ejs_param_data); } /* |