AM_CFLAGS += -DSWITCH_MOD_DIR=\"$(PREFIX)/mod\"
AM_CFLAGS += -DSWITCH_PREFIX_DIR=\"$(PREFIX)\"
AM_CFLAGS += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\"
+AM_CFLAGS += -DSWITCH_DB_DIR=\"$(PREFIX)/db\"
libfreeswitch_la_SOURCES = \
src/include/switch.h \
depends:
./buildlib.sh . install sqlite-3.2.8.tar.gz --disable-tcl --enable-threadsafe
- ./buildlib.sh . install apr-1.2.2.tar.gz --prefix=/usr/local
+ ./buildlib.sh . install apr-1.2.2.tar.gz
+ ./buildlib.sh . install apr-util-1.2.2.tar.gz --with-apr=/usr/src/freeswitch/libs/apr-1.2.2
modules: $(NAME)
@echo making modules
-I$(PWD)/src/include -I$(PREFIX)/include \
-DSWITCH_MOD_DIR=\"$(PREFIX)/mod\" \
-DSWITCH_PREFIX_DIR=\"$(PREFIX)\" \
- -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\"
+ -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" \
+ -DSWITCH_DB_DIR=\"$(PREFIX)/db\"
AM_LDFLAGS = $(shell $(APR_CONFIG) --link-ld --libs ) -lsqlite3 \
$(am__append_1)
OSARCH = $(shell uname -s)
depends:
./buildlib.sh . install sqlite-3.2.8.tar.gz --disable-tcl --enable-threadsafe
- ./buildlib.sh . install apr-1.2.2.tar.gz --prefix=/usr/local
+ ./buildlib.sh . install apr-1.2.2.tar.gz
+ ./buildlib.sh . install apr-util-1.2.2.tar.gz --with-apr=/usr/src/freeswitch/libs/apr-1.2.2
modules: $(NAME)
@echo making modules
cd $uncompressed
make clean 2>&1
-sh ./configure $@
+sh ./configure --prefix=/usr/local $@
if [ $? == 0 ] ; then
make
SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *dtmf, size_t len);
SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *channel, int freq, int bits, int channels, int ms, int kbps);
SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode (switch_channel *channel, int *freq, int *bits, int *channels, int *ms, int *kbps);
-
+SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state state);
+SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, switch_event *event);
#ifdef __cplusplus
}
#endif
SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_session *session);
SWITCH_DECLARE(void) pbx_core_session_signal_state_change(switch_core_session *session);
SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup);
+SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename);
+
+#define SWITCH_CORE_DB "core"
+#define switch_core_db_handle() switch_core_db_open_file(SWITCH_CORE_DB)
#ifdef __cplusplus
}
SWITCH_DECLARE(char *) switch_event_name(switch_event_t event);
SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner, char *subclass_name);
SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...);
+SWITCH_DECLARE(switch_status) switch_event_running(void);
#define switch_event_reserve_subclass(subclass_name) switch_event_reserve_subclass_detailed(__FILE__, subclass_name)
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
#endif
#include <switch.h>
-//#include <sqlite3.h>
-//#include <apr_thread_mutex.h>
-//#include <apr_thread_proc.h>
-//#include <apr_hash.h>
-//#include <apr_network_io.h>
-//#include <apr_poll.h>
-//#include <sys/types.h>
#define SWITCH_GLOBAL_VERSION "1"
#define SWITCH_MAX_CODECS 30
typedef enum {
SWITCH_CHANNEL_ID_CONSOLE,
- SWITCH_CHANNEL_ID_CONSOLE_CLEAN
+ SWITCH_CHANNEL_ID_CONSOLE_CLEAN,
+ SWITCH_CHANNEL_ID_EVENT
} switch_text_channel;
#if defined(_MSC_VER) && _MSC_VER < 1300
#endif
#endif
-
+
#define SWITCH_CHANNEL_CONSOLE SWITCH_CHANNEL_ID_CONSOLE, __FILE__, __FUNCTION__, __LINE__
#define SWITCH_CHANNEL_CONSOLE_CLEAN SWITCH_CHANNEL_ID_CONSOLE_CLEAN, __FILE__, __FUNCTION__, __LINE__
+#define SWITCH_CHANNEL_EVENT SWITCH_CHANNEL_ID_EVENT, __FILE__, __FUNCTION__, __LINE__
typedef enum {
CS_NEW,
*/
typedef enum {
SWITCH_EVENT_CUSTOM,
+ SWITCH_EVENT_CHANNEL_STATE,
+ SWITCH_EVENT_CHANNEL_ANSWER,
+ SWITCH_EVENT_LOG,
SWITCH_EVENT_INBOUND_CHAN,
SWITCH_EVENT_OUTBOUND_CHAN,
SWITCH_EVENT_ANSWER_CHAN,
} switch_event_t;
+
typedef struct switch_event_header switch_event_header;
typedef struct switch_event switch_event;
typedef struct switch_event_subclass switch_event_subclass;
#define SWITCH_FPROT_OS_DEFAULT APR_FPROT_OS_DEFAULT
#define SWITCH_FPROT_FILE_SOURCE_PERMS APR_FPROT_FILE_SOURCE_PERMS
+/* SQLITE */
+typedef sqlite3 switch_core_db;
+#define switch_core_db_aggregate_context sqlite3_aggregate_context
+#define switch_core_db_aggregate_count sqlite3_aggregate_count
+#define switch_core_db_bind_blob sqlite3_bind_blob
+#define switch_core_db_bind_double sqlite3_bind_double
+#define switch_core_db_bind_int sqlite3_bind_int
+#define switch_core_db_bind_int64 sqlite3_bind_int64
+#define switch_core_db_bind_null sqlite3_bind_null
+#define switch_core_db_bind_parameter_count sqlite3_bind_parameter_count
+#define switch_core_db_bind_parameter_index sqlite3_bind_parameter_index
+#define switch_core_db_bind_parameter_name sqlite3_bind_parameter_name
+#define switch_core_db_bind_text sqlite3_bind_text
+#define switch_core_db_bind_text16 sqlite3_bind_text16
+#define switch_core_db_btree_trace sqlite3_btree_trace
+#define switch_core_db_busy_handler sqlite3_busy_handler
+#define switch_core_db_busy_timeout sqlite3_busy_timeout
+#define switch_core_db_changes sqlite3_changes
+#define switch_core_db_close sqlite3_close
+#define switch_core_db_collation_needed sqlite3_collation_needed
+#define switch_core_db_collation_needed16 sqlite3_collation_needed16
+#define switch_core_db_column_blob sqlite3_column_blob
+#define switch_core_db_column_bytes sqlite3_column_bytes
+#define switch_core_db_column_bytes16 sqlite3_column_bytes16
+#define switch_core_db_column_count sqlite3_column_count
+#define switch_core_db_column_decltype sqlite3_column_decltype
+#define switch_core_db_column_decltype16 sqlite3_column_decltype16
+#define switch_core_db_column_double sqlite3_column_double
+#define switch_core_db_column_int sqlite3_column_int
+#define switch_core_db_column_int64 sqlite3_column_int64
+#define switch_core_db_column_name sqlite3_column_name
+#define switch_core_db_column_name16 sqlite3_column_name16
+#define switch_core_db_column_text sqlite3_column_text
+#define switch_core_db_column_text16 sqlite3_column_text16
+#define switch_core_db_column_type sqlite3_column_type
+#define switch_core_db_commit_hook sqlite3_commit_hook
+#define switch_core_db_complete sqlite3_complete
+#define switch_core_db_complete16 sqlite3_complete16
+#define switch_core_db_create_collation sqlite3_create_collation
+#define switch_core_db_create_collation16 sqlite3_create_collation16
+#define switch_core_db_create_function sqlite3_create_function
+#define switch_core_db_create_function16 sqlite3_create_function16
+#define switch_core_db_data_count sqlite3_data_count
+#define switch_core_db_db_handle sqlite3_db_handle
+#define switch_core_db_errcode sqlite3_errcode
+#define switch_core_db_errmsg sqlite3_errmsg
+#define switch_core_db_errmsg16 sqlite3_errmsg16
+#define switch_core_db_exec sqlite3_exec
+#define switch_core_db_expired sqlite3_expired
+#define switch_core_db_finalize sqlite3_finalize
+#define switch_core_db_free sqlite3_free
+#define switch_core_db_free_table sqlite3_free_table
+#define switch_core_db_get_autocommit sqlite3_get_autocommit
+#define switch_core_db_get_auxdata sqlite3_get_auxdata
+#define switch_core_db_get_table sqlite3_get_table
+#define switch_core_db_get_table_cb sqlite3_get_table_cb
+#define switch_core_db_global_recover sqlite3_global_recover
+#define switch_core_db_interrupt sqlite3_interrupt
+#define switch_core_db_interrupt_count sqlite3_interrupt_count
+#define switch_core_db_last_insert_rowid sqlite3_last_insert_rowid
+#define switch_core_db_libversion sqlite3_libversion
+#define switch_core_db_libversion_number sqlite3_libversion_number
+#define switch_core_db_malloc_failed sqlite3_malloc_failed
+#define switch_core_db_mprintf sqlite3_mprintf
+#define switch_core_db_open sqlite3_open
+#define switch_core_db_open16 sqlite3_open16
+#define switch_core_db_opentemp_count sqlite3_opentemp_count
+#define switch_core_db_os_trace sqlite3_os_trace
+#define switch_core_db_prepare sqlite3_prepare
+#define switch_core_db_prepare16 sqlite3_prepare16
+#define switch_core_db_profile sqlite3_profile
+#define switch_core_db_progress_handler sqlite3_progress_handler
+#define switch_core_db_reset sqlite3_reset
+#define switch_core_db_result_blob sqlite3_result_blob
+#define switch_core_db_result_double sqlite3_result_double
+#define switch_core_db_result_error sqlite3_result_error
+#define switch_core_db_result_error16 sqlite3_result_error16
+#define switch_core_db_result_int sqlite3_result_int
+#define switch_core_db_result_int64 sqlite3_result_int64
+#define switch_core_db_result_null sqlite3_result_null
+#define switch_core_db_result_text sqlite3_result_text
+#define switch_core_db_result_text16 sqlite3_result_text16
+#define switch_core_db_result_text16be sqlite3_result_text16be
+#define switch_core_db_result_text16le sqlite3_result_text16le
+#define switch_core_db_result_value sqlite3_result_value
+#define switch_core_db_search_count sqlite3_search_count
+#define switch_core_db_set_authorizer sqlite3_set_authorizer
+#define switch_core_db_set_auxdata sqlite3_set_auxdata
+#define switch_core_db_snprintf sqlite3_snprintf
+#define switch_core_db_sort_count sqlite3_sort_count
+#define switch_core_db_step sqlite3_step
+#define switch_core_db_temp_directory sqlite3_temp_directory
+#define switch_core_db_total_changes sqlite3_total_changes
+#define switch_core_db_trace sqlite3_trace
+#define switch_core_db_transfer_bindings sqlite3_transfer_bindings
+#define switch_core_db_user_data sqlite3_user_data
+#define switch_core_db_value_blob sqlite3_value_blob
+#define switch_core_db_value_bytes sqlite3_value_bytes
+#define switch_core_db_value_bytes16 sqlite3_value_bytes16
+#define switch_core_db_value_double sqlite3_value_double
+#define switch_core_db_value_int sqlite3_value_int
+#define switch_core_db_value_int64 sqlite3_value_int64
+#define switch_core_db_value_text sqlite3_value_text
+#define switch_core_db_value_text16 sqlite3_value_text16
+#define switch_core_db_value_text16be sqlite3_value_text16be
+#define switch_core_db_value_text16le sqlite3_value_text16le
+#define switch_core_db_value_type sqlite3_value_type
+#define switch_core_db_version sqlite3_version
+#define switch_core_db_vmprintf sqlite3_vmprintf
+
+
/* things we don't deserve to know about */
struct switch_channel;
struct switch_core_session;
static void event_handler (switch_event *event)
{
char buf[1024];
- switch_event_serialize(event, buf, sizeof(buf), NULL);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf);
+
+ switch(event->event_id) {
+ case SWITCH_EVENT_LOG:
+ return;
+ break;
+ default:
+ switch_event_serialize(event, buf, sizeof(buf), NULL);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf);
+ break;
+ }
}
endif
depends:
- $(BASE)/buildlib.sh $(BASE) install jthread-1.1.2.tar.gz --prefix=/usr/local
- $(BASE)/buildlib.sh $(BASE) install jrtplib-3.3.0.tar.gz --prefix=/usr/local
+ $(BASE)/buildlib.sh $(BASE) install jthread-1.1.2.tar.gz
+ $(BASE)/buildlib.sh $(BASE) install jrtplib-3.3.0.tar.gz
$(BASE)/buildlib.sh $(BASE) install jrtp4c
- $(BASE)/buildlib.sh $(BASE) install libosip2-2.2.2.tar.gz --prefix=/usr/local
- $(BASE)/buildlib.sh $(BASE) install libeXosip2-2.2.2.tar.gz --prefix=/usr/local --disable-josua
+ $(BASE)/buildlib.sh $(BASE) install libosip2-2.2.2.tar.gz
+ $(BASE)/buildlib.sh $(BASE) install libeXosip2-2.2.2.tar.gz --disable-josua
$(MOD).so: $(MOD).c
iax_shutdown();
while (running) {
- if (x++ > 1000) {
+ if (x++ > 100) {
break;
}
switch_yield(20000);
depends:
- $(BASE)/buildlib.sh $(BASE) install speex-1.1.11.1.tar.gz --prefix=/usr/local
+ $(BASE)/buildlib.sh $(BASE) install speex-1.1.11.1.tar.gz
$(MOD).so: $(MOD).c
$(CC) $(CFLAGS) -fPIC -c $(MOD).c -o $(MOD).o
SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel, char *dtmf)
{
switch_status status;
-
+
assert(channel != NULL);
switch_mutex_lock(channel->dtmf_mutex);
SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *dtmf, size_t len)
{
int bytes;
+ switch_event *event;
assert(channel != NULL);
}
switch_mutex_unlock(channel->dtmf_mutex);
+ if (bytes && switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(channel, event);
+ switch_event_add_header(event, "dtmf_string", dtmf);
+ switch_event_fire(&event);
+ }
return bytes;
return channel->state;
}
+static const char *state_names[] = {
+ "CS_NEW",
+ "CS_INIT",
+ "CS_RING",
+ "CS_TRANSMIT",
+ "CS_EXECUTE",
+ "CS_LOOPBACK",
+ "CS_HANGUP",
+ "CS_DONE"
+};
+
+SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state state)
+{
+ return state_names[state];
+}
+
SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *channel, switch_channel_state state)
{
switch_channel_state last_state;
int ok = 0;
- const char *state_names[] = {
- "CS_NEW",
- "CS_INIT",
- "CS_RING",
- "CS_TRANSMIT",
- "CS_EXECUTE",
- "CS_LOOPBACK",
- "CS_HANGUP",
- "CS_DONE"
- };
+
assert(channel != NULL);
last_state = channel->state;
return channel->state;
}
+SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, switch_event *event)
+{
+ switch_caller_profile *caller_profile, *originator_caller_profile;
+ switch_hash_index_t* hi;
+ void *val;
+ const void *var;
+
+ caller_profile = switch_channel_get_caller_profile(channel);
+ originator_caller_profile = switch_channel_get_originator_caller_profile(channel);
+
+ switch_event_add_header(event, "channel_state", (char *) switch_channel_state_name(channel->state));
+ switch_event_add_header(event, "channel_name", switch_channel_get_name(channel));
+
+ /* Index Caller's Profile */
+ if (caller_profile) {
+ if (caller_profile->dialplan) {
+ switch_event_add_header(event, "channel_dialplan", caller_profile->dialplan);
+ }
+ if (caller_profile->caller_id_name) {
+ switch_event_add_header(event, "channel_caller_id_name", caller_profile->caller_id_name);
+ }
+ if (caller_profile->caller_id_number) {
+ switch_event_add_header(event, "channel_caller_id_number", caller_profile->caller_id_number);
+ }
+ if (caller_profile->network_addr) {
+ switch_event_add_header(event, "channel_network_addr", caller_profile->network_addr);
+ }
+ if (caller_profile->ani) {
+ switch_event_add_header(event, "channel_ani", caller_profile->ani);
+ }
+ if (caller_profile->ani2) {
+ switch_event_add_header(event, "channel_ani2", caller_profile->ani2);
+ }
+ if (caller_profile->destination_number) {
+ switch_event_add_header(event, "channel_destination_number", caller_profile->destination_number);
+ }
+ }
+ /* Index Originator's Profile */
+ if (originator_caller_profile) {
+ if (originator_caller_profile->dialplan) {
+ switch_event_add_header(event, "channel_dialplan", originator_caller_profile->dialplan);
+ }
+ if (originator_caller_profile->caller_id_name) {
+ switch_event_add_header(event, "channel_caller_id_name", originator_caller_profile->caller_id_name);
+ }
+ if (originator_caller_profile->caller_id_number) {
+ switch_event_add_header(event, "channel_caller_id_number", originator_caller_profile->caller_id_number);
+ }
+ if (originator_caller_profile->network_addr) {
+ switch_event_add_header(event, "channel_network_addr", originator_caller_profile->network_addr);
+ }
+ if (originator_caller_profile->ani) {
+ switch_event_add_header(event, "channel_ani", originator_caller_profile->ani);
+ }
+ if (originator_caller_profile->ani2) {
+ switch_event_add_header(event, "channel_ani2", originator_caller_profile->ani2);
+ }
+ if (originator_caller_profile->destination_number) {
+ switch_event_add_header(event, "channel_destination_number", originator_caller_profile->destination_number);
+ }
+ }
+ /* Index Variables */
+ for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
+ char buf[1024];
+ switch_event_subclass *subclass;
+ switch_hash_this(hi, &var, NULL, &val);
+ subclass = val;
+ snprintf(buf, sizeof(buf), "variable_%s", (char *) var);
+ switch_event_add_header(event, buf, (char *) val);
+ }
+
+
+
+}
+
SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile)
{
assert(channel != NULL);
if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) {
+ switch_event *event;
+
switch_channel_set_flag(channel, CF_ANSWERED);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer!\n");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s!\n", channel->name);
+ if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(channel, event);
+ switch_event_fire(&event);
+ }
return SWITCH_STATUS_SUCCESS;
}
} else {
size_t retsize;
switch_time_exp_t tm;
+ switch_event *event;
switch_time_exp_lt(&tm, switch_time_now());
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
- fprintf(handle, "[%d] %s %s:%d %s() %s", (int)getpid(), date, filep, line, func, data);
+
+ if (channel == SWITCH_CHANNEL_ID_CONSOLE) {
+ fprintf(handle, "[%d] %s %s:%d %s() %s", (int)getpid(), date, filep, line, func, data);
+ }
+
+ else if (channel == SWITCH_CHANNEL_ID_EVENT &&
+ switch_event_running() == SWITCH_STATUS_SUCCESS &&
+ switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
+
+ switch_event_add_header(event, "log_data", "%s", data);
+ switch_event_add_header(event, "log_file", "%s", filep);
+ switch_event_add_header(event, "log_function", "%s", func);
+ switch_event_add_header(event, "log_line", "%d", line);
+ switch_event_fire(&event);
+ }
free(data);
}
}
EXTERN_C void xs_init (pTHX);
#endif
-//#include <sys/types.h>
-//#include <sys/stat.h>
-//#include <fcntl.h>
+
+#ifndef SWITCH_DB_DIR
+#ifdef WIN32
+#define SWITCH_DB_DIR ".\\db"
+#else
+#define SWITCH_DB_DIR "/usr/local/freeswitch/db"
+#endif
+#endif
struct switch_core_session {
unsigned long id;
unsigned long session_id;
apr_pool_t *memory_pool;
switch_hash *session_table;
+ switch_core_db *db;
#ifdef EMBED_PERL
PerlInterpreter *my_perl;
#endif
static void switch_core_standard_on_loopback(switch_core_session *session);
static void switch_core_standard_on_transmit(switch_core_session *session);
+
/* The main runtime obj we keep this hidden for ourselves */
static struct switch_core_runtime runtime;
return 0;
}
+
+static void db_pick_path(char *dbname, char *buf, size_t size)
+{
+
+ memset(buf, 0, size);
+ if (strchr(dbname, '/')) {
+ strncpy(buf, dbname, size);
+ } else {
+ snprintf(buf, size, "%s/%s.db", SWITCH_DB_DIR, dbname);
+ }
+}
+
+SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename)
+{
+ switch_core_db *db;
+ char path[1024];
+
+ db_pick_path(filename, path, sizeof(path));
+ if (switch_core_db_open(path, &db)) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
+ switch_core_db_close(db);
+ db=NULL;
+ }
+ return db;
+}
+
SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel)
{
FILE *handle = stdout;
switch_mutex_lock(session->mutex);
while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
- if (state != laststate) {
+ switch_event *event;
+ if (state != laststate) {
midstate = state;
+ if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(session->channel, event);
+ switch_event_fire(&event);
+ }
+
switch ( state ) {
case CS_NEW: /* Just created, Waiting for first instructions */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n");
return switch_core_session_request(endpoint_interface, pool);
}
+
+static void core_event_handler (switch_event *event)
+{
+ char buf[1024];
+
+ switch(event->event_id) {
+ case SWITCH_EVENT_LOG:
+ return;
+ break;
+ default:
+ switch_event_serialize(event, buf, sizeof(buf), NULL);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
+ break;
+ }
+}
+
SWITCH_DECLARE(switch_status) switch_core_init(void)
{
#ifdef EMBED_PERL
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Allocated memory pool.\n");
switch_event_init(runtime.memory_pool);
-
+
+ /* Activate SQL database */
+ if (!(runtime.db = switch_core_db_handle())) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening DB!\n");
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening DB\n");
+ if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind event handler!\n");
+ }
+ }
+
#ifdef EMBED_PERL
if (! (my_perl = perl_alloc())) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate perl intrepreter\n");
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Closing Event Engine.\n");
switch_event_shutdown();
+
+ switch_core_db_close(runtime.db);
+
if (runtime.memory_pool) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unallocating memory pool.\n");
apr_pool_destroy(runtime.memory_pool);
*/
static char *EVENT_NAMES[] = {
"CUSTOM",
+ "CHANNEL_STATE",
+ "CHANNEL_ANSWER",
+ "LOG",
"INBOUND_CHAN",
"OUTBOUND_CHAN",
"ANSWER_CHAN",
return NULL;
}
-
+SWITCH_DECLARE(switch_status) switch_event_running(void)
+{
+ return THREAD_RUNNING ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+}
SWITCH_DECLARE(char *) switch_event_name(switch_event_t event)
{
}
}
- snprintf(buf, buflen, "name: %s\n", switch_event_name(event->event_id));
+ snprintf(buf, buflen, "event_name: %s\n", switch_event_name(event->event_id));
len = strlen(buf);
if (event->subclass) {
snprintf(buf+len, buflen-len, "subclass-name: %s\nowner: %s", event->subclass->name, event->subclass->owner);
{
switch_event *ep;
+ switch_time_exp_t tm;
+ char date[80] = "";
+ size_t retsize;
assert(BLOCK != NULL);
assert(EPOOL != NULL);
- switch_event_add_header(*event, "file", file);
- switch_event_add_header(*event, "function", func);
- switch_event_add_header(*event, "line_number", "%d", line);
+ switch_time_exp_lt(&tm, switch_time_now());
+ switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d", &tm);
+ switch_event_add_header(*event, "event_date", date);
+
+ switch_strftime(date, &retsize, sizeof(date), "%T", &tm);
+ switch_event_add_header(*event, "event_time", date);
+
+ switch_event_add_header(*event, "event_file", file);
+ switch_event_add_header(*event, "event_function", func);
+ switch_event_add_header(*event, "event_line_number", "%d", line);
if (user_data) {
(*event)->event_user_data = user_data;