diff options
Diffstat (limited to 'OpenSim/Framework/Communications/Services/GridInfoService.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Services/GridInfoService.cs | 344 |
1 files changed, 172 insertions, 172 deletions
diff --git a/OpenSim/Framework/Communications/Services/GridInfoService.cs b/OpenSim/Framework/Communications/Services/GridInfoService.cs index 96fe0d8..030ea61 100644 --- a/OpenSim/Framework/Communications/Services/GridInfoService.cs +++ b/OpenSim/Framework/Communications/Services/GridInfoService.cs | |||
@@ -1,172 +1,172 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text; | 32 | using System.Text; |
33 | using log4net; | 33 | using log4net; |
34 | using Nini.Config; | 34 | using Nini.Config; |
35 | using Nwc.XmlRpc; | 35 | using Nwc.XmlRpc; |
36 | using OpenSim.Framework.Servers; | 36 | using OpenSim.Framework.Servers; |
37 | 37 | ||
38 | namespace OpenSim.Framework.Communications.Services | 38 | namespace OpenSim.Framework.Communications.Services |
39 | { | 39 | { |
40 | public class GridInfoService | 40 | public class GridInfoService |
41 | { | 41 | { |
42 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | 43 | ||
44 | private Hashtable _info = new Hashtable(); | 44 | private Hashtable _info = new Hashtable(); |
45 | 45 | ||
46 | /// <summary> | 46 | /// <summary> |
47 | /// Instantiate a GridInfoService object. | 47 | /// Instantiate a GridInfoService object. |
48 | /// </summary> | 48 | /// </summary> |
49 | /// <param name="configPath">path to config path containing | 49 | /// <param name="configPath">path to config path containing |
50 | /// grid information</param> | 50 | /// grid information</param> |
51 | /// <remarks> | 51 | /// <remarks> |
52 | /// GridInfoService uses the [GridInfo] section of the | 52 | /// GridInfoService uses the [GridInfo] section of the |
53 | /// standard OpenSim.ini file --- which is not optimal, but | 53 | /// standard OpenSim.ini file --- which is not optimal, but |
54 | /// anything else requires a general redesign of the config | 54 | /// anything else requires a general redesign of the config |
55 | /// system. | 55 | /// system. |
56 | /// </remarks> | 56 | /// </remarks> |
57 | public GridInfoService(IConfigSource configSource) | 57 | public GridInfoService(IConfigSource configSource) |
58 | { | 58 | { |
59 | loadGridInfo(configSource); | 59 | loadGridInfo(configSource); |
60 | } | 60 | } |
61 | 61 | ||
62 | /// <summary> | 62 | /// <summary> |
63 | /// Default constructor, uses OpenSim.ini. | 63 | /// Default constructor, uses OpenSim.ini. |
64 | /// </summary> | 64 | /// </summary> |
65 | public GridInfoService() | 65 | public GridInfoService() |
66 | { | 66 | { |
67 | try | 67 | try |
68 | { | 68 | { |
69 | IConfigSource configSource = new IniConfigSource(Path.Combine(Util.configDir(), "OpenSim.ini")); | 69 | IConfigSource configSource = new IniConfigSource(Path.Combine(Util.configDir(), "OpenSim.ini")); |
70 | loadGridInfo(configSource); | 70 | loadGridInfo(configSource); |
71 | } | 71 | } |
72 | catch (FileNotFoundException) | 72 | catch (FileNotFoundException) |
73 | { | 73 | { |
74 | _log.Warn("[GridInfoService] no OpenSim.ini file found --- GridInfoServices WILL NOT BE AVAILABLE to your users"); | 74 | _log.Warn("[GridInfoService] no OpenSim.ini file found --- GridInfoServices WILL NOT BE AVAILABLE to your users"); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | private void loadGridInfo(IConfigSource configSource) | 78 | private void loadGridInfo(IConfigSource configSource) |
79 | { | 79 | { |
80 | _info["platform"] = "OpenSim"; | 80 | _info["platform"] = "OpenSim"; |
81 | try | 81 | try |
82 | { | 82 | { |
83 | IConfig startupCfg = configSource.Configs["Startup"]; | 83 | IConfig startupCfg = configSource.Configs["Startup"]; |
84 | IConfig gridCfg = configSource.Configs["GridInfo"]; | 84 | IConfig gridCfg = configSource.Configs["GridInfo"]; |
85 | IConfig netCfg = configSource.Configs["Network"]; | 85 | IConfig netCfg = configSource.Configs["Network"]; |
86 | 86 | ||
87 | bool grid = startupCfg.GetBoolean("gridmode", false); | 87 | bool grid = startupCfg.GetBoolean("gridmode", false); |
88 | 88 | ||
89 | if (grid) | 89 | if (grid) |
90 | _info["mode"] = "grid"; | 90 | _info["mode"] = "grid"; |
91 | else | 91 | else |
92 | _info["mode"] = "standalone"; | 92 | _info["mode"] = "standalone"; |
93 | 93 | ||
94 | 94 | ||
95 | if (null != gridCfg) | 95 | if (null != gridCfg) |
96 | { | 96 | { |
97 | foreach (string k in gridCfg.GetKeys()) | 97 | foreach (string k in gridCfg.GetKeys()) |
98 | { | 98 | { |
99 | _info[k] = gridCfg.GetString(k); | 99 | _info[k] = gridCfg.GetString(k); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | else if (null != netCfg) | 102 | else if (null != netCfg) |
103 | { | 103 | { |
104 | if (grid) | 104 | if (grid) |
105 | _info["login"] | 105 | _info["login"] |
106 | = netCfg.GetString( | 106 | = netCfg.GetString( |
107 | "user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString()); | 107 | "user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString()); |
108 | else | 108 | else |
109 | _info["login"] | 109 | _info["login"] |
110 | = String.Format( | 110 | = String.Format( |
111 | "http://127.0.0.1:{0}/", | 111 | "http://127.0.0.1:{0}/", |
112 | netCfg.GetString( | 112 | netCfg.GetString( |
113 | "http_listener_port", NetworkServersInfo.DefaultHttpListenerPort.ToString())); | 113 | "http_listener_port", NetworkServersInfo.DefaultHttpListenerPort.ToString())); |
114 | 114 | ||
115 | IssueWarning(); | 115 | IssueWarning(); |
116 | } | 116 | } |
117 | else | 117 | else |
118 | { | 118 | { |
119 | _info["login"] = "http://127.0.0.1:9000/"; | 119 | _info["login"] = "http://127.0.0.1:9000/"; |
120 | IssueWarning(); | 120 | IssueWarning(); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | catch (Exception) | 123 | catch (Exception) |
124 | { | 124 | { |
125 | _log.Debug("[GridInfoService] cannot get grid info from config source, using minimal defaults"); | 125 | _log.Debug("[GridInfoService] cannot get grid info from config source, using minimal defaults"); |
126 | } | 126 | } |
127 | _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); | 127 | _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); |
128 | 128 | ||
129 | } | 129 | } |
130 | 130 | ||
131 | private void IssueWarning() | 131 | private void IssueWarning() |
132 | { | 132 | { |
133 | _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini"); | 133 | _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini"); |
134 | _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:"); | 134 | _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:"); |
135 | foreach (string k in _info.Keys) | 135 | foreach (string k in _info.Keys) |
136 | { | 136 | { |
137 | _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]); | 137 | _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) | 141 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) |
142 | { | 142 | { |
143 | XmlRpcResponse response = new XmlRpcResponse(); | 143 | XmlRpcResponse response = new XmlRpcResponse(); |
144 | Hashtable responseData = new Hashtable(); | 144 | Hashtable responseData = new Hashtable(); |
145 | 145 | ||
146 | _log.Info("[GridInfo]: Request for grid info"); | 146 | _log.Info("[GridInfo]: Request for grid info"); |
147 | 147 | ||
148 | foreach (string k in _info.Keys) | 148 | foreach (string k in _info.Keys) |
149 | { | 149 | { |
150 | responseData[k] = _info[k]; | 150 | responseData[k] = _info[k]; |
151 | } | 151 | } |
152 | response.Value = responseData; | 152 | response.Value = responseData; |
153 | 153 | ||
154 | return response; | 154 | return response; |
155 | } | 155 | } |
156 | 156 | ||
157 | public string RestGetGridInfoMethod(string request, string path, string param, | 157 | public string RestGetGridInfoMethod(string request, string path, string param, |
158 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 158 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
159 | { | 159 | { |
160 | StringBuilder sb = new StringBuilder(); | 160 | StringBuilder sb = new StringBuilder(); |
161 | 161 | ||
162 | sb.Append("<gridinfo>\n"); | 162 | sb.Append("<gridinfo>\n"); |
163 | foreach (string k in _info.Keys) | 163 | foreach (string k in _info.Keys) |
164 | { | 164 | { |
165 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]); | 165 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]); |
166 | } | 166 | } |
167 | sb.Append("</gridinfo>\n"); | 167 | sb.Append("</gridinfo>\n"); |
168 | 168 | ||
169 | return sb.ToString(); | 169 | return sb.ToString(); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | } | 172 | } |