add call_uuid

This commit is contained in:
Anthony Minessale 2010-06-25 13:19:53 -05:00
parent 6914b1c855
commit ff1a52ab18
3 changed files with 172 additions and 139 deletions

View File

@ -1761,6 +1761,9 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v);
}
if ((v = switch_channel_get_variable(channel, "call_uuid"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v);
}
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");

View File

@ -924,9 +924,13 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
return NULL;
}
#define MAX_SQL 5
#define new_sql() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++]
static void core_event_handler(switch_event_t *event)
{
char *sql = NULL;
char *sql[MAX_SQL] = { 0 };
int sql_idx = 0;
switch_assert(event);
@ -937,7 +941,7 @@ static void core_event_handler(switch_event_t *event)
const char *manager = switch_event_get_header(event, "task-sql_manager");
if (id) {
sql = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
new_sql() = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
id,
switch_event_get_header_nil(event, "task-desc"),
switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_variable("hostname")
@ -947,7 +951,7 @@ static void core_event_handler(switch_event_t *event)
break;
case SWITCH_EVENT_DEL_SCHEDULE:
case SWITCH_EVENT_EXE_SCHEDULE:
sql = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
new_sql() = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
switch_event_get_header_nil(event, "task-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_RE_SCHEDULE:
@ -956,19 +960,19 @@ static void core_event_handler(switch_event_t *event)
const char *manager = switch_event_get_header(event, "task-sql_manager");
if (id) {
sql = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
new_sql() = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
switch_event_get_header_nil(event, "task-desc"),
switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id, switch_core_get_variable("hostname"));
}
}
break;
case SWITCH_EVENT_CHANNEL_DESTROY:
sql = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_CHANNEL_UUID:
{
sql = switch_mprintf("update channels set uuid='%q' where uuid='%q' and hostname='%q';"
new_sql() = switch_mprintf("update channels set uuid='%q' where uuid='%q' and hostname='%q';"
"update calls set caller_uuid='%q' where caller_uuid='%q' and hostname='%q';"
"update calls set callee_uuid='%q' where callee_uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "unique-id"),
@ -983,7 +987,7 @@ static void core_event_handler(switch_event_t *event)
break;
}
case SWITCH_EVENT_CHANNEL_CREATE:
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) "
"values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q')",
switch_event_get_header_nil(event, "unique-id"),
switch_event_get_header_nil(event, "call-direction"),
@ -997,7 +1001,7 @@ static void core_event_handler(switch_event_t *event)
);
break;
case SWITCH_EVENT_CODEC:
sql =
new_sql() =
switch_mprintf
("update channels set read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "channel-read-codec-name"),
@ -1009,7 +1013,7 @@ static void core_event_handler(switch_event_t *event)
case SWITCH_EVENT_CHANNEL_HOLD:
case SWITCH_EVENT_CHANNEL_UNHOLD:
case SWITCH_EVENT_CHANNEL_EXECUTE:
sql = switch_mprintf("update channels set application='%q',application_data='%q',"
new_sql() = switch_mprintf("update channels set application='%q',application_data='%q',"
"presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "application"),
switch_event_get_header_nil(event, "application-data"),
@ -1019,6 +1023,19 @@ static void core_event_handler(switch_event_t *event)
);
break;
case SWITCH_EVENT_CHANNEL_ORIGINATE:
{
new_sql() = switch_mprintf("update channels set "
"presence_id='%q',presence_data='%q', call_uuid='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "channel-presence-id"),
switch_event_get_header_nil(event, "channel-presence-data"),
switch_event_get_header_nil(event, "channel-call-uuid"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
}
break;
case SWITCH_EVENT_CALL_UPDATE:
{
const char *name = switch_event_get_header(event, "callee-name");
@ -1033,7 +1050,7 @@ static void core_event_handler(switch_event_t *event)
}
if (!zstr(name) && !zstr(number)) {
sql = switch_mprintf("update channels set state='%s',callstate='%s',callee_name='%q',"
new_sql() = switch_mprintf("update channels set state='%s',callstate='%s',callee_name='%q',"
"callee_num='%q',callee_direction='%q' where uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "channel-state"),
switch_event_get_header_nil(event, "channel-call-state"),
@ -1046,7 +1063,7 @@ static void core_event_handler(switch_event_t *event)
break;
case SWITCH_EVENT_CHANNEL_CALLSTATE:
{
sql = switch_mprintf("update channels set callstate='%q' where uuid='%q' and hostname='%q'",
new_sql() = switch_mprintf("update channels set callstate='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "channel-call-state"),
switch_event_get_header_nil(event, "unique-id"),
switch_core_get_variable("hostname"));
@ -1067,7 +1084,7 @@ static void core_event_handler(switch_event_t *event)
case CS_DESTROY:
break;
case CS_ROUTING:
sql = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
"ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q' "
"where uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "channel-state"),
@ -1082,15 +1099,22 @@ static void core_event_handler(switch_event_t *event)
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
default:
sql = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "channel-state"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
}
break;
}
case SWITCH_EVENT_CHANNEL_BRIDGE:
sql = switch_mprintf("insert into calls values ('%s', '%ld', '%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s','%q')",
new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "channel-call-uuid"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
new_sql() = switch_mprintf("insert into calls values ('%s', '%s', '%ld', '%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s','%q')",
switch_event_get_header_nil(event, "channel-call-uuid"),
switch_event_get_header_nil(event, "event-date-local"),
(long) switch_epoch_time_now(NULL),
switch_event_get_header_nil(event, "event-calling-function"),
@ -1107,11 +1131,11 @@ static void core_event_handler(switch_event_t *event)
);
break;
case SWITCH_EVENT_CHANNEL_UNBRIDGE:
sql = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",
new_sql() = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_SHUTDOWN:
sql = switch_mprintf("delete from channels where hostname='%q';"
new_sql() = switch_mprintf("delete from channels where hostname='%q';"
"delete from interfaces where hostname='%q';"
"delete from calls where hostname='%q'",
switch_core_get_variable("hostname"), switch_core_get_variable("hostname"), switch_core_get_variable("hostname")
@ -1128,7 +1152,7 @@ static void core_event_handler(switch_event_t *event)
const char *key = switch_event_get_header_nil(event, "key");
const char *filename = switch_event_get_header_nil(event, "filename");
if (!zstr(type) && !zstr(name)) {
sql =
new_sql() =
switch_mprintf
("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name,
switch_str_nil(description), switch_str_nil(syntax), switch_str_nil(key), switch_str_nil(filename),
@ -1142,7 +1166,7 @@ static void core_event_handler(switch_event_t *event)
const char *type = switch_event_get_header_nil(event, "type");
const char *name = switch_event_get_header_nil(event, "name");
if (!zstr(type) && !zstr(name)) {
sql = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
new_sql() = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
switch_core_get_variable("hostname"));
}
break;
@ -1154,7 +1178,7 @@ static void core_event_handler(switch_event_t *event)
if (zstr(type)) {
break;
}
sql = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
new_sql() = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname")
);
break;
@ -1164,12 +1188,12 @@ static void core_event_handler(switch_event_t *event)
const char *op = switch_event_get_header_nil(event, "op");
switch_bool_t sticky = switch_true(switch_event_get_header_nil(event, "sticky"));
if (!strcmp("add", op)) {
sql = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
new_sql() = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
switch_event_get_header_nil(event, "port"),
switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_variable("hostname")
);
} else if (!strcmp("del", op)) {
sql = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
new_sql() = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
switch_event_get_header_nil(event, "port"),
switch_event_get_header_nil(event, "proto"), switch_core_get_variable("hostname"));
} else if (!strcmp("status", op)) {
@ -1185,13 +1209,17 @@ static void core_event_handler(switch_event_t *event)
break;
}
if (sql) {
if (switch_stristr("update channels", sql) || switch_stristr("delete from channels", sql)) {
switch_queue_push(sql_manager.sql_queue[1], sql);
if (sql_idx) {
int i = 0;
for(i = 0; i < sql_idx; i++) {
if (switch_stristr("update channels", sql[i]) || switch_stristr("delete from channels", sql[i])) {
switch_queue_push(sql_manager.sql_queue[1], sql[i]);
} else {
switch_queue_push(sql_manager.sql_queue[0], sql);
switch_queue_push(sql_manager.sql_queue[0], sql[i]);
}
sql[i] = NULL;
}
sql = NULL;
}
}
@ -1247,11 +1275,15 @@ static char create_channels_sql[] =
" callstate VARCHAR(64),\n"
" callee_name VARCHAR(1024),\n"
" callee_num VARCHAR(256),\n"
" callee_direction VARCHAR(5)\n"
");\ncreate index uuindex on channels (uuid,hostname);\n";
" callee_direction VARCHAR(5),\n"
" call_uuid VARCHAR(256)\n"
");\n"
"create index uuindex on channels (uuid,hostname);\n"
"create index uuindex2 on channels (call_uuid,hostname);\n";
static char create_calls_sql[] =
"CREATE TABLE calls (\n"
" call_uuid VARCHAR(255),\n"
" call_created VARCHAR(128),\n"
" call_created_epoch INTEGER,\n"
" function VARCHAR(1024),\n"
@ -1266,7 +1298,10 @@ static char create_calls_sql[] =
" callee_chan_name VARCHAR(1024),\n"
" callee_uuid VARCHAR(256),\n"
" hostname VARCHAR(256)\n"
");\n" "create index eruuindex on calls (caller_uuid,hostname);\n" "create index eeuuindex on calls (callee_uuid,hostname);\n";
");\n" "create index eruuindex on calls (caller_uuid,hostname);\n"
"create index eeuuindex on calls (callee_uuid,hostname);\n"
"create index eeuuindex2 on calls (call_uuid,hostname);\n"
;
static char create_interfaces_sql[] =
"CREATE TABLE interfaces (\n"
@ -1369,8 +1404,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
case SCDB_TYPE_ODBC:
{
char *err;
switch_cache_db_test_reactive(dbh, "select callee_direction from channels", "DROP TABLE channels", create_channels_sql);
switch_cache_db_test_reactive(dbh, "select hostname from calls", "DROP TABLE calls", create_calls_sql);
switch_cache_db_test_reactive(dbh, "select call_uuid from channels", "DROP TABLE channels", create_channels_sql);
switch_cache_db_test_reactive(dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql);
switch_cache_db_test_reactive(dbh, "select ikey from interfaces", "DROP TABLE interfaces", create_interfaces_sql);
switch_cache_db_test_reactive(dbh, "select hostname from tasks", "DROP TABLE tasks", create_tasks_sql);

View File

@ -2326,7 +2326,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
char *vdata;
const char *current_variable;
char variable_buffer[512] = "";
switch_event_t *local_var_event = NULL, *originate_var_event = NULL;
switch_event_t *local_var_event = NULL, *originate_var_event = NULL, *event = NULL;
end = NULL;
chan_type = peer_names[i];
@ -2582,16 +2582,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (local_clobber) {
if (var_event) {
switch_event_t *event;
switch_event_header_t *header;
/* install the vars from the {} params */
for (header = var_event->headers; header; header = header->next) {
switch_channel_set_variable(originate_status[i].peer_channel, header->name, header->value);
}
switch_event_create(&event, SWITCH_EVENT_CHANNEL_ORIGINATE);
switch_assert(event);
switch_channel_event_set_data(originate_status[i].peer_channel, event);
switch_event_fire(&event);
}
}
@ -2606,18 +2601,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (!local_clobber) {
if (var_event) {
switch_event_t *event;
switch_event_header_t *header;
/* install the vars from the {} params */
for (header = var_event->headers; header; header = header->next) {
switch_channel_set_variable(originate_status[i].peer_channel, header->name, header->value);
}
}
}
switch_event_create(&event, SWITCH_EVENT_CHANNEL_ORIGINATE);
switch_assert(event);
switch_channel_event_set_data(originate_status[i].peer_channel, event);
switch_event_fire(&event);
}
}
if (originate_status[i].peer_channel) {
const char *vvar;