29 using System.Collections;
31 using System.Reflection;
33 using OpenSim.Server.Base;
34 using OpenSim.Services.Interfaces;
35 using OpenSim.Framework.Servers.HttpServer;
36 using OpenSim.Server.Handlers.Base;
39 using OpenMetaverse.StructuredData;
41 namespace OpenSim.Server.Handlers.Freeswitch
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private string m_ConfigName =
"FreeswitchService";
49 protected readonly
string m_freeSwitchAPIPrefix =
"/fsapi";
52 base(config, server, configName)
54 if (configName != String.Empty)
55 m_ConfigName = configName;
57 IConfig serverConfig = config.Configs[m_ConfigName];
58 if (serverConfig == null)
59 throw new Exception(String.Format(
"No section '{0}' in config file", m_ConfigName));
61 string freeswitchService = serverConfig.GetString(
"LocalServiceModule",
64 if (freeswitchService == String.Empty)
65 throw new Exception(
"No LocalServiceModule in config file");
67 Object[] args =
new Object[] { config };
71 server.AddHTTPHandler(String.Format(
"{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);
72 server.AddHTTPHandler(String.Format(
"{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler);
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;
83 Hashtable requestBody = ParseRequestBody((
string) request[
"body"]);
85 string section = (string) requestBody[
"section"];
87 if (section ==
"directory")
88 response = m_FreeswitchService.HandleDirectoryRequest(requestBody);
89 else if (section ==
"dialplan")
90 response = m_FreeswitchService.HandleDialplanRequest(requestBody);
92 m_log.WarnFormat(
"[FreeSwitchVoice]: section was {0}", section);
97 private Hashtable ParseRequestBody(
string body)
99 Hashtable bodyParams =
new Hashtable();
101 string [] nvps = body.Split(
new Char [] {
'&'});
103 foreach (
string s
in nvps)
107 string [] nvp = s.Split(
new Char [] {
'='});
108 bodyParams.Add(HttpUtility.UrlDecode(nvp[0]), HttpUtility.UrlDecode(nvp[1]));
117 Hashtable response =
new Hashtable();
118 response[
"content_type"] =
"text/json";
119 response[
"keepalive"] =
false;
120 response[
"int_response_code"] = 200;
122 response[
"str_response_string"] = m_FreeswitchService.GetJsonConfig();
FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName)
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
Hashtable RegionConfigHTTPHandler(Hashtable request)
Interactive OpenSim region server
Hashtable FreeSwitchConfigHTTPHandler(Hashtable request)