From 2fa210243b64bb10fbca37f89176f10efeb25f41 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 19 Apr 2011 21:54:26 +0100
Subject: Clean up freeswitch config to what is currently required.  Add
 explanation to config parameters.  Clean up some log messages.

---
 .../Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs | 28 ++++++++-------
 .../FreeswitchService/FreeswitchService.cs         | 29 ++++++++-------
 .../FreeswitchService/FreeswitchServiceBase.cs     |  2 +-
 bin/OpenSim.ini.example                            | 42 +++++++++++++++-------
 bin/Robust.ini.example                             | 38 ++++++++++++++------
 bin/config-include/StandaloneCommon.ini.example    | 18 +++-------
 6 files changed, 95 insertions(+), 62 deletions(-)

diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
index 7909d8a..962b5ca 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs
@@ -118,7 +118,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
 
                 if (serviceDll == String.Empty)
                 {
-                    m_log.Error("[FreeSwitchVoice]: No LocalServiceModule named in section FreeSwitchVoice");
+                    m_log.Error("[FreeSwitchVoice]: No LocalServiceModule named in section FreeSwitchVoice.  Not starting.");
                     return;
                 }
 
@@ -143,8 +143,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
                 if (String.IsNullOrEmpty(m_freeSwitchRealm) ||
                     String.IsNullOrEmpty(m_freeSwitchAPIPrefix))
                 {
-                    m_log.Error("[FreeSwitchVoice] plugin mis-configured");
-                    m_log.Info("[FreeSwitchVoice] plugin disabled: incomplete configuration");
+                    m_log.Error("[FreeSwitchVoice]: Freeswitch service mis-configured.  Not starting.");                    
                     return;
                 }
 
@@ -172,16 +171,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
                 MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                  FreeSwitchSLVoiceBuddyHTTPHandler);
 
-                m_log.InfoFormat("[FreeSwitchVoice] using FreeSwitch server {0}", m_freeSwitchRealm);
+                m_log.InfoFormat("[FreeSwitchVoice]: using FreeSwitch server {0}", m_freeSwitchRealm);
 
                 m_Enabled = true;
 
-                m_log.Info("[FreeSwitchVoice] plugin enabled");
+                m_log.Info("[FreeSwitchVoice]: plugin enabled");
             }
             catch (Exception e)
             {
-                m_log.ErrorFormat("[FreeSwitchVoice] plugin initialization failed: {0}", e.Message);
-                m_log.DebugFormat("[FreeSwitchVoice] plugin initialization failed: {0}", e.ToString());
+                m_log.ErrorFormat("[FreeSwitchVoice]: plugin initialization failed: {0} {1}", e.Message, e.StackTrace);
                 return;
             }
 
@@ -240,7 +238,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
         {
             if (m_Enabled)
             {
-                m_log.Info("[FreeSwitchVoice] registering IVoiceModule with the scene");
+                m_log.Info("[FreeSwitchVoice]: registering IVoiceModule with the scene");
 
                 // register the voice interface for this module, so the script engine can call us
                 scene.RegisterModuleInterface<IVoiceModule>(this);
@@ -302,7 +300,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
         // </summary>
         public void OnRegisterCaps(Scene scene, UUID agentID, Caps caps)
         {
-            m_log.DebugFormat("[FreeSwitchVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
+            m_log.DebugFormat(
+                "[FreeSwitchVoice]: OnRegisterCaps called with agentID {0} caps {1} in scene {2}", 
+                agentID, caps, scene.RegionInfo.RegionName);
 
             string capsBase = "/CAPS/" + caps.CapsObjectPath;
             caps.RegisterHandler("ProvisionVoiceAccountRequest",
@@ -558,7 +558,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
 
         public Hashtable FreeSwitchSLVoiceGetPreloginHTTPHandler(Hashtable request)
         {
-            m_log.Debug("[FreeSwitchVoice] FreeSwitchSLVoiceGetPreloginHTTPHandler called");
+            m_log.Debug("[FreeSwitchVoice]: FreeSwitchSLVoiceGetPreloginHTTPHandler called");
 
             Hashtable response = new Hashtable();
             response["content_type"] = "text/xml";
@@ -664,7 +664,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
 
         public Hashtable FreeSwitchSLVoiceSigninHTTPHandler(Hashtable request)
         {
-            m_log.Debug("[FreeSwitchVoice] FreeSwitchSLVoiceSigninHTTPHandler called");
+            m_log.Debug("[FreeSwitchVoice]: FreeSwitchSLVoiceSigninHTTPHandler called");
 //            string requestbody = (string)request["body"];
 //            string uri = (string)request["uri"];
 //            string contenttype = (string)request["content-type"];
@@ -795,16 +795,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice
             response["keepalive"] = false;
             response["int_response_code"] = 500;
 
-            Hashtable requestBody = ParseRequestBody((string) request["body"]);
+            Hashtable requestBody = ParseRequestBody((string)request["body"]);                                   
 
             string section = (string) requestBody["section"];
+            
+            m_log.DebugFormat("[FreeSwitchVoice]: Received request for config section {0}", section);            
 
             if (section == "directory")
                 response = m_FreeswitchService.HandleDirectoryRequest(requestBody);
             else if (section == "dialplan")
                 response = m_FreeswitchService.HandleDialplanRequest(requestBody);
             else
-                m_log.WarnFormat("[FreeSwitchVoice]: section was {0}", section);
+                m_log.WarnFormat("[FreeSwitchVoice]: Unknown section {0} was requested.", section);
 
             return response;
         }
diff --git a/OpenSim/Services/FreeswitchService/FreeswitchService.cs b/OpenSim/Services/FreeswitchService/FreeswitchService.cs
index fe6f5cd..1ec89da 100644
--- a/OpenSim/Services/FreeswitchService/FreeswitchService.cs
+++ b/OpenSim/Services/FreeswitchService/FreeswitchService.cs
@@ -50,13 +50,13 @@ namespace OpenSim.Services.FreeswitchService
 
         public Hashtable HandleDialplanRequest(Hashtable request)
         {
-            m_log.DebugFormat("[FreeSwitchVoice] HandleDialplanRequest called with {0}",request.ToString());
+            m_log.DebugFormat("[FreeSwitchVoice]: HandleDialplanRequest called with {0}",request.ToString());
 
             Hashtable response = new Hashtable();
 
             foreach (DictionaryEntry item in request)
             {
-               m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}",item.Key, item.Value);
+               m_log.InfoFormat("[FreeSwitchDirectory]: requestBody item {0} {1}",item.Key, item.Value);
             }
 
             string requestcontext = (string) request["Hunt-Context"];
@@ -66,7 +66,7 @@ namespace OpenSim.Services.FreeswitchService
 
             if (m_freeSwitchContext != String.Empty && m_freeSwitchContext != requestcontext)
             {
-                m_log.Debug("[FreeSwitchDirectory] returning empty as it's for another context");
+                m_log.Debug("[FreeSwitchDirectory]: returning empty as it's for another context");
                 response["str_response_string"] = "";
             }
             else
@@ -116,13 +116,16 @@ namespace OpenSim.Services.FreeswitchService
         {
             Hashtable response = new Hashtable();
             string domain = (string) request["domain"];
-            if (domain != m_freeSwitchRealm) {
+            if (domain != m_freeSwitchRealm) 
+            {
                 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());
+            } 
+            else 
+            {
+//                 m_log.DebugFormat("[FreeSwitchDirectory]: HandleDirectoryRequest called with {0}",request.ToString());
             
                  // information in the request we might be interested in
              
@@ -145,7 +148,7 @@ namespace OpenSim.Services.FreeswitchService
              
                  foreach (DictionaryEntry item in request)
                  {
-                    m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}", item.Key, item.Value);
+                    m_log.DebugFormat("[FreeSwitchDirectory]: requestBody item {0} {1}", item.Key, item.Value);
                  }
              
                  string eventCallingFunction = (string) request["Event-Calling-Function"];
@@ -173,7 +176,7 @@ namespace OpenSim.Services.FreeswitchService
                      }
                      else
                      {
-                         m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod);
+                         m_log.ErrorFormat("[FreeSwitchVoice]: HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod);
                          response["int_response_code"] = 404;
                          response["content_type"] = "text/xml";
                          response["str_response_string"] = "";
@@ -205,7 +208,7 @@ namespace OpenSim.Services.FreeswitchService
                  }
                  else
                  {
-                     m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction);
+                     m_log.ErrorFormat("[FreeSwitchVoice]: HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction);
                      response["int_response_code"] = 404;
                      response["keepalive"] = false;
                      response["content_type"] = "text/xml";
@@ -217,7 +220,7 @@ namespace OpenSim.Services.FreeswitchService
         
         private Hashtable HandleRegister(string Context, string Realm, Hashtable request)
         {
-            m_log.Info("[FreeSwitchDirectory] HandleRegister called");
+            m_log.Info("[FreeSwitchDirectory]: HandleRegister called");
             
             // TODO the password we return needs to match that sent in the request, this is hard coded for now
             string password = "1234";
@@ -254,7 +257,7 @@ namespace OpenSim.Services.FreeswitchService
         
         private Hashtable HandleInvite(string Context, string Realm, Hashtable request)
         {
-            m_log.Info("[FreeSwitchDirectory] HandleInvite called");
+            m_log.Info("[FreeSwitchDirectory]: HandleInvite called");
             
             // TODO the password we return needs to match that sent in the request, this is hard coded for now
             string password = "1234";
@@ -301,7 +304,7 @@ namespace OpenSim.Services.FreeswitchService
 
         private Hashtable HandleLocateUser(String Realm, Hashtable request)
         {
-            m_log.Info("[FreeSwitchDirectory] HandleLocateUser called");
+            m_log.Info("[FreeSwitchDirectory]: HandleLocateUser called");
             
             // TODO the password we return needs to match that sent in the request, this is hard coded for now
             string domain = (string) request["domain"];
@@ -335,7 +338,7 @@ namespace OpenSim.Services.FreeswitchService
        
         private Hashtable HandleConfigSofia(string Context, string Realm, Hashtable request)
         {
-            m_log.Info("[FreeSwitchDirectory] HandleConfigSofia called");
+            m_log.Info("[FreeSwitchDirectory]: HandleConfigSofia called.");
             
             // TODO the password we return needs to match that sent in the request, this is hard coded for now
             string domain = (string) request["domain"];
diff --git a/OpenSim/Services/FreeswitchService/FreeswitchServiceBase.cs b/OpenSim/Services/FreeswitchService/FreeswitchServiceBase.cs
index ebbb1b0..25c18b6 100644
--- a/OpenSim/Services/FreeswitchService/FreeswitchServiceBase.cs
+++ b/OpenSim/Services/FreeswitchService/FreeswitchServiceBase.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Services.FreeswitchService
                 m_freeSwitchDefaultWellKnownIP = freeswitchConfig.GetString("ServerAddress", String.Empty);
                 if (m_freeSwitchDefaultWellKnownIP == String.Empty)
                 {
-                    m_log.Error("[FREESWITCH]: No FreeswitchServerAddress given, can't continue");
+                    m_log.Error("[FREESWITCH]: No ServerAddress given, cannot start service.");
                     return;
                 }
 
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index c05c3de..fbaa590 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -621,10 +621,11 @@
 
     ;; You need to load a local service for a standalone, and a remote service
     ;; for a grid region. Use one of the lines below, as appropriate
+    ;; If you're using Freeswitch on a standalone then you will also need to configure the [FreeswitchService] section
     ; LocalServiceModule = OpenSim.Services.FreeswitchService.dll:FreeswitchService
     ; LocalServiceModule = OpenSim.Services.Connectors.dll:RemoteFreeswitchConnector
 
-    ;; If using a remote module, specify the server URL
+    ;; If using a remote connector, specify the server URL
     ; FreeswitchServiceURL = http://my.grid.server:8003/fsapi
 
 
@@ -632,20 +633,37 @@
     ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!
     ;; !!!!!!STANDALONE ONLY!!!!!!
     ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!
-    ;; IP of your FS server
-    ;ServerAddress = 85.25.142.92
+    ;; The IP address of your FreeSWITCH server.  The common case is for this to be the same as the server running the OpenSim standalone
+    ;; This has to be set for the FreeSWITCH service to work
+    ;ServerAddress = 127.0.0.1
 
-    ;; All other options are - well - optional
-    ; Realm = "127.0.0.1"
-    ; SIPProxy = "127.0.0.1:5060"
-    ; EchoServer = "127.0.0.1"
-    ; EchoPort = 50505
-    ; AttemptSTUN = "false"
+    ;; The following configuration parameters are optional
+
+    ;; By default, this is the same as the ServerAddress
+    ; Realm = 127.0.0.1
+
+    ;; By default, this is the same as the ServerAddress on port 5060
+    ; SIPProxy = 127.0.0.1:5060
+
+    ;; Default is 5000ms
     ; DefaultTimeout = 5000
-    ; Context = "default"
-    ; UserName = "freeswitch"
-    ; Password = "password"
 
+    ;; The dial plan context.  Default is "default"
+    ; Context = default
+
+    ;; Currently unused
+    ; UserName = freeswitch
+
+    ;; Currently unused
+    ; Password = password
+
+    ;; The following parameters are for STUN = Simple Traversal of UDP through NATs
+    ;; See http://wiki.freeswitch.org/wiki/NAT_Traversal
+    ;; stun.freeswitch.org is not guaranteed to be running so use it in
+    ;; production at your own risk    
+    ; EchoServer = 127.0.0.1
+    ; EchoPort = 50505
+    ; AttemptSTUN = false
 
 [Groups]
     ;# {Enabled} {} {Enable groups?} {true false} false
diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example
index 7c13076..4d16236 100644
--- a/bin/Robust.ini.example
+++ b/bin/Robust.ini.example
@@ -69,19 +69,37 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
 ; * This is the configuration for the freeswitch server in grid mode
 [FreeswitchService]
     LocalServiceModule = "OpenSim.Services.FreeswitchService.dll:FreeswitchService"
-    ;; IP of your FS server
+
+    ;; The IP address of your FreeSWITCH server.
     ; ServerAddress = 127.0.0.1
 
-    ;; All other options are - well - optional
-    ; Realm = "127.0.0.1"
-    ; SIPProxy = "127.0.0.1:5060"
-    ; EchoServer = "127.0.0.1"
-    ; EchoPort = 50505
-    ; AttemptSTUN = "false"
+    ;; The following configuration parameters are optional
+
+    ;; By default, this is the same as the ServerAddress
+    ; Realm = 127.0.0.1
+
+    ;; By default, this is the same as the ServerAddress on port 5060
+    ; SIPProxy = 127.0.0.1:5060
+
+    ;; Default is 5000ms
     ; DefaultTimeout = 5000
-    ; Context = "default"
-    ; UserName = "freeswitch"
-    ; Password = "password"
+
+    ;; The dial plan context.  Default is "default"
+    ; Context = default
+
+    ;; Currently unused
+    ; UserName = freeswitch
+
+    ;; Currently unused
+    ; Password = password
+
+    ;; The following parameters are for STUN = Simple Traversal of UDP through NATs
+    ;; See http://wiki.freeswitch.org/wiki/NAT_Traversal
+    ;; stun.freeswitch.org is not guaranteed to be running so use it in
+    ;; production at your own risk    
+    ; EchoServer = 127.0.0.1
+    ; EchoPort = 50505
+    ; AttemptSTUN = false
 
 ; * This is the new style authentication service. Currently, only MySQL
 ; * is implemented. 
diff --git a/bin/config-include/StandaloneCommon.ini.example b/bin/config-include/StandaloneCommon.ini.example
index d6f15bb..dcebd63 100644
--- a/bin/config-include/StandaloneCommon.ini.example
+++ b/bin/config-include/StandaloneCommon.ini.example
@@ -28,10 +28,10 @@
 
 [HGInventoryAccessModule]
     ProfileServerURI = "http://127.0.0.1:9000/profiles"
-	;; If you want to protect your assets from being copied by foreign visitors
-	;; uncomment the next line. You may want to do this on sims that have licensed content.
-	; OutboundPermission = False
 
+    ;; If you want to protect your assets from being copied by foreign visitors
+    ;; uncomment the next line. You may want to do this on sims that have licensed content.
+    ; OutboundPermission = False
 
 [Modules]
     ;; Choose 0 or 1 cache modules, and the corresponding config file, if it exists.
@@ -45,16 +45,9 @@
     AssetCaching = "CenomeMemoryAssetCache"
     Include-CenomeCache = "config-include/CenomeCache.ini"
 
-    ;; Enable this to use Freeswitch on a standalone
-    ;FreeswitchServiceInConnector = True
-
     ;; Authorization is not on by default, as it depends on external php
     ;AuthorizationServices = "LocalAuthorizationServicesConnector"
 
-[FreeswitchService]
-    ;; Configuration for the freeswitch service goes here
-    LocalServiceModule = "OpenSim.Services.FreeswitchService.dll:FreeswitchService"
-
 [GridService]
     ;; For in-memory region storage (default)
     StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"
@@ -74,9 +67,8 @@
     Region_Welcome_Area = "DefaultRegion, FallbackRegion"
 
     ; === HG ONLY ===
-	;; change this to the address of your simulator
-	Gatekeeper="http://127.0.0.1:9000"
-
+    ;; change this to the address of your simulator
+    Gatekeeper="http://127.0.0.1:9000"
 
 [LibraryModule]
     ; Set this if you want to change the name of the OpenSim Library
-- 
cgit v1.1