aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
diff options
context:
space:
mode:
authorDr Scofield2008-05-19 11:52:51 +0000
committerDr Scofield2008-05-19 11:52:51 +0000
commit4e93228e25a941dde4b01c4ec934cd1907096a6f (patch)
tree8c7a7d1f36bbc55c834bc52b5fe1d0582f648c87 /OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
parentadding OSHttpRequest and OSHttpResponse which wrap HttpListenerRequest and Ht... (diff)
downloadopensim-SC_OLD-4e93228e25a941dde4b01c4ec934cd1907096a6f.zip
opensim-SC_OLD-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.gz
opensim-SC_OLD-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.bz2
opensim-SC_OLD-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.xz
fixing exception when RestPlugin not configured. refactors RestRegionPlugin, adds error checking.
Diffstat (limited to '')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/RestPlugin.cs74
1 files changed, 61 insertions, 13 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
index 05ea956..199bff8 100644
--- a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
@@ -23,16 +23,18 @@
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 28
29using System; 29using System;
30using System.Threading; 30using System.Threading;
31using System.Collections; 31using System.Collections;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.IO;
33using System.Net; 34using System.Net;
34using System.Reflection; 35using System.Reflection;
35using System.Timers; 36using System.Timers;
37using System.Xml;
36using libsecondlife; 38using libsecondlife;
37using Mono.Addins; 39using Mono.Addins;
38using Nwc.XmlRpc; 40using Nwc.XmlRpc;
@@ -54,14 +56,18 @@ namespace OpenSim.ApplicationPlugins.Rest
54 { 56 {
55 #region properties 57 #region properties
56 58
57 protected static readonly log4net.ILog m_log = 59 protected static readonly log4net.ILog m_log =
58 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 60 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 61
60 private IConfig _config; // Configuration source: Rest Plugins 62 private IConfig _config; // Configuration source: Rest Plugins
61 private IConfig _pluginConfig; // Configuration source: Plugin specific 63 private IConfig _pluginConfig; // Configuration source: Plugin specific
62 private OpenSimMain _app; // The 'server' 64 private OpenSimMain _app; // The 'server'
63 private BaseHttpServer _httpd; // The server's RPC interface 65 private BaseHttpServer _httpd; // The server's RPC interface
64 private string _prefix; // URL prefix below which all REST URLs are living 66 private string _prefix; // URL prefix below
67 // which all REST URLs
68 // are living
69 private StringWriter _sw = null;
70 private XmlTextWriter _xw = null;
65 71
66 private string _godkey; 72 private string _godkey;
67 private int _reqk; 73 private int _reqk;
@@ -100,8 +106,8 @@ namespace OpenSim.ApplicationPlugins.Rest
100 /// </summary> 106 /// </summary>
101 public bool IsEnabled 107 public bool IsEnabled
102 { 108 {
103 get 109 get
104 { 110 {
105 return (null != _pluginConfig) && _pluginConfig.GetBoolean("enabled", false); 111 return (null != _pluginConfig) && _pluginConfig.GetBoolean("enabled", false);
106 } 112 }
107 } 113 }
@@ -109,7 +115,7 @@ namespace OpenSim.ApplicationPlugins.Rest
109 /// <summary> 115 /// <summary>
110 /// OpenSimMain application 116 /// OpenSimMain application
111 /// </summary> 117 /// </summary>
112 public OpenSimMain App 118 public OpenSimMain App
113 { 119 {
114 get { return _app; } 120 get { return _app; }
115 } 121 }
@@ -117,7 +123,7 @@ namespace OpenSim.ApplicationPlugins.Rest
117 /// <summary> 123 /// <summary>
118 /// RPC server 124 /// RPC server
119 /// </summary> 125 /// </summary>
120 public BaseHttpServer HttpServer 126 public BaseHttpServer HttpServer
121 { 127 {
122 get { return _httpd; } 128 get { return _httpd; }
123 } 129 }
@@ -147,6 +153,29 @@ namespace OpenSim.ApplicationPlugins.Rest
147 /// Return the config section name 153 /// Return the config section name
148 /// </summary> 154 /// </summary>
149 public abstract string ConfigName { get; } 155 public abstract string ConfigName { get; }
156
157 public XmlTextWriter XmlWriter
158 {
159 get {
160 if (null == _xw)
161 {
162 _sw = new StringWriter();
163 _xw = new XmlTextWriter(_sw);
164 _xw.Formatting = Formatting.Indented;
165 }
166 return _xw; }
167 }
168
169 public string XmlWriterResult
170 {
171 get
172 {
173 _xw.Flush();
174 _xw = null;
175
176 return _sw.ToString();
177 }
178 }
150 #endregion properties 179 #endregion properties
151 180
152 181
@@ -171,7 +200,7 @@ namespace OpenSim.ApplicationPlugins.Rest
171 return; 200 return;
172 } 201 }
173 202
174 if (!_config.GetBoolean("enabled", false)) 203 if (!_config.GetBoolean("enabled", false))
175 { 204 {
176 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID); 205 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
177 return; 206 return;
@@ -184,10 +213,11 @@ namespace OpenSim.ApplicationPlugins.Rest
184 _godkey = _config.GetString("god_key", String.Empty); 213 _godkey = _config.GetString("god_key", String.Empty);
185 // Retrive prefix if any. 214 // Retrive prefix if any.
186 _prefix = _config.GetString("prefix", "/admin"); 215 _prefix = _config.GetString("prefix", "/admin");
187 216
188 // Get plugin specific config 217 // Get plugin specific config
189 _pluginConfig = openSim.ConfigSource.Configs[ConfigName]; 218 _pluginConfig = openSim.ConfigSource.Configs[ConfigName];
190 219
220
191 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID); 221 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID);
192 } 222 }
193 catch (Exception e) 223 catch (Exception e)
@@ -200,7 +230,7 @@ namespace OpenSim.ApplicationPlugins.Rest
200 // not possible for the openSim pointer to be null. However 230 // not possible for the openSim pointer to be null. However
201 // were the implementation to be changed, this could 231 // were the implementation to be changed, this could
202 // result in a silent initialization failure. Harmless 232 // result in a silent initialization failure. Harmless
203 // except for lack of function and lack of any 233 // except for lack of function and lack of any
204 // diagnostic indication as to why. The same is true if 234 // diagnostic indication as to why. The same is true if
205 // the HTTP server reference is bad. 235 // the HTTP server reference is bad.
206 // We should at least issue a message... 236 // We should at least issue a message...
@@ -214,7 +244,9 @@ namespace OpenSim.ApplicationPlugins.Rest
214 244
215 public void AddRestStreamHandler(string httpMethod, string path, RestMethod method) 245 public void AddRestStreamHandler(string httpMethod, string path, RestMethod method)
216 { 246 {
217 if (!path.StartsWith(_prefix)) 247 if (!IsEnabled) return;
248
249 if (!path.StartsWith(_prefix))
218 { 250 {
219 path = String.Format("{0}{1}", _prefix, path); 251 path = String.Format("{0}{1}", _prefix, path);
220 } 252 }
@@ -226,10 +258,12 @@ namespace OpenSim.ApplicationPlugins.Rest
226 m_log.DebugFormat("{0} Added REST handler {1} {2}", MsgID, httpMethod, path); 258 m_log.DebugFormat("{0} Added REST handler {1} {2}", MsgID, httpMethod, path);
227 } 259 }
228 260
229 261
230 public bool VerifyGod(string key) 262 protected bool VerifyGod(string key)
231 { 263 {
232 if (String.IsNullOrEmpty(key)) return false; 264 if (String.IsNullOrEmpty(key)) return false;
265 if (!IsEnabled) return false;
266
233 return key == _godkey; 267 return key == _godkey;
234 } 268 }
235 269
@@ -241,6 +275,20 @@ namespace OpenSim.ApplicationPlugins.Rest
241 } 275 }
242 _handlers = null; 276 _handlers = null;
243 } 277 }
278
279 protected string Failure(string method, string message)
280 {
281 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, message);
282 return String.Format("<error>{0}</error>", message);
283 }
284
285 public string Failure(string method, Exception e)
286 {
287 m_log.DebugFormat("{0} {1} failed: {2}", MsgID, method, e.ToString());
288 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, e.Message);
289
290 return String.Format("<error>{0}</error>", e.Message);
291 }
244 #endregion methods 292 #endregion methods
245 } 293 }
246} 294}