diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 35292d8c3d..172cf6572b 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1421,24 +1421,25 @@ static void core_event_handler(switch_event_t *event) } case SWITCH_EVENT_CHANNEL_BRIDGE: { - const char *a_uuid, *b_uuid; + const char *a_uuid, *b_uuid, *uuid; a_uuid = switch_event_get_header(event, "Bridge-A-Unique-ID"); b_uuid = switch_event_get_header(event, "Bridge-B-Unique-ID"); + uuid = switch_event_get_header(event, "unique-id"); if (zstr(a_uuid) || zstr(b_uuid)) { a_uuid = switch_event_get_header_nil(event, "caller-unique-id"); b_uuid = switch_event_get_header_nil(event, "other-leg-unique-id"); } - if ((extra_cols = parse_presence_data_cols(event))) { - new_sql() = switch_mprintf("update channels set call_uuid='%q',%s where uuid='%s' or uuid='%s'", - switch_event_get_header_nil(event, "channel-call-uuid"), extra_cols, a_uuid, b_uuid); + if (uuid && (extra_cols = parse_presence_data_cols(event))) { + new_sql() = switch_mprintf("update channels set %s where uuid='%s'", extra_cols, uuid); free(extra_cols); - } else { - new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' or uuid='%s'", + } + + new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' or uuid='%s'", switch_event_get_header_nil(event, "channel-call-uuid"), a_uuid, b_uuid); - } + new_sql() = switch_mprintf("insert into calls (call_uuid,call_created,call_created_epoch," "caller_uuid,callee_uuid,hostname) " @@ -1454,20 +1455,19 @@ static void core_event_handler(switch_event_t *event) break; case SWITCH_EVENT_CHANNEL_UNBRIDGE: { - char *uuid = switch_event_get_header_nil(event, "caller-unique-id"); + char *cuuid = switch_event_get_header_nil(event, "caller-unique-id"); + char *uuid = switch_event_get_header(event, "unique-id"); - if ((extra_cols = parse_presence_data_cols(event))) { - new_sql() = switch_mprintf("update channels set call_uuid=uuid,%s where call_uuid='%s'", - extra_cols, - switch_event_get_header_nil(event, "channel-call-uuid")); + if (uuid && (extra_cols = parse_presence_data_cols(event))) { + new_sql() = switch_mprintf("update channels set %s where uuid='%s'", extra_cols, uuid); free(extra_cols); - } else { - new_sql() = switch_mprintf("update channels set call_uuid=uuid where call_uuid='%s'", - switch_event_get_header_nil(event, "channel-call-uuid")); - } + } + new_sql() = switch_mprintf("update channels set call_uuid=uuid where call_uuid='%s'", + switch_event_get_header_nil(event, "channel-call-uuid")); + new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q')", - uuid, uuid); + cuuid, cuuid); break; } case SWITCH_EVENT_SHUTDOWN: