aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs')
-rw-r--r--OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs65
1 files changed, 64 insertions, 1 deletions
diff --git a/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs b/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs
index 07bafc8..da56b87 100644
--- a/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs
+++ b/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs
@@ -26,18 +26,27 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
30using System.Web;
31using System.Reflection;
29using Nini.Config; 32using Nini.Config;
30using OpenSim.Server.Base; 33using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 34using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer; 35using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 36using OpenSim.Server.Handlers.Base;
37using log4net;
38using OpenMetaverse;
39using OpenMetaverse.StructuredData;
34 40
35namespace OpenSim.Server.Handlers.Freeswitch 41namespace OpenSim.Server.Handlers.Freeswitch
36{ 42{
37 public class FreeswitchServerConnector : ServiceConnector 43 public class FreeswitchServerConnector : ServiceConnector
38 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
39 private IFreeswitchService m_FreeswitchService; 47 private IFreeswitchService m_FreeswitchService;
40 private string m_ConfigName = "FreeswitchService"; 48 private string m_ConfigName = "FreeswitchService";
49 protected readonly string m_freeSwitchAPIPrefix = "/fsapi";
41 50
42 public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) : 51 public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName) 52 base(config, server, configName)
@@ -59,7 +68,61 @@ namespace OpenSim.Server.Handlers.Freeswitch
59 m_FreeswitchService = 68 m_FreeswitchService =
60 ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args); 69 ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args);
61 70
62 server.AddStreamHandler(new FreeswitchServerGetHandler(m_FreeswitchService)); 71 server.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);
72 server.AddHTTPHandler(String.Format("{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler);
73 }
74
75 public Hashtable FreeSwitchConfigHTTPHandler(Hashtable request)
76 {
77 Hashtable response = new Hashtable();
78 response["str_response_string"] = string.Empty;
79 response["content_type"] = "text/plain";
80 response["keepalive"] = false;
81 response["int_response_code"] = 500;
82
83 Hashtable requestBody = ParseRequestBody((string) request["body"]);
84
85 string section = (string) requestBody["section"];
86
87 if (section == "directory")
88 response = m_FreeswitchService.HandleDirectoryRequest(requestBody);
89 else if (section == "dialplan")
90 response = m_FreeswitchService.HandleDialplanRequest(requestBody);
91 else
92 m_log.WarnFormat("[FreeSwitchVoice]: section was {0}", section);
93
94 return response;
63 } 95 }
96
97 private Hashtable ParseRequestBody(string body)
98 {
99 Hashtable bodyParams = new Hashtable();
100 // split string
101 string [] nvps = body.Split(new Char [] {'&'});
102
103 foreach (string s in nvps)
104 {
105 if (s.Trim() != "")
106 {
107 string [] nvp = s.Split(new Char [] {'='});
108 bodyParams.Add(HttpUtility.UrlDecode(nvp[0]), HttpUtility.UrlDecode(nvp[1]));
109 }
110 }
111
112 return bodyParams;
113 }
114
115 public Hashtable RegionConfigHTTPHandler(Hashtable request)
116 {
117 Hashtable response = new Hashtable();
118 response["content_type"] = "text/json";
119 response["keepalive"] = false;
120 response["int_response_code"] = 200;
121
122 response["str_response_string"] = m_FreeswitchService.GetJsonConfig();
123
124 return response;
125 }
126
64 } 127 }
65} 128}