From 7fc9358ec36b40c8226a0d76fd9cb5ae70151b5e Mon Sep 17 00:00:00 2001
From: Melanie
Date: Sat, 8 Aug 2009 03:29:00 +0100
Subject: Patch from otakup0pe: A better solution for making the FreeSwitch
module cooperate with existing installations
---
.../Voice/FreeSwitchVoice/FreeSwitchDialplan.cs | 29 ++++++++-----
.../Voice/FreeSwitchVoice/FreeSwitchDirectory.cs | 48 ++++++++++++----------
.../Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs | 8 ++--
3 files changed, 51 insertions(+), 34 deletions(-)
(limited to 'OpenSim/Region/OptionalModules/Avatar')
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDialplan.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDialplan.cs
index c05d598..b1f93e9 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDialplan.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDialplan.cs
@@ -26,7 +26,9 @@
*/
using log4net;
+using System;
using System.Reflection;
+using System.Text;
using System.Collections;
namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
@@ -37,7 +39,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public Hashtable HandleDialplanRequest(Hashtable request)
+ public Hashtable HandleDialplanRequest(string Context, string Realm, Hashtable request)
{
m_log.DebugFormat("[FreeSwitchVoice] HandleDialplanRequest called with {0}",request.ToString());
@@ -48,33 +50,39 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}",item.Key, item.Value);
}
+ string requestcontext = (string) request["Hunt-Context"];
response["content_type"] = "text/xml";
response["keepalive"] = false;
- response["int_response_code"] = 200;
- response["str_response_string"] = @"
+ response["int_response_code"] = 200;
+ if ( Context != String.Empty && Context != requestcontext)
+ {
+ m_log.Debug("[FreeSwitchDirectory] returning empty as it's for another context");
+ response["str_response_string"] = "";
+ } else {
+ response["str_response_string"] = String.Format(@"
-
+ " +
-
+/*
-
+ */
-
+ @"
-
+
-
+
@@ -86,7 +94,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
- ";
+ ", Context, Realm);
+ }
return response;
}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
index 0a9f69d..8afaeea 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
@@ -38,12 +38,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public Hashtable HandleDirectoryRequest(Hashtable request)
+ public Hashtable HandleDirectoryRequest(string Context, string Realm, Hashtable request)
{
+ Hashtable response = new Hashtable();
+ string domain = (string) request["domain"];
+ if ( domain != Realm) {
+ response["content_type"] = "text/xml";
+ response["keepalive"] = false;
+ response["int_response_code"] = 200;
+ response["str_response_string"] = "";
+ } else {
m_log.DebugFormat("[FreeSwitchDirectory] HandleDirectoryRequest called with {0}",request.ToString());
- Hashtable response = new Hashtable();
-
// information in the request we might be interested in
// Request 1 sip_auth for users account
@@ -85,11 +91,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
if (sipAuthMethod == "REGISTER")
{
- response = HandleRegister(request);
+ response = HandleRegister(Context, Realm, request);
}
else if (sipAuthMethod == "INVITE")
{
- response = HandleInvite(request);
+ response = HandleInvite(Context, Realm, request);
}
else
{
@@ -101,19 +107,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
}
else if (eventCallingFunction == "switch_xml_locate_user")
{
- response = HandleLocateUser(request);
+ response = HandleLocateUser(Realm, request);
}
else if (eventCallingFunction == "user_data_function") // gets called when an avatar to avatar call is made
{
- response = HandleLocateUser(request);
+ response = HandleLocateUser(Realm, request);
}
else if (eventCallingFunction == "user_outgoing_channel")
{
- response = HandleRegister(request);
+ response = HandleRegister(Context, Realm, request);
}
else if (eventCallingFunction == "config_sofia") // happens once on freeswitch startup
{
- response = HandleConfigSofia(request);
+ response = HandleConfigSofia(Context, Realm, request);
}
else if (eventCallingFunction == "switch_load_network_lists")
{
@@ -131,10 +137,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
response["content_type"] = "text/xml";
response["str_response_string"] = "";
}
+ }
return response;
}
- private Hashtable HandleRegister(Hashtable request)
+ private Hashtable HandleRegister(string Context, string Realm, Hashtable request)
{
m_log.Info("[FreeSwitchDirectory] HandleRegister called");
@@ -159,19 +166,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"\r\n" +
"\r\n" +
"\r\n" +
- "\r\n" +
+ "\r\n" +
""+
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n",
- domain , user, password);
+ domain , user, password, Context);
return response;
}
- private Hashtable HandleInvite(Hashtable request)
+ private Hashtable HandleInvite(string Context, string Realm, Hashtable request)
{
m_log.Info("[FreeSwitchDirectory] HandleInvite called");
@@ -196,7 +203,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"\r\n" +
"\r\n" +
"\r\n" +
- "\r\n" +
+ "\r\n" +
""+
"\r\n" +
"\r\n" +
@@ -206,20 +213,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"\r\n" +
"\r\n" +
"\r\n" +
- "\r\n" +
+ "\r\n" +
""+
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n",
- domain , user, password,sipRequestUser);
+ domain , user, password,sipRequestUser, Context);
return response;
}
-
- private Hashtable HandleLocateUser(Hashtable request)
+ private Hashtable HandleLocateUser(String Realm, Hashtable request)
{
m_log.Info("[FreeSwitchDirectory] HandleLocateUser called");
@@ -253,7 +259,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
return response;
}
- private Hashtable HandleConfigSofia(Hashtable request)
+ private Hashtable HandleConfigSofia(string Context, string Realm, Hashtable request)
{
m_log.Info("[FreeSwitchDirectory] HandleConfigSofia called");
@@ -286,7 +292,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"\r\n"+
"\r\n"+
"\r\n"+
- "\r\n"+
+ "\r\n"+
"\r\n"+
"\r\n"+
"\r\n"+
@@ -301,7 +307,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"\r\n" +
"\r\n" +
"\r\n",
- domain);
+ domain, Context);
return response;
}
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
index f9cb1c4..faa0157 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
@@ -95,6 +95,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
// private static IPEndPoint m_FreeSwitchServiceIP;
private int m_freeSwitchServicePort;
private string m_openSimWellKnownHTTPAddress;
+ private string m_freeSwitchContext;
private FreeSwitchDirectory m_FreeSwitchDirectory;
private FreeSwitchDialplan m_FreeSwitchDialplan;
@@ -151,6 +152,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
m_freeSwitchDefaultTimeout = m_config.GetInt("freeswitch_default_timeout", 5000);
// m_freeSwitchSubscribeRetry = m_config.GetInt("freeswitch_subscribe_retry", 120);
m_freeSwitchUrlResetPassword = m_config.GetString("freeswitch_password_reset_url", String.Empty);
+ m_freeSwitchContext = m_config.GetString("freeswitch_context", "default");
if (String.IsNullOrEmpty(m_freeSwitchServerUser) ||
String.IsNullOrEmpty(m_freeSwitchServerPass) ||
@@ -572,7 +574,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
"false\r\n"+
"",
m_freeSwitchRealm, m_freeSwitchSIPProxy, m_freeSwitchAttemptUseSTUN,
- m_freeSwitchSTUNServer, m_freeSwitchEchoServer, m_freeSwitchEchoPort,
+ m_freeSwitchEchoServer, m_freeSwitchEchoPort,
m_freeSwitchDefaultWellKnownIP, m_freeSwitchDefaultTimeout,
m_freeSwitchUrlResetPassword, "");
@@ -728,9 +730,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
string section = (string) requestBody["section"];
if (section == "directory")
- response = m_FreeSwitchDirectory.HandleDirectoryRequest(requestBody);
+ response = m_FreeSwitchDirectory.HandleDirectoryRequest(m_freeSwitchContext, m_freeSwitchRealm, requestBody);
else if (section == "dialplan")
- response = m_FreeSwitchDialplan.HandleDialplanRequest(requestBody);
+ response = m_FreeSwitchDialplan.HandleDialplanRequest(m_freeSwitchContext, m_freeSwitchRealm, requestBody);
else
m_log.WarnFormat("[FreeSwitchVoice]: section was {0}", section);
--
cgit v1.1