FS-4296 --resolve initial calling/called nums in 'show channels'

Store initial caller and destination numbers in 'channels' table,
so `show channels` can display it.

Patch provided by Mariusz Czułada <manieq.net@gmail.com>
This commit is contained in:
Ken Rice 2014-05-23 15:03:47 -05:00
parent 042b162bc4
commit b08138d058

View File

@ -2269,8 +2269,8 @@ static void core_event_handler(switch_event_t *event)
break; break;
} }
case SWITCH_EVENT_CHANNEL_CREATE: case SWITCH_EVENT_CHANNEL_CREATE:
new_sql() = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,callstate,dialplan,context,hostname) " new_sql() = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,callstate,dialplan,context,hostname,initial_cid_num,initial_dest) "
"values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q')", "values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q','%q','%q')",
switch_event_get_header_nil(event, "unique-id"), switch_event_get_header_nil(event, "unique-id"),
switch_event_get_header_nil(event, "call-direction"), switch_event_get_header_nil(event, "call-direction"),
switch_event_get_header_nil(event, "event-date-local"), switch_event_get_header_nil(event, "event-date-local"),
@ -2279,7 +2279,9 @@ static void core_event_handler(switch_event_t *event)
switch_event_get_header_nil(event, "channel-state"), switch_event_get_header_nil(event, "channel-state"),
switch_event_get_header_nil(event, "channel-call-state"), switch_event_get_header_nil(event, "channel-call-state"),
switch_event_get_header_nil(event, "caller-dialplan"), switch_event_get_header_nil(event, "caller-dialplan"),
switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname() switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname(),
switch_event_get_header_nil(event, "caller-caller-id-number"),
switch_event_get_header_nil(event, "caller-destination-number")
); );
break; break;
case SWITCH_EVENT_CHANNEL_ANSWER: case SWITCH_EVENT_CHANNEL_ANSWER:
@ -2666,9 +2668,16 @@ static char create_channels_sql[] =
" callee_direction VARCHAR(5),\n" " callee_direction VARCHAR(5),\n"
" call_uuid VARCHAR(256),\n" " call_uuid VARCHAR(256),\n"
" sent_callee_name VARCHAR(1024),\n" " sent_callee_name VARCHAR(1024),\n"
" sent_callee_num VARCHAR(256)\n" " sent_callee_num VARCHAR(256),\n"
" initial_cid_num VARCHAR(256),\n"
" initial_dest VARCHAR(256)\n"
");\n"; ");\n";
static char *alter_channels_sql[2][2] = {
{ "select initial_cid_num from channels", "ALTER TABLE channels ADD COLUMN initial_cid_num VARCHAR(256);\n" },
{ "select initial_dest from channels", "ALTER TABLE channels ADD COLUMN initial_dest VARCHAR(256);\n" }
};
static char create_calls_sql[] = static char create_calls_sql[] =
"CREATE TABLE calls (\n" "CREATE TABLE calls (\n"
" call_uuid VARCHAR(255),\n" " call_uuid VARCHAR(255),\n"
@ -3386,6 +3395,9 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
int result = 0; int result = 0;
switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name from channels", "DROP TABLE channels", create_channels_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name from channels", "DROP TABLE channels", create_channels_sql);
for (int i=0; i<sizeof(alter_channels_sql); i++) {
switch_cache_db_test_reactive(sql_manager.dbh, alter_channels_sql[i][0], NULL, alter_channels_sql[i][1]);
};
switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql);
switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql);
switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql);