]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more events and some build changes
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 21 Dec 2005 22:25:22 +0000 (22:25 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 21 Dec 2005 22:25:22 +0000 (22:25 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@188 d0543943-73ff-0310-b7d9-9358b9ac24b2

15 files changed:
Makefile.am
Makefile.in
buildlib.sh
src/include/switch_channel.h
src/include/switch_core.h
src/include/switch_event.h
src/include/switch_types.h
src/mod/mod_event_test/mod_event_test.c
src/mod/mod_exosip/Makefile
src/mod/mod_iaxchan/mod_iaxchan.c
src/mod/mod_speexcodec/Makefile
src/switch_channel.c
src/switch_console.c
src/switch_core.c
src/switch_event.c

index f9ab678bbda781505e8828d521f4ea960efc62f9..c634c89d8342f68cf107137c36a3406e9ba3b689 100644 (file)
@@ -28,6 +28,7 @@ AM_CFLAGS  +=-I$(PWD)/src/sqlite -I$(PWD) -I$(PWD)/src/include -I$(PREFIX)/inclu
 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 \
@@ -88,7 +89,8 @@ nodepends:
 
 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
index fdee85b5ec52f8e778ecb9c3b94b22cd40cdaa1a..b2cc52046f195f159defa9710132ee11d0bf1772 100644 (file)
@@ -233,7 +233,8 @@ AM_CFLAGS = $(shell $(APR_CONFIG) --cflags --cppflags --includes) \
        -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)
@@ -946,7 +947,8 @@ nodepends:
 
 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
index 02eabfd35099c3722998f43bb99a7bc9b7900460..6fe729454b98a10cd6fa465d7df6e4ccd4be0565 100755 (executable)
@@ -47,7 +47,7 @@ fi
 
 cd $uncompressed
 make clean 2>&1
-sh ./configure $@
+sh ./configure --prefix=/usr/local $@
 
 if [ $? == 0 ] ; then
     make
index c8aa1d01f56b0f3c3e7a7408116f1d35ca76b699..8948059a0122d41b7145cab925cbb3afbd575461 100644 (file)
@@ -74,7 +74,8 @@ SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel,
 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
index 197d743380f4193be251724ef48aeba74a824ae9..786300df157c0e2309c25017362df4bea7e53f34 100644 (file)
@@ -121,6 +121,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_write_codec(switch_core_se
 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
 }
index 533da22e12560dac9e2876f32d45d56cc79b78ac..4f2e28b5a57a67cc51709d832f09075021a08d30 100644 (file)
@@ -82,6 +82,7 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event,
 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)
index c53a3c9ef6659f478df60666b9230719b3b72718..c9b5c18076d54a1bdcf29ce1b0a444233234ce0c 100644 (file)
@@ -36,13 +36,6 @@ extern "C" {
 #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
@@ -62,7 +55,8 @@ typedef enum {
 
 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
@@ -71,9 +65,10 @@ typedef enum {
 #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,
@@ -128,6 +123,9 @@ typedef enum {
 */
 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,
@@ -139,6 +137,7 @@ typedef enum {
 } 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;
@@ -321,6 +320,117 @@ typedef apr_hash_index_t switch_hash_index_t;
 #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;
index 4bf140d84772075f1d80634bc5dcf9fd5d14b08f..648f31660b80fa5fa6c42f3dedca5b036247324e 100644 (file)
@@ -36,8 +36,16 @@ static const char modname[] = "mod_event_test";
 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;
+       }
 }
                                                  
 
index 30bfab84e1843bccfd7b01e393b05d11cc59b4c4..efdc2147dd736e803de66496ea3e0ad38450f6f8 100644 (file)
@@ -8,11 +8,11 @@ else
 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
index df1d4ed9cd04fe43b3552a806e0c34c4d833b435..fa999d3299057cb9fb69cc7233507c4c1f31c7ac 100644 (file)
@@ -982,7 +982,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
        iax_shutdown();
 
        while (running) {
-               if (x++ > 1000) {
+               if (x++ > 100) {
                        break;
                }
                switch_yield(20000);
index 7b6a521b14f7ab7cc25473e2d72b31e122d0bbf7..f3c29c43912eaaf9dde3358558f7dba58eb1f0b2 100644 (file)
@@ -1,5 +1,5 @@
 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
index 931a9d0d0911288562ba851ca1513253b8a1e0c9..df572d0645f96f8d4b3f9489fb1b94a289ad5853 100644 (file)
@@ -122,7 +122,7 @@ SWITCH_DECLARE(int) switch_channel_has_dtmf(switch_channel *channel)
 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);
@@ -140,6 +140,7 @@ SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel,
 SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *dtmf, size_t len)
 {
        int bytes;
+       switch_event *event;
 
        assert(channel != NULL);
 
@@ -149,6 +150,11 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
        }
        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;
 
@@ -235,20 +241,27 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *ch
        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;
@@ -381,6 +394,81 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
        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);
@@ -448,8 +536,14 @@ SWITCH_DECLARE(switch_status) switch_channel_answer(switch_channel *channel)
 
 
        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;
        }
 
index afc0960cb4281b61cf63eef9b4a5e8f61e9e7a4f..47256e687e3bd6d05ed4322f62139617ba72b1ed 100644 (file)
@@ -116,9 +116,24 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
                } 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);
                }
        }
index 2c643556ee6e2759a0730bd0b607c6b21ba00f9d..21cada090f70787b024130f8d349599ad49a6f58 100644 (file)
@@ -39,9 +39,14 @@ static char *embedding[] = { "", "-e", ""};
 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;
@@ -77,6 +82,7 @@ struct switch_core_runtime {
        unsigned long session_id;
        apr_pool_t *memory_pool;
        switch_hash *session_table;
+       switch_core_db *db;
 #ifdef EMBED_PERL
        PerlInterpreter *my_perl;
 #endif
@@ -94,6 +100,7 @@ static void switch_core_standard_on_execute(switch_core_session *session);
 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;
 
@@ -118,6 +125,32 @@ static int handle_SIGINT(int sig)
        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;
@@ -1195,10 +1228,16 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
        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");
@@ -1510,6 +1549,22 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request_by_name(char *
        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
@@ -1531,7 +1586,17 @@ SWITCH_DECLARE(switch_status) switch_core_init(void)
        }
        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");
@@ -1580,6 +1645,9 @@ SWITCH_DECLARE(switch_status) switch_core_destroy(void)
        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);
index a5c6ac2d5bda15b922290d9ad56e0a3a571536b9..05e314d229699fd8a9c492532fb3b6a97f892393 100644 (file)
@@ -46,6 +46,9 @@ static int THREAD_RUNNING = 0;
 */
 static char *EVENT_NAMES[] = {
        "CUSTOM",
+       "CHANNEL_STATE",
+       "CHANNEL_ANSWER",
+       "LOG",
        "INBOUND_CHAN",
        "OUTBOUND_CHAN",
        "ANSWER_CHAN",
@@ -161,7 +164,10 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
        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)
 {
@@ -387,7 +393,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
                }
        }
 
-       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);
@@ -412,13 +418,23 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func,
 {
 
        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;