aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers
diff options
context:
space:
mode:
authorDiva Canto2009-09-21 11:05:01 -0700
committerDiva Canto2009-09-21 11:05:01 -0700
commit390137d540b9ae39eba3ba9136bd49d5e992bc5f (patch)
tree2a42679f2da4acff8943ed414a75a7ea0bd13ecb /OpenSim/Server/Handlers
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.zip
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.gz
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.bz2
opensim-SC-390137d540b9ae39eba3ba9136bd49d5e992bc5f.tar.xz
Added grid handler and grid remote connector.
Diffstat (limited to 'OpenSim/Server/Handlers')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerConnector.cs60
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs269
2 files changed, 329 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
new file mode 100644
index 0000000..b80c479
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
@@ -0,0 +1,60 @@
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 System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Grid
36{
37 public class GridServiceConnector : ServiceConnector
38 {
39 private IGridService m_GridService;
40
41 public GridServiceConnector(IConfigSource config, IHttpServer server) :
42 base(config, server)
43 {
44 IConfig serverConfig = config.Configs["GridService"];
45 if (serverConfig == null)
46 throw new Exception("No section 'Server' in config file");
47
48 string gridService = serverConfig.GetString("GridServiceModule",
49 String.Empty);
50
51 if (gridService == String.Empty)
52 throw new Exception("No AuthenticationService in config file");
53
54 Object[] args = new Object[] { config };
55 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
56
57 server.AddStreamHandler(new GridServerPostHandler(m_GridService));
58 }
59 }
60}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
new file mode 100644
index 0000000..39c0584
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -0,0 +1,269 @@
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.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Grid
46{
47 public class GridServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridService m_GridService;
52
53 public GridServerPostHandler(IGridService service) :
54 base("POST", "/grid")
55 {
56 m_GridService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65
66 Dictionary<string, string> request =
67 ServerUtils.ParseQueryString(body);
68
69 if (!request.ContainsKey("METHOD"))
70 return FailureResult();
71
72 string method = request["METHOD"];
73
74 switch (method)
75 {
76 case "register":
77 return Register(request);
78
79 case "deregister":
80 return Deregister(request);
81
82 case "get_neighbours":
83 return GetNeighbours(request);
84
85 case "get_region_by_uuid":
86 return GetRegionByUUID(request);
87
88 case "get_region_by_position":
89 return GetRegionByPosition(request);
90
91 case "get_region_by_name":
92 return GetRegionByName(request);
93
94 case "get_regions_by_name":
95 return GetRegionsByName(request);
96
97 case "get_region_range":
98 return GetRegionRange(request);
99
100 default:
101 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
102 return FailureResult();
103 }
104
105 }
106
107 #region Method-specific handlers
108
109 byte[] Register(Dictionary<string, string> request)
110 {
111 UUID scopeID = UUID.Zero;
112 if (request["SCOPEID"] != null)
113 UUID.TryParse(request["SCOPEID"], out scopeID);
114 else
115 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
116
117 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
118 foreach (KeyValuePair<string, string> kvp in request)
119 rinfoData[kvp.Key] = kvp.Value;
120 SimpleRegionInfo rinfo = new SimpleRegionInfo(rinfoData);
121
122 bool result = m_GridService.RegisterRegion(scopeID, rinfo);
123
124 if (result)
125 return SuccessResult();
126 else
127 return FailureResult();
128 }
129
130 byte[] Deregister(Dictionary<string, string> request)
131 {
132 UUID regionID = UUID.Zero;
133 if (request["REGIONID"] != null)
134 UUID.TryParse(request["REGIONID"], out regionID);
135 else
136 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
137
138 bool result = m_GridService.DeregisterRegion(regionID);
139
140 if (result)
141 return SuccessResult();
142 else
143 return FailureResult();
144
145 }
146
147 byte[] GetNeighbours(Dictionary<string, string> request)
148 {
149 UUID scopeID = UUID.Zero;
150 if (request["SCOPEID"] != null)
151 UUID.TryParse(request["SCOPEID"], out scopeID);
152 else
153 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
154
155 UUID regionID = UUID.Zero;
156 if (request["REGIONID"] != null)
157 UUID.TryParse(request["REGIONID"], out scopeID);
158 else
159 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
160
161 List<SimpleRegionInfo> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
162
163 Dictionary<string, object> result = new Dictionary<string, object>();
164 int i = 0;
165 foreach (SimpleRegionInfo rinfo in rinfos)
166 {
167 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
168 result["region" + i] = rinfoDict;
169 i++;
170 }
171
172 string xmlString = ServerUtils.BuildXmlResponse(result);
173 UTF8Encoding encoding = new UTF8Encoding();
174 return encoding.GetBytes(xmlString);
175
176 }
177
178 byte[] GetRegionByUUID(Dictionary<string, string> request)
179 {
180 // TODO
181 return new byte[0];
182 }
183
184 byte[] GetRegionByPosition(Dictionary<string, string> request)
185 {
186 // TODO
187 return new byte[0];
188 }
189
190 byte[] GetRegionByName(Dictionary<string, string> request)
191 {
192 // TODO
193 return new byte[0];
194 }
195
196 byte[] GetRegionsByName(Dictionary<string, string> request)
197 {
198 // TODO
199 return new byte[0];
200 }
201
202 byte[] GetRegionRange(Dictionary<string, string> request)
203 {
204 // TODO
205 return new byte[0];
206 }
207
208 #endregion
209
210 #region Misc
211
212 private byte[] SuccessResult()
213 {
214 XmlDocument doc = new XmlDocument();
215
216 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
217 "", "");
218
219 doc.AppendChild(xmlnode);
220
221 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
222 "");
223
224 doc.AppendChild(rootElement);
225
226 XmlElement result = doc.CreateElement("", "Result", "");
227 result.AppendChild(doc.CreateTextNode("Success"));
228
229 rootElement.AppendChild(result);
230
231 return DocToBytes(doc);
232 }
233
234 private byte[] FailureResult()
235 {
236 XmlDocument doc = new XmlDocument();
237
238 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
239 "", "");
240
241 doc.AppendChild(xmlnode);
242
243 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
244 "");
245
246 doc.AppendChild(rootElement);
247
248 XmlElement result = doc.CreateElement("", "Result", "");
249 result.AppendChild(doc.CreateTextNode("Failure"));
250
251 rootElement.AppendChild(result);
252
253 return DocToBytes(doc);
254 }
255
256 private byte[] DocToBytes(XmlDocument doc)
257 {
258 MemoryStream ms = new MemoryStream();
259 XmlTextWriter xw = new XmlTextWriter(ms, null);
260 xw.Formatting = Formatting.Indented;
261 doc.WriteTo(xw);
262 xw.Flush();
263
264 return ms.GetBuffer();
265 }
266
267 #endregion
268 }
269}