From 5f763d0d1bc2724024934b03114d87070b623a29 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 17 Aug 2010 17:26:36 -0500 Subject: [PATCH] fix caller id fields in show channels show calls etc --- src/include/switch_caller.h | 1 + src/include/switch_utils.h | 2 +- src/switch_caller.c | 5 +++ src/switch_channel.c | 7 ++++ src/switch_core_sqldb.c | 80 ++++++++++++++++++++++++++----------- 5 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/include/switch_caller.h b/src/include/switch_caller.h index 35a1119d7b..b3002081da 100644 --- a/src/include/switch_caller.h +++ b/src/include/switch_caller.h @@ -108,6 +108,7 @@ SWITCH_BEGIN_EXTERN_C struct switch_caller_extension *caller_extension; switch_memory_pool_t *pool; struct switch_caller_profile *next; + switch_call_direction_t direction; }; /*! \brief An Abstract Representation of a dialplan Application */ diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 9c5f7202ac..9bec46687d 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -708,7 +708,7 @@ SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domai #endif #endif -#define DUMP_EVENT(_e) {char *event_str;switch_event_serialize(_e, &event_str, SWITCH_FALSE);printf("DUMP\n%s\n", event_str);free(event_str);} +#define DUMP_EVENT(_e) {char *event_str;switch_event_serialize(_e, &event_str, SWITCH_FALSE);switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DUMP\n%s\n", event_str);free(event_str);} #ifndef _MSC_VER #define switch_inet_ntop inet_ntop diff --git a/src/switch_caller.c b/src/switch_caller.c index b611b09ebd..5d5d1ab4ca 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -126,6 +126,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_dup(switch_memor profile->destination_number_numplan = tocopy->destination_number_numplan; profile->flags = tocopy->flags; profile->pool = pool; + profile->direction = tocopy->direction; return profile; } @@ -255,6 +256,10 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ { char header_name[1024]; + switch_snprintf(header_name, sizeof(header_name), "%s-Direction", prefix); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->direction == SWITCH_CALL_DIRECTION_INBOUND ? + "inbound" : "outbound"); + if (!zstr(caller_profile->username)) { switch_snprintf(header_name, sizeof(header_name), "%s-Username", prefix); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->username); diff --git a/src/switch_channel.c b/src/switch_channel.c index 254c82f4d4..2ce9a80a35 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1847,8 +1847,10 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann } else { /* Index Originator's Profile */ if (originator_caller_profile) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originator"); switch_caller_profile_event_set_data(originator_caller_profile, "Other-Leg", event); } else if (originatee_caller_profile) { /* Index Originatee's Profile */ + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Other-Type", "originatee"); switch_caller_profile_event_set_data(originatee_caller_profile, "Other-Leg", event); } } @@ -1932,6 +1934,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel switch_mutex_lock(channel->profile_mutex); switch_assert(caller_profile != NULL); + caller_profile->direction = channel->direction; uuid = switch_core_session_get_uuid(channel->session); if (!caller_profile->uuid || strcasecmp(caller_profile->uuid, uuid)) { @@ -1974,6 +1977,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel caller_profile->times->created = switch_micro_time_now(); } + caller_profile->next = channel->caller_profile; channel->caller_profile = caller_profile; caller_profile->profile_index = switch_core_sprintf(caller_profile->pool, "%d", ++channel->profile_index); @@ -2017,6 +2021,7 @@ SWITCH_DECLARE(void) switch_channel_set_hunt_caller_profile(switch_channel_t *ch switch_assert(channel->caller_profile != NULL); switch_mutex_lock(channel->profile_mutex); + caller_profile->direction = channel->direction; channel->caller_profile->hunt_caller_profile = NULL; if (channel->caller_profile && caller_profile) { channel->caller_profile->hunt_caller_profile = caller_profile; @@ -2030,6 +2035,7 @@ SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel switch_assert(channel->caller_profile != NULL); switch_mutex_lock(channel->profile_mutex); + if (channel->caller_profile) { caller_profile->next = channel->caller_profile->originatee_caller_profile; channel->caller_profile->originatee_caller_profile = caller_profile; @@ -2044,6 +2050,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_p switch_assert(channel != NULL); switch_mutex_lock(channel->profile_mutex); + if (channel->caller_profile) { profile = channel->caller_profile->originator_caller_profile; } diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 98d8704be2..42935102c5 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1135,9 +1135,17 @@ static void core_event_handler(switch_event_t *event) break; case SWITCH_EVENT_CALL_UPDATE: { - const char *name = switch_event_get_header(event, "callee-name"); - const char *number = switch_event_get_header(event, "callee-number"); + const char *name = NULL, *number = NULL, *direction; + int recv = 0; + direction = switch_event_get_header(event, "direction"); + + if (direction && strcasecmp(direction, "send")) { + recv = 1; + name = switch_event_get_header(event, "callee-name"); + number = switch_event_get_header(event, "callee-number"); + } + if (!name) { name = switch_event_get_header(event, "caller-callee-id-name"); } @@ -1155,6 +1163,15 @@ static void core_event_handler(switch_event_t *event) switch_str_nil(number), switch_event_get_header_nil(event, "direction"), switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + + name = switch_event_get_header(event, "callee-name"); + number = switch_event_get_header(event, "callee-number"); + + if (name && number && recv) { + new_sql() = switch_mprintf("update calls set callee_cid_name='%q',callee_cid_num='%q' where caller_uuid='%q'", + name, number, switch_event_get_header_nil(event, "unique-id")); + + } } } break; @@ -1224,28 +1241,43 @@ static void core_event_handler(switch_event_t *event) } case SWITCH_EVENT_CHANNEL_BRIDGE: - 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 (call_uuid,call_created,call_created_epoch,function,caller_cid_name," - "caller_cid_num,caller_dest_num,caller_chan_name,caller_uuid,callee_cid_name," - "callee_cid_num,callee_dest_num,callee_chan_name,callee_uuid,hostname) " - "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"), - switch_event_get_header_nil(event, "caller-caller-id-name"), - switch_event_get_header_nil(event, "caller-caller-id-number"), - switch_event_get_header_nil(event, "caller-destination-number"), - switch_event_get_header_nil(event, "caller-channel-name"), - switch_event_get_header_nil(event, "caller-unique-id"), - switch_event_get_header_nil(event, "Other-Leg-caller-id-name"), - switch_event_get_header_nil(event, "Other-Leg-caller-id-number"), - switch_event_get_header_nil(event, "Other-Leg-destination-number"), - switch_event_get_header_nil(event, "Other-Leg-channel-name"), - switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_variable("hostname") - ); + { + const char *callee_cid_name, *callee_cid_num, *direction; + + direction = switch_event_get_header(event, "other-leg-direction"); + + if (direction && !strcasecmp(direction, "outbound")) { + callee_cid_name = switch_event_get_header_nil(event, "Other-Leg-callee-id-name"); + callee_cid_num = switch_event_get_header_nil(event, "Other-Leg-callee-id-number"); + } else { + callee_cid_name = switch_event_get_header_nil(event, "Other-Leg-caller-id-name"); + callee_cid_num = switch_event_get_header_nil(event, "Other-Leg-caller-id-number"); + } + + + 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 (call_uuid,call_created,call_created_epoch,function,caller_cid_name," + "caller_cid_num,caller_dest_num,caller_chan_name,caller_uuid,callee_cid_name," + "callee_cid_num,callee_dest_num,callee_chan_name,callee_uuid,hostname) " + "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"), + switch_event_get_header_nil(event, "caller-caller-id-name"), + switch_event_get_header_nil(event, "caller-caller-id-number"), + switch_event_get_header_nil(event, "caller-destination-number"), + switch_event_get_header_nil(event, "caller-channel-name"), + switch_event_get_header_nil(event, "caller-unique-id"), + callee_cid_name, + callee_cid_num, + switch_event_get_header_nil(event, "Other-Leg-destination-number"), + switch_event_get_header_nil(event, "Other-Leg-channel-name"), + switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_variable("hostname") + ); + } break; case SWITCH_EVENT_CHANNEL_UNBRIDGE: new_sql() = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",