diff options
author | Jeff Ames | 2008-08-18 00:39:10 +0000 |
---|---|---|
committer | Jeff Ames | 2008-08-18 00:39:10 +0000 |
commit | 6ef9d4da901a346c232458317cca6268da888e2e (patch) | |
tree | dd1d935b10f34f261839da9f9879c02322e8ede7 /OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs | |
parent | Update svn properties, minor formatting cleanup. (diff) | |
download | opensim-SC_OLD-6ef9d4da901a346c232458317cca6268da888e2e.zip opensim-SC_OLD-6ef9d4da901a346c232458317cca6268da888e2e.tar.gz opensim-SC_OLD-6ef9d4da901a346c232458317cca6268da888e2e.tar.bz2 opensim-SC_OLD-6ef9d4da901a346c232458317cca6268da888e2e.tar.xz |
Formatting cleanup.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs index 7bd83c1..7f4157c 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs | |||
@@ -23,7 +23,6 @@ | |||
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 | * | ||
27 | */ | 26 | */ |
28 | 27 | ||
29 | using System; | 28 | using System; |
@@ -37,7 +36,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
37 | { | 36 | { |
38 | public class RestHandler : RestPlugin, IHttpAgentHandler | 37 | public class RestHandler : RestPlugin, IHttpAgentHandler |
39 | { | 38 | { |
40 | |||
41 | /// <remarks> | 39 | /// <remarks> |
42 | /// The handler delegates are not noteworthy. The allocator allows | 40 | /// The handler delegates are not noteworthy. The allocator allows |
43 | /// a given handler to optionally subclass the base RequestData | 41 | /// a given handler to optionally subclass the base RequestData |
@@ -66,10 +64,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
66 | /// <summary> | 64 | /// <summary> |
67 | /// This static initializer scans the ASSEMBLY for classes that | 65 | /// This static initializer scans the ASSEMBLY for classes that |
68 | /// export the IRest interface and builds a list of them. These | 66 | /// export the IRest interface and builds a list of them. These |
69 | /// are later activated by the handler. To add a new handler it | 67 | /// are later activated by the handler. To add a new handler it |
70 | /// is only necessary to create a new services class that implements | 68 | /// is only necessary to create a new services class that implements |
71 | /// the IRest interface, and recompile the handler. This gives | 69 | /// the IRest interface, and recompile the handler. This gives |
72 | /// all of the build-time flexibility of a modular approach | 70 | /// all of the build-time flexibility of a modular approach |
73 | /// while not introducing yet-another module loader. Note that | 71 | /// while not introducing yet-another module loader. Note that |
74 | /// multiple assembles can still be built, each with its own set | 72 | /// multiple assembles can still be built, each with its own set |
75 | /// of handlers. Examples of services classes are RestInventoryServices | 73 | /// of handlers. Examples of services classes are RestInventoryServices |
@@ -78,13 +76,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
78 | 76 | ||
79 | static RestHandler() | 77 | static RestHandler() |
80 | { | 78 | { |
81 | |||
82 | Module[] mods = Assembly.GetExecutingAssembly().GetModules(); | 79 | Module[] mods = Assembly.GetExecutingAssembly().GetModules(); |
83 | 80 | ||
84 | foreach (Module m in mods) | 81 | foreach (Module m in mods) |
85 | { | 82 | { |
86 | Type[] types = m.GetTypes(); | 83 | Type[] types = m.GetTypes(); |
87 | foreach (Type t in types) | 84 | foreach (Type t in types) |
88 | { | 85 | { |
89 | try | 86 | try |
90 | { | 87 | { |
@@ -100,7 +97,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
100 | } | 97 | } |
101 | } | 98 | } |
102 | } | 99 | } |
103 | |||
104 | } | 100 | } |
105 | 101 | ||
106 | #endregion local static state | 102 | #endregion local static state |
@@ -109,13 +105,13 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
109 | 105 | ||
110 | /// <summary> | 106 | /// <summary> |
111 | /// This routine loads all of the handlers discovered during | 107 | /// This routine loads all of the handlers discovered during |
112 | /// instance initialization. | 108 | /// instance initialization. |
113 | /// A table of all loaded and successfully constructed handlers | 109 | /// A table of all loaded and successfully constructed handlers |
114 | /// is built, and this table is then used by the constructor to | 110 | /// is built, and this table is then used by the constructor to |
115 | /// initialize each of the handlers in turn. | 111 | /// initialize each of the handlers in turn. |
116 | /// NOTE: The loading process does not automatically imply that | 112 | /// NOTE: The loading process does not automatically imply that |
117 | /// the handler has registered any kind of an interface, that | 113 | /// the handler has registered any kind of an interface, that |
118 | /// may be (optionally) done by the handler either during | 114 | /// may be (optionally) done by the handler either during |
119 | /// construction, or during initialization. | 115 | /// construction, or during initialization. |
120 | /// | 116 | /// |
121 | /// I was not able to make this code work within a constructor | 117 | /// I was not able to make this code work within a constructor |
@@ -128,7 +124,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
128 | { | 124 | { |
129 | if (!handlersLoaded) | 125 | if (!handlersLoaded) |
130 | { | 126 | { |
131 | |||
132 | ConstructorInfo ci; | 127 | ConstructorInfo ci; |
133 | Object ht; | 128 | Object ht; |
134 | 129 | ||
@@ -159,8 +154,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
159 | 154 | ||
160 | // Name is used to differentiate the message header. | 155 | // Name is used to differentiate the message header. |
161 | 156 | ||
162 | public override string Name | 157 | public override string Name |
163 | { | 158 | { |
164 | get { return "HANDLER"; } | 159 | get { return "HANDLER"; } |
165 | } | 160 | } |
166 | 161 | ||
@@ -173,7 +168,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
173 | 168 | ||
174 | // We have to rename these because we want | 169 | // We have to rename these because we want |
175 | // to be able to share the values with other | 170 | // to be able to share the values with other |
176 | // classes in our assembly and the base | 171 | // classes in our assembly and the base |
177 | // names are protected. | 172 | // names are protected. |
178 | 173 | ||
179 | internal string MsgId | 174 | internal string MsgId |
@@ -203,7 +198,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
203 | { | 198 | { |
204 | try | 199 | try |
205 | { | 200 | { |
206 | |||
207 | // This plugin will only be enabled if the broader | 201 | // This plugin will only be enabled if the broader |
208 | // REST plugin mechanism is enabled. | 202 | // REST plugin mechanism is enabled. |
209 | 203 | ||
@@ -214,7 +208,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
214 | // IsEnabled is implemented by the base class and | 208 | // IsEnabled is implemented by the base class and |
215 | // reflects an overall RestPlugin status | 209 | // reflects an overall RestPlugin status |
216 | 210 | ||
217 | if (!IsEnabled) | 211 | if (!IsEnabled) |
218 | { | 212 | { |
219 | Rest.Log.WarnFormat("{0} Plugins are disabled", MsgId); | 213 | Rest.Log.WarnFormat("{0} Plugins are disabled", MsgId); |
220 | return; | 214 | return; |
@@ -263,15 +257,15 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
263 | Rest.DumpLineSize); | 257 | Rest.DumpLineSize); |
264 | } | 258 | } |
265 | 259 | ||
266 | // Load all of the handlers present in the | 260 | // Load all of the handlers present in the |
267 | // assembly | 261 | // assembly |
268 | 262 | ||
269 | // In principle, as we're an application plug-in, | 263 | // In principle, as we're an application plug-in, |
270 | // most of what needs to be done could be done using | 264 | // most of what needs to be done could be done using |
271 | // static resources, however the Open Sim plug-in | 265 | // static resources, however the Open Sim plug-in |
272 | // model makes this an instance, so that's what we | 266 | // model makes this an instance, so that's what we |
273 | // need to be. | 267 | // need to be. |
274 | // There is only one Communications manager per | 268 | // There is only one Communications manager per |
275 | // server, and by inference, only one each of the | 269 | // server, and by inference, only one each of the |
276 | // user, asset, and inventory servers. So we can cache | 270 | // user, asset, and inventory servers. So we can cache |
277 | // those using a static initializer. | 271 | // those using a static initializer. |
@@ -314,13 +308,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
314 | { | 308 | { |
315 | Rest.Log.ErrorFormat("{0} Plugin initialization has failed: {1}", MsgId, e.Message); | 309 | Rest.Log.ErrorFormat("{0} Plugin initialization has failed: {1}", MsgId, e.Message); |
316 | } | 310 | } |
317 | |||
318 | } | 311 | } |
319 | 312 | ||
320 | /// <summary> | 313 | /// <summary> |
321 | /// In the interests of efficiency, and because we cannot determine whether | 314 | /// In the interests of efficiency, and because we cannot determine whether |
322 | /// or not this instance will actually be harvested, we clobber the only | 315 | /// or not this instance will actually be harvested, we clobber the only |
323 | /// anchoring reference to the working state for this plug-in. What the | 316 | /// anchoring reference to the working state for this plug-in. What the |
324 | /// call to close does is irrelevant to this class beyond knowing that it | 317 | /// call to close does is irrelevant to this class beyond knowing that it |
325 | /// can nullify the reference when it returns. | 318 | /// can nullify the reference when it returns. |
326 | /// To make sure everything is copacetic we make sure the primary interface | 319 | /// To make sure everything is copacetic we make sure the primary interface |
@@ -329,7 +322,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
329 | 322 | ||
330 | public override void Close() | 323 | public override void Close() |
331 | { | 324 | { |
332 | |||
333 | Rest.Log.InfoFormat("{0} Plugin is terminating", MsgId); | 325 | Rest.Log.InfoFormat("{0} Plugin is terminating", MsgId); |
334 | 326 | ||
335 | try | 327 | try |
@@ -337,12 +329,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
337 | RemoveAgentHandler(Rest.Name, this); | 329 | RemoveAgentHandler(Rest.Name, this); |
338 | } | 330 | } |
339 | catch (KeyNotFoundException){} | 331 | catch (KeyNotFoundException){} |
340 | 332 | ||
341 | foreach (IRest handler in handlers) | 333 | foreach (IRest handler in handlers) |
342 | { | 334 | { |
343 | handler.Close(); | 335 | handler.Close(); |
344 | } | 336 | } |
345 | |||
346 | } | 337 | } |
347 | 338 | ||
348 | #endregion overriding methods | 339 | #endregion overriding methods |
@@ -380,7 +371,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
380 | return true; | 371 | return true; |
381 | } | 372 | } |
382 | } | 373 | } |
383 | |||
384 | } | 374 | } |
385 | catch (Exception e) | 375 | catch (Exception e) |
386 | { | 376 | { |
@@ -414,7 +404,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
414 | 404 | ||
415 | for (int i = 0; i < request.Headers.Count; i++) | 405 | for (int i = 0; i < request.Headers.Count; i++) |
416 | { | 406 | { |
417 | Rest.Log.DebugFormat("{0} Header [{1}] : <{2}> = <{3}>", | 407 | Rest.Log.DebugFormat("{0} Header [{1}] : <{2}> = <{3}>", |
418 | MsgId, i, request.Headers.GetKey(i), request.Headers.Get(i)); | 408 | MsgId, i, request.Headers.GetKey(i), request.Headers.Get(i)); |
419 | } | 409 | } |
420 | Rest.Log.DebugFormat("{0} URI: {1}", MsgId, request.RawUrl); | 410 | Rest.Log.DebugFormat("{0} URI: {1}", MsgId, request.RawUrl); |
@@ -425,8 +415,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
425 | 415 | ||
426 | try | 416 | try |
427 | { | 417 | { |
428 | handled = ( FindPathHandler(request, response) || | 418 | handled = FindPathHandler(request, response) || |
429 | FindStreamHandler(request, response) ); | 419 | FindStreamHandler(request, response); |
430 | } | 420 | } |
431 | catch (Exception e) | 421 | catch (Exception e) |
432 | { | 422 | { |
@@ -440,7 +430,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
440 | Rest.Log.DebugFormat("{0} EXIT", MsgId); | 430 | Rest.Log.DebugFormat("{0} EXIT", MsgId); |
441 | 431 | ||
442 | return handled; | 432 | return handled; |
443 | |||
444 | } | 433 | } |
445 | 434 | ||
446 | #endregion interface methods | 435 | #endregion interface methods |
@@ -488,7 +477,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
488 | } | 477 | } |
489 | 478 | ||
490 | return rdata.handled; | 479 | return rdata.handled; |
491 | |||
492 | } | 480 | } |
493 | 481 | ||
494 | /// <summary> | 482 | /// <summary> |
@@ -501,13 +489,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
501 | 489 | ||
502 | public void AddStreamHandler(string httpMethod, string path, RestMethod method) | 490 | public void AddStreamHandler(string httpMethod, string path, RestMethod method) |
503 | { | 491 | { |
504 | |||
505 | if (!IsEnabled) | 492 | if (!IsEnabled) |
506 | { | 493 | { |
507 | return; | 494 | return; |
508 | } | 495 | } |
509 | 496 | ||
510 | if (!path.StartsWith(Rest.Prefix)) | 497 | if (!path.StartsWith(Rest.Prefix)) |
511 | { | 498 | { |
512 | path = String.Format("{0}{1}", Rest.Prefix, path); | 499 | path = String.Format("{0}{1}", Rest.Prefix, path); |
513 | } | 500 | } |
@@ -525,7 +512,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
525 | { | 512 | { |
526 | Rest.Log.WarnFormat("{0} Ignoring duplicate handler for {1}", MsgId, path); | 513 | Rest.Log.WarnFormat("{0} Ignoring duplicate handler for {1}", MsgId, path); |
527 | } | 514 | } |
528 | |||
529 | } | 515 | } |
530 | 516 | ||
531 | /// <summary> | 517 | /// <summary> |
@@ -540,10 +526,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
540 | 526 | ||
541 | internal bool FindPathHandler(OSHttpRequest request, OSHttpResponse response) | 527 | internal bool FindPathHandler(OSHttpRequest request, OSHttpResponse response) |
542 | { | 528 | { |
543 | |||
544 | RequestData rdata = null; | 529 | RequestData rdata = null; |
545 | string bestMatch = null; | 530 | string bestMatch = null; |
546 | 531 | ||
547 | if (!IsEnabled) | 532 | if (!IsEnabled) |
548 | { | 533 | { |
549 | return false; | 534 | return false; |
@@ -566,7 +551,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
566 | 551 | ||
567 | if (!String.IsNullOrEmpty(bestMatch)) | 552 | if (!String.IsNullOrEmpty(bestMatch)) |
568 | { | 553 | { |
569 | |||
570 | rdata = pathAllocators[bestMatch](request, response); | 554 | rdata = pathAllocators[bestMatch](request, response); |
571 | 555 | ||
572 | Rest.Log.DebugFormat("{0} Path based REST handler matched with <{1}>", MsgId, bestMatch); | 556 | Rest.Log.DebugFormat("{0} Path based REST handler matched with <{1}>", MsgId, bestMatch); |
@@ -575,7 +559,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
575 | { | 559 | { |
576 | pathHandlers[bestMatch](rdata); | 560 | pathHandlers[bestMatch](rdata); |
577 | } | 561 | } |
578 | 562 | ||
579 | // A plugin generated error indicates a request-related error | 563 | // A plugin generated error indicates a request-related error |
580 | // that has been handled by the plugin. | 564 | // that has been handled by the plugin. |
581 | 565 | ||
@@ -583,11 +567,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
583 | { | 567 | { |
584 | Rest.Log.WarnFormat("{0} Request failed: {1}", MsgId, r.Message); | 568 | Rest.Log.WarnFormat("{0} Request failed: {1}", MsgId, r.Message); |
585 | } | 569 | } |
586 | |||
587 | } | 570 | } |
588 | 571 | ||
589 | return (rdata == null) ? false : rdata.handled; | 572 | return (rdata == null) ? false : rdata.handled; |
590 | |||
591 | } | 573 | } |
592 | 574 | ||
593 | /// <summary> | 575 | /// <summary> |
@@ -597,7 +579,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
597 | 579 | ||
598 | internal void AddPathHandler(RestMethodHandler mh, string path, RestMethodAllocator ra) | 580 | internal void AddPathHandler(RestMethodHandler mh, string path, RestMethodAllocator ra) |
599 | { | 581 | { |
600 | |||
601 | if (!IsEnabled) | 582 | if (!IsEnabled) |
602 | { | 583 | { |
603 | return; | 584 | return; |
@@ -619,8 +600,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
619 | 600 | ||
620 | pathHandlers.Add(path, mh); | 601 | pathHandlers.Add(path, mh); |
621 | pathAllocators.Add(path, ra); | 602 | pathAllocators.Add(path, ra); |
622 | |||
623 | } | 603 | } |
624 | } | 604 | } |
625 | |||
626 | } | 605 | } |