From 2e2e4caa45bc5e7259b12abe33fe14ab414e1516 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Thu, 29 Aug 2013 22:20:00 +0500
Subject: [PATCH] FS-5737 revert

---
 libs/esl/src/esl_event.c                     |   2 +
 libs/esl/src/include/esl_event.h             |   3 -
 src/include/switch_types.h                   | 113 +++++++------------
 src/mod/endpoints/mod_sofia/sofia_presence.c |  21 ++--
 src/switch_event.c                           |   2 +
 5 files changed, 55 insertions(+), 86 deletions(-)

diff --git a/libs/esl/src/esl_event.c b/libs/esl/src/esl_event.c
index b5a6be4d58..159c5bed43 100644
--- a/libs/esl/src/esl_event.c
+++ b/libs/esl/src/esl_event.c
@@ -98,6 +98,8 @@ static const char *EVENT_NAMES[] = {
 	"MESSAGE",
 	"PRESENCE_IN",
 	"NOTIFY_IN",
+	"PHONE_FEATURE",
+	"PHONE_FEATURE_SUBSCRIBE",
 	"PRESENCE_OUT",
 	"PRESENCE_PROBE",
 	"MESSAGE_WAITING",
diff --git a/libs/esl/src/include/esl_event.h b/libs/esl/src/include/esl_event.h
index 44cfd184dc..0bf9259a37 100644
--- a/libs/esl/src/include/esl_event.h
+++ b/libs/esl/src/include/esl_event.h
@@ -106,8 +106,6 @@ typedef enum {
 	ESL_EVENT_RE_SCHEDULE,
 	ESL_EVENT_RELOADXML,
 	ESL_EVENT_NOTIFY,
-	ESL_EVENT_PHONE_FEATURE,
-	ESL_EVENT_PHONE_FEATURE_SUBSCRIBE,
 	ESL_EVENT_SEND_MESSAGE,
 	ESL_EVENT_RECV_MESSAGE,
 	ESL_EVENT_REQUEST_PARAMS,
@@ -119,7 +117,6 @@ typedef enum {
 	ESL_EVENT_SERVER_DISCONNECTED,
 	ESL_EVENT_SEND_INFO,
 	ESL_EVENT_RECV_INFO,
-	ESL_EVENT_RECV_RTCP_MESSAGE,
 	ESL_EVENT_CALL_SECURE,
 	ESL_EVENT_NAT,
 	ESL_EVENT_RECORD_START,
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index f90f1e190e..006050bdc8 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -1630,94 +1630,63 @@ typedef uint32_t switch_io_flag_t;
 
 <pre>
     SWITCH_EVENT_CUSTOM				- A custom event
-    SWITCH_EVENT_CLONE				- A cloned event
     SWITCH_EVENT_CHANNEL_CREATE		- A channel has been created
     SWITCH_EVENT_CHANNEL_DESTROY	- A channel has been destroyed
     SWITCH_EVENT_CHANNEL_STATE		- A channel has changed state
-    SWITCH_EVENT_CHANNEL_CALLSTATE	- A channel has changed call state
     SWITCH_EVENT_CHANNEL_ANSWER		- A channel has been answered
     SWITCH_EVENT_CHANNEL_HANGUP		- A channel has been hungup
-    SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE	- A channel has completed the hangup
     SWITCH_EVENT_CHANNEL_EXECUTE	- A channel has executed a module's application
     SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE	- A channel has finshed executing a module's application
-    SWITCH_EVENT_CHANNEL_HOLD		- A channel has been put on hold
-    SWITCH_EVENT_CHANNEL_UNHOLD		- A channel has been unheld
-    SWITCH_EVENT_CHANNEL_BRIDGE     - A channel has bridged to another channel
-    SWITCH_EVENT_CHANNEL_UNBRIDGE   - A channel has unbridged from another channel
+	SWITCH_EVENT_CHANNEL_BRIDGE     - A channel has bridged to another channel
+	SWITCH_EVENT_CHANNEL_UNBRIDGE   - A channel has unbridged from another channel
     SWITCH_EVENT_CHANNEL_PROGRESS	- A channel has started ringing
     SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA	- A channel has started early media
     SWITCH_EVENT_CHANNEL_OUTGOING	- A channel has been unparked
-    SWITCH_EVENT_CHANNEL_PARK 		- A channel has been parked
-    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_CHANNEL_PARK 		- A channel has been parked
+	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
     SWITCH_EVENT_OUTBOUND_CHAN		- A new outbound channel has been created
     SWITCH_EVENT_STARTUP			- The system has been started
     SWITCH_EVENT_SHUTDOWN			- The system has been shutdown
-    SWITCH_EVENT_PUBLISH			- Publish
-    SWITCH_EVENT_UNPUBLISH			- UnPublish
-    SWITCH_EVENT_TALK				- Talking Detected
-    SWITCH_EVENT_NOTALK				- Not Talking Detected
-    SWITCH_EVENT_SESSION_CRASH		- Session Crashed
-    SWITCH_EVENT_MODULE_LOAD		- Module was loaded
-    SWITCH_EVENT_MODULE_UNLOAD		- Module was unloaded
-    SWITCH_EVENT_DTMF				- DTMF was sent
-    SWITCH_EVENT_MESSAGE			- A Basic Message
-    SWITCH_EVENT_PRESENCE_IN		- Presence in
-    SWITCH_EVENT_NOTIFY_IN			- Received incoming NOTIFY from gateway subscription
-    SWITCH_EVENT_PRESENCE_OUT		- Presence out
-    SWITCH_EVENT_PRESENCE_PROBE		- Presence probe
-    SWITCH_EVENT_MESSAGE_WAITING	- A message is waiting
-    SWITCH_EVENT_MESSAGE_QUERY		- A query for MESSAGE_WAITING events
-    SWITCH_EVENT_ROSTER				- ?
-    SWITCH_EVENT_CODEC				- Codec Change
-    SWITCH_EVENT_BACKGROUND_JOB		- Background Job
-    SWITCH_EVENT_DETECTED_SPEECH	- Detected Speech
-    SWITCH_EVENT_DETECTED_TONE      - Detected Tone
-    SWITCH_EVENT_PRIVATE_COMMAND	- A private command event 
-    SWITCH_EVENT_HEARTBEAT			- Machine is alive
-    SWITCH_EVENT_TRAP				- Error Trap
-    SWITCH_EVENT_ADD_SCHEDULE		- Something has been scheduled
-    SWITCH_EVENT_DEL_SCHEDULE		- Something has been unscheduled
-    SWITCH_EVENT_EXE_SCHEDULE		- Something scheduled has been executed
-    SWITCH_EVENT_RE_SCHEDULE		- Something scheduled has been rescheduled
-    SWITCH_EVENT_RELOADXML			- XML registry has been reloaded
-    SWITCH_EVENT_NOTIFY				- Notification
-    SWITCH_EVENT_PHONE_FEATURE		- Notification (DND/CFWD/etc)
-    SWITCH_EVENT_PHONE_FEATURE_SUBSCRIBE - Phone feature subscription
-    SWITCH_EVENT_SEND_MESSAGE		- Message
-    SWITCH_EVENT_RECV_MESSAGE		- Message
-    SWITCH_EVENT_REQUEST_PARAMS
-    SWITCH_EVENT_CHANNEL_DATA
-    SWITCH_EVENT_GENERAL
-    SWITCH_EVENT_COMMAND
-    SWITCH_EVENT_SESSION_HEARTBEAT
-    SWITCH_EVENT_CLIENT_DISCONNECTED
-    SWITCH_EVENT_SERVER_DISCONNECTED
-    SWITCH_EVENT_SEND_INFO
-    SWITCH_EVENT_RECV_INFO
-    SWITCH_EVENT_RECV_RTCP_MESSAGE
-    SWITCH_EVENT_CALL_SECURE
-    SWITCH_EVENT_NAT            	- NAT Management (new/del/status)
-    SWITCH_EVENT_RECORD_START
-    SWITCH_EVENT_RECORD_STOP
-    SWITCH_EVENT_PLAYBACK_START
-    SWITCH_EVENT_PLAYBACK_STOP
-    SWITCH_EVENT_CALL_UPDATE
-    SWITCH_EVENT_FAILURE            - A failure occurred which might impact the normal functioning of the switch
-    SWITCH_EVENT_SOCKET_DATA
-    SWITCH_EVENT_MEDIA_BUG_START
-    SWITCH_EVENT_MEDIA_BUG_STOP
-    SWITCH_EVENT_CONFERENCE_DATA_QUERY
-    SWITCH_EVENT_CONFERENCE_DATA
-    SWITCH_EVENT_CALL_SETUP_REQ
-    SWITCH_EVENT_CALL_SETUP_RESULT
-    SWITCH_EVENT_CALL_DETAIL
-    SWITCH_EVENT_DEVICE_STATE
+	SWITCH_EVENT_PUBLISH			- Publish
+	SWITCH_EVENT_UNPUBLISH			- UnPublish
+	SWITCH_EVENT_TALK				- Talking Detected
+	SWITCH_EVENT_NOTALK				- Not Talking Detected
+	SWITCH_EVENT_SESSION_CRASH		- Session Crashed
+	SWITCH_EVENT_MODULE_LOAD		- Module was loaded
+	SWITCH_EVENT_MODULE_UNLOAD		- Module was unloaded
+	SWITCH_EVENT_DTMF				- DTMF was sent
+	SWITCH_EVENT_MESSAGE			- A Basic Message
+	SWITCH_EVENT_PRESENCE_IN		- Presence in
+	SWITCH_EVENT_NOTIFY_IN			- Received incoming NOTIFY from gateway subscription
+	SWITCH_EVENT_PRESENCE_OUT		- Presence out
+	SWITCH_EVENT_PRESENCE_PROBE		- Presence probe
+	SWITCH_EVENT_MESSAGE_WAITING	- A message is waiting
+	SWITCH_EVENT_MESSAGE_QUERY		- A query for MESSAGE_WAITING events
+	SWITCH_EVENT_CODEC				- Codec Change
+	SWITCH_EVENT_BACKGROUND_JOB		- Background Job
+	SWITCH_EVENT_DETECTED_SPEECH	- Detected Speech
+	SWITCH_EVENT_DETECTED_TONE      - Detected Tone
+	SWITCH_EVENT_PRIVATE_COMMAND	- A private command event 
+	SWITCH_EVENT_HEARTBEAT			- Machine is alive
+	SWITCH_EVENT_TRAP				- Error Trap
+	SWITCH_EVENT_ADD_SCHEDULE		- Something has been scheduled
+	SWITCH_EVENT_DEL_SCHEDULE		- Something has been unscheduled
+	SWITCH_EVENT_EXE_SCHEDULE		- Something scheduled has been executed
+	SWITCH_EVENT_RE_SCHEDULE		- Something scheduled has been rescheduled
+	SWITCH_EVENT_RELOADXML			- XML registry has been reloaded
+	SWITCH_EVENT_NOTIFY				- Notification
+	SWITCH_EVENT_PHONE_FEATURE			- Notification (DND/CFWD/etc)
+	SWITCH_EVENT_PHONE_FEATURE_SUBSCRIBE - Phone feature subscription
+	SWITCH_EVENT_SEND_MESSAGE		- Message
+	SWITCH_EVENT_RECV_MESSAGE		- Message
+	SWITCH_EVENT_NAT            - NAT Management (new/del/status)
+	SWITCH_EVENT_FAILURE            - A failure occurred which might impact the normal functioning of the switch
     SWITCH_EVENT_ALL				- All events at once
 </pre>
 
diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c
index 17a85a94c8..465455568b 100644
--- a/src/mod/endpoints/mod_sofia/sofia_presence.c
+++ b/src/mod/endpoints/mod_sofia/sofia_presence.c
@@ -1346,18 +1346,18 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
 										 "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc", 
 										 uuid, mod_sofia_globals.hostname, profile->name, euser, host, euser, host);
 				}
-
-				sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_dialog_callback, &dh);
-								
+				
 				if (mod_sofia_globals.debug_presence > 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHECK SQL: %s@%s [%s]\nhits: %d\n", euser, host, sql, dh.hits);
 				}
 
-				switch_safe_free(sql);
+				sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_presence_dialog_callback, &dh);
+				
 
+				switch_safe_free(sql);
+#if 0
 				if (hup && dh.hits > 0) {
 					/* sigh, mangle this packet to simulate a call that is up instead of hungup */
-					hup = 0;
 					event->flags |= EF_UNIQ_HEADERS;
 
 					if (!strcasecmp(dh.state, "early")) {
@@ -1386,7 +1386,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
 						switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "confirmed"); 
 					}
 				}
-
+#endif
 				
 
 				if (zstr(call_id) && (dh.hits && presence_source && (!strcasecmp(presence_source, "register") || switch_stristr("register", status)))) {
@@ -2553,8 +2553,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
 	char *open_closed = NULL;
 	char *dialog_status = NULL;
 	char *dialog_rpid = NULL;
-	//char *default_dialog = "partial";
-	char *default_dialog = "full";
+	char *default_dialog = "partial";
 	const char *ct = "no/idea";
 
 	char *to = NULL;
@@ -2732,9 +2731,9 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
 		}
 
 
-		//if (user_agent && switch_stristr("snom", user_agent) && uuid) {
-		//	default_dialog = "full" ;
-		//}
+		if (user_agent && switch_stristr("snom", user_agent) && uuid) {
+			default_dialog = "full" ;
+		}
 		
 		if (call_state && !strcasecmp(call_state, "cs_hangup")) {
 			astate = "hangup";
diff --git a/src/switch_event.c b/src/switch_event.c
index bdb9bad9a7..938bb2ff87 100644
--- a/src/switch_event.c
+++ b/src/switch_event.c
@@ -154,6 +154,8 @@ static char *EVENT_NAMES[] = {
 	"MESSAGE",
 	"PRESENCE_IN",
 	"NOTIFY_IN",
+	"PHONE_FEATURE",
+	"PHONE_FEATURE_SUBSCRIBE",
 	"PRESENCE_OUT",
 	"PRESENCE_PROBE",
 	"MESSAGE_WAITING",