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"
29 return the type of a variable
31 static int ejs_typeof(MprVarHandle eid, int argc, struct MprVar **argv)
37 { MPR_TYPE_UNDEFINED, "undefined" },
38 { MPR_TYPE_NULL, "object" },
39 { MPR_TYPE_BOOL, "boolean" },
40 { MPR_TYPE_CFUNCTION, "function" },
41 { MPR_TYPE_FLOAT, "number" },
42 { MPR_TYPE_INT, "number" },
43 { MPR_TYPE_INT64, "number" },
44 { MPR_TYPE_OBJECT, "object" },
45 { MPR_TYPE_FUNCTION, "function" },
46 { MPR_TYPE_STRING, "string" },
47 { MPR_TYPE_STRING_CFUNCTION, "function" },
48 { MPR_TYPE_PTR, "pointer" }
51 const char *type = NULL;
53 if (argc != 1) return -1;
55 for (i=0;i<ARRAY_SIZE(types);i++) {
56 if (argv[0]->type == types[i].type) {
61 if (type == NULL) return -1;
63 mpr_ReturnString(eid, type);
68 libinclude() allows you to include js files using a search path specified
69 in "js include =" in smb.conf.
71 static int ejs_libinclude(int eid, int argc, char **argv)
74 const char **js_include = lp_js_include();
76 if (js_include == NULL || js_include[0] == NULL) {
77 ejsSetErrorMsg(eid, "js include path not set");
81 for (i = 0; i < argc; i++) {
82 const char *script = argv[i];
84 for (j=0;js_include[j];j++) {
86 path = talloc_asprintf(mprMemCtx(), "%s/%s", js_include[j], script);
90 if (file_exist(path)) {
95 ret = ejsEvalFile(eid, path, &result, &emsg);
98 ejsSetErrorMsg(eid, "%s: %s", script, emsg);
105 if (js_include[j] == NULL) {
106 ejsSetErrorMsg(eid, "unable to include '%s'", script);
115 setup C functions that be called from ejs
117 void smb_setup_ejs_functions(void)
119 smb_setup_ejs_config();
124 smb_setup_ejs_auth();
125 smb_setup_ejs_options();
127 smb_setup_ejs_string();
128 smb_setup_ejs_random();
129 smb_setup_ejs_system();
130 smb_setup_ejs_credentials();
132 ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
133 ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);