aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
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
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 'OpenSim')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs184
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs34
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs76
-rw-r--r--OpenSim/ApplicationPlugins/Rest/RestPlugin.cs74
4 files changed, 288 insertions, 80 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs
new file mode 100644
index 0000000..2b006e0
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs
@@ -0,0 +1,184 @@
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 OpenSim 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
29using System;
30using System.Threading;
31using System.Collections;
32using System.Collections.Generic;
33using System.IO;
34using System.Net;
35using System.Reflection;
36using System.Text.RegularExpressions;
37using System.Timers;
38using System.Xml;
39using System.Xml.Serialization;
40using libsecondlife;
41using Mono.Addins;
42using Nwc.XmlRpc;
43using Nini.Config;
44using OpenSim.Framework;
45using OpenSim.Framework.Console;
46using OpenSim.Framework.Servers;
47using OpenSim.Framework.Communications;
48using OpenSim.Region.Environment.Scenes;
49using OpenSim.ApplicationPlugins.Rest;
50
51namespace OpenSim.ApplicationPlugins.Rest.Regions
52{
53
54 public partial class RestRegionPlugin : RestPlugin
55 {
56 #region GET methods
57 public string GetHandler(string request, string path, string param)
58 {
59 m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param);
60
61 try
62 {
63 // param empty: regions list
64 if (String.IsNullOrEmpty(param)) return GetHandlerRegions();
65
66 // param not empty: specific region
67 return GetHandlerRegion(param);
68 }
69 catch (Exception e)
70 {
71 return Failure("GET", e);
72 }
73 }
74
75 public string GetHandlerRegions()
76 {
77 XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
78 foreach (Scene s in App.SceneManager.Scenes)
79 {
80 XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty);
81 XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
82 XmlWriter.WriteEndElement();
83 }
84 XmlWriter.WriteEndElement();
85
86 return XmlWriterResult;
87 }
88
89 protected string ShortRegionInfo(string key, string value)
90 {
91 if (String.IsNullOrEmpty(value) ||
92 String.IsNullOrEmpty(key)) return null;
93
94 XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
95 XmlWriter.WriteStartElement(String.Empty, key, String.Empty);
96 XmlWriter.WriteString(value);
97 XmlWriter.WriteEndDocument();
98
99 return XmlWriterResult;
100 }
101
102 public string GetHandlerRegion(string param)
103 {
104 // be resilient and don't get confused by a terminating '/'
105 param = param.TrimEnd(new char[]{'/'});
106 string[] comps = param.Split('/');
107 LLUUID regionID = (LLUUID)comps[0];
108
109 m_log.DebugFormat("{0} GET region UUID {1}", MsgID, regionID.ToString());
110
111 if (LLUUID.Zero == regionID) throw new Exception("missing region ID");
112
113 Scene scene = null;
114 App.SceneManager.TryGetScene(regionID, out scene);
115 if (null == scene) return Failure("GET", "cannot find region");
116
117 RegionDetails details = new RegionDetails(scene.RegionInfo);
118
119 // m_log.DebugFormat("{0} GET comps {1}", MsgID, comps.Length);
120 // for (int i = 0; i < comps.Length; i++) m_log.DebugFormat("{0} GET comps[{1}] >{2}<", MsgID, i, comps[i]);
121
122 if (1 == comps.Length)
123 {
124 // complete region details requested
125 XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
126 xs.Serialize(XmlWriter, details);
127 return XmlWriterResult;
128 }
129
130 if (2 == comps.Length) {
131 string resp = ShortRegionInfo(comps[1], details[comps[1]]);
132 if (null != resp) return resp;
133
134 // m_log.DebugFormat("{0} GET comps advanced: >{1}<", MsgID, comps[1]);
135
136 // check for {terrain,stats,prims}
137 switch (comps[1].ToLower())
138 {
139 case "terrain":
140 return RegionTerrain(scene);
141
142 case "stats":
143 return RegionStats(scene);
144
145 case "prims":
146 return RegionPrims(scene);
147 }
148 }
149 return Failure("GET", "too many parameters");
150 }
151 #endregion GET methods
152
153 protected string RegionTerrain(Scene scene)
154 {
155 return Failure("GET", "terrain not implemented");
156 }
157
158 protected string RegionStats(Scene scene)
159 {
160 int users = scene.GetAvatars().Count;
161 int objects = scene.Entities.Count - users;
162
163 XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
164 XmlWriter.WriteStartElement(String.Empty, "stats", String.Empty);
165
166 XmlWriter.WriteStartElement(String.Empty, "users", String.Empty);
167 XmlWriter.WriteString(users.ToString());
168 XmlWriter.WriteEndElement();
169
170 XmlWriter.WriteStartElement(String.Empty, "objects", String.Empty);
171 XmlWriter.WriteString(objects.ToString());
172 XmlWriter.WriteEndElement();
173
174 XmlWriter.WriteEndDocument();
175
176 return XmlWriterResult;
177 }
178
179 protected string RegionPrims(Scene scene)
180 {
181 return Failure("GET", "prims not implemented");
182 }
183 }
184}
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs
index 5102e3f..c86c67f 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs
@@ -23,7 +23,7 @@
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 libsecondlife; 29using libsecondlife;
@@ -65,8 +65,38 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
65 region_external_hostname = regInfo.ExternalHostName; 65 region_external_hostname = regInfo.ExternalHostName;
66 66
67 if (!String.IsNullOrEmpty(regInfo.MasterAvatarFirstName)) 67 if (!String.IsNullOrEmpty(regInfo.MasterAvatarFirstName))
68 region_owner = String.Format("{0} {1}", regInfo.MasterAvatarFirstName, 68 region_owner = String.Format("{0} {1}", regInfo.MasterAvatarFirstName,
69 regInfo.MasterAvatarLastName); 69 regInfo.MasterAvatarLastName);
70 } 70 }
71
72 public string this[string idx]
73 {
74 get
75 {
76 switch(idx.ToLower())
77 {
78 case "name":
79 return region_name;
80 case "id":
81 return region_id;
82 case "location":
83 return String.Format("<x>{0}</x><y>{1}</y>", region_x, region_y);
84 case "owner":
85 return region_owner;
86 case "owner_id":
87 return region_owner_id;
88 case "http_port":
89 return region_http_port.ToString();
90 case "server_uri":
91 return region_server_uri;
92 case "external_hostname":
93 case "hostname":
94 return region_external_hostname;
95
96 default:
97 return null;
98 }
99 }
100 }
71 } 101 }
72} \ No newline at end of file 102} \ No newline at end of file
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
index 0716cf6..9b888fa 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
@@ -23,7 +23,7 @@
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;
@@ -55,14 +55,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
55{ 55{
56 56
57 [Extension("/OpenSim/Startup")] 57 [Extension("/OpenSim/Startup")]
58 public class RestRegionPlugin : RestPlugin 58 public partial class RestRegionPlugin : RestPlugin
59 { 59 {
60 private static readonly log4net.ILog _log =
61 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62
63 #region overriding properties 60 #region overriding properties
64 public override string Name 61 public override string Name
65 { 62 {
66 get { return "REGION"; } 63 get { return "REGION"; }
67 } 64 }
68 65
@@ -86,18 +83,20 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
86 try 83 try
87 { 84 {
88 base.Initialise(openSim); 85 base.Initialise(openSim);
89 if (IsEnabled) 86 if (!IsEnabled)
90 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID); 87 {
91 else
92 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID); 88 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
89 return;
90 }
91 m_log.InfoFormat("{0} REST region plugin enabled", MsgID);
93 92
94 // add REST method handlers 93 // add REST method handlers
95 AddRestStreamHandler("GET", "/regions/", GetHandler); 94 AddRestStreamHandler("GET", "/regions/", GetHandler);
96 } 95 }
97 catch (Exception e) 96 catch (Exception e)
98 { 97 {
99 _log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message); 98 m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
100 _log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString()); 99 m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
101 } 100 }
102 } 101 }
103 102
@@ -105,58 +104,5 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
105 { 104 {
106 } 105 }
107 #endregion overriding methods 106 #endregion overriding methods
108
109 #region methods
110 public string GetHandler(string request, string path, string param)
111 {
112 m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param);
113
114 // param empty: regions list
115 if (String.IsNullOrEmpty(param)) return GetHandlerRegions();
116
117 return GetHandlerRegion(param);
118 }
119
120 public string GetHandlerRegions()
121 {
122 StringWriter sw = new StringWriter();
123 XmlTextWriter xw = new XmlTextWriter(sw);
124 xw.Formatting = Formatting.Indented;
125
126 xw.WriteStartElement(String.Empty, "regions", String.Empty);
127 foreach (Scene s in App.SceneManager.Scenes)
128 {
129 xw.WriteStartElement(String.Empty, "uuid", String.Empty);
130 xw.WriteString(s.RegionInfo.RegionID.ToString());
131 xw.WriteEndElement();
132 }
133 xw.WriteEndElement();
134 xw.Close();
135
136 return sw.ToString();
137 }
138
139 public string GetHandlerRegion(string param)
140 {
141 string[] comps = param.Split('/');
142 LLUUID regionID = (LLUUID)comps[0];
143 _log.DebugFormat("{0} region UUID {1}", MsgID, regionID.ToString());
144
145 if (LLUUID.Zero == regionID) throw new Exception("missing region ID");
146
147 Scene scene = null;
148 App.SceneManager.TryGetScene(regionID, out scene);
149
150 XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
151 StringWriter sw = new StringWriter();
152 XmlTextWriter xw = new XmlTextWriter(sw);
153 xw.Formatting = Formatting.Indented;
154
155 xs.Serialize(xw, new RegionDetails(scene.RegionInfo));
156 xw.Close();
157
158 return sw.ToString();
159 }
160 #endregion methods
161 } 107 }
162} 108}
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}