[Freeswitch-svn] [commit] r4471 - in freeswitch/trunk/src: . include mod/languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Wed Mar 7 17:17:02 EST 2007


Author: anthm
Date: Wed Mar  7 17:17:02 2007
New Revision: 4471

Modified:
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
   freeswitch/trunk/src/switch_utils.c

Log:
fix fatal include

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Wed Mar  7 17:17:02 2007
@@ -289,6 +289,7 @@
 #define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
 SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len);
 SWITCH_DECLARE(char *) switch_url_decode(char *s);
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename);
 SWITCH_END_EXTERN_C
 
 #endif

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile	Wed Mar  7 17:17:02 2007
@@ -7,7 +7,7 @@
 	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install js --prefix=$(PREFIX) --with-pic --with-nspr=yes
 	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl --prefix=$(PREFIX) --without-libidn
 
-$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c
+$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).h
 	$(CC) $(CFLAGS) -c $(MODNAME).c -o $(MODNAME).o 
 	$(CC) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN)  $(MODNAME).o $(OBJS) $(LDFLAGS)
 

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Wed Mar  7 17:17:02 2007
@@ -2248,7 +2248,9 @@
 {
 	char *code;
 	if ( argc > 0 && (code = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
-		eval_some_js(code, cx, obj, rval);
+		if (eval_some_js(code, cx, obj, rval) < 0) {
+			return JS_FALSE;
+		}
 		return JS_TRUE;
 	}
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Arguements\n");

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	Wed Mar  7 17:17:02 2007
@@ -81,7 +81,8 @@
 	JSScript *script = NULL;
 	char *cptr;
 	char *path = NULL;
-	int res = 0;
+	char *script_name;
+	int result = 0;
 
 	JS_ClearPendingException(cx);
 
@@ -90,19 +91,28 @@
 		script = JS_CompileScript(cx, obj, cptr, strlen(cptr), "inline", 1);
 	} else {
 		if (*code == '/') {
-			script = JS_CompileFile(cx, obj, code);
+			script_name = code;
 		} else if ((path = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR, code))) {
-			script = JS_CompileFile(cx, obj, path);
-			switch_safe_free(path);
+			script_name = path;
 		}
+		if (script_name) {
+			if (switch_file_exists(script_name) == SWITCH_STATUS_SUCCESS) {
+				script = JS_CompileFile(cx, obj, script_name);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name);
+			}
+		} 
 	}
-
+	
 	if (script) {
-		res = JS_ExecuteScript(cx, obj, script, rval) == JS_TRUE ? 1 : 0;
+		result = JS_ExecuteScript(cx, obj, script, rval) == JS_TRUE ? 1 : 0;
 		JS_DestroyScript(cx, script);
+	} else {
+		result = -1;
 	}
-
-	return res;
+	
+	switch_safe_free(path);
+	return result;
 }
 
 

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Wed Mar  7 17:17:02 2007
@@ -331,6 +331,20 @@
 
 }
 
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
+{
+	int32_t wanted = APR_FINFO_TYPE;
+	apr_finfo_t info = {0};
+	if (filename) {
+		apr_stat(&info, filename, wanted, NULL);
+		if (info.filetype != APR_NOFILE) {
+			return SWITCH_STATUS_SUCCESS;
+		}
+	}
+	return SWITCH_STATUS_FALSE;
+}
+
+
 SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
 {
 	switch(priority) { /*lol*/



More information about the Freeswitch-svn mailing list