add some events and more data to core DB

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1115 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2006-04-11 14:55:14 +00:00
parent 72820b56f2
commit 628e59a3ae
6 changed files with 89 additions and 20 deletions

View File

@ -431,7 +431,9 @@ typedef enum {
SWITCH_EVENT_CHANNEL_STATE - A channel has changed state SWITCH_EVENT_CHANNEL_STATE - A channel has changed state
SWITCH_EVENT_CHANNEL_ANSWER - A channel has been answered SWITCH_EVENT_CHANNEL_ANSWER - A channel has been answered
SWITCH_EVENT_CHANNEL_HANGUP - A channel has been hungup SWITCH_EVENT_CHANNEL_HANGUP - A channel has been hungup
SWITCH_EVENT_CHANNEL_EXEC - A channel has executed a module's application SWITCH_EVENT_CHANNEL_EXECUTE - A channel has executed a module's application
SWITCH_EVENT_CHANNEL_BRIDGE - A channel has bridged to another channel
SWITCH_EVENT_CHANNEL_UNBRIDGE - A channel has unbridged from another channel
SWITCH_EVENT_API - An API call has been executed SWITCH_EVENT_API - An API call has been executed
SWITCH_EVENT_LOG - A LOG event has been triggered SWITCH_EVENT_LOG - A LOG event has been triggered
SWITCH_EVENT_INBOUND_CHAN - A new inbound channel has been created SWITCH_EVENT_INBOUND_CHAN - A new inbound channel has been created
@ -450,7 +452,9 @@ typedef enum {
SWITCH_EVENT_CHANNEL_STATE, SWITCH_EVENT_CHANNEL_STATE,
SWITCH_EVENT_CHANNEL_ANSWER, SWITCH_EVENT_CHANNEL_ANSWER,
SWITCH_EVENT_CHANNEL_HANGUP, SWITCH_EVENT_CHANNEL_HANGUP,
SWITCH_EVENT_CHANNEL_EXEC, SWITCH_EVENT_CHANNEL_EXECUTE,
SWITCH_EVENT_CHANNEL_BRIDGE,
SWITCH_EVENT_CHANNEL_UNBRIDGE,
SWITCH_EVENT_API, SWITCH_EVENT_API,
SWITCH_EVENT_LOG, SWITCH_EVENT_LOG,
SWITCH_EVENT_INBOUND_CHAN, SWITCH_EVENT_INBOUND_CHAN,

View File

@ -1086,6 +1086,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
osip_from_t *from; osip_from_t *from;
char *displayname, *username; char *displayname, *username;
osip_header_t *tedious; osip_header_t *tedious;
char *val;
switch_core_session_add_stream(session, NULL); switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) { if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
@ -1112,10 +1113,21 @@ static switch_status exosip_create_call(eXosip_event_t * event)
switch_core_session_destroy(&session); switch_core_session_destroy(&session);
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
if (!(displayname = osip_from_get_displayname(from))) { if (!(val = osip_from_get_displayname(from))) {
displayname = event->request->from->url->username; val = event->request->from->url->username;
if (!displayname) { if (!val) {
displayname = "n/a"; val = "n/a";
}
}
displayname = switch_core_session_strdup(session, val);
if (*displayname == '"') {
char *p;
displayname++;
if ((p = strchr(displayname, '"'))) {
*p = '\0';
} }
} }

View File

@ -108,6 +108,14 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile
snprintf(header_name, sizeof(header_name), "%s-Destination-Number", prefix); snprintf(header_name, sizeof(header_name), "%s-Destination-Number", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->destination_number); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->destination_number);
} }
if (caller_profile->uuid) {
snprintf(header_name, sizeof(header_name), "%s-Unique-ID", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->uuid);
}
if (caller_profile->chan_name) {
snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->chan_name);
}
} }

View File

@ -1705,7 +1705,7 @@ static void switch_core_standard_on_execute(switch_core_session *session)
return; return;
} }
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXEC) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event); switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", extension->current_application->application_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", extension->current_application->application_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", extension->current_application->application_data); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", extension->current_application->application_data);
@ -2279,7 +2279,7 @@ static void core_event_handler(switch_event *event)
switch (event->event_id) { switch (event->event_id) {
case SWITCH_EVENT_CHANNEL_CREATE: case SWITCH_EVENT_CHANNEL_CREATE:
snprintf(buf, sizeof(buf), "insert into calls (uuid,created,name,state) values('%s','%s','%s','%s')", snprintf(buf, sizeof(buf), "insert into channels (uuid,created,name,state) values('%s','%s','%s','%s')",
switch_event_get_header(event, "unique-id"), switch_event_get_header(event, "unique-id"),
switch_event_get_header(event, "event-date-local"), switch_event_get_header(event, "event-date-local"),
switch_event_get_header(event, "channel-name"), switch_event_get_header(event, "channel-name"),
@ -2287,8 +2287,8 @@ static void core_event_handler(switch_event *event)
); );
sql = buf; sql = buf;
break; break;
case SWITCH_EVENT_CHANNEL_EXEC: case SWITCH_EVENT_CHANNEL_EXECUTE:
snprintf(buf, sizeof(buf), "update calls set application='%s',application_data='%s' where uuid='%s'", snprintf(buf, sizeof(buf), "update channels set application='%s',application_data='%s' where uuid='%s'",
switch_event_get_header(event, "application"), switch_event_get_header(event, "application"),
switch_event_get_header(event, "application-data"), switch_event_get_header(event, "application-data"),
switch_event_get_header(event, "unique-id") switch_event_get_header(event, "unique-id")
@ -2302,11 +2302,11 @@ static void core_event_handler(switch_event *event)
switch(state_i) { switch(state_i) {
case CS_HANGUP: case CS_HANGUP:
snprintf(buf, sizeof(buf), "delete from calls where uuid='%s'", switch_event_get_header(event, "unique-id")); snprintf(buf, sizeof(buf), "delete from channels where uuid='%s'", switch_event_get_header(event, "unique-id"));
sql = buf; sql = buf;
break; break;
case CS_RING: case CS_RING:
snprintf(buf, sizeof(buf), "update calls set state='%s',cid_name='%s',cid_num='%s',ip_addr='%s',dest='%s'" snprintf(buf, sizeof(buf), "update channels set state='%s',cid_name='%s',cid_num='%s',ip_addr='%s',dest='%s'"
"where uuid='%s'", "where uuid='%s'",
switch_event_get_header(event, "channel-state"), switch_event_get_header(event, "channel-state"),
switch_event_get_header(event, "caller-caller-id-name"), switch_event_get_header(event, "caller-caller-id-name"),
@ -2318,7 +2318,7 @@ static void core_event_handler(switch_event *event)
sql = buf; sql = buf;
break; break;
default: default:
snprintf(buf, sizeof(buf), "update calls set state='%s' where uuid='%s'", snprintf(buf, sizeof(buf), "update channels set state='%s' where uuid='%s'",
switch_event_get_header(event, "channel-state"), switch_event_get_header(event, "channel-state"),
switch_event_get_header(event, "unique-id") switch_event_get_header(event, "unique-id")
); );
@ -2328,8 +2328,28 @@ static void core_event_handler(switch_event *event)
} }
break; break;
case SWITCH_EVENT_CHANNEL_BRIDGE:
snprintf(buf, sizeof(buf), "insert into calls values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
switch_event_get_header(event, "event-calling-function"),
switch_event_get_header(event, "caller-caller-id-name"),
switch_event_get_header(event, "caller-caller-id-number"),
switch_event_get_header(event, "caller-destination-number"),
switch_event_get_header(event, "caller-channel-name"),
switch_event_get_header(event, "caller-unique-id"),
switch_event_get_header(event, "originatee-caller-id-name"),
switch_event_get_header(event, "originatee-caller-id-number"),
switch_event_get_header(event, "originatee-destination-number"),
switch_event_get_header(event, "originatee-channel-name"),
switch_event_get_header(event, "originatee-unique-id")
);
sql = buf;
break;
case SWITCH_EVENT_CHANNEL_UNBRIDGE:
snprintf(buf, sizeof(buf), "delete from calls where caller_uuid='%s'", switch_event_get_header(event, "caller-unique-id"));
sql = buf;
break;
case SWITCH_EVENT_SHUTDOWN: case SWITCH_EVENT_SHUTDOWN:
snprintf(buf, sizeof(buf), "delete from calls"); snprintf(buf, sizeof(buf), "delete from channels");
sql = buf; sql = buf;
break; break;
case SWITCH_EVENT_LOG: case SWITCH_EVENT_LOG:
@ -2430,8 +2450,8 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console)
if ((runtime.db = switch_core_db_handle()) == 0 ) { if ((runtime.db = switch_core_db_handle()) == 0 ) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening DB!\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening DB!\n");
} else { } else {
char create_calls_sql[] = char create_channels_sql[] =
"CREATE TABLE calls (\n" "CREATE TABLE channels (\n"
" uuid VARCHAR(255),\n" " uuid VARCHAR(255),\n"
" created VARCHAR(255),\n" " created VARCHAR(255),\n"
" name VARCHAR(255),\n" " name VARCHAR(255),\n"
@ -2443,9 +2463,25 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console)
" application VARCHAR(255),\n" " application VARCHAR(255),\n"
" application_data VARCHAR(255)\n" " application_data VARCHAR(255)\n"
");\n"; ");\n";
char create_calls_sql[] =
"CREATE TABLE calls (\n"
" function VARCHAR(255),\n"
" caller_cid_name VARCHAR(255),\n"
" caller_cid_num VARCHAR(255),\n"
" caller_dest_num VARCHAR(255),\n"
" caller_chan_name VARCHAR(255),\n"
" caller_uuid VARCHAR(255),\n"
" callee_cid_name VARCHAR(255),\n"
" callee_cid_num VARCHAR(255),\n"
" callee_dest_num VARCHAR(255),\n"
" callee_chan_name VARCHAR(255),\n"
" callee_uuid VARCHAR(255)\n"
");\n";
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening DB\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening DB\n");
switch_core_db_exec(runtime.db, "drop table channels", NULL, NULL, NULL);
switch_core_db_exec(runtime.db, "drop table calls", NULL, NULL, NULL); switch_core_db_exec(runtime.db, "drop table calls", NULL, NULL, NULL);
switch_core_db_exec(runtime.db, create_channels_sql, NULL, NULL, NULL);
switch_core_db_exec(runtime.db, create_calls_sql, NULL, NULL, NULL); switch_core_db_exec(runtime.db, create_calls_sql, NULL, NULL, NULL);
if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) !=

View File

@ -89,6 +89,8 @@ static char *EVENT_NAMES[] = {
"CHANNEL_ANSWER", "CHANNEL_ANSWER",
"CHANNEL_HANGUP", "CHANNEL_HANGUP",
"CHANNEL_EXECUTE", "CHANNEL_EXECUTE",
"CHANNEL_BRIDGE",
"CHANNEL_UNBRIDGE",
"API", "API",
"LOG", "LOG",
"INBOUND_CHAN", "INBOUND_CHAN",

View File

@ -33,8 +33,6 @@
#include <switch_ivr.h> #include <switch_ivr.h>
/* TBD (Lots! there are not very many functions in here lol) */
SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_callback(switch_core_session *session, SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_callback(switch_core_session *session,
switch_dtmf_callback_function dtmf_callback, switch_dtmf_callback_function dtmf_callback,
void *buf, void *buf,
@ -927,12 +925,21 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_channel_answer(caller_channel); switch_channel_answer(caller_channel);
} }
if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) { switch_event *event;
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(caller_channel, event);
switch_event_fire(&event);
}
switch_core_session_launch_thread(session, audio_bridge_thread, (void *) &other_audio_thread); switch_core_session_launch_thread(session, audio_bridge_thread, (void *) &other_audio_thread);
audio_bridge_thread(NULL, (void *) &this_audio_thread); audio_bridge_thread(NULL, (void *) &this_audio_thread);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(caller_channel, event);
switch_event_fire(&event);
}
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }