aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
diff options
context:
space:
mode:
authorDiva Canto2010-01-10 19:19:34 -0800
committerDiva Canto2010-01-10 19:19:34 -0800
commit49618dc102c42b7125303511d826f76f0ebaab4c (patch)
treefba3817eb6ee8547914892dbae45c955d78734e8 /OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
parentRemoved refs to OpenIdService in UserServer. (diff)
downloadopensim-SC_OLD-49618dc102c42b7125303511d826f76f0ebaab4c.zip
opensim-SC_OLD-49618dc102c42b7125303511d826f76f0ebaab4c.tar.gz
opensim-SC_OLD-49618dc102c42b7125303511d826f76f0ebaab4c.tar.bz2
opensim-SC_OLD-49618dc102c42b7125303511d826f76f0ebaab4c.tar.xz
Moved GridInfo service from where it was to Handlers/Grid
Diffstat (limited to 'OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs154
1 files changed, 154 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}