aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Grid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Grid')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs154
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs55
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs77
3 files changed, 286 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
new file mode 100644
index 0000000..d1233dc
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
@@ -0,0 +1,154 @@
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 System.Collections;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using log4net;
35using Nini.Config;
36using Nwc.XmlRpc;
37using OpenSim.Framework;
38using OpenSim.Framework.Servers.HttpServer;
39
40namespace OpenSim.Server.Handlers.Grid
41{
42 public class GridInfoHandlers
43 {
44 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 private Hashtable _info = new Hashtable();
47
48 /// <summary>
49 /// Instantiate a GridInfoService object.
50 /// </summary>
51 /// <param name="configPath">path to config path containing
52 /// grid information</param>
53 /// <remarks>
54 /// GridInfoService uses the [GridInfo] section of the
55 /// standard OpenSim.ini file --- which is not optimal, but
56 /// anything else requires a general redesign of the config
57 /// system.
58 /// </remarks>
59 public GridInfoHandlers(IConfigSource configSource)
60 {
61 loadGridInfo(configSource);
62 }
63
64 private void loadGridInfo(IConfigSource configSource)
65 {
66 _info["platform"] = "OpenSim";
67 try
68 {
69 IConfig startupCfg = configSource.Configs["Startup"];
70 IConfig gridCfg = configSource.Configs["GridInfoService"];
71 IConfig netCfg = configSource.Configs["Network"];
72
73 bool grid = startupCfg.GetBoolean("gridmode", false);
74
75 if (null != gridCfg)
76 {
77 foreach (string k in gridCfg.GetKeys())
78 {
79 _info[k] = gridCfg.GetString(k);
80 }
81 }
82 else if (null != netCfg)
83 {
84 if (grid)
85 _info["login"]
86 = netCfg.GetString(
87 "user_server_url", "http://127.0.0.1:" + ConfigSettings.DefaultUserServerHttpPort.ToString());
88 else
89 _info["login"]
90 = String.Format(
91 "http://127.0.0.1:{0}/",
92 netCfg.GetString(
93 "http_listener_port", ConfigSettings.DefaultRegionHttpPort.ToString()));
94
95 IssueWarning();
96 }
97 else
98 {
99 _info["login"] = "http://127.0.0.1:9000/";
100 IssueWarning();
101 }
102 }
103 catch (Exception)
104 {
105 _log.Debug("[GRID INFO SERVICE]: Cannot get grid info from config source, using minimal defaults");
106 }
107
108 _log.DebugFormat("[GRID INFO SERVICE]: Grid info service initialized with {0} keys", _info.Count);
109
110 }
111
112 private void IssueWarning()
113 {
114 _log.Warn("[GRID INFO SERVICE]: found no [GridInfo] section in your OpenSim.ini");
115 _log.Warn("[GRID INFO SERVICE]: trying to guess sensible defaults, you might want to provide better ones:");
116
117 foreach (string k in _info.Keys)
118 {
119 _log.WarnFormat("[GRID INFO SERVICE]: {0}: {1}", k, _info[k]);
120 }
121 }
122
123 public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient)
124 {
125 XmlRpcResponse response = new XmlRpcResponse();
126 Hashtable responseData = new Hashtable();
127
128 _log.Info("[GRID INFO SERVICE]: Request for grid info");
129
130 foreach (string k in _info.Keys)
131 {
132 responseData[k] = _info[k];
133 }
134 response.Value = responseData;
135
136 return response;
137 }
138
139 public string RestGetGridInfoMethod(string request, string path, string param,
140 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
141 {
142 StringBuilder sb = new StringBuilder();
143
144 sb.Append("<gridinfo>\n");
145 foreach (string k in _info.Keys)
146 {
147 sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]);
148 }
149 sb.Append("</gridinfo>\n");
150
151 return sb.ToString();
152 }
153 }
154}
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs
new file mode 100644
index 0000000..c9e80d9
--- /dev/null
+++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs
@@ -0,0 +1,55 @@
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 System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers.HttpServer;
36using OpenSim.Server.Handlers.Base;
37
38namespace OpenSim.Server.Handlers.Grid
39{
40 public class GridInfoServerInConnector : ServiceConnector
41 {
42 private string m_ConfigName = "GridInfoService";
43
44 public GridInfoServerInConnector(IConfigSource config, IHttpServer server, string configName) :
45 base(config, server, configName)
46 {
47 GridInfoHandlers handlers = new GridInfoHandlers(config);
48
49 server.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info",
50 handlers.RestGetGridInfoMethod));
51 server.AddXmlRPCHandler("get_grid_info", handlers.XmlRpcGridInfoMethod);
52 }
53
54 }
55}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
index 85a8738..318ce85 100644
--- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -103,6 +103,12 @@ namespace OpenSim.Server.Handlers.Grid
103 case "get_region_range": 103 case "get_region_range":
104 return GetRegionRange(request); 104 return GetRegionRange(request);
105 105
106 case "get_default_regions":
107 return GetDefaultRegions(request);
108
109 case "get_fallback_regions":
110 return GetFallbackRegions(request);
111
106 } 112 }
107 m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method); 113 m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method);
108 } 114 }
@@ -404,6 +410,77 @@ namespace OpenSim.Server.Handlers.Grid
404 return encoding.GetBytes(xmlString); 410 return encoding.GetBytes(xmlString);
405 } 411 }
406 412
413 byte[] GetDefaultRegions(Dictionary<string, object> request)
414 {
415 //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
416 UUID scopeID = UUID.Zero;
417 if (request.ContainsKey("SCOPEID"))
418 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
419 else
420 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
421
422 List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
423
424 Dictionary<string, object> result = new Dictionary<string, object>();
425 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
426 result["result"] = "null";
427 else
428 {
429 int i = 0;
430 foreach (GridRegion rinfo in rinfos)
431 {
432 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
433 result["region" + i] = rinfoDict;
434 i++;
435 }
436 }
437 string xmlString = ServerUtils.BuildXmlResponse(result);
438 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
439 UTF8Encoding encoding = new UTF8Encoding();
440 return encoding.GetBytes(xmlString);
441 }
442
443 byte[] GetFallbackRegions(Dictionary<string, object> request)
444 {
445 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
446 UUID scopeID = UUID.Zero;
447 if (request.ContainsKey("SCOPEID"))
448 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
449 else
450 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
451
452 int x = 0, y = 0;
453 if (request.ContainsKey("X"))
454 Int32.TryParse(request["X"].ToString(), out x);
455 else
456 m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
457 if (request.ContainsKey("Y"))
458 Int32.TryParse(request["Y"].ToString(), out y);
459 else
460 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
461
462
463 List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
464
465 Dictionary<string, object> result = new Dictionary<string, object>();
466 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
467 result["result"] = "null";
468 else
469 {
470 int i = 0;
471 foreach (GridRegion rinfo in rinfos)
472 {
473 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
474 result["region" + i] = rinfoDict;
475 i++;
476 }
477 }
478 string xmlString = ServerUtils.BuildXmlResponse(result);
479 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
480 UTF8Encoding encoding = new UTF8Encoding();
481 return encoding.GetBytes(xmlString);
482 }
483
407 #endregion 484 #endregion
408 485
409 #region Misc 486 #region Misc