OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
GridInfoHandlers.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections;
30 using System.IO;
31 using System.Net;
32 using System.Reflection;
33 using System.Security;
34 using System.Text;
35 using log4net;
36 using Nini.Config;
37 using Nwc.XmlRpc;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers.HttpServer;
40 using OpenMetaverse.StructuredData;
41 
42 namespace OpenSim.Server.Handlers.Grid
43 {
44  public class GridInfoHandlers
45  {
46  private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47  private IConfigSource m_Config;
48  private Hashtable _info = new Hashtable();
49 
61  public GridInfoHandlers(IConfigSource configSource)
62  {
63  m_Config = configSource;
64  loadGridInfo(configSource);
65  }
66 
67  private void loadGridInfo(IConfigSource configSource)
68  {
69  _info["platform"] = "OpenSim";
70  try
71  {
72  IConfig gridCfg = configSource.Configs["GridInfoService"];
73  IConfig netCfg = configSource.Configs["Network"];
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  _info["login"]
85  = String.Format(
86  "http://127.0.0.1:{0}/",
87  netCfg.GetString(
88  "http_listener_port", ConfigSettings.DefaultRegionHttpPort.ToString()));
89 
90  IssueWarning();
91  }
92  else
93  {
94  _info["login"] = "http://127.0.0.1:9000/";
95  IssueWarning();
96  }
97  }
98  catch (Exception)
99  {
100  _log.Warn("[GRID INFO SERVICE]: Cannot get grid info from config source, using minimal defaults");
101  }
102 
103  _log.DebugFormat("[GRID INFO SERVICE]: Grid info service initialized with {0} keys", _info.Count);
104  }
105 
106  private void IssueWarning()
107  {
108  _log.Warn("[GRID INFO SERVICE]: found no [GridInfo] section in your configuration files");
109  _log.Warn("[GRID INFO SERVICE]: trying to guess sensible defaults, you might want to provide better ones:");
110 
111  foreach (string k in _info.Keys)
112  {
113  _log.WarnFormat("[GRID INFO SERVICE]: {0}: {1}", k, _info[k]);
114  }
115  }
116 
117  public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient)
118  {
119  XmlRpcResponse response = new XmlRpcResponse();
120  Hashtable responseData = new Hashtable();
121 
122  _log.Debug("[GRID INFO SERVICE]: Request for grid info");
123 
124  foreach (string k in _info.Keys)
125  {
126  responseData[k] = _info[k];
127  }
128  response.Value = responseData;
129 
130  return response;
131  }
132 
133  public string RestGetGridInfoMethod(string request, string path, string param,
134  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
135  {
136  StringBuilder sb = new StringBuilder();
137 
138  sb.Append("<gridinfo>\n");
139  foreach (string k in _info.Keys)
140  {
141  sb.AppendFormat("<{0}>{1}</{0}>\n", k, SecurityElement.Escape(_info[k].ToString()));
142  }
143  sb.Append("</gridinfo>\n");
144 
145  return sb.ToString();
146  }
147 
170  public string JsonGetGridInfoMethod(string request, string path, string param,
171  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
172  {
173  OSDMap map = new OSDMap();
174 
175  foreach (string k in _info.Keys)
176  {
177  map[k] = OSD.FromString(_info[k].ToString());
178  }
179 
180  string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI",
181  new string[] { "Startup", "Hypergrid" }, String.Empty);
182 
183  if (!String.IsNullOrEmpty(HomeURI))
184  map["home"] = OSD.FromString(HomeURI);
185  else // Legacy. Remove soon!
186  {
187  IConfig cfg = m_Config.Configs["LoginService"];
188 
189  if (null != cfg)
190  HomeURI = cfg.GetString("SRV_HomeURI", HomeURI);
191 
192  if (!String.IsNullOrEmpty(HomeURI))
193  map["home"] = OSD.FromString(HomeURI);
194  }
195 
196  return OSDParser.SerializeJsonString(map).ToString();
197  }
198  }
199 }
OpenMetaverse.StructuredData.OSDMap OSDMap
string RestGetGridInfoMethod(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient)
OpenMetaverse.StructuredData.OSD OSD
Interactive OpenSim region server
Definition: OpenSim.cs:55
string JsonGetGridInfoMethod(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Get GridInfo in json format: Used bu the OSSL osGetGrid* Adding the SRV_HomeIRI to the kvp returned f...
GridInfoHandlers(IConfigSource configSource)
Instantiate a GridInfoService object.