]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add ability to choose uuid from originate string (use at your own risk)
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Nov 2008 16:46:33 +0000 (16:46 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 4 Nov 2008 16:46:33 +0000 (16:46 +0000)
[origination_uuid=someid]sofia/default/100@dom.com

it's only valid in [], cannot be used on 2 existing calls at once and is not
reccommended if you don't need it.

event_socket users can use it to do

api create_uuid
#### (then save uuid into a local variable say $uuid) ###
filter unique-id $uuid
events all
originate [origination_uuid=$uuid]sofia/default/100@dom.com

Then you can get all the events in anticipation on that channel.

Anything people do to cause problems misusing this will not be supported.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10239 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/include/switch_types.h
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
src/switch_channel.c
src/switch_core_session.c
src/switch_core_sqldb.c
src/switch_event.c
src/switch_ivr_originate.c

index 23e0a467d48a6858f0b9d6f9b0851f839f719dd3..edcddac5298be1e7c97a468f36cbde49e6a4c32d 100644 (file)
@@ -502,9 +502,11 @@ SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(_In_ switch_
   \param pool the pool to use for the allocation (a new one will be used if NULL)
   \return the newly created session
 */
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(_In_ const switch_endpoint_interface_t *endpoint_interface,
-                                                                                                                                       _Inout_opt_ switch_memory_pool_t **pool);
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ const switch_endpoint_interface_t *endpoint_interface,
+                                                                                                                                                _Inout_opt_ switch_memory_pool_t **pool, _In_ const char *use_uuid);
+#define switch_core_session_request(_ep, _p) switch_core_session_request_uuid(_ep, _p, NULL)
 
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session_t *session, const char *use_uuid);
 
 SWITCH_DECLARE(void) switch_core_session_perform_destroy(_Inout_ switch_core_session_t **session,
                                                                                                                 _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
index 1390605901e6d43abc42d43abcfbc82288098a6c..7adb22add8c782de9658dc45f76a505ae165ced7 100644 (file)
@@ -1038,6 +1038,7 @@ typedef uint32_t switch_io_flag_t;
        SWITCH_EVENT_CHANNEL_UNPARK     - A channel has been unparked
        SWITCH_EVENT_CHANNEL_APPLICATION- A channel has called and event from an application
        SWITCH_EVENT_CHANNEL_ORIGINATE  - A channel has been originated
+       SWITCH_EVENT_CHANNEL_UUID       - A channel has changed uuid
     SWITCH_EVENT_API                           - An API call has been executed
     SWITCH_EVENT_LOG                           - A LOG event has been triggered
     SWITCH_EVENT_INBOUND_CHAN          - A new inbound channel has been created
@@ -1095,6 +1096,7 @@ typedef enum {
        SWITCH_EVENT_CHANNEL_UNPARK,
        SWITCH_EVENT_CHANNEL_APPLICATION,
        SWITCH_EVENT_CHANNEL_ORIGINATE,
+       SWITCH_EVENT_CHANNEL_UUID,
        SWITCH_EVENT_API,
        SWITCH_EVENT_LOG,
        SWITCH_EVENT_INBOUND_CHAN,
index fc22da5047f76d9bd81aa10b5751225818e8887d..0bd3d4674dfca2d26a61b62a1dfffbea76e0672e 100644 (file)
@@ -1250,6 +1250,7 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even
                        listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE] = 1;
                        listener->event_list[SWITCH_EVENT_CHANNEL_HANGUP] = 1;
                        listener->event_list[SWITCH_EVENT_CHANNEL_ORIGINATE] = 1;
+                       listener->event_list[SWITCH_EVENT_CHANNEL_UUID] = 1;
                        listener->event_list[SWITCH_EVENT_CHANNEL_OUTGOING] = 1;
                        listener->event_list[SWITCH_EVENT_CHANNEL_PARK] = 1;
                        listener->event_list[SWITCH_EVENT_CHANNEL_PROGRESS] = 1;
index 49ce775ee6dd89e6f87f9e19949b60a467f14aab..df242ad640812ed001c5068ae8953071b47ca7ee 100644 (file)
@@ -1150,6 +1150,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
 
        if (switch_test_flag(channel, CF_VERBOSE_EVENTS) || 
                event->event_id == SWITCH_EVENT_CHANNEL_ORIGINATE ||
+               event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
                event->event_id == SWITCH_EVENT_CHANNEL_ANSWER ||
                event->event_id == SWITCH_EVENT_CHANNEL_PROGRESS ||
                event->event_id == SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA ||
index 76a9aab68981452ca11f029a39d4ad474a337054..6475af16b0ebe8686527f18be6e39e5e469f8393 100644 (file)
@@ -316,11 +316,21 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
                switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
                switch_event_t *event;
                switch_channel_t *peer_channel = switch_core_session_get_channel(*new_session);
+               const char *use_uuid;
 
                switch_assert(peer_channel);
 
                peer_profile = switch_channel_get_caller_profile(peer_channel);
-
+               
+               if ((use_uuid = switch_event_get_header(var_event, "origination_uuid"))) {
+                       if (switch_core_session_set_uuid(*new_session, use_uuid) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_del_header(var_event, "origination_uuid");
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(peer_channel), use_uuid);
+                       } else {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", switch_channel_get_name(peer_channel), use_uuid);
+                       }
+               }
+               
                if (channel) {
                        const char *export_vars, *val;
                        switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@@ -917,8 +927,33 @@ SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session_t *se
 
 }
 
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch_endpoint_interface_t
-                                                                                                                                       *endpoint_interface, switch_memory_pool_t **pool)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(switch_core_session_t *session, const char *use_uuid)
+{
+       switch_event_t *event;
+
+       switch_assert(use_uuid);
+
+       if (switch_core_hash_find(session_manager.session_table, use_uuid)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
+        return SWITCH_STATUS_FALSE;
+       }
+
+       switch_event_create(&event, SWITCH_EVENT_CHANNEL_UUID);
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Old-Unique-ID", session->uuid_str);
+       switch_mutex_lock(runtime.throttle_mutex);
+       switch_core_hash_delete(session_manager.session_table, session->uuid_str);
+       switch_set_string(session->uuid_str, use_uuid);
+       switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);
+       switch_mutex_unlock(runtime.throttle_mutex);
+       switch_channel_event_set_data(session->channel, event);
+       switch_event_fire(&event);
+       
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(const switch_endpoint_interface_t
+                                                                                                                                                *endpoint_interface, switch_memory_pool_t **pool, const char *use_uuid)
 {
        switch_memory_pool_t *usepool;
        switch_core_session_t *session;
@@ -926,6 +961,11 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
        uint32_t count = 0;
        int32_t sps = 0;
 
+       if (use_uuid && switch_core_hash_find(session_manager.session_table, use_uuid)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
+        return NULL;
+       }
+
        if (!switch_core_ready() || endpoint_interface == NULL) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The system cannot create any sessions at this time.\n");
                return NULL;
@@ -957,7 +997,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
 
        session = switch_core_alloc(usepool, sizeof(*session));
        session->pool = usepool;
-
+       
        if (switch_channel_alloc(&session->channel, session->pool) != SWITCH_STATUS_SUCCESS) {
                abort();
        }
@@ -967,8 +1007,13 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
        /* The session *IS* the pool you may not alter it because you have no idea how
           its all private it will be passed to the thread run function */
 
-       switch_uuid_get(&uuid);
-       switch_uuid_format(session->uuid_str, &uuid);
+       if (use_uuid) {
+               switch_set_string(session->uuid_str, use_uuid);
+       } else {
+               switch_uuid_get(&uuid);
+               switch_uuid_format(session->uuid_str, &uuid);
+       }
+
        session->endpoint_interface = endpoint_interface;
        session->raw_write_frame.data = session->raw_write_buf;
        session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
index 06bca958596ef11bd244694526cd64831ca93745..7727e0729b09a1ea8e8ee1a22b8d11d5f8ed9dc1 100644 (file)
@@ -258,6 +258,21 @@ static void core_event_handler(switch_event_t *event)
        case SWITCH_EVENT_CHANNEL_DESTROY:
                sql = switch_mprintf("delete from channels where uuid='%q'", switch_event_get_header_nil(event, "unique-id"));
                break;
+       case SWITCH_EVENT_CHANNEL_UUID:
+               {
+                       sql = switch_mprintf(
+                                                                "update channels set uuid='%q' where uuid='%q';"
+                                                                "update calls set caller_uuid='%q' where caller_uuid='%q';"
+                                                                "update calls set callee_uuid='%q' where callee_uuid='%q'",
+                                                                switch_event_get_header_nil(event, "unique-id"),
+                                                                switch_event_get_header_nil(event, "old-unique-id"),
+                                                                switch_event_get_header_nil(event, "unique-id"),
+                                                                switch_event_get_header_nil(event, "old-unique-id"),
+                                                                switch_event_get_header_nil(event, "unique-id"),
+                                                                switch_event_get_header_nil(event, "old-unique-id")
+                                                                );
+                       break;
+               }
        case SWITCH_EVENT_CHANNEL_CREATE:
                sql = switch_mprintf("insert into channels (uuid,created,created_epoch, name,state,dialplan,context) values('%q','%q','%ld','%q','%q','%q','%q')",
                                                         switch_event_get_header_nil(event, "unique-id"),
index 31e7d2e5a3b5bf480c3a1cdafc2d1fff2c6b2f5a..22e8ecd93f1275d8c6b3daa1236c8a09525b4c55 100644 (file)
@@ -125,6 +125,7 @@ static char *EVENT_NAMES[] = {
        "CHANNEL_UNPARK",
        "CHANNEL_APPLICATION",
        "CHANNEL_ORIGINATE",
+       "CHANNEL_UUID",
        "API",
        "LOG",
        "INBOUND_CHAN",
index 52961857a7254084bd02f1c44533675d6339f0ac..8c4d19d24ae803482cface21b04de1539dbf878e 100644 (file)
@@ -1043,6 +1043,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                        myflags |= SOF_NO_EFFECTIVE_CID_NAME;
                                }
 
+                               if (vdata && (var_begin = switch_stristr("origination_uuid=", vdata))) {
+                                       char tmp[512] = "";
+                                       var_begin += strlen("origination_uuid=");
+                                       var_end = strchr(var_begin, '|');
+                                       if (var_end) {
+                                               strncpy(tmp, var_begin, var_end-var_begin);
+                                       } else {
+                                               strncpy(tmp, var_begin, strlen(var_begin));
+                                       }
+                                       new_profile->caller_id_name = switch_core_strdup(new_profile->pool, tmp);
+                                       switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "origination_uuid", tmp);
+                               }
+                               
                                switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "originate_early_media", early_ok ? "true" : "false");