From 8beb10d25b5ff0fd69fd6053462bcfe1f80e8bfb Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Thu, 23 Jun 2011 14:57:46 -0500
Subject: [PATCH] FS-3367 --resolve the start was actually broken in the same
 way, instead of your exact patch I replaced both original functions to work
 as your patch suggests

---
 .../applications/mod_spandsp/mod_spandsp.c    | 33 ++++++++++++++-----
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c
index fd2ac7f947..644f17f1ac 100644
--- a/src/mod/applications/mod_spandsp/mod_spandsp.c
+++ b/src/mod/applications/mod_spandsp/mod_spandsp.c
@@ -183,23 +183,28 @@ SWITCH_STANDARD_APP(start_tone_detect_app)
 SWITCH_STANDARD_API(start_tone_detect_api)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	 switch_core_session_t *psession = NULL;
 
 	if (zstr(cmd)) {
 		stream->write_function(stream, "-ERR missing descriptor name\n");
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (!session) {
-		stream->write_function(stream, "-ERR no session\n");
-		return SWITCH_STATUS_SUCCESS;
-	}
+    if (!(psession = switch_core_session_locate(cmd))) {
+        stream->write_function(stream, "-ERR Cannot locate session\n");
+        return SWITCH_STATUS_SUCCESS;
+    }
+
+
+	status = callprogress_detector_start(psession, cmd);
 
-	status = callprogress_detector_start(session, cmd);
 	if (status == SWITCH_STATUS_SUCCESS) {
 		stream->write_function(stream, "+OK started\n");
 	} else {
 		stream->write_function(stream, "-ERR failed to start tone detector\n");
 	}
+    
+    switch_core_session_rwunlock(psession);
 
 	return status;
 }
@@ -227,12 +232,22 @@ SWITCH_STANDARD_APP(stop_tone_detect_app)
 SWITCH_STANDARD_API(stop_tone_detect_api)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	if (!session) {
-		stream->write_function(stream, "-ERR no session\n");
+	 switch_core_session_t *psession = NULL;
+
+	if (zstr(cmd)) {
+		stream->write_function(stream, "-ERR missing descriptor name\n");
 		return SWITCH_STATUS_SUCCESS;
 	}
-	callprogress_detector_stop(session);
-	stream->write_function(stream, "+OK stopped\n");
+
+    if (!(psession = switch_core_session_locate(cmd))) {
+        stream->write_function(stream, "-ERR Cannot locate session\n");
+        return SWITCH_STATUS_SUCCESS;
+    }
+
+    callprogress_detector_stop(psession);
+    stream->write_function(stream, "+OK stopped\n");
+    switch_core_session_rwunlock(psession);
+    
 	return status;
 }