[Freeswitch-svn] [commit] r3510 - in freeswitch/trunk/src/mod/languages: mod_spidermonkey mod_spidermonkey_etpan mod_spidermonkey_odbc

Freeswitch SVN mikej at freeswitch.org
Fri Dec 1 14:16:46 EST 2006


Author: mikej
Date: Fri Dec  1 14:16:46 2006
New Revision: 3510

Modified:
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c

Log:
move email to etpan, cleanup the new stubs.

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	Fri Dec  1 14:16:46 2006
@@ -1996,20 +1996,6 @@
 	return JS_FALSE;
 }
 
-#define B64BUFFLEN 1024
-static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static int write_buf(int fd, char *buf) {
-
-	int len = (int)strlen(buf);
-	if (fd && write(fd, buf, len) != len) {
-		close(fd);
-		return 0;
-	}
-
-	return 1;
-}
-
 static JSBool js_api_use(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
 	char *mod_name = NULL;
@@ -2121,135 +2107,10 @@
 	return JS_TRUE;
 }
 
-static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-	char *to = NULL, *from = NULL, *headers, *body = NULL, *file = NULL;
-	char *bound = "XXXX_boundary_XXXX";
-	char filename[80], buf[B64BUFFLEN];
-	int fd = 0, ifd = 0;
-	int x=0, y=0, bytes=0, ilen=0;
-	unsigned int b=0, l=0;
-	unsigned char in[B64BUFFLEN];
-	unsigned char out[B64BUFFLEN+512];
-	char *path = NULL;
-
-	
-	if ( 
-		argc > 3 && 
-		(from = JS_GetStringBytes(JS_ValueToString(cx, argv[0]))) &&
-		(to = JS_GetStringBytes(JS_ValueToString(cx, argv[1]))) &&
-		(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) &&
-		(body = JS_GetStringBytes(JS_ValueToString(cx, argv[3]))) 
-		) {
-		if ( argc > 4) {
-			file = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
-		}
-		snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
-
-		if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
-			if (file) {
-				path = file;
-				if ((ifd = open(path, O_RDONLY)) < 1) {
-					return JS_FALSE;
-				}
-
-				snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
-				if (!write_buf(fd, buf)) {
-					return JS_FALSE;
-				}
-			}
-			
-			if (!write_buf(fd, headers))
-				return JS_FALSE;
-
-			if (!write_buf(fd, "\n\n"))
-				return JS_FALSE;
-			
-			if (file) {
-				snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
-				if (!write_buf(fd, buf))
-					return JS_FALSE;
-			}
-			
-			if (!write_buf(fd, body))
-				return JS_FALSE;
-			
-			if (file) {
-				snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
-						 "Content-Transfer-Encoding: base64\n"
-						 "Content-Description: Sound attachment.\n"
-						 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, file);
-				if (!write_buf(fd, buf))
-					return JS_FALSE;
-				
-				while((ilen=read(ifd, in, B64BUFFLEN))) {
-					for (x=0;x<ilen;x++) {
-						b = (b<<8) + in[x];
-						l += 8;
-						while (l >= 6) {
-							out[bytes++] = c64[(b>>(l-=6))%64];
-							if (++y!=72)
-								continue;
-							out[bytes++] = '\n';
-							y=0;
-						}
-					}
-					if (write(fd, &out, bytes) != bytes) { 
-						return -1;
-					} else 
-						bytes=0;
-					
-				}
-				
-				if (l > 0) {
-					out[bytes++] = c64[((b%16)<<(6-l))%64];
-				}
-				if (l != 0) while (l < 6) {
-					out[bytes++] = '=', l += 2;
-				}
-				if (write(fd, &out, bytes) != bytes) { 
-					return -1;
-				}
-
-			}
-			
-
-			
-			if (file) {
-				snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
-				if (!write_buf(fd, buf))
-					return JS_FALSE;
-			}
-		}
-
-		if (fd) {
-			close(fd);
-		}
-		if (ifd) {
-			close(ifd);
-		}
-		snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to);
-		system(buf);
-		unlink(filename);
-
-
-		if (file) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Emailed file [%s] to [%s]\n", filename, to);
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Emailed data to [%s]\n", to);
-		}
-		return JS_TRUE;
-	}
-	
-
-	return JS_FALSE;
-}
-
 static JSFunctionSpec fs_functions[] = {
 	{"console_log", js_log, 2}, 
 	{"exit", js_exit, 0}, 
 	{"include", js_include, 1}, 
-	{"email", js_email, 2}, 
 	{"bridge", js_bridge, 2},
 	{"apiExecute", js_api_execute, 2},
 	{"use", js_api_use, 1},

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	Fri Dec  1 14:16:46 2006
@@ -34,6 +34,20 @@
 
 static const char modname[] = "etpan";
 
+#define B64BUFFLEN 1024
+static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static int write_buf(int fd, char *buf) {
+
+	int len = (int)strlen(buf);
+	if (fd && write(fd, buf, len) != len) {
+		close(fd);
+		return 0;
+	}
+
+	return 1;
+}
+
 /* etpan Object */
 /*********************************************************************************/
 static JSBool etpan_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
@@ -54,14 +68,137 @@
 	etpan_NAME
 };
 
+static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+	char *to = NULL, *from = NULL, *headers, *body = NULL, *file = NULL;
+	char *bound = "XXXX_boundary_XXXX";
+	char filename[80], buf[B64BUFFLEN];
+	int fd = 0, ifd = 0;
+	int x=0, y=0, bytes=0, ilen=0;
+	unsigned int b=0, l=0;
+	unsigned char in[B64BUFFLEN];
+	unsigned char out[B64BUFFLEN+512];
+	char *path = NULL;
+
+	
+	if ( 
+		argc > 3 && 
+		(from = JS_GetStringBytes(JS_ValueToString(cx, argv[0]))) &&
+		(to = JS_GetStringBytes(JS_ValueToString(cx, argv[1]))) &&
+		(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) &&
+		(body = JS_GetStringBytes(JS_ValueToString(cx, argv[3]))) 
+		) {
+		if ( argc > 4) {
+			file = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
+		}
+		snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
+
+		if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
+			if (file) {
+				path = file;
+				if ((ifd = open(path, O_RDONLY)) < 1) {
+					return JS_FALSE;
+				}
+
+				snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
+				if (!write_buf(fd, buf)) {
+					return JS_FALSE;
+				}
+			}
+			
+			if (!write_buf(fd, headers))
+				return JS_FALSE;
+
+			if (!write_buf(fd, "\n\n"))
+				return JS_FALSE;
+			
+			if (file) {
+				snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
+				if (!write_buf(fd, buf))
+					return JS_FALSE;
+			}
+			
+			if (!write_buf(fd, body))
+				return JS_FALSE;
+			
+			if (file) {
+				snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
+						 "Content-Transfer-Encoding: base64\n"
+						 "Content-Description: Sound attachment.\n"
+						 "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, file);
+				if (!write_buf(fd, buf))
+					return JS_FALSE;
+				
+				while((ilen=read(ifd, in, B64BUFFLEN))) {
+					for (x=0;x<ilen;x++) {
+						b = (b<<8) + in[x];
+						l += 8;
+						while (l >= 6) {
+							out[bytes++] = c64[(b>>(l-=6))%64];
+							if (++y!=72)
+								continue;
+							out[bytes++] = '\n';
+							y=0;
+						}
+					}
+					if (write(fd, &out, bytes) != bytes) { 
+						return -1;
+					} else 
+						bytes=0;
+					
+				}
+				
+				if (l > 0) {
+					out[bytes++] = c64[((b%16)<<(6-l))%64];
+				}
+				if (l != 0) while (l < 6) {
+					out[bytes++] = '=', l += 2;
+				}
+				if (write(fd, &out, bytes) != bytes) { 
+					return -1;
+				}
+
+			}
+			
+
+			
+			if (file) {
+				snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
+				if (!write_buf(fd, buf))
+					return JS_FALSE;
+			}
+		}
+
+		if (fd) {
+			close(fd);
+		}
+		if (ifd) {
+			close(ifd);
+		}
+		snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to);
+		system(buf);
+		unlink(filename);
+
+
+		if (file) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Emailed file [%s] to [%s]\n", filename, to);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Emailed data to [%s]\n", to);
+		}
+		return JS_TRUE;
+	}
+	
+
+	return JS_FALSE;
+}
+
 static JSFunctionSpec etpan_methods[] = {
-	{"myMethod", etpan_my_method, 1},
+//	{"myMethod", odbc_my_method, 1},
 	{0}
 };
 
-
 static JSPropertySpec etpan_props[] = {
-	{"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+//	{"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
 	{0}
 };
 
@@ -81,8 +218,15 @@
 };
 
 
+static JSFunctionSpec etpan_functions[] = {
+	{"email", js_email, 2}, 
+	{0}
+};
+
 switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
 {
+	JS_DefineFunctions(cx, obj, etpan_functions);
+
 	JS_InitClass(cx,
 				 obj,
 				 NULL,

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	Fri Dec  1 14:16:46 2006
@@ -30,18 +30,18 @@
  *
  */
 #include "mod_spidermonkey.h"
-
-#include <sql.h>
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4201)
-#include <sqlext.h>
-#pragma warning(pop)
-#else
-#include <sqlext.h>
-#endif
-#include <sqltypes.h>
 
+#include <sql.h>
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4201)
+#include <sqlext.h>
+#pragma warning(pop)
+#else
+#include <sqlext.h>
+#endif
+#include <sqltypes.h>
+
 static const char modname[] = "odbc";
 
 /* ODBC Object */
@@ -65,13 +65,13 @@
 };
 
 static JSFunctionSpec odbc_methods[] = {
-	{"myMethod", odbc_my_method, 1},
+//	{"myMethod", odbc_my_method, 1},
 	{0}
 };
 
 
 static JSPropertySpec odbc_props[] = {
-	{"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+//	{"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
 	{0}
 };
 



More information about the Freeswitch-svn mailing list