clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections;
30 using System.Web;
31 using System.Reflection;
32 using Nini.Config;
33 using OpenSim.Server.Base;
34 using OpenSim.Services.Interfaces;
35 using OpenSim.Framework.Servers.HttpServer;
36 using OpenSim.Server.Handlers.Base;
37 using log4net;
38 using OpenMetaverse;
39 using OpenMetaverse.StructuredData;
40  
41 namespace OpenSim.Server.Handlers.Freeswitch
42 {
43 public class FreeswitchServerConnector : ServiceConnector
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46  
47 private IFreeswitchService m_FreeswitchService;
48 private string m_ConfigName = "FreeswitchService";
49 protected readonly string m_freeSwitchAPIPrefix = "/fsapi";
50  
51 public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) :
52 base(config, server, configName)
53 {
54 if (configName != String.Empty)
55 m_ConfigName = configName;
56  
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));
60  
61 string freeswitchService = serverConfig.GetString("LocalServiceModule",
62 String.Empty);
63  
64 if (freeswitchService == String.Empty)
65 throw new Exception("No LocalServiceModule in config file");
66  
67 Object[] args = new Object[] { config };
68 m_FreeswitchService =
69 ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args);
70  
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;
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  
127 }
128 }