2 Unix SMB/CIFS implementation.
4 provide hooks into smbd C calls from ejs scripts
6 Copyright (C) Andrew Tridgell 2005
7 Copyright (C) Tim Potter 2005
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "lib/appweb/ejs/ejs.h"
26 #include "scripting/ejs/smbcalls.h"
31 return the type of a variable
33 static int ejs_typeof(MprVarHandle eid, int argc, struct MprVar **argv)
39 { MPR_TYPE_UNDEFINED, "undefined" },
40 { MPR_TYPE_NULL, "object" },
41 { MPR_TYPE_BOOL, "boolean" },
42 { MPR_TYPE_CFUNCTION, "function" },
43 { MPR_TYPE_FLOAT, "number" },
44 { MPR_TYPE_INT, "number" },
45 { MPR_TYPE_INT64, "number" },
46 { MPR_TYPE_OBJECT, "object" },
47 { MPR_TYPE_FUNCTION, "function" },
48 { MPR_TYPE_STRING, "string" },
49 { MPR_TYPE_STRING_CFUNCTION, "function" },
50 { MPR_TYPE_PTR, "pointer" }
53 const char *type = NULL;
55 if (argc != 1) return -1;
57 for (i=0;i<ARRAY_SIZE(types);i++) {
58 if (argv[0]->type == types[i].type) {
63 if (type == NULL) return -1;
65 mpr_ReturnString(eid, type);
70 libinclude() allows you to include js files using a search path specified
71 in "js include =" in smb.conf.
73 static int ejs_libinclude(int eid, int argc, char **argv)
76 const char **js_include = lp_js_include();
78 if (js_include == NULL || js_include[0] == NULL) {
79 ejsSetErrorMsg(eid, "js include path not set");
83 for (i = 0; i < argc; i++) {
84 const char *script = argv[i];
86 for (j=0;js_include[j];j++) {
88 path = talloc_asprintf(mprMemCtx(), "%s/%s", js_include[j], script);
92 if (file_exist(path)) {
97 ret = ejsEvalFile(eid, path, &result, &emsg);
100 ejsSetErrorMsg(eid, "%s: %s", script, emsg);
107 if (js_include[j] == NULL) {
108 ejsSetErrorMsg(eid, "unable to include '%s'", script);
116 return the current version
118 static int ejs_version(MprVarHandle eid, int argc, struct MprVar **argv)
120 mpr_ReturnString(eid, SAMBA_VERSION_STRING);
124 static void (*ejs_exception_handler) (const char *) = NULL;
126 _PUBLIC_ void ejs_exception(const char *reason)
128 ejs_exception_handler(reason);
132 setup C functions that be called from ejs
134 void smb_setup_ejs_functions(void (*exception_handler)(const char *))
136 init_module_fn static_init[] = STATIC_smbcalls_MODULES;
137 init_module_fn *shared_init;
139 ejs_exception_handler = exception_handler;
142 smb_setup_ejs_options();
143 smb_setup_ejs_credentials();
144 smb_setup_ejs_param();
148 shared_init = load_samba_modules(NULL, "smbcalls");
150 run_init_functions(static_init);
151 run_init_functions(shared_init);
153 talloc_free(shared_init);
155 ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
156 ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
157 ejsDefineCFunction(-1, "version", ejs_version, NULL, MPR_VAR_SCRIPT_HANDLE);