31 using System.Reflection;
35 using System.Text.RegularExpressions;
37 using System.Xml.Serialization;
38 using System.Collections.Generic;
39 using OpenSim.Server.Base;
40 using OpenSim.Services.Interfaces;
42 using OpenSim.Framework;
43 using OpenSim.Framework.ServiceAuth;
44 using OpenSim.Framework.Servers.HttpServer;
47 namespace OpenSim.Server.Handlers.Grid
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 #pragma warning disable 414
54 private static string LogHeader =
"[GRID HANDLER]";
55 #pragma warning restore 414
60 base(
"POST",
"/grid", auth)
62 m_GridService = service;
68 StreamReader sr =
new StreamReader(requestData);
69 string body = sr.ReadToEnd();
77 Dictionary<string, object> request =
78 ServerUtils.ParseQueryString(body);
80 if (!request.ContainsKey(
"METHOD"))
81 return FailureResult();
83 string method = request[
"METHOD"].ToString();
88 return Register(request);
91 return Deregister(request);
93 case "get_neighbours":
94 return GetNeighbours(request);
96 case "get_region_by_uuid":
97 return GetRegionByUUID(request);
99 case "get_region_by_position":
100 return GetRegionByPosition(request);
102 case "get_region_by_name":
103 return GetRegionByName(request);
105 case "get_regions_by_name":
106 return GetRegionsByName(request);
108 case "get_region_range":
109 return GetRegionRange(request);
111 case "get_default_regions":
112 return GetDefaultRegions(request);
114 case "get_default_hypergrid_regions":
115 return GetDefaultHypergridRegions(request);
117 case "get_fallback_regions":
118 return GetFallbackRegions(request);
120 case "get_hyperlinks":
121 return GetHyperlinks(request);
123 case "get_region_flags":
124 return GetRegionFlags(request);
126 case "get_grid_extra_features":
127 return GetGridExtraFeatures(request);
130 m_log.DebugFormat(
"[GRID HANDLER]: unknown method request {0}", method);
134 m_log.ErrorFormat(
"[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
137 return FailureResult();
140 #region Method-specific handlers
142 byte[] Register(Dictionary<string, object> request)
144 UUID scopeID = UUID.Zero;
145 if (request.ContainsKey(
"SCOPEID"))
146 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
148 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to register region");
150 int versionNumberMin = 0, versionNumberMax = 0;
151 if (request.ContainsKey(
"VERSIONMIN"))
152 Int32.TryParse(request[
"VERSIONMIN"].ToString(), out versionNumberMin);
154 m_log.WarnFormat(
"[GRID HANDLER]: no minimum protocol version in request to register region");
156 if (request.ContainsKey(
"VERSIONMAX"))
157 Int32.TryParse(request[
"VERSIONMAX"].ToString(), out versionNumberMax);
159 m_log.WarnFormat(
"[GRID HANDLER]: no maximum protocol version in request to register region");
182 return FailureResult();
185 Dictionary<string, object> rinfoData =
new Dictionary<string, object>();
189 foreach (KeyValuePair<string, object> kvp
in request)
190 rinfoData[kvp.Key] = kvp.Value.ToString();
195 m_log.DebugFormat(
"[GRID HANDLER]: exception unpacking region data: {0}", e);
198 string result =
"Error communicating with grid service";
200 result = m_GridService.RegisterRegion(scopeID, rinfo);
202 if (result == String.Empty)
203 return SuccessResult();
205 return FailureResult(result);
208 byte[] Deregister(Dictionary<string, object> request)
210 UUID regionID = UUID.Zero;
211 if (request.ContainsKey(
"REGIONID"))
212 UUID.TryParse(request[
"REGIONID"].ToString(), out regionID);
214 m_log.WarnFormat(
"[GRID HANDLER]: no regionID in request to deregister region");
216 bool result = m_GridService.DeregisterRegion(regionID);
219 return SuccessResult();
221 return FailureResult();
225 byte[] GetNeighbours(Dictionary<string, object> request)
227 UUID scopeID = UUID.Zero;
228 if (request.ContainsKey(
"SCOPEID"))
229 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
231 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get neighbours");
233 UUID regionID = UUID.Zero;
234 if (request.ContainsKey(
"REGIONID"))
235 UUID.TryParse(request[
"REGIONID"].ToString(), out regionID);
237 m_log.WarnFormat(
"[GRID HANDLER]: no regionID in request to get neighbours");
239 List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
242 Dictionary<string, object> result =
new Dictionary<string, object>();
243 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
244 result[
"result"] =
"null";
250 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
251 result[
"region" + i] = rinfoDict;
256 string xmlString = ServerUtils.BuildXmlResponse(result);
259 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
262 byte[] GetRegionByUUID(Dictionary<string, object> request)
264 UUID scopeID = UUID.Zero;
265 if (request.ContainsKey(
"SCOPEID"))
266 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
268 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get neighbours");
270 UUID regionID = UUID.Zero;
271 if (request.ContainsKey(
"REGIONID"))
272 UUID.TryParse(request[
"REGIONID"].ToString(), out regionID);
274 m_log.WarnFormat(
"[GRID HANDLER]: no regionID in request to get neighbours");
276 GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
279 Dictionary<string, object> result =
new Dictionary<string, object>();
281 result[
"result"] =
"null";
283 result[
"result"] = rinfo.ToKeyValuePairs();
285 string xmlString = ServerUtils.BuildXmlResponse(result);
288 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
291 byte[] GetRegionByPosition(Dictionary<string, object> request)
293 UUID scopeID = UUID.Zero;
294 if (request.ContainsKey(
"SCOPEID"))
295 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
297 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get region by position");
300 if (request.ContainsKey(
"X"))
301 Int32.TryParse(request[
"X"].ToString(), out x);
303 m_log.WarnFormat(
"[GRID HANDLER]: no X in request to get region by position");
304 if (request.ContainsKey(
"Y"))
305 Int32.TryParse(request[
"Y"].ToString(), out y);
307 m_log.WarnFormat(
"[GRID HANDLER]: no Y in request to get region by position");
310 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
312 Dictionary<string, object> result =
new Dictionary<string, object>();
314 result[
"result"] =
"null";
316 result[
"result"] = rinfo.ToKeyValuePairs();
318 string xmlString = ServerUtils.BuildXmlResponse(result);
321 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
324 byte[] GetRegionByName(Dictionary<string, object> request)
326 UUID scopeID = UUID.Zero;
327 if (request.ContainsKey(
"SCOPEID"))
328 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
330 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get region by name");
332 string regionName = string.Empty;
333 if (request.ContainsKey(
"NAME"))
334 regionName = request[
"NAME"].ToString();
336 m_log.WarnFormat(
"[GRID HANDLER]: no name in request to get region by name");
338 GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
341 Dictionary<string, object> result =
new Dictionary<string, object>();
343 result[
"result"] =
"null";
345 result[
"result"] = rinfo.ToKeyValuePairs();
347 string xmlString = ServerUtils.BuildXmlResponse(result);
350 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
353 byte[] GetRegionsByName(Dictionary<string, object> request)
355 UUID scopeID = UUID.Zero;
356 if (request.ContainsKey(
"SCOPEID"))
357 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
359 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get regions by name");
361 string regionName = string.Empty;
362 if (request.ContainsKey(
"NAME"))
363 regionName = request[
"NAME"].ToString();
365 m_log.WarnFormat(
"[GRID HANDLER]: no NAME in request to get regions by name");
368 if (request.ContainsKey(
"MAX"))
369 Int32.TryParse(request[
"MAX"].ToString(), out max);
371 m_log.WarnFormat(
"[GRID HANDLER]: no MAX in request to get regions by name");
373 List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
376 Dictionary<string, object> result =
new Dictionary<string, object>();
377 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
378 result[
"result"] =
"null";
384 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
385 result[
"region" + i] = rinfoDict;
390 string xmlString = ServerUtils.BuildXmlResponse(result);
393 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
396 byte[] GetRegionRange(Dictionary<string, object> request)
399 UUID scopeID = UUID.Zero;
400 if (request.ContainsKey(
"SCOPEID"))
401 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
403 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get region range");
405 int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
406 if (request.ContainsKey(
"XMIN"))
407 Int32.TryParse(request[
"XMIN"].ToString(), out xmin);
409 m_log.WarnFormat(
"[GRID HANDLER]: no XMIN in request to get region range");
410 if (request.ContainsKey(
"XMAX"))
411 Int32.TryParse(request[
"XMAX"].ToString(), out xmax);
413 m_log.WarnFormat(
"[GRID HANDLER]: no XMAX in request to get region range");
414 if (request.ContainsKey(
"YMIN"))
415 Int32.TryParse(request[
"YMIN"].ToString(), out ymin);
417 m_log.WarnFormat(
"[GRID HANDLER]: no YMIN in request to get region range");
418 if (request.ContainsKey(
"YMAX"))
419 Int32.TryParse(request[
"YMAX"].ToString(), out ymax);
421 m_log.WarnFormat(
"[GRID HANDLER]: no YMAX in request to get region range");
424 List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
426 Dictionary<string, object> result =
new Dictionary<string, object>();
427 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
428 result[
"result"] =
"null";
434 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
435 result[
"region" + i] = rinfoDict;
439 string xmlString = ServerUtils.BuildXmlResponse(result);
442 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
445 byte[] GetDefaultRegions(Dictionary<string, object> request)
448 UUID scopeID = UUID.Zero;
449 if (request.ContainsKey(
"SCOPEID"))
450 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
452 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get region range");
454 List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
456 Dictionary<string, object> result =
new Dictionary<string, object>();
457 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
458 result[
"result"] =
"null";
464 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
465 result[
"region" + i] = rinfoDict;
469 string xmlString = ServerUtils.BuildXmlResponse(result);
472 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
475 byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
478 UUID scopeID = UUID.Zero;
479 if (request.ContainsKey(
"SCOPEID"))
480 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
482 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get region range");
484 List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
486 Dictionary<string, object> result =
new Dictionary<string, object>();
487 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
488 result[
"result"] =
"null";
494 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
495 result[
"region" + i] = rinfoDict;
499 string xmlString = ServerUtils.BuildXmlResponse(result);
502 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
505 byte[] GetFallbackRegions(Dictionary<string, object> request)
508 UUID scopeID = UUID.Zero;
509 if (request.ContainsKey(
"SCOPEID"))
510 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
512 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get fallback regions");
515 if (request.ContainsKey(
"X"))
516 Int32.TryParse(request[
"X"].ToString(), out x);
518 m_log.WarnFormat(
"[GRID HANDLER]: no X in request to get fallback regions");
519 if (request.ContainsKey(
"Y"))
520 Int32.TryParse(request[
"Y"].ToString(), out y);
522 m_log.WarnFormat(
"[GRID HANDLER]: no Y in request to get fallback regions");
525 List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
527 Dictionary<string, object> result =
new Dictionary<string, object>();
528 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
529 result[
"result"] =
"null";
535 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
536 result[
"region" + i] = rinfoDict;
540 string xmlString = ServerUtils.BuildXmlResponse(result);
543 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
546 byte[] GetHyperlinks(Dictionary<string, object> request)
549 UUID scopeID = UUID.Zero;
550 if (request.ContainsKey(
"SCOPEID"))
551 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
553 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get linked regions");
555 List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
557 Dictionary<string, object> result =
new Dictionary<string, object>();
558 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
559 result[
"result"] =
"null";
565 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
566 result[
"region" + i] = rinfoDict;
570 string xmlString = ServerUtils.BuildXmlResponse(result);
573 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
576 byte[] GetRegionFlags(Dictionary<string, object> request)
578 UUID scopeID = UUID.Zero;
579 if (request.ContainsKey(
"SCOPEID"))
580 UUID.TryParse(request[
"SCOPEID"].ToString(), out scopeID);
582 m_log.WarnFormat(
"[GRID HANDLER]: no scopeID in request to get neighbours");
584 UUID regionID = UUID.Zero;
585 if (request.ContainsKey(
"REGIONID"))
586 UUID.TryParse(request[
"REGIONID"].ToString(), out regionID);
588 m_log.WarnFormat(
"[GRID HANDLER]: no regionID in request to get neighbours");
590 int flags = m_GridService.GetRegionFlags(scopeID, regionID);
593 Dictionary<string, object> result =
new Dictionary<string, object>();
594 result[
"result"] = flags.ToString();
596 string xmlString = ServerUtils.BuildXmlResponse(result);
599 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
602 byte[] GetGridExtraFeatures(Dictionary<string, object> request)
605 Dictionary<string, object> result =
new Dictionary<string, object> ();
606 Dictionary<string, object> extraFeatures = m_GridService.GetExtraFeatures ();
608 foreach (
string key in extraFeatures.Keys)
610 result [
key] = extraFeatures [
key];
613 string xmlString = ServerUtils.BuildXmlResponse(result);
615 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
622 private byte[] SuccessResult()
624 XmlDocument doc =
new XmlDocument();
626 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
629 doc.AppendChild(xmlnode);
631 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
634 doc.AppendChild(rootElement);
636 XmlElement result = doc.CreateElement(
"",
"Result",
"");
637 result.AppendChild(doc.CreateTextNode(
"Success"));
639 rootElement.AppendChild(result);
641 return Util.DocToBytes(doc);
644 private byte[] FailureResult()
646 return FailureResult(
String.Empty);
649 private byte[] FailureResult(
string msg)
651 XmlDocument doc =
new XmlDocument();
653 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
656 doc.AppendChild(xmlnode);
658 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
661 doc.AppendChild(rootElement);
663 XmlElement result = doc.CreateElement(
"",
"Result",
"");
664 result.AppendChild(doc.CreateTextNode(
"Failure"));
666 rootElement.AppendChild(result);
668 XmlElement message = doc.CreateElement(
"",
"Message",
"");
669 message.AppendChild(doc.CreateTextNode(msg));
671 rootElement.AppendChild(message);
673 return Util.DocToBytes(doc);
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
OpenSim.Services.Interfaces.GridRegion GridRegion
Base streamed request handler.
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
static readonly int ServerProtocolVersionMax
GridServerPostHandler(IGridService service, IServiceAuth auth)
static readonly int ServerProtocolVersionMin