aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Freeswitch
diff options
context:
space:
mode:
authorJonathan Freedman2010-11-21 20:01:48 -0800
committerJonathan Freedman2010-11-21 20:01:48 -0800
commitb7f5e8284360f92e0e102b9546076573c57d9397 (patch)
tree132663da8c1882e524241b55a739ef2758ef8958 /OpenSim/Server/Handlers/Freeswitch
parentMerge https://github.com/opensim/opensim into mantis5110 (diff)
parentMerge branch 'master' of /var/git/opensim/ (diff)
downloadopensim-SC_OLD-b7f5e8284360f92e0e102b9546076573c57d9397.zip
opensim-SC_OLD-b7f5e8284360f92e0e102b9546076573c57d9397.tar.gz
opensim-SC_OLD-b7f5e8284360f92e0e102b9546076573c57d9397.tar.bz2
opensim-SC_OLD-b7f5e8284360f92e0e102b9546076573c57d9397.tar.xz
Merge branch 'master-core' into mantis5110
Diffstat (limited to 'OpenSim/Server/Handlers/Freeswitch')
-rw-r--r--OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs65
-rw-r--r--OpenSim/Server/Handlers/Freeswitch/FreeswitchServerGetHandler.cs72
2 files changed, 64 insertions, 73 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}
diff --git a/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerGetHandler.cs b/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerGetHandler.cs
deleted file mode 100644
index 8b41742..0000000
--- a/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerGetHandler.cs
+++ /dev/null
@@ -1,72 +0,0 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.IO;
32using System.Reflection;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.Servers.HttpServer;
42
43namespace OpenSim.Server.Handlers.Freeswitch
44{
45 public class FreeswitchServerGetHandler : BaseStreamHandler
46 {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 //private IFreeswitchService m_FreeswitchService;
50
51 public FreeswitchServerGetHandler(IFreeswitchService service) :
52 base("GET", "/api")
53 {
54 //m_FreeswitchService = service;
55 }
56
57 public override byte[] Handle(string path, Stream request,
58 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
59 {
60 byte[] result = new byte[0];
61
62 string[] p = SplitParams(path);
63
64 if (p.Length == 0)
65 return result;
66
67 // Process web request
68
69 return result;
70 }
71 }
72}