Merge branch 'v4-0-trivial' into v4-0-test
[kai/samba.git] / source / scripting / ejs / smbcalls.c
index 815b3e2b5d8f1cd5246bbb2620cb9df1e57803a5..63a80e17db65a85fce6a17bba418f1f66538f5ee 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
-#include "lib/appweb/ejs/ejs.h"
+#include "param/param.h"
 #include "scripting/ejs/smbcalls.h"
 #include "build.h"
 #include "version.h"
@@ -112,7 +111,7 @@ static int ejs_typeof_native(MprVarHandle eid, int argc, struct MprVar **argv)
 static int ejs_libinclude(int eid, int argc, char **argv)
 {
        int i, j;
-       const char **js_include = lp_js_include();
+       const char **js_include = lp_js_include(mprLpCtx());
 
        if (js_include == NULL || js_include[0] == NULL) {
                ejsSetErrorMsg(eid, "js include path not set");
@@ -121,17 +120,17 @@ static int ejs_libinclude(int eid, int argc, char **argv)
 
        for (i = 0; i < argc; i++) {
                const char *script = argv[i];
+               struct MprVar result;
+               char *path, *emsg;
+               int ret;
 
+               /* use specfied path to search for requested file */
                for (j=0;js_include[j];j++) {
-                       char *path;
                        path = talloc_asprintf(mprMemCtx(), "%s/%s", js_include[j], script);
                        if (path == NULL) {
                                return -1;
                        }
                        if (file_exist(path)) {
-                               int ret;
-                               struct MprVar result;
-                               char *emsg;
 
                                ret = ejsEvalFile(eid, path, &result, &emsg);
                                talloc_free(path);
@@ -143,6 +142,7 @@ static int ejs_libinclude(int eid, int argc, char **argv)
                        }
                        talloc_free(path);
                }
+
                if (js_include[j] == NULL) {
                        ejsSetErrorMsg(eid, "unable to include '%s'", script);
                        return -1;
@@ -161,81 +161,6 @@ static int ejs_version(MprVarHandle eid, int argc, struct MprVar **argv)
 }
 
 
-/*
- * jsonrpc_include() allows you to include jsonrpc files from a path based at
- * "jsonrpc base =" in smb.conf.
- */
-static int jsonrpc_include(int eid, int argc, char **argv)
-{
-        int ret = -1;
-        char *path;
-        char *emsg;
-       const char *jsonrpc_base = lp_jsonrpc_base();
-        struct MprVar result;
-
-
-       if (jsonrpc_base == NULL || jsonrpc_base == NULL) {
-               ejsSetErrorMsg(eid, "js include path not set");
-               return -1;
-       }
-
-        if (argc != 1) {
-                mpr_Return(eid, mprCreateIntegerVar(-1));
-               return 0;
-        }
-
-        path = talloc_asprintf(mprMemCtx(), "%s/%s", jsonrpc_base, argv[0]);
-        if (path == NULL) {
-                mpr_Return(eid, mprCreateIntegerVar(-1));
-                return 0;
-        }
-
-        if (file_exist(path)) {
-                ret = ejsEvalFile(eid, path, &result, &emsg);
-                if (ret < 0) {
-                        printf("file found; ret=%d (%s)\n", ret, emsg);
-                }
-        }
-        
-        mpr_Return(eid, mprCreateIntegerVar(ret));
-        talloc_free(path);
-       return 0;
-}
-
-
-static int ejs_debug(int eid, int argc, char **argv)
-{
-        int i;
-        int level;
-        void *ctx = mprMemCtx();
-        char *msg;
-
-
-        if (argc < 2) {
-               return -1;
-        }
-
-        level = atoi(argv[0]);
-
-        msg = talloc_zero_size(ctx, 1);
-        if (msg == NULL) {
-                DEBUG(0, ("out of memory in debug()\n"));
-                return 0;
-        }
-
-        for (i = 1; i < argc; i++) {
-                msg = talloc_append_string(ctx, msg, argv[i]);
-                if (msg == NULL) {
-                        DEBUG(0, ("out of memory in debug()\n"));
-                        return 0;
-                }
-        }
-
-        DEBUG(level, ("%s", msg));
-        talloc_free(msg);
-       return 0;
-}
-
 static void (*ejs_exception_handler) (const char *) = NULL;
 
 _PUBLIC_ void ejs_exception(const char *reason)
@@ -248,7 +173,7 @@ _PUBLIC_ void ejs_exception(const char *reason)
 */
 void smb_setup_ejs_functions(void (*exception_handler)(const char *))
 {
-       init_module_fn static_init[] = STATIC_smbcalls_MODULES;
+       init_module_fn static_init[] = { STATIC_smbcalls_MODULES };
        init_module_fn *shared_init;
 
        ejs_exception_handler = exception_handler;
@@ -259,9 +184,7 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *))
        smb_setup_ejs_param();
         smb_setup_ejs_literal();
        
-       ejsnet_setup();
-
-       shared_init = load_samba_modules(NULL, "smbcalls");
+       shared_init = load_samba_modules(NULL, mprLpCtx(), "smbcalls");
        
        run_init_functions(static_init);
        run_init_functions(shared_init);
@@ -272,7 +195,5 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *))
        ejsDefineCFunction(-1, "nativeTypeOf", ejs_typeof_native, NULL, MPR_VAR_SCRIPT_HANDLE);
        ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
        ejsDefineCFunction(-1, "version", ejs_version, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineStringCFunction(-1, "jsonrpc_include", jsonrpc_include, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineStringCFunction(-1, "debug", ejs_debug, NULL, MPR_VAR_SCRIPT_HANDLE);
 }