Add ability to choose uuid from originate string (use at your own risk)

[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
This commit is contained in:
Anthony Minessale 2008-11-04 16:46:33 +00:00
parent 807bef81ed
commit c9a24dd36e
8 changed files with 88 additions and 8 deletions

View 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);

View 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,

View 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;

View 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 ||

View 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);

View 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"),

View File

@ -125,6 +125,7 @@ static char *EVENT_NAMES[] = {
"CHANNEL_UNPARK",
"CHANNEL_APPLICATION",
"CHANNEL_ORIGINATE",
"CHANNEL_UUID",
"API",
"LOG",
"INBOUND_CHAN",

View 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");