[Freeswitch-svn] [commit] r9932 - freeswitch/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN mikej at freeswitch.org
Fri Oct 10 11:36:03 EDT 2008


Author: mikej
Date: Fri Oct 10 11:36:02 2008
New Revision: 9932

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
(MODENDP-112) custom sofia::gateway_state event

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Oct 10 11:36:02 2008
@@ -1193,7 +1193,8 @@
 
 typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
 
-static const char *sofia_state_names[] = { "UNREGED",
+static const char *sofia_state_names[] = { 
+	"UNREGED",
 	"TRYING",
 	"REGISTER",
 	"REGED",
@@ -1204,6 +1205,11 @@
 	NULL
 };
 
+const char * sofia_state_string(int state) 
+{
+	return sofia_state_names[state];
+}
+
 struct cb_helper {
 	sofia_profile_t *profile;
 	switch_stream_handle_t *stream;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Fri Oct 10 11:36:02 2008
@@ -72,6 +72,7 @@
 #define MY_EVENT_REGISTER "sofia::register"
 #define MY_EVENT_UNREGISTER "sofia::unregister"
 #define MY_EVENT_EXPIRE "sofia::expire"
+#define MY_EVENT_GATEWAY_STATE "sofia::gateway_state"
 
 #define MULTICAST_EVENT "multicast::event"
 #define SOFIA_REPLACES_HEADER "_sofia_replaces_"
@@ -699,3 +700,4 @@
 void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent);
 void sofia_glue_restart_all_profiles(void);
 void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
+const char * sofia_state_string(int state);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Fri Oct 10 11:36:02 2008
@@ -56,6 +56,15 @@
 
 }
 
+static void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway) {
+	switch_event_t *s_event;
+	if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_STATE) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Gateway", "%s", gateway->name);
+		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "State", "%s", sofia_state_string(gateway->state));
+		switch_event_fire(&s_event);
+	}
+}
+
 void sofia_reg_unregister(sofia_profile_t *profile)
 {
 	sofia_gateway_t *gateway_ptr;
@@ -197,6 +206,9 @@
 			}
 			break;
 		}
+		if (ostate != gateway_ptr->state) {
+			sofia_reg_fire_custom_gateway_state_event(gateway_ptr);
+		}
 	}
 }
 
@@ -1021,6 +1033,7 @@
 									 tagi_t tags[])
 {
 	if (sofia_private && sofia_private->gateway) {
+		reg_state_t ostate = sofia_private->gateway->state;
 		switch (status) {
 		case 200:
 			if (sip && sip->sip_contact) {
@@ -1056,6 +1069,9 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Registration Failed with status %d\n", status);
 			break;
 		}
+		if (ostate != sofia_private->gateway->state) {
+			sofia_reg_fire_custom_gateway_state_event(sofia_private->gateway);
+		}
 	}
 }
 
@@ -1480,12 +1496,16 @@
 											}
 
 											if ((gateway_ptr = sofia_reg_find_gateway(name))) {
+												reg_state_t ostate = gateway_ptr->state;
 												gateway_ptr->retry = 0;
 												if (exptime) {
 													gateway_ptr->state = REG_STATE_UNREGED;
 												} else {
 													gateway_ptr->state = REG_STATE_UNREGISTER;
 												}
+												if (ostate != gateway_ptr->state) {
+													sofia_reg_fire_custom_gateway_state_event(gateway_ptr);
+												}
 												sofia_reg_release_gateway(gateway_ptr);
 											}
 
@@ -1502,12 +1522,16 @@
 
 									for (x = 0; x < argc; x++) {
 										if ((gateway_ptr = sofia_reg_find_gateway((char *) argv[x]))) {
+											reg_state_t ostate = gateway_ptr->state;
 											gateway_ptr->retry = 0;
 											if (exptime) {
 												gateway_ptr->state = REG_STATE_UNREGED;
 											} else {
 												gateway_ptr->state = REG_STATE_UNREGISTER;
 											}
+											if (ostate != gateway_ptr->state) {
+												sofia_reg_fire_custom_gateway_state_event(gateway_ptr);
+											}
 											sofia_reg_release_gateway(gateway_ptr);
 										} else {
 											switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Gateway '%s' not found.\n", argv[x]);



More information about the Freeswitch-svn mailing list