2 Unix SMB/CIFS implementation.
4 provide hooks into smbd C calls from ejs scripts
6 Copyright (C) Jelmer Vernooij 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "scripting/ejs/smbcalls.h"
25 #include "lib/appweb/ejs/ejs.h"
26 #include "param/generic.h"
27 #include "dynconfig.h"
32 value = param.get("name");
33 value = param.get("section", "name");
35 static int ejs_param_get(MprVarHandle eid, int argc, char **argv)
37 struct param_context *ctx;
39 if (argc != 1 && argc != 2) {
40 ejsSetErrorMsg(eid, "param.get invalid argument count");
44 ctx = mprGetThisPtr(eid, "param");
48 ret = param_get_string(ctx, argv[0], argv[1]);
50 ret = param_get_string(ctx, NULL, argv[0]);
54 mpr_Return(eid, mprString(ret));
56 mpr_Return(eid, mprCreateUndefinedVar());
64 ok = param.get_list("name");
65 ok = param.get_list("section", "name");
67 static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv)
69 struct param_context *ctx;
72 if (argc != 1 && argc != 2) {
73 ejsSetErrorMsg(eid, "param.get invalid argument count");
77 ctx = mprGetThisPtr(eid, "param");
81 ret = param_get_string_list(ctx, argv[0], argv[1], NULL);
83 ret = param_get_string_list(ctx, NULL, argv[0], NULL);
87 mpr_Return(eid, mprList("array", ret));
89 mpr_Return(eid, mprCreateUndefinedVar());
97 ok = param.set("name", "value");
98 ok = param.set("section", "name", "value");
100 static int ejs_param_set(MprVarHandle eid, int argc, char **argv)
102 struct param_context *ctx;
104 if (argc != 2 && argc != 3) {
105 ejsSetErrorMsg(eid, "param.set invalid argument count");
109 ctx = mprGetThisPtr(eid, "param");
113 ret = param_set_string(ctx, argv[0], argv[1], argv[2]);
115 ret = param_set_string(ctx, NULL, argv[0], argv[2]);
118 mpr_Return(eid, mprCreateBoolVar(ret));
125 ok = param.load(file);
127 static int ejs_param_load(MprVarHandle eid, int argc, char **argv)
129 struct param_context *ctx;
133 ejsSetErrorMsg(eid, "param.load invalid argument count");
137 ctx = mprGetThisPtr(eid, "param");
140 ret = param_read(ctx, argv[0]);
142 mpr_Return(eid, mprCreateBoolVar(ret));
149 ok = param.save(file);
151 static int ejs_param_save(MprVarHandle eid, int argc, char **argv)
153 struct param_context *ctx;
157 ejsSetErrorMsg(eid, "param.save invalid argument count");
161 ctx = mprGetThisPtr(eid, "param");
164 ret = param_write(ctx, argv[0]);
166 mpr_Return(eid, mprCreateBoolVar(ret));
170 static void param_add_members(struct MprVar *obj)
172 mprSetStringCFunction(obj, "get", ejs_param_get);
173 mprSetStringCFunction(obj, "get_list", ejs_param_get_list);
174 mprSetStringCFunction(obj, "set", ejs_param_set);
175 mprSetStringCFunction(obj, "load", ejs_param_load);
176 mprSetStringCFunction(obj, "save", ejs_param_save);
180 initialise param ejs subsystem
182 static int ejs_param_init(MprVarHandle eid, int argc, struct MprVar **argv)
184 struct MprVar *obj = mprInitObject(eid, "param", argc, argv);
186 mprSetPtrChild(obj, "param", param_init(mprMemCtx()));
188 param_add_members(obj);
193 struct MprVar mprParam(struct param_context *ctx)
195 struct MprVar mpv = mprObject("param");
196 mprSetPtrChild(&mpv, "param", ctx);
197 param_add_members(&mpv);
202 setup C functions that be called from ejs
204 void smb_setup_ejs_param(void)
206 ejsDefineCFunction(-1, "param_init", ejs_param_init, NULL, MPR_VAR_SCRIPT_HANDLE);