[Freeswitch-svn] [commit] r10239 - in freeswitch/trunk/src: . include mod/event_handlers/mod_event_socket

Freeswitch SVN anthm at freeswitch.org
Tue Nov 4 11:46:33 EST 2008


Author: anthm
Date: Tue Nov  4 11:46:33 2008
New Revision: 10239

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

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


[origination_uuid=someid]sofia/default/100 at 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 at 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.




Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Tue Nov  4 11:46:33 2008
@@ -502,9 +502,11 @@
   \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);

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Tue Nov  4 11:46:33 2008
@@ -1038,6 +1038,7 @@
 	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 @@
 	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,

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Tue Nov  4 11:46:33 2008
@@ -1250,6 +1250,7 @@
 			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;

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Tue Nov  4 11:46:33 2008
@@ -1150,6 +1150,7 @@
 
 	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 ||

Modified: freeswitch/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/trunk/src/switch_core_session.c	(original)
+++ freeswitch/trunk/src/switch_core_session.c	Tue Nov  4 11:46:33 2008
@@ -316,11 +316,21 @@
 		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(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 @@
 	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 @@
 
 	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 @@
 	/* 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);

Modified: freeswitch/trunk/src/switch_core_sqldb.c
==============================================================================
--- freeswitch/trunk/src/switch_core_sqldb.c	(original)
+++ freeswitch/trunk/src/switch_core_sqldb.c	Tue Nov  4 11:46:33 2008
@@ -258,6 +258,21 @@
 	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"),

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Tue Nov  4 11:46:33 2008
@@ -125,6 +125,7 @@
 	"CHANNEL_UNPARK",
 	"CHANNEL_APPLICATION",
 	"CHANNEL_ORIGINATE",
+	"CHANNEL_UUID",
 	"API",
 	"LOG",
 	"INBOUND_CHAN",

Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c	(original)
+++ freeswitch/trunk/src/switch_ivr_originate.c	Tue Nov  4 11:46:33 2008
@@ -1043,6 +1043,19 @@
 					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");
 				
 



More information about the Freeswitch-svn mailing list