]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix caller id fields in show channels show calls etc
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 17 Aug 2010 22:26:36 +0000 (17:26 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 17 Aug 2010 22:26:36 +0000 (17:26 -0500)
src/include/switch_caller.h
src/include/switch_utils.h
src/switch_caller.c
src/switch_channel.c
src/switch_core_sqldb.c

index 35a1119d7bb57d8ff2e2b98eeb642a10544e2cd1..b3002081da25791400e9098b749cb284b0c61463 100644 (file)
@@ -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 */
index 9c5f7202ac7acb2957376f8a2940e3c8cb89811f..9bec46687d8d72bfe5a11da339e5a0b306461b39 100644 (file)
@@ -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
index b611b09ebda0796be1dab0a2a2f64beadfe90ddb..5d5d1ab4cac1888b9990d908cb47489364672d26 100644 (file)
@@ -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);
index 254c82f4d46e638b6277c325a26a8a2d10b33b80..2ce9a80a351d7da36b0b27f678de77539267eacd 100644 (file)
@@ -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;
        }
index 98d8704be20b240b45f05af53e5d0b7fb2f429d3..42935102c54f78c8abc5b13b19dcc666e114b1ef 100644 (file)
@@ -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'",