aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
diff options
context:
space:
mode:
authorKitto Flora2009-09-30 19:07:18 +0200
committerKitto Flora2009-09-30 19:07:18 +0200
commit07df0e0ab0c69633a6afec8d05cccc117656d3d9 (patch)
tree3048cc38b313e255cbf03fa3e2900e28cadc47c9 /OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
parentAnd another merge issue (diff)
parentFix loading modules with alternate configurations and ports into ROBUST. (diff)
downloadopensim-SC-07df0e0ab0c69633a6afec8d05cccc117656d3d9.zip
opensim-SC-07df0e0ab0c69633a6afec8d05cccc117656d3d9.tar.gz
opensim-SC-07df0e0ab0c69633a6afec8d05cccc117656d3d9.tar.bz2
opensim-SC-07df0e0ab0c69633a6afec8d05cccc117656d3d9.tar.xz
Merge branch '0.6.7-post-fixes' into vehicles
Diffstat (limited to 'OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs433
1 files changed, 433 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
new file mode 100644
index 0000000..b9a4867
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -0,0 +1,433 @@
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 GridRegion = OpenSim.Services.Interfaces.GridRegion;
42using OpenSim.Framework;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.Grid
47{
48 public class GridServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IGridService m_GridService;
53
54 public GridServerPostHandler(IGridService service) :
55 base("POST", "/grid")
56 {
57 m_GridService = service;
58 }
59
60 public override byte[] Handle(string path, Stream requestData,
61 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 Dictionary<string, string> request =
71 ServerUtils.ParseQueryString(body);
72
73 if (!request.ContainsKey("METHOD"))
74 return FailureResult();
75
76 string method = request["METHOD"];
77
78 switch (method)
79 {
80 case "register":
81 return Register(request);
82
83 case "deregister":
84 return Deregister(request);
85
86 case "get_neighbours":
87 return GetNeighbours(request);
88
89 case "get_region_by_uuid":
90 return GetRegionByUUID(request);
91
92 case "get_region_by_position":
93 return GetRegionByPosition(request);
94
95 case "get_region_by_name":
96 return GetRegionByName(request);
97
98 case "get_regions_by_name":
99 return GetRegionsByName(request);
100
101 case "get_region_range":
102 return GetRegionRange(request);
103
104 }
105
106 m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method);
107 return FailureResult();
108
109 }
110
111 #region Method-specific handlers
112
113 byte[] Register(Dictionary<string, string> request)
114 {
115 UUID scopeID = UUID.Zero;
116 if (request["SCOPEID"] != null)
117 UUID.TryParse(request["SCOPEID"], out scopeID);
118 else
119 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
120
121 Dictionary<string, object> rinfoData = new Dictionary<string, object>();
122 foreach (KeyValuePair<string, string> kvp in request)
123 rinfoData[kvp.Key] = kvp.Value;
124 GridRegion rinfo = new GridRegion(rinfoData);
125
126 bool result = m_GridService.RegisterRegion(scopeID, rinfo);
127
128 if (result)
129 return SuccessResult();
130 else
131 return FailureResult();
132 }
133
134 byte[] Deregister(Dictionary<string, string> request)
135 {
136 UUID regionID = UUID.Zero;
137 if (request["REGIONID"] != null)
138 UUID.TryParse(request["REGIONID"], out regionID);
139 else
140 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
141
142 bool result = m_GridService.DeregisterRegion(regionID);
143
144 if (result)
145 return SuccessResult();
146 else
147 return FailureResult();
148
149 }
150
151 byte[] GetNeighbours(Dictionary<string, string> request)
152 {
153 UUID scopeID = UUID.Zero;
154 if (request["SCOPEID"] != null)
155 UUID.TryParse(request["SCOPEID"], out scopeID);
156 else
157 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
158
159 UUID regionID = UUID.Zero;
160 if (request["REGIONID"] != null)
161 UUID.TryParse(request["REGIONID"], out regionID);
162 else
163 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
164
165 List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
166 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
167
168 Dictionary<string, object> result = new Dictionary<string, object>();
169 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
170 result["result"] = "null";
171 else
172 {
173 int i = 0;
174 foreach (GridRegion rinfo in rinfos)
175 {
176 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
177 result["region" + i] = rinfoDict;
178 i++;
179 }
180 }
181
182 string xmlString = ServerUtils.BuildXmlResponse(result);
183 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
184 UTF8Encoding encoding = new UTF8Encoding();
185 return encoding.GetBytes(xmlString);
186
187 }
188
189 byte[] GetRegionByUUID(Dictionary<string, string> request)
190 {
191 UUID scopeID = UUID.Zero;
192 if (request["SCOPEID"] != null)
193 UUID.TryParse(request["SCOPEID"], out scopeID);
194 else
195 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
196
197 UUID regionID = UUID.Zero;
198 if (request["REGIONID"] != null)
199 UUID.TryParse(request["REGIONID"], out regionID);
200 else
201 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
202
203 GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
204 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
205
206 Dictionary<string, object> result = new Dictionary<string, object>();
207 if (rinfo == null)
208 result["result"] = "null";
209 else
210 result["result"] = rinfo.ToKeyValuePairs();
211
212 string xmlString = ServerUtils.BuildXmlResponse(result);
213 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
214 UTF8Encoding encoding = new UTF8Encoding();
215 return encoding.GetBytes(xmlString);
216 }
217
218 byte[] GetRegionByPosition(Dictionary<string, string> request)
219 {
220 UUID scopeID = UUID.Zero;
221 if (request["SCOPEID"] != null)
222 UUID.TryParse(request["SCOPEID"], out scopeID);
223 else
224 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
225
226 int x = 0, y = 0;
227 if (request["X"] != null)
228 Int32.TryParse(request["X"], out x);
229 else
230 m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
231 if (request["Y"] != null)
232 Int32.TryParse(request["Y"], out y);
233 else
234 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
235
236 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
237 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
238
239 Dictionary<string, object> result = new Dictionary<string, object>();
240 if (rinfo == null)
241 result["result"] = "null";
242 else
243 result["result"] = rinfo.ToKeyValuePairs();
244
245 string xmlString = ServerUtils.BuildXmlResponse(result);
246 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
247 UTF8Encoding encoding = new UTF8Encoding();
248 return encoding.GetBytes(xmlString);
249 }
250
251 byte[] GetRegionByName(Dictionary<string, string> request)
252 {
253 UUID scopeID = UUID.Zero;
254 if (request["SCOPEID"] != null)
255 UUID.TryParse(request["SCOPEID"], out scopeID);
256 else
257 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
258
259 string regionName = string.Empty;
260 if (request["NAME"] != null)
261 regionName = request["NAME"];
262 else
263 m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
264
265 GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
266 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
267
268 Dictionary<string, object> result = new Dictionary<string, object>();
269 if (rinfo == null)
270 result["result"] = "null";
271 else
272 result["result"] = rinfo.ToKeyValuePairs();
273
274 string xmlString = ServerUtils.BuildXmlResponse(result);
275 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
276 UTF8Encoding encoding = new UTF8Encoding();
277 return encoding.GetBytes(xmlString);
278 }
279
280 byte[] GetRegionsByName(Dictionary<string, string> request)
281 {
282 UUID scopeID = UUID.Zero;
283 if (request["SCOPEID"] != null)
284 UUID.TryParse(request["SCOPEID"], out scopeID);
285 else
286 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
287
288 string regionName = string.Empty;
289 if (request["NAME"] != null)
290 regionName = request["NAME"];
291 else
292 m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
293
294 int max = 0;
295 if (request["MAX"] != null)
296 Int32.TryParse(request["MAX"], out max);
297 else
298 m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
299
300 List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
301 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
302
303 Dictionary<string, object> result = new Dictionary<string, object>();
304 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
305 result["result"] = "null";
306 else
307 {
308 int i = 0;
309 foreach (GridRegion rinfo in rinfos)
310 {
311 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
312 result["region" + i] = rinfoDict;
313 i++;
314 }
315 }
316
317 string xmlString = ServerUtils.BuildXmlResponse(result);
318 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
319 UTF8Encoding encoding = new UTF8Encoding();
320 return encoding.GetBytes(xmlString);
321 }
322
323 byte[] GetRegionRange(Dictionary<string, string> request)
324 {
325 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
326 UUID scopeID = UUID.Zero;
327 if (request.ContainsKey("SCOPEID"))
328 UUID.TryParse(request["SCOPEID"], out scopeID);
329 else
330 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
331
332 int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
333 if (request.ContainsKey("XMIN"))
334 Int32.TryParse(request["XMIN"], out xmin);
335 else
336 m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
337 if (request.ContainsKey("XMAX"))
338 Int32.TryParse(request["XMAX"], out xmax);
339 else
340 m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
341 if (request.ContainsKey("YMIN"))
342 Int32.TryParse(request["YMIN"], out ymin);
343 else
344 m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
345 if (request.ContainsKey("YMAX"))
346 Int32.TryParse(request["YMAX"], out ymax);
347 else
348 m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
349
350
351 List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
352
353 Dictionary<string, object> result = new Dictionary<string, object>();
354 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
355 result["result"] = "null";
356 else
357 {
358 int i = 0;
359 foreach (GridRegion rinfo in rinfos)
360 {
361 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
362 result["region" + i] = rinfoDict;
363 i++;
364 }
365 }
366 string xmlString = ServerUtils.BuildXmlResponse(result);
367 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
368 UTF8Encoding encoding = new UTF8Encoding();
369 return encoding.GetBytes(xmlString);
370 }
371
372 #endregion
373
374 #region Misc
375
376 private byte[] SuccessResult()
377 {
378 XmlDocument doc = new XmlDocument();
379
380 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
381 "", "");
382
383 doc.AppendChild(xmlnode);
384
385 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
386 "");
387
388 doc.AppendChild(rootElement);
389
390 XmlElement result = doc.CreateElement("", "Result", "");
391 result.AppendChild(doc.CreateTextNode("Success"));
392
393 rootElement.AppendChild(result);
394
395 return DocToBytes(doc);
396 }
397
398 private byte[] FailureResult()
399 {
400 XmlDocument doc = new XmlDocument();
401
402 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
403 "", "");
404
405 doc.AppendChild(xmlnode);
406
407 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
408 "");
409
410 doc.AppendChild(rootElement);
411
412 XmlElement result = doc.CreateElement("", "Result", "");
413 result.AppendChild(doc.CreateTextNode("Failure"));
414
415 rootElement.AppendChild(result);
416
417 return DocToBytes(doc);
418 }
419
420 private byte[] DocToBytes(XmlDocument doc)
421 {
422 MemoryStream ms = new MemoryStream();
423 XmlTextWriter xw = new XmlTextWriter(ms, null);
424 xw.Formatting = Formatting.Indented;
425 doc.WriteTo(xw);
426 xw.Flush();
427
428 return ms.ToArray();
429 }
430
431 #endregion
432 }
433}