]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
general haphazzard rearrangement
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 28 Feb 2006 21:21:48 +0000 (21:21 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 28 Feb 2006 21:21:48 +0000 (21:21 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@702 d0543943-73ff-0310-b7d9-9358b9ac24b2

Makefile.am
Makefile.in
src/include/switch_core.h
src/include/switch_types.h
src/mod/languages/mod_spidermonkey/Makefile
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch.c
src/switch_config.c
src/switch_core.c
src/switch_ivr.c
src/switch_loadable_module.c

index c91eacc884740c91a35980588ece1b9b8bc38bcb..b89307fa4f610eb406e11fd0d09d21caa482a1f3 100644 (file)
@@ -40,6 +40,7 @@ AM_CFLAGS     += -DSWITCH_PREFIX_DIR=\"$(PREFIX)\"
 AM_CFLAGS      += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\"
 AM_CFLAGS      += -DSWITCH_DB_DIR=\"$(PREFIX)/db\"
 AM_CFLAGS      += -DSWITCH_LOG_DIR=\"$(PREFIX)/log\"
+AM_CFLAGS      += -DSWITCH_SCRIPT_DIR=\"$(PREFIX)/scripts\"
 
 
 libfreeswitch_la_SOURCES       = \
@@ -184,7 +185,7 @@ modwipe:
 
 install_mod: modules
        @echo Installing $(NAME)
-       @mkdir -p $(PREFIX) $(PREFIX)/conf $(PREFIX)/mod $(PREFIX)/db $(PREFIX)/log $(PREFIX)/bin
+       @mkdir -p $(PREFIX) $(PREFIX)/conf $(PREFIX)/mod $(PREFIX)/db $(PREFIX)/log $(PREFIX)/bin $(PREFIX)/scripts
        @if [ -f .libs/$(NAME) ] ; then /bin/cp -p .libs/$(NAME) $(PREFIX)/bin ; else /bin/cp -p ./$(NAME) $(PREFIX)/bin ; fi
        @echo Installing Modules
        @rm -f build/freeswitch.env
index 1b9da9d21b9b33a6cb245fc5dff794b9132df1ac..4a84a57dd7f655caa77cadec7e98e46aa77b86ee 100644 (file)
@@ -244,7 +244,8 @@ AM_CFLAGS = -I$(PREFIX)/include $(shell $(APR_CONFIG) --cflags \
        -DSWITCH_PREFIX_DIR=\"$(PREFIX)\" \
        -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" \
        -DSWITCH_DB_DIR=\"$(PREFIX)/db\" \
-       -DSWITCH_LOG_DIR=\"$(PREFIX)/log\"
+       -DSWITCH_LOG_DIR=\"$(PREFIX)/log\" \
+       -DSWITCH_SCRIPT_DIR=\"$(PREFIX)/scripts\"
 AM_LDFLAGS = -L$(PREFIX)/lib $(shell $(APR_CONFIG) --link-ld --libs ) \
        $(shell $(APU_CONFIG) --link-ld --libs ) -lsqlite3 -lteletone \
        -lresample -lm -L/usr/local/lib/db42 -L/usr/local/lib \
@@ -1059,7 +1060,7 @@ modwipe:
 
 install_mod: modules
        @echo Installing $(NAME)
-       @mkdir -p $(PREFIX) $(PREFIX)/conf $(PREFIX)/mod $(PREFIX)/db $(PREFIX)/log $(PREFIX)/bin
+       @mkdir -p $(PREFIX) $(PREFIX)/conf $(PREFIX)/mod $(PREFIX)/db $(PREFIX)/log $(PREFIX)/bin $(PREFIX)/scripts
        @if [ -f .libs/$(NAME) ] ; then /bin/cp -p .libs/$(NAME) $(PREFIX)/bin ; else /bin/cp -p ./$(NAME) $(PREFIX)/bin ; fi
        @echo Installing Modules
        @rm -f build/freeswitch.env
index eec970ca3a82298318586ce925fd5ef48417edc1..e5be44969b65b0ea209381e545ea45aa3153a8a8 100644 (file)
@@ -892,11 +892,16 @@ SWITCH_DECLARE(switch_status) switch_core_directory_close(switch_directory_handl
 SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel);
 
 /*!
-  \brief Set the output console to the desired FILE stream
-  \param handle the FILE stream
+  \brief Set the output console to the desired file
+  \param console the file path
 */
-SWITCH_DECLARE(void) switch_core_set_console(FILE *handle);
+SWITCH_DECLARE(switch_status) switch_core_set_console(char *console);
 
+/*!
+  \brief Get the output console
+  \return the FILE stream
+*/
+SWITCH_DECLARE(FILE *) switch_core_get_console(void);
 /*! 
   \brief Launch a thread
 */
index be1a4eb4be11f9ef4dfee05190c7c0473a48e8e5..00e85696fd5c18708b1e598ace1ff71000e02225 100644 (file)
@@ -41,6 +41,42 @@ extern "C" {
 #include <switch.h>
 #include <switch_platform.h>
 
+#ifndef SWITCH_PREFIX_DIR
+#define SWITCH_PREFIX_DIR "."
+#endif
+
+#ifndef SWITCH_MOD_DIR
+#define SWITCH_MODDIR "./mod"
+#endif
+
+#ifndef SWITCH_CONF_DIR
+#define SWITCH_CONF_DIR "./conf"
+#endif
+
+#ifndef SWITCH_LOG_DIR
+#define SWITCH_LOG_DIR "./log"
+#endif
+
+#ifndef SWITCH_DB_DIR
+#define SWITCH_DB_DIR "./db"
+#endif
+
+#ifndef SWITCH_SCRIPT_DIR
+#define SWITCH_SCRIPT_DIR "./scripts"
+#endif
+
+struct switch_directories {
+       char *base_dir;
+       char *mod_dir;
+       char *conf_dir;
+       char *log_dir;
+       char *db_dir;
+       char *script_dir;
+};
+
+typedef struct switch_directories switch_directories;
+extern switch_directories SWITCH_GLOBAL_dirs;
+
 #define SWITCH_RECCOMMENDED_BUFFER_SIZE 131072
 #define SWITCH_MAX_CODECS 30
 #define SWITCH_MAX_STATE_HANDLERS 30
index 3fb4e5482e6d64ce9ebee4e52c90b8d15efef454..fb0ae3d9f43c652e931cf1cd429a9d3bfc66b4de 100644 (file)
@@ -60,7 +60,7 @@ endif
 endif
 
 CFLAGS += -I$(BASE)/libs/mozilla/js/src -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/js/src -I$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -I$(OS_CONFIG)_DBG.OBJ
-LDFLAGS +=-DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr
+LDFLAGS +=-DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX  -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -lteletone
 OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
 LINKER=$(CC)
 
index 87ec46e76ccd6ad27f3fa29d9df0a9a6e32d443a..b84351f7e1b14d23ea22d5e635e8c9a1388b4d8a 100644 (file)
@@ -45,6 +45,7 @@
 #include "jsparse.h"
 #include "jsscope.h"
 #include "jsscript.h"
+#include <libteletone.h>
 #include <switch.h>
 
 #ifdef _MSC_VER
@@ -92,6 +93,19 @@ struct js_session {
        unsigned int flags;
 };
 
+struct teletone_obj {
+       teletone_generation_session_t ts;
+       JSContext *cx;
+       JSObject *obj;
+       switch_core_session *session;
+       switch_codec codec;
+       switch_buffer *audio_buffer;
+       switch_memory_pool *pool;
+       switch_timer *timer;
+       switch_timer timer_base;
+};
+
+
 
 static void js_error(JSContext *cx, const char *message, JSErrorReport *report)
 {
@@ -157,57 +171,62 @@ static switch_status js_dtmf_callback(switch_core_session *session, char *dtmf,
                eval_some_js(code, jss->cx, jss->obj, &rval);
                ret = JS_GetStringBytes(JS_ValueToString(jss->cx, rval));
 
-               if (*ret == 'F') {
-                       int step;
-                       ret++;
+               if (!strncasecmp(ret, "speed", 4)) {
+                       char *p;
                        
-                       step = *ret ? atoi(ret) : 1;
-                       fh->speed += step ? step : 1;
-                       return SWITCH_STATUS_SUCCESS;
-               }
-
-               if (*ret == 'S') {
-                       int step;
-            ret++;
-
-                       step = *ret ? atoi(ret) : 1;
-            fh->speed -= step ? step : 1;
-                       return SWITCH_STATUS_SUCCESS;
-               }
-
-               if (*ret == 'N') {
-                       fh->speed = 0;
-                       return SWITCH_STATUS_SUCCESS;
-               }
-               
-               if (*ret == 'P') {
+                       if ((p = strchr(ret, ':'))) {
+                               p++;
+                               if (*p == '+' || *p == '-') {
+                                       int step;
+                                       if (!(step = atoi(p))) {
+                                               step = 1;
+                                       }
+                                       fh->speed += step;
+                               } else {
+                                       int speed = atoi(p);
+                                       fh->speed = speed;
+                               }
+                               return SWITCH_STATUS_SUCCESS;
+                       }
+                       
+                       return SWITCH_STATUS_FALSE;
+               } else if (!strcasecmp(ret, "pause")) {
                        if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
                                switch_clear_flag(fh, SWITCH_FILE_PAUSE);
                        } else {
                                switch_set_flag(fh, SWITCH_FILE_PAUSE);
                        }
                        return SWITCH_STATUS_SUCCESS;
-               }
-
-               if (*ret == 'R') {
+               } else if (!strcasecmp(ret, "restart")) {
                        unsigned int pos = 0;
                        fh->speed = 0;
                        switch_core_file_seek(fh, &pos, 0, SEEK_SET);
                        return SWITCH_STATUS_SUCCESS;
-               }
-
-               if (*ret == '+' || *ret == '-') {
+               } else if (!strncasecmp(ret, "seek", 4)) {
                        switch_codec *codec;
                        unsigned int samps = 0;
                        unsigned int pos = 0;
+                       char *p;
                        codec = switch_core_session_get_read_codec(jss->session);
-                       if (*ret == '+') {
-                               ret++;
-                               samps = atoi(ret) * (codec->implementation->samples_per_second / 1000);
-                               switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
-                       } else {
-                               samps = atoi(ret) * (codec->implementation->samples_per_second / 1000);
-                               switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
+
+                       if ((p = strchr(ret, ':'))) {
+                               p++;
+                               if (*p == '+' || *p == '-') {
+                    int step;
+                    if (!(step = atoi(p))) {
+                        step = 1000;
+                    }
+                                       if (step > 0) {
+                                               samps = step * (codec->implementation->samples_per_second / 1000);
+                                               switch_core_file_seek(fh, &pos, samps, SEEK_CUR);               
+                                       } else {
+                                               samps = step * (codec->implementation->samples_per_second / 1000);
+                                               switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
+                                       }
+                } else {
+                                       samps = atoi(p) * (codec->implementation->samples_per_second / 1000);
+                                       switch_core_file_seek(fh, &pos, samps, SEEK_SET);
+                }
                        }
 
                        return SWITCH_STATUS_SUCCESS;
@@ -225,7 +244,7 @@ static switch_status js_dtmf_callback(switch_core_session *session, char *dtmf,
        return SWITCH_STATUS_FALSE;
 }
 
-static JSBool chan_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
        struct js_session *jss = JS_GetPrivate(cx, obj);
     switch_channel *channel;
@@ -277,7 +296,7 @@ static JSBool chan_streamfile(JSContext *cx, JSObject *obj, uintN argc, jsval *a
        return (switch_channel_get_state(channel) == CS_EXECUTE) ? JS_TRUE : JS_FALSE;
 }
 
-static JSBool chan_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
        struct js_session *jss = JS_GetPrivate(cx, obj);
     switch_channel *channel;
@@ -328,7 +347,7 @@ static JSBool chan_speak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
        
 }
 
-static JSBool chan_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
        struct js_session *jss = JS_GetPrivate(cx, obj);
        char *terminators = NULL;
@@ -350,7 +369,7 @@ static JSBool chan_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *a
        return JS_FALSE;
 }
 
-static JSBool chan_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static JSBool session_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
        struct js_session *jss = JS_GetPrivate(cx, obj);
        switch_channel *channel;
@@ -362,26 +381,28 @@ static JSBool chan_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
        return JS_TRUE;
 }
 
-enum its_tinyid {
-    CHAN_NAME, CHAN_STATE
+/* Session Object */
+/*********************************************************************************/
+enum session_tinyid {
+    SESSION_NAME, SESSION_STATE
 };
 
-static JSFunctionSpec chan_methods[] = {
-    {"streamFile", chan_streamfile, 1}, 
-    {"speak", chan_speak, 1}, 
-    {"getDigits", chan_get_digits, 1},
-    {"answer", chan_answer, 0}, 
+static JSFunctionSpec session_methods[] = {
+    {"streamFile", session_streamfile, 1}, 
+    {"speak", session_speak, 1}, 
+    {"getDigits", session_get_digits, 1},
+    {"answer", session_answer, 0}, 
        {0}
 };
 
 
-static JSPropertySpec chan_props[] = {
-    {"name", CHAN_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
-    {"state", CHAN_STATE, JSPROP_READONLY|JSPROP_PERMANENT}, 
+static JSPropertySpec session_props[] = {
+    {"name", SESSION_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+    {"state", SESSION_STATE, JSPROP_READONLY|JSPROP_PERMANENT}, 
     {0}
 };
 
-static JSBool chan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+static JSBool session_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 {
        struct js_session *jss = JS_GetPrivate(cx, obj);
        int param = 0;
@@ -401,10 +422,10 @@ static JSBool chan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp
        }
        
        switch(param) {
-       case CHAN_NAME:
+       case SESSION_NAME:
                *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_get_name(channel)));
                break;
-       case CHAN_STATE:
+       case SESSION_STATE:
                *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_state_name(switch_channel_get_state(channel)) ));
                break;
        default:
@@ -416,14 +437,261 @@ static JSBool chan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp
     return res;
 }
 
-
 JSClass session_class = {
     "Session", JSCLASS_HAS_PRIVATE, 
-       JS_PropertyStub,  JS_PropertyStub,  chan_getProperty,  JS_PropertyStub, 
+       JS_PropertyStub,  JS_PropertyStub,  session_getProperty,  JS_PropertyStub, 
     JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   JS_FinalizeStub
 };
 
 
+static JSObject *new_js_session(JSContext *cx, JSObject *obj, switch_core_session *session, struct js_session *jss, char *name, int flags) 
+{
+       JSObject *session_obj;
+       if ((session_obj = JS_DefineObject(cx, obj, name, &session_class, NULL, 0))) {
+               memset(jss, 0, sizeof(struct js_session));
+               jss->session = session;
+               jss->flags = flags;
+               jss->cx = cx;
+               jss->obj = obj;
+               if ((JS_SetPrivate(cx, session_obj, jss) &&
+                         JS_DefineProperties(cx, session_obj, session_props) &&
+                         JS_DefineFunctions(cx, session_obj, session_methods))) {
+                       return session_obj;
+               }
+       }
+       
+       return NULL;
+}
+
+static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
+{
+       struct teletone_obj *tto = ts->user_data;
+       int wrote;
+
+       if (!tto) {
+               return -1;
+       }
+       wrote = teletone_mux_tones(ts, map);
+       switch_buffer_write(tto->audio_buffer, ts->buffer, wrote * 2);
+
+       return 0;
+}
+
+/* TeleTone Object */
+/*********************************************************************************/
+static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+       int32 memory = 65535;
+       JSObject *session_obj;
+       struct teletone_obj *tto = NULL;
+       struct js_session *jss = NULL;
+       switch_codec *read_codec;
+       switch_memory_pool *pool;
+       char *timer_name = NULL;
+       
+       if (argc > 0) {
+               if (JS_ValueToObject(cx, argv[0], &session_obj)) {
+                       if (!(jss = JS_GetPrivate(cx, session_obj))) {
+                               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Session [1]\n");
+                               return JS_FALSE;
+                       }
+               } else {
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Session [2]\n");
+                       return JS_FALSE;
+               }
+       } else {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Missing Session Arg\n");
+               return JS_FALSE;
+       }
+       if (argc > 1) {
+               timer_name = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+       }
+
+       if (argc > 2) {
+               if (!JS_ValueToInt32(cx, argv[2], &memory)) {
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Convert to INT\n");
+                       return JS_FALSE;
+               }
+       } 
+       switch_core_new_memory_pool(&pool);
+
+       if (!(tto = switch_core_alloc(pool, sizeof(*tto)))) {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Memory Error\n");
+               return JS_FALSE;
+       }
+
+       read_codec = switch_core_session_get_read_codec(jss->session);
+
+       if (switch_core_codec_init(&tto->codec,
+                                                          "L16",
+                                                          read_codec->implementation->samples_per_second,
+                                                          read_codec->implementation->microseconds_per_frame / 1000,
+                                                          read_codec->implementation->number_of_channels,
+                                                          SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+                                                          NULL, pool) == SWITCH_STATUS_SUCCESS) {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
+       } else {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed\n");
+               return JS_FALSE;
+       }
+
+       if (timer_name) {
+               unsigned int ms = read_codec->implementation->microseconds_per_frame / 1000;
+               if (switch_core_timer_init(&tto->timer_base,
+                                                                  timer_name,
+                                                                  ms,
+                                                                  (read_codec->implementation->samples_per_second / 50) * read_codec->implementation->number_of_channels,
+                                                                  pool) == SWITCH_STATUS_SUCCESS) {
+                       tto->timer = &tto->timer_base;
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Timer INIT Success %d\n", ms);
+               } else {
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Timer INIT Failed\n");
+               }
+       }
+
+       switch_buffer_create(pool, &tto->audio_buffer, SWITCH_RECCOMMENDED_BUFFER_SIZE);
+       tto->pool = pool;
+       tto->obj = obj;
+       tto->cx = cx;
+       tto->session = jss->session;
+       teletone_init_session(&tto->ts, memory, teletone_handler, tto);
+       JS_SetPrivate(cx, obj, tto);
+
+       return JS_TRUE;
+}
+
+static void teletone_destroy(JSContext *cx, JSObject *obj)
+{
+       struct teletone_obj *tto = JS_GetPrivate(cx, obj);
+       switch_memory_pool *pool;
+       if (tto) {
+               pool = tto->pool;
+               if (tto->timer) {
+                       switch_core_timer_destroy(tto->timer);
+               }
+               teletone_destroy_session(&tto->ts);
+               switch_core_destroy_memory_pool(&pool);
+               switch_core_codec_destroy(&tto->codec);
+       }
+}
+
+static JSBool teletone_add_tone(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+       struct teletone_obj *tto = JS_GetPrivate(cx, obj);
+       if (argc > 2) { 
+               int x;
+               char *fval;
+               char *map_str;
+               map_str = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+
+               for(x = 1; x < TELETONE_MAX_TONES; x++) {
+                       fval = JS_GetStringBytes(JS_ValueToString(cx, argv[x]));
+                       tto->ts.TONES[(int)*map_str].freqs[x-1] = strtod(fval, NULL);
+               }
+               return JS_TRUE;
+       }
+       
+       return JS_FALSE;
+}
+
+static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+       struct teletone_obj *tto = JS_GetPrivate(cx, obj);
+
+       if (argc > 0) {
+               char *script;
+               switch_core_session *session;
+               switch_frame write_frame = {0};
+               unsigned char *fdata[1024];
+               switch_frame *read_frame;
+               int stream_id;
+               switch_core_thread_session thread_session;
+
+
+               tto->ts.debug = 1;
+               tto->ts.debug_stream = switch_core_get_console();
+
+        script = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+               teletone_run(&tto->ts, script);
+
+               session = tto->session;
+               write_frame.codec = &tto->codec;
+               write_frame.data = fdata;
+               
+               if (tto->timer) {
+                       for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
+                               switch_core_service_session(session, &thread_session, stream_id);
+                       }
+               }
+
+               for(;;) {
+                       if (tto->timer) {
+                               int x;
+
+                               if ((x = switch_core_timer_next(tto->timer)) < 0) {
+                                       break;
+                               }
+
+                       } else {
+                               if (switch_core_session_read_frame(session, &read_frame, -1, 0) != SWITCH_STATUS_SUCCESS) {
+                                       break;
+                               }
+                       }
+                       if ((write_frame.datalen = switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+                               break;
+                       }
+
+                       write_frame.samples = write_frame.datalen / 2;
+                       for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
+
+                               if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
+                                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
+                                       break;
+                               }
+                       }
+               }
+
+               switch_core_thread_session_end(&thread_session);
+               return JS_TRUE;
+       }
+       
+       return JS_FALSE;
+}
+
+enum teletone_tinyid {
+    TELETONE_NAME
+};
+
+static JSFunctionSpec teletone_methods[] = {
+    {"generate", teletone_generate, 1},
+    {"addTone", teletone_add_tone, 10},  
+       {0}
+};
+
+
+static JSPropertySpec teletone_props[] = {
+    {"name", TELETONE_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+    {0}
+};
+
+
+static JSBool teletone_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+{
+       JSBool res = JS_TRUE;
+
+    return res;
+}
+
+JSClass teletone_class = {
+    "TeleTone", JSCLASS_HAS_PRIVATE, 
+       JS_PropertyStub,  JS_PropertyStub,  teletone_getProperty,  JS_PropertyStub, 
+    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   teletone_destroy, NULL, NULL, NULL,
+       teletone_construct
+};
+
+
+/* Built-In*/
+/*********************************************************************************/
 static JSBool js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
        char *msg;
@@ -443,25 +711,6 @@ static JSFunctionSpec fs_functions[] = {
 };
 
 
-static JSObject *new_js_session(JSContext *cx, JSObject *obj, switch_core_session *session, struct js_session *jss, char *name, int flags) 
-{
-       JSObject *session_obj;
-       if ((session_obj = JS_DefineObject(cx, obj, name, &session_class, NULL, 0))) {
-               memset(jss, 0, sizeof(struct js_session));
-               jss->session = session;
-               jss->flags = flags;
-               jss->cx = cx;
-               jss->obj = obj;
-               if ((JS_SetPrivate(cx, session_obj, jss) &&
-                         JS_DefineProperties(cx, session_obj, chan_props) &&
-                         JS_DefineFunctions(cx, session_obj, chan_methods))) {
-                       return session_obj;
-               }
-       }
-       
-       return NULL;
-}
-
 static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval) 
 {
        JSScript *script;
@@ -478,7 +727,7 @@ static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
                if (code[0] == '/') {
                        script = JS_CompileFile(cx, obj, code);
                } else {
-                       snprintf(path, sizeof(path), "%s/%s", "/tmp", code);
+                       snprintf(path, sizeof(path), "%s/%s", SWITCH_GLOBAL_dirs.script_dir, code);
                        script = JS_CompileFile(cx, obj, path);
                }
        }
@@ -537,6 +786,21 @@ static void js_exec(switch_core_session *session, char *data)
                        JS_SetPrivate(cx, javascript_global_object, session);
                        res = 0;
        
+
+                       JS_InitClass(cx,
+                                                javascript_global_object,
+                                                NULL,
+                                                &teletone_class,
+                                                teletone_construct,
+                                                3,
+                                                teletone_props,
+                                                teletone_methods,
+                                                teletone_props,
+                                                teletone_methods
+                                                );
+
+
+
                        do {
                                if ((next = strchr(code, '|'))) {
                                        *next = '\0';
index 77b5d98e045c7a1d640d706a0c53a2a728332802..6b96b19e4099d7e6098ad18754538c020f0783d4 100644 (file)
  * switch.c -- Main
  *
  */
+
 #include <switch.h>
-#ifndef SWITCH_LOG_DIR
-#ifdef WIN32
-#define SWITCH_LOG_DIR ".\\log"
-#else
-#define SWITCH_LOG_DIR "/usr/local/freeswitch/log"
-#endif
-#endif
 
 static int RUNNING = 0;
 
@@ -82,10 +76,17 @@ int main(int argc, char *argv[])
        char sep = '/';
        int pid;
        nice(-20);
+#endif
 
+       if (switch_core_init(NULL) != SWITCH_STATUS_SUCCESS) {
+               fprintf(stderr, "Cannot Initilize\n");
+               return 255;
+       }
+
+#ifndef WIN32
        if (argv[1] && !strcmp(argv[1], "-stop")) {
                pid_t pid = 0;
-               snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
+               snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
                if ((f = fopen(path, "r")) == 0) {
                        fprintf(stderr, "Cannot open pid file %s.\n", path);
                        return 255;
@@ -128,7 +129,7 @@ int main(int argc, char *argv[])
 #endif
        }
 
-       snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
+       snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
        if ((f = fopen(path, "w")) == 0) {
                fprintf(stderr, "Cannot open pid file %s.\n", path);
                return 255;
@@ -138,13 +139,13 @@ int main(int argc, char *argv[])
        fclose(f);
 
        if (bg) {
-               snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, lfile);
-       }
-
-       if (switch_core_init(bg ? path : NULL) != SWITCH_STATUS_SUCCESS) {
-               err = "Cannot Initilize\n";
+               snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, lfile);
+               if (switch_core_set_console(path) != SWITCH_STATUS_SUCCESS) {
+                       err = "Cannot open log file\n";
+               }
        }
 
+       
        if (!err) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bringing up environment.\n");
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loading Modules.\n");
@@ -164,7 +165,7 @@ int main(int argc, char *argv[])
        }
 
        switch_console_printf(SWITCH_CHANNEL_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_VERSION_FULL);
-       snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, pfile);
+       snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
 
        if (bg) {
                bg = 0;
index 856299ea3ca216b07cf5bd7600d6d129d803fe1a..c36edf5a1fc23c402a07382bc5f5b05c3e864249 100644 (file)
  */
 #include <switch_config.h>
 
-#ifndef SWITCH_CONF_DIR
-#ifdef WIN32
-#define SWITCH_CONF_DIR ".\\conf"
-#else
-#define SWITCH_CONF_DIR "/usr/local/freeswitch/conf"
-#endif
-#endif
-
 SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
 {
        FILE *f;
@@ -48,7 +40,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
        if (file_path[0] == '/') {
                path = file_path;
        } else {
-               snprintf(path_buf, sizeof(path_buf), "%s/%s", SWITCH_CONF_DIR, file_path);
+               snprintf(path_buf, sizeof(path_buf), "%s/%s", SWITCH_GLOBAL_dirs.conf_dir, file_path);
                path = path_buf;
        }
 
@@ -64,7 +56,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
                        int last = -1;
                        char *var, *val;
 
-                       snprintf(path_buf, sizeof(path_buf), "%s/freeswitch.conf", SWITCH_CONF_DIR);
+                       snprintf(path_buf, sizeof(path_buf), "%s/freeswitch.conf", SWITCH_GLOBAL_dirs.conf_dir);
                        path = path_buf;
 
                        if ((f = fopen(path, "r")) == 0) {
index 4d756b3a5cc78a54dd2f1c33e9575a65c760b221..97ddcddcf8c445c422db8e0497df9d09daffa109 100644 (file)
@@ -85,6 +85,8 @@ struct switch_core_session {
        void *private_info;
 };
 
+switch_directories SWITCH_GLOBAL_dirs;
+
 struct switch_core_runtime {
        time_t initiated;
        unsigned long session_id;
@@ -137,9 +139,19 @@ SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename)
        return db;
 }
 
-SWITCH_DECLARE(void) switch_core_set_console(FILE *handle)
+SWITCH_DECLARE(switch_status) switch_core_set_console(char *console)
 {
-       runtime.console = handle;
+       if ((runtime.console = fopen(console, "a")) == 0) {
+               fprintf(stderr, "Cannot open output file %s.\n", console);
+               return SWITCH_STATUS_FALSE;
+       }
+       
+       return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(FILE *) switch_core_get_console(void)
+{
+       return runtime.console;
 }
 
 SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel)
@@ -2179,14 +2191,21 @@ static void core_event_handler(switch_event *event)
 
 SWITCH_DECLARE(switch_status) switch_core_init(char *console)
 {
+       memset(&runtime, 0, sizeof(runtime));
+       
+       SWITCH_GLOBAL_dirs.base_dir = SWITCH_PREFIX_DIR;
+       SWITCH_GLOBAL_dirs.mod_dir = SWITCH_MOD_DIR;
+       SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR;
+       SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR;
+       SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR;
+       SWITCH_GLOBAL_dirs.script_dir = SWITCH_SCRIPT_DIR;
+       
+       
 #ifdef EMBED_PERL
        PerlInterpreter *my_perl;
 #endif
        if(console) {
-               if ((runtime.console = fopen(console, "a")) == 0) {
-                       fprintf(stderr, "Cannot open output file %s.\n", console);
-                       return SWITCH_STATUS_FALSE;
-               }
+               switch_core_set_console(console);
        } else {
                runtime.console = stdout;
        }
@@ -2241,7 +2260,6 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console)
        switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
 
        time(&runtime.initiated);
-
        return SWITCH_STATUS_SUCCESS;
 }
 
index 64e0580c1f8282a8ea8225235340d6ba96edf7ea..d1693e3cf60895a07a0f554ff125e9ecdde4ac2e 100644 (file)
@@ -259,7 +259,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
                return SWITCH_STATUS_GENERR;
        }
 
-       switch_channel_answer(channel);
 
        write_frame.data = abuf;
        write_frame.buflen = sizeof(abuf);
@@ -313,7 +312,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
                int do_speed = 1;
                int last_speed = -1;
 
-
                if (dtmf_callback || buf) {
                        /*
                          dtmf handler function you can hook up to be executed when a digit is dialed during playback 
@@ -414,7 +412,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
                                done = 1;
                                break;
                        }
-
                        if (done) {
                                break;
                        }
index 258cd11e56fcb7fd8c3eb726514d0e4d415c3998..143c3f8687da41bb1d4c49a6823dcc4e71b3af9f 100644 (file)
  */
 #include <switch_console.h>
 
-#ifndef SWITCH_MOD_DIR
-#ifdef WIN32
-#define SWITCH_MOD_DIR ".\\mod"
-#else
-#define SWITCH_MOD_DIR "/usr/local/freeswitch/mod"
-#endif
-#endif
 
 struct switch_loadable_module {
        char *filename;
@@ -371,7 +364,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
                                                        switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid extension for %s\n", val);
                                                        continue;
                                                }
-                                               process_module_file((char *) SWITCH_MOD_DIR, (char *) val);
+                                               process_module_file((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val);
                                        }
                                }
                        }
@@ -387,8 +380,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
        }
 
        if (all) {
-               if (apr_dir_open(&module_dir_handle, SWITCH_MOD_DIR, loadable_modules.pool) != APR_SUCCESS) {
-                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open directory: %s\n", SWITCH_MOD_DIR);
+               if (apr_dir_open(&module_dir_handle, SWITCH_GLOBAL_dirs.mod_dir, loadable_modules.pool) != APR_SUCCESS) {
+                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open directory: %s\n", SWITCH_GLOBAL_dirs.mod_dir);
                        return SWITCH_STATUS_GENERR;
                }
        }
@@ -413,7 +406,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
                                continue;
                        }
 
-                       process_module_file((char *) SWITCH_MOD_DIR, (char *) fname);
+                       process_module_file((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) fname);
                }
                apr_dir_close(module_dir_handle);
        }