aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins
diff options
context:
space:
mode:
authorDr Scofield2008-05-20 16:51:45 +0000
committerDr Scofield2008-05-20 16:51:45 +0000
commita53cea6b7e4094ea51339c80ab5fe160a19a9f6b (patch)
tree7294600ad7bbec50ff34e35b1c46a380d2d7d549 /OpenSim/ApplicationPlugins
parentFrom: Jeremy Bongio <jbongio@us.ibm.com> (diff)
downloadopensim-SC-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.zip
opensim-SC-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.tar.gz
opensim-SC-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.tar.bz2
opensim-SC-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.tar.xz
i'm extending the RestStreamHandler.Handler(...) signature to actually
provide OSHttpRequest and OSHttpResponse to our REST handler. also, this adds proper RestPlugin.IsGod() checking against the X-OpenSim-Godkey HTTP request header. last, i added XML doc comments to RestPlugin.cs
Diffstat (limited to 'OpenSim/ApplicationPlugins')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs10
-rw-r--r--OpenSim/ApplicationPlugins/Rest/RestPlugin.cs58
2 files changed, 62 insertions, 6 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs
index 2b006e0..a319a8b 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETRestRegionPlugin.cs
@@ -54,10 +54,16 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
54 public partial class RestRegionPlugin : RestPlugin 54 public partial class RestRegionPlugin : RestPlugin
55 { 55 {
56 #region GET methods 56 #region GET methods
57 public string GetHandler(string request, string path, string param) 57 public string GetHandler(string request, string path, string param,
58 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
58 { 59 {
60 // foreach (string h in httpRequest.Headers.AllKeys)
61 // foreach (string v in httpRequest.Headers.GetValues(h))
62 // m_log.DebugFormat("{0} IsGod: {1} -> {2}", MsgID, h, v);
63
64 MsgID = RequestID;
59 m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param); 65 m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param);
60 66
61 try 67 try
62 { 68 {
63 // param empty: regions list 69 // param empty: regions list
diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
index 8c370ed..4b8cdc1 100644
--- a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
@@ -240,9 +240,15 @@ namespace OpenSim.ApplicationPlugins.Rest
240 } 240 }
241 } 241 }
242 242
243
244 private List<RestStreamHandler> _handlers = new List<RestStreamHandler>(); 243 private List<RestStreamHandler> _handlers = new List<RestStreamHandler>();
245 244
245 /// <summary>
246 /// Add a REST stream handler to the underlying HTTP server.
247 /// </summary>
248 /// <param name="httpMethod">GET/PUT/POST/DELETE or
249 /// similar</param>
250 /// <param name="path">URL prefix</param>
251 /// <param name="method">RestMethod handler doing the actual work</param>
246 public virtual void AddRestStreamHandler(string httpMethod, string path, RestMethod method) 252 public virtual void AddRestStreamHandler(string httpMethod, string path, RestMethod method)
247 { 253 {
248 if (!IsEnabled) return; 254 if (!IsEnabled) return;
@@ -259,20 +265,50 @@ namespace OpenSim.ApplicationPlugins.Rest
259 m_log.DebugFormat("{0} Added REST handler {1} {2}", MsgID, httpMethod, path); 265 m_log.DebugFormat("{0} Added REST handler {1} {2}", MsgID, httpMethod, path);
260 } 266 }
261 267
262 public bool AddAgentHandler(string agentname, IHttpAgentHandler handler) 268 /// <summary>
269 /// Add a powerful Agent handler to the underlying HTTP
270 /// server.
271 /// </summary>
272 /// <param name="agentName">name of agent handler</param>
273 /// <param name="handler">agent handler method</param>
274 /// <returns>true when the plugin is disabled or the agent
275 /// handler could not be added..</returns>
276 public bool AddAgentHandler(string agentName, IHttpAgentHandler handler)
263 { 277 {
264 if (!IsEnabled) return false; 278 if (!IsEnabled) return false;
265 return _httpd.AddAgentHandler(agentname, handler); 279 return _httpd.AddAgentHandler(agentName, handler);
266 } 280 }
267 281
282 /// <summary>
283 /// Check whether the HTTP request came from god; that is, is
284 /// the god_key as configured in the config section supplied
285 /// via X-OpenSim-Godkey?
286 /// </summary>
287 /// <param name="request">HTTP request header</param>
288 /// <returns>true when the HTTP request came from god.</returns>
268 protected bool IsGod(OSHttpRequest request) 289 protected bool IsGod(OSHttpRequest request)
269 { 290 {
270 string[] keys = request.Headers.GetValues("x-opensim-godkey"); 291 string[] keys = request.Headers.GetValues("X-OpenSim-Godkey");
271 if (null == keys) return false; 292 if (null == keys) return false;
293
272 // we take the last key supplied 294 // we take the last key supplied
273 return keys[keys.Length-1] == _godkey; 295 return keys[keys.Length-1] == _godkey;
274 } 296 }
275 297
298 /// <summary>
299 /// Checks wether the X-OpenSim-Password value provided in the
300 /// HTTP header is indeed the password on file for the avatar
301 /// specified by the UUID
302 /// </summary>
303 protected bool IsVerifiedUser(OSHttpRequest request, LLUUID uuid)
304 {
305 // XXX under construction
306 return false;
307 }
308
309 /// <summary>
310 /// Clean up and remove all handlers that were added earlier.
311 /// </summary>
276 public virtual void Close() 312 public virtual void Close()
277 { 313 {
278 foreach (RestStreamHandler h in _handlers) 314 foreach (RestStreamHandler h in _handlers)
@@ -282,12 +318,26 @@ namespace OpenSim.ApplicationPlugins.Rest
282 _handlers = null; 318 _handlers = null;
283 } 319 }
284 320
321 /// <summary>
322 /// Return a failure message.
323 /// </summary>
324 /// <param name="method">origin of the failure message</param>
325 /// <param name="message>failure message</param>
326 /// <remarks>This should probably set a return code as
327 /// well. (?)</remarks>
285 protected string Failure(string method, string message) 328 protected string Failure(string method, string message)
286 { 329 {
287 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, message); 330 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, message);
288 return String.Format("<error>{0}</error>", message); 331 return String.Format("<error>{0}</error>", message);
289 } 332 }
290 333
334 /// <summary>
335 /// Return a failure message.
336 /// </summary>
337 /// <param name="method">origin of the failure message</param>
338 /// <param name="e">exception causing the failure message</param>
339 /// <remarks>This should probably set a return code as
340 /// well. (?)</remarks>
291 public string Failure(string method, Exception e) 341 public string Failure(string method, Exception e)
292 { 342 {
293 m_log.DebugFormat("{0} {1} failed: {2}", MsgID, method, e.ToString()); 343 m_log.DebugFormat("{0} {1} failed: {2}", MsgID, method, e.ToString());