diff options
author | Dr Scofield | 2008-05-20 16:51:45 +0000 |
---|---|---|
committer | Dr Scofield | 2008-05-20 16:51:45 +0000 |
commit | a53cea6b7e4094ea51339c80ab5fe160a19a9f6b (patch) | |
tree | 7294600ad7bbec50ff34e35b1c46a380d2d7d549 /OpenSim/ApplicationPlugins/Rest/RestPlugin.cs | |
parent | From: Jeremy Bongio <jbongio@us.ibm.com> (diff) | |
download | opensim-SC_OLD-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.zip opensim-SC_OLD-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.tar.gz opensim-SC_OLD-a53cea6b7e4094ea51339c80ab5fe160a19a9f6b.tar.bz2 opensim-SC_OLD-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/Rest/RestPlugin.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/RestPlugin.cs | 58 |
1 files changed, 54 insertions, 4 deletions
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()); |