Revision
16820
Author
sathieu
Date
2010-02-25 09:23:11 -0600 (Thu, 25 Feb 2010)

Log Message

Skinny: handle UnregisterMessage and properly flush listener

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (16819 => 16820)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-25 14:34:43 UTC (rev 16819)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c	2010-02-25 15:23:11 UTC (rev 16820)
@@ -990,7 +990,28 @@
 static void flush_listener(listener_t *listener, switch_bool_t flush_log, switch_bool_t flush_events)
 {
 
-	/* TODO */
+	if(!zstr(listener->device_name)) {
+		skinny_profile_t *profile = listener->profile;
+		char *sql;
+	
+		if ((sql = switch_mprintf(
+				"DELETE FROM skinny_devices "
+					"WHERE name='%s'",
+				listener->device_name))) {
+			skinny_execute_sql(profile, sql, profile->listener_mutex);
+			switch_safe_free(sql);
+		}
+
+		if ((sql = switch_mprintf(
+				"DELETE FROM skinny_buttons "
+					"WHERE device_name='%s'",
+				listener->device_name))) {
+			skinny_execute_sql(profile, sql, profile->listener_mutex);
+			switch_safe_free(sql);
+		}
+
+		strcpy(listener->device_name, "");
+	}
 }
 
 static int dump_device_callback(void *pArg, int argc, char **argv, char **columnNames)

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c (16819 => 16820)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c	2010-02-25 14:34:43 UTC (rev 16819)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c	2010-02-25 15:23:11 UTC (rev 16820)
@@ -109,6 +109,7 @@
 	{"DisplayPromptStatusMessage", DISPLAY_PROMPT_STATUS_MESSAGE},
 	{"ClearPromptStatusMessage", CLEAR_PROMPT_STATUS_MESSAGE},
 	{"ActivateCallPlaneMessage", ACTIVATE_CALL_PLANE_MESSAGE},
+	{"UnregisterAckMessage", UNREGISTER_ACK_MESSAGE},
 	{"DialedNumberMessage", DIALED_NUMBER_MESSAGE},
 	{"FeatureResMessage", FEATURE_STAT_RES_MESSAGE},
 	{NULL, 0}
@@ -1997,9 +1998,21 @@
 switch_status_t skinny_handle_unregister(listener_t *listener, skinny_message_t *request)
 {
 	switch_event_t *event = NULL;
+	skinny_message_t *message;
+
 	/* skinny::unregister event */
 	skinny_device_event(listener, &event, SWITCH_EVENT_CUSTOM, SKINNY_EVENT_UNREGISTER);
 	switch_event_fire(&event);
+
+	message = switch_core_alloc(listener->pool, 12+sizeof(message->data.unregister_ack));
+	message->type = UNREGISTER_ACK_MESSAGE;
+	message->length = 4 + sizeof(message->data.unregister_ack);
+	message->data.unregister_ack.unregister_status = 0; /* OK */
+	skinny_send_reply(listener, message);
+
+	/* Close socket */
+	switch_clear_flag_locked(listener, LFLAG_RUNNING);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -2061,8 +2074,8 @@
 		case UNREGISTER_MESSAGE:
 			return skinny_handle_unregister(listener, request);
 		default:
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
-				"Unknown request type: %x (length=%d).\n", request->type, request->length);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+				"Unhandled request %s (type=%x,length=%d).\n", skinny_message_type2str(request->type), request->type, request->length);
 			return SWITCH_STATUS_SUCCESS;
 	}
 }

Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h (16819 => 16820)


--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h	2010-02-25 14:34:43 UTC (rev 16819)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h	2010-02-25 15:23:11 UTC (rev 16820)
@@ -441,6 +441,12 @@
 	uint32_t line_instance;
 };
 
+/* UnregisterAckMessage */
+#define UNREGISTER_ACK_MESSAGE 0x0118
+struct unregister_ack_message {
+	uint32_t unregister_status;
+};
+
 /* DialedNumberMessage */
 #define DIALED_NUMBER_MESSAGE 0x011D
 struct dialed_number_message {
@@ -506,6 +512,7 @@
 	struct display_prompt_status_message display_prompt_status;
 	struct clear_prompt_status_message clear_prompt_status;
 	struct activate_call_plane_message activate_call_plane;
+	struct unregister_ack_message unregister_ack;
 	struct dialed_number_message dialed_number;
 	struct feature_stat_res_message feature_res;
 	
@@ -619,7 +626,7 @@
 		status = SWITCH_STATUS_SUCCESS;\
 	}
 	
-struct skinny_table SKINNY_MESSAGE_TYPES[52];
+struct skinny_table SKINNY_MESSAGE_TYPES[53];
 const char *skinny_message_type2str(uint32_t id);
 uint32_t skinny_str2message_type(const char *str);
 #define SKINNY_PUSH_MESSAGE_TYPES SKINNY_DECLARE_PUSH_MATCH(SKINNY_MESSAGE_TYPES)