mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-15 11:29:56 +00:00
general haphazzard rearrangement
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@702 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
bafc46686e
commit
62e510c9b1
@ -40,6 +40,7 @@ AM_CFLAGS += -DSWITCH_PREFIX_DIR=\"$(PREFIX)\"
|
|||||||
AM_CFLAGS += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\"
|
AM_CFLAGS += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\"
|
||||||
AM_CFLAGS += -DSWITCH_DB_DIR=\"$(PREFIX)/db\"
|
AM_CFLAGS += -DSWITCH_DB_DIR=\"$(PREFIX)/db\"
|
||||||
AM_CFLAGS += -DSWITCH_LOG_DIR=\"$(PREFIX)/log\"
|
AM_CFLAGS += -DSWITCH_LOG_DIR=\"$(PREFIX)/log\"
|
||||||
|
AM_CFLAGS += -DSWITCH_SCRIPT_DIR=\"$(PREFIX)/scripts\"
|
||||||
|
|
||||||
|
|
||||||
libfreeswitch_la_SOURCES = \
|
libfreeswitch_la_SOURCES = \
|
||||||
@ -184,7 +185,7 @@ modwipe:
|
|||||||
|
|
||||||
install_mod: modules
|
install_mod: modules
|
||||||
@echo Installing $(NAME)
|
@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
|
@if [ -f .libs/$(NAME) ] ; then /bin/cp -p .libs/$(NAME) $(PREFIX)/bin ; else /bin/cp -p ./$(NAME) $(PREFIX)/bin ; fi
|
||||||
@echo Installing Modules
|
@echo Installing Modules
|
||||||
@rm -f build/freeswitch.env
|
@rm -f build/freeswitch.env
|
||||||
|
@ -244,7 +244,8 @@ AM_CFLAGS = -I$(PREFIX)/include $(shell $(APR_CONFIG) --cflags \
|
|||||||
-DSWITCH_PREFIX_DIR=\"$(PREFIX)\" \
|
-DSWITCH_PREFIX_DIR=\"$(PREFIX)\" \
|
||||||
-DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" \
|
-DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" \
|
||||||
-DSWITCH_DB_DIR=\"$(PREFIX)/db\" \
|
-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 ) \
|
AM_LDFLAGS = -L$(PREFIX)/lib $(shell $(APR_CONFIG) --link-ld --libs ) \
|
||||||
$(shell $(APU_CONFIG) --link-ld --libs ) -lsqlite3 -lteletone \
|
$(shell $(APU_CONFIG) --link-ld --libs ) -lsqlite3 -lteletone \
|
||||||
-lresample -lm -L/usr/local/lib/db42 -L/usr/local/lib \
|
-lresample -lm -L/usr/local/lib/db42 -L/usr/local/lib \
|
||||||
@ -1059,7 +1060,7 @@ modwipe:
|
|||||||
|
|
||||||
install_mod: modules
|
install_mod: modules
|
||||||
@echo Installing $(NAME)
|
@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
|
@if [ -f .libs/$(NAME) ] ; then /bin/cp -p .libs/$(NAME) $(PREFIX)/bin ; else /bin/cp -p ./$(NAME) $(PREFIX)/bin ; fi
|
||||||
@echo Installing Modules
|
@echo Installing Modules
|
||||||
@rm -f build/freeswitch.env
|
@rm -f build/freeswitch.env
|
||||||
|
@ -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);
|
SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Set the output console to the desired FILE stream
|
\brief Set the output console to the desired file
|
||||||
\param handle the FILE stream
|
\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
|
\brief Launch a thread
|
||||||
*/
|
*/
|
||||||
|
@ -41,6 +41,42 @@ extern "C" {
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <switch_platform.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_RECCOMMENDED_BUFFER_SIZE 131072
|
||||||
#define SWITCH_MAX_CODECS 30
|
#define SWITCH_MAX_CODECS 30
|
||||||
#define SWITCH_MAX_STATE_HANDLERS 30
|
#define SWITCH_MAX_STATE_HANDLERS 30
|
||||||
|
@ -60,7 +60,7 @@ endif
|
|||||||
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
|
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
|
OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
|
||||||
LINKER=$(CC)
|
LINKER=$(CC)
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "jsparse.h"
|
#include "jsparse.h"
|
||||||
#include "jsscope.h"
|
#include "jsscope.h"
|
||||||
#include "jsscript.h"
|
#include "jsscript.h"
|
||||||
|
#include <libteletone.h>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -92,6 +93,19 @@ struct js_session {
|
|||||||
unsigned int flags;
|
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)
|
static void js_error(JSContext *cx, const char *message, JSErrorReport *report)
|
||||||
{
|
{
|
||||||
@ -157,58 +171,63 @@ static switch_status js_dtmf_callback(switch_core_session *session, char *dtmf,
|
|||||||
eval_some_js(code, jss->cx, jss->obj, &rval);
|
eval_some_js(code, jss->cx, jss->obj, &rval);
|
||||||
ret = JS_GetStringBytes(JS_ValueToString(jss->cx, rval));
|
ret = JS_GetStringBytes(JS_ValueToString(jss->cx, rval));
|
||||||
|
|
||||||
if (*ret == 'F') {
|
if (!strncasecmp(ret, "speed", 4)) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if ((p = strchr(ret, ':'))) {
|
||||||
|
p++;
|
||||||
|
if (*p == '+' || *p == '-') {
|
||||||
int step;
|
int step;
|
||||||
ret++;
|
if (!(step = atoi(p))) {
|
||||||
|
step = 1;
|
||||||
step = *ret ? atoi(ret) : 1;
|
}
|
||||||
fh->speed += step ? step : 1;
|
fh->speed += step;
|
||||||
|
} else {
|
||||||
|
int speed = atoi(p);
|
||||||
|
fh->speed = speed;
|
||||||
|
}
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ret == 'S') {
|
return SWITCH_STATUS_FALSE;
|
||||||
int step;
|
} else if (!strcasecmp(ret, "pause")) {
|
||||||
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 (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
|
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
|
||||||
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
|
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
|
||||||
} else {
|
} else {
|
||||||
switch_set_flag(fh, SWITCH_FILE_PAUSE);
|
switch_set_flag(fh, SWITCH_FILE_PAUSE);
|
||||||
}
|
}
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
} else if (!strcasecmp(ret, "restart")) {
|
||||||
|
|
||||||
if (*ret == 'R') {
|
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
fh->speed = 0;
|
fh->speed = 0;
|
||||||
switch_core_file_seek(fh, &pos, 0, SEEK_SET);
|
switch_core_file_seek(fh, &pos, 0, SEEK_SET);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
} else if (!strncasecmp(ret, "seek", 4)) {
|
||||||
|
|
||||||
if (*ret == '+' || *ret == '-') {
|
|
||||||
switch_codec *codec;
|
switch_codec *codec;
|
||||||
unsigned int samps = 0;
|
unsigned int samps = 0;
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
|
char *p;
|
||||||
codec = switch_core_session_get_read_codec(jss->session);
|
codec = switch_core_session_get_read_codec(jss->session);
|
||||||
if (*ret == '+') {
|
|
||||||
ret++;
|
if ((p = strchr(ret, ':'))) {
|
||||||
samps = atoi(ret) * (codec->implementation->samples_per_second / 1000);
|
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);
|
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
|
||||||
} else {
|
} else {
|
||||||
samps = atoi(ret) * (codec->implementation->samples_per_second / 1000);
|
samps = step * (codec->implementation->samples_per_second / 1000);
|
||||||
switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
|
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;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -225,7 +244,7 @@ static switch_status js_dtmf_callback(switch_core_session *session, char *dtmf,
|
|||||||
return SWITCH_STATUS_FALSE;
|
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);
|
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||||
switch_channel *channel;
|
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;
|
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);
|
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||||
switch_channel *channel;
|
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);
|
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||||
char *terminators = NULL;
|
char *terminators = NULL;
|
||||||
@ -350,7 +369,7 @@ static JSBool chan_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval *a
|
|||||||
return JS_FALSE;
|
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);
|
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||||
switch_channel *channel;
|
switch_channel *channel;
|
||||||
@ -362,26 +381,28 @@ static JSBool chan_answer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum its_tinyid {
|
/* Session Object */
|
||||||
CHAN_NAME, CHAN_STATE
|
/*********************************************************************************/
|
||||||
|
enum session_tinyid {
|
||||||
|
SESSION_NAME, SESSION_STATE
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSFunctionSpec chan_methods[] = {
|
static JSFunctionSpec session_methods[] = {
|
||||||
{"streamFile", chan_streamfile, 1},
|
{"streamFile", session_streamfile, 1},
|
||||||
{"speak", chan_speak, 1},
|
{"speak", session_speak, 1},
|
||||||
{"getDigits", chan_get_digits, 1},
|
{"getDigits", session_get_digits, 1},
|
||||||
{"answer", chan_answer, 0},
|
{"answer", session_answer, 0},
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static JSPropertySpec chan_props[] = {
|
static JSPropertySpec session_props[] = {
|
||||||
{"name", CHAN_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
|
{"name", SESSION_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
|
||||||
{"state", CHAN_STATE, JSPROP_READONLY|JSPROP_PERMANENT},
|
{"state", SESSION_STATE, JSPROP_READONLY|JSPROP_PERMANENT},
|
||||||
{0}
|
{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);
|
struct js_session *jss = JS_GetPrivate(cx, obj);
|
||||||
int param = 0;
|
int param = 0;
|
||||||
@ -401,10 +422,10 @@ static JSBool chan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(param) {
|
switch(param) {
|
||||||
case CHAN_NAME:
|
case SESSION_NAME:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_get_name(channel)));
|
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_get_name(channel)));
|
||||||
break;
|
break;
|
||||||
case CHAN_STATE:
|
case SESSION_STATE:
|
||||||
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_state_name(switch_channel_get_state(channel)) ));
|
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_channel_state_name(switch_channel_get_state(channel)) ));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -416,14 +437,261 @@ static JSBool chan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSClass session_class = {
|
JSClass session_class = {
|
||||||
"Session", JSCLASS_HAS_PRIVATE,
|
"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
|
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)
|
static JSBool js_log(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
{
|
{
|
||||||
char *msg;
|
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)
|
static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
|
||||||
{
|
{
|
||||||
JSScript *script;
|
JSScript *script;
|
||||||
@ -478,7 +727,7 @@ static int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
|
|||||||
if (code[0] == '/') {
|
if (code[0] == '/') {
|
||||||
script = JS_CompileFile(cx, obj, code);
|
script = JS_CompileFile(cx, obj, code);
|
||||||
} else {
|
} 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);
|
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);
|
JS_SetPrivate(cx, javascript_global_object, session);
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
|
|
||||||
|
JS_InitClass(cx,
|
||||||
|
javascript_global_object,
|
||||||
|
NULL,
|
||||||
|
&teletone_class,
|
||||||
|
teletone_construct,
|
||||||
|
3,
|
||||||
|
teletone_props,
|
||||||
|
teletone_methods,
|
||||||
|
teletone_props,
|
||||||
|
teletone_methods
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ((next = strchr(code, '|'))) {
|
if ((next = strchr(code, '|'))) {
|
||||||
*next = '\0';
|
*next = '\0';
|
||||||
|
29
src/switch.c
29
src/switch.c
@ -29,14 +29,8 @@
|
|||||||
* switch.c -- Main
|
* switch.c -- Main
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <switch.h>
|
#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;
|
static int RUNNING = 0;
|
||||||
|
|
||||||
@ -82,10 +76,17 @@ int main(int argc, char *argv[])
|
|||||||
char sep = '/';
|
char sep = '/';
|
||||||
int pid;
|
int pid;
|
||||||
nice(-20);
|
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")) {
|
if (argv[1] && !strcmp(argv[1], "-stop")) {
|
||||||
pid_t pid = 0;
|
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) {
|
if ((f = fopen(path, "r")) == 0) {
|
||||||
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||||
return 255;
|
return 255;
|
||||||
@ -128,7 +129,7 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#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) {
|
if ((f = fopen(path, "w")) == 0) {
|
||||||
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||||
return 255;
|
return 255;
|
||||||
@ -138,12 +139,12 @@ int main(int argc, char *argv[])
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (bg) {
|
if (bg) {
|
||||||
snprintf(path, sizeof(path), "%s%c%s", SWITCH_LOG_DIR, sep, lfile);
|
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 (switch_core_init(bg ? path : NULL) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
err = "Cannot Initilize\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bringing up environment.\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bringing up environment.\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);
|
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) {
|
if (bg) {
|
||||||
bg = 0;
|
bg = 0;
|
||||||
|
@ -31,14 +31,6 @@
|
|||||||
*/
|
*/
|
||||||
#include <switch_config.h>
|
#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)
|
SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@ -48,7 +40,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
|
|||||||
if (file_path[0] == '/') {
|
if (file_path[0] == '/') {
|
||||||
path = file_path;
|
path = file_path;
|
||||||
} else {
|
} 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;
|
path = path_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +56,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config *cfg, char *file_path)
|
|||||||
int last = -1;
|
int last = -1;
|
||||||
char *var, *val;
|
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;
|
path = path_buf;
|
||||||
|
|
||||||
if ((f = fopen(path, "r")) == 0) {
|
if ((f = fopen(path, "r")) == 0) {
|
||||||
|
@ -85,6 +85,8 @@ struct switch_core_session {
|
|||||||
void *private_info;
|
void *private_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
switch_directories SWITCH_GLOBAL_dirs;
|
||||||
|
|
||||||
struct switch_core_runtime {
|
struct switch_core_runtime {
|
||||||
time_t initiated;
|
time_t initiated;
|
||||||
unsigned long session_id;
|
unsigned long session_id;
|
||||||
@ -137,9 +139,19 @@ SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename)
|
|||||||
return db;
|
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)
|
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)
|
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
|
#ifdef EMBED_PERL
|
||||||
PerlInterpreter *my_perl;
|
PerlInterpreter *my_perl;
|
||||||
#endif
|
#endif
|
||||||
if(console) {
|
if(console) {
|
||||||
if ((runtime.console = fopen(console, "a")) == 0) {
|
switch_core_set_console(console);
|
||||||
fprintf(stderr, "Cannot open output file %s.\n", console);
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
runtime.console = stdout;
|
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);
|
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
|
||||||
|
|
||||||
time(&runtime.initiated);
|
time(&runtime.initiated);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
|
|||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_answer(channel);
|
|
||||||
|
|
||||||
write_frame.data = abuf;
|
write_frame.data = abuf;
|
||||||
write_frame.buflen = sizeof(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 do_speed = 1;
|
||||||
int last_speed = -1;
|
int last_speed = -1;
|
||||||
|
|
||||||
|
|
||||||
if (dtmf_callback || buf) {
|
if (dtmf_callback || buf) {
|
||||||
/*
|
/*
|
||||||
dtmf handler function you can hook up to be executed when a digit is dialed during playback
|
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;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,6 @@
|
|||||||
*/
|
*/
|
||||||
#include <switch_console.h>
|
#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 {
|
struct switch_loadable_module {
|
||||||
char *filename;
|
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);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid extension for %s\n", val);
|
||||||
continue;
|
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 (all) {
|
||||||
if (apr_dir_open(&module_dir_handle, SWITCH_MOD_DIR, loadable_modules.pool) != APR_SUCCESS) {
|
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_MOD_DIR);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open directory: %s\n", SWITCH_GLOBAL_dirs.mod_dir);
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +406,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
|||||||
continue;
|
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);
|
apr_dir_close(module_dir_handle);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user