diff options
author | Jeff Ames | 2008-08-28 14:41:54 +0000 |
---|---|---|
committer | Jeff Ames | 2008-08-28 14:41:54 +0000 |
commit | 3bf88587277b83c0b6f058fabba7d46a3b5a6a00 (patch) | |
tree | ed4ad9dc27e649a6f52661665fb681984251f480 /OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs | |
parent | Thannk you, Ralphos, for a patch the corrects an improper cast in (diff) | |
download | opensim-SC-3bf88587277b83c0b6f058fabba7d46a3b5a6a00.zip opensim-SC-3bf88587277b83c0b6f058fabba7d46a3b5a6a00.tar.gz opensim-SC-3bf88587277b83c0b6f058fabba7d46a3b5a6a00.tar.bz2 opensim-SC-3bf88587277b83c0b6f058fabba7d46a3b5a6a00.tar.xz |
Update svn properties, formatting cleanup.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs | 70 |
1 files changed, 24 insertions, 46 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs index 61cf0e4..ab6128f 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; |
@@ -35,7 +34,6 @@ using OpenSim.ApplicationPlugins.Rest; | |||
35 | 34 | ||
36 | namespace OpenSim.ApplicationPlugins.Rest.Inventory | 35 | namespace OpenSim.ApplicationPlugins.Rest.Inventory |
37 | { | 36 | { |
38 | |||
39 | /// <remarks> | 37 | /// <remarks> |
40 | /// The class signature reveals the roles that RestHandler plays. | 38 | /// The class signature reveals the roles that RestHandler plays. |
41 | /// | 39 | /// |
@@ -74,10 +72,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
74 | /// <summary> | 72 | /// <summary> |
75 | /// This static initializer scans the ASSEMBLY for classes that | 73 | /// This static initializer scans the ASSEMBLY for classes that |
76 | /// export the IRest interface and builds a list of them. These | 74 | /// export the IRest interface and builds a list of them. These |
77 | /// are later activated by the handler. To add a new handler it | 75 | /// are later activated by the handler. To add a new handler it |
78 | /// is only necessary to create a new services class that implements | 76 | /// is only necessary to create a new services class that implements |
79 | /// the IRest interface, and recompile the handler. This gives | 77 | /// the IRest interface, and recompile the handler. This gives |
80 | /// all of the build-time flexibility of a modular approach | 78 | /// all of the build-time flexibility of a modular approach |
81 | /// while not introducing yet-another module loader. Note that | 79 | /// while not introducing yet-another module loader. Note that |
82 | /// multiple assembles can still be built, each with its own set | 80 | /// multiple assembles can still be built, each with its own set |
83 | /// of handlers. Examples of services classes are RestInventoryServices | 81 | /// of handlers. Examples of services classes are RestInventoryServices |
@@ -86,13 +84,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
86 | 84 | ||
87 | static RestHandler() | 85 | static RestHandler() |
88 | { | 86 | { |
89 | |||
90 | Module[] mods = Assembly.GetExecutingAssembly().GetModules(); | 87 | Module[] mods = Assembly.GetExecutingAssembly().GetModules(); |
91 | 88 | ||
92 | foreach (Module m in mods) | 89 | foreach (Module m in mods) |
93 | { | 90 | { |
94 | Type[] types = m.GetTypes(); | 91 | Type[] types = m.GetTypes(); |
95 | foreach (Type t in types) | 92 | foreach (Type t in types) |
96 | { | 93 | { |
97 | try | 94 | try |
98 | { | 95 | { |
@@ -108,7 +105,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
108 | } | 105 | } |
109 | } | 106 | } |
110 | } | 107 | } |
111 | |||
112 | } | 108 | } |
113 | 109 | ||
114 | #endregion local static state | 110 | #endregion local static state |
@@ -117,13 +113,13 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
117 | 113 | ||
118 | /// <summary> | 114 | /// <summary> |
119 | /// This routine loads all of the handlers discovered during | 115 | /// This routine loads all of the handlers discovered during |
120 | /// instance initialization. | 116 | /// instance initialization. |
121 | /// A table of all loaded and successfully constructed handlers | 117 | /// A table of all loaded and successfully constructed handlers |
122 | /// is built, and this table is then used by the constructor to | 118 | /// is built, and this table is then used by the constructor to |
123 | /// initialize each of the handlers in turn. | 119 | /// initialize each of the handlers in turn. |
124 | /// NOTE: The loading process does not automatically imply that | 120 | /// NOTE: The loading process does not automatically imply that |
125 | /// the handler has registered any kind of an interface, that | 121 | /// the handler has registered any kind of an interface, that |
126 | /// may be (optionally) done by the handler either during | 122 | /// may be (optionally) done by the handler either during |
127 | /// construction, or during initialization. | 123 | /// construction, or during initialization. |
128 | /// | 124 | /// |
129 | /// I was not able to make this code work within a constructor | 125 | /// I was not able to make this code work within a constructor |
@@ -136,7 +132,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
136 | { | 132 | { |
137 | if (!handlersLoaded) | 133 | if (!handlersLoaded) |
138 | { | 134 | { |
139 | |||
140 | ConstructorInfo ci; | 135 | ConstructorInfo ci; |
141 | Object ht; | 136 | Object ht; |
142 | 137 | ||
@@ -167,8 +162,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
167 | 162 | ||
168 | // Name is used to differentiate the message header. | 163 | // Name is used to differentiate the message header. |
169 | 164 | ||
170 | public override string Name | 165 | public override string Name |
171 | { | 166 | { |
172 | get { return "HANDLER"; } | 167 | get { return "HANDLER"; } |
173 | } | 168 | } |
174 | 169 | ||
@@ -181,7 +176,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
181 | 176 | ||
182 | // We have to rename these because we want | 177 | // We have to rename these because we want |
183 | // to be able to share the values with other | 178 | // to be able to share the values with other |
184 | // classes in our assembly and the base | 179 | // classes in our assembly and the base |
185 | // names are protected. | 180 | // names are protected. |
186 | 181 | ||
187 | public string MsgId | 182 | public string MsgId |
@@ -211,7 +206,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
211 | { | 206 | { |
212 | try | 207 | try |
213 | { | 208 | { |
214 | |||
215 | // This plugin will only be enabled if the broader | 209 | // This plugin will only be enabled if the broader |
216 | // REST plugin mechanism is enabled. | 210 | // REST plugin mechanism is enabled. |
217 | 211 | ||
@@ -222,7 +216,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
222 | // IsEnabled is implemented by the base class and | 216 | // IsEnabled is implemented by the base class and |
223 | // reflects an overall RestPlugin status | 217 | // reflects an overall RestPlugin status |
224 | 218 | ||
225 | if (!IsEnabled) | 219 | if (!IsEnabled) |
226 | { | 220 | { |
227 | Rest.Log.WarnFormat("{0} Plugins are disabled", MsgId); | 221 | Rest.Log.WarnFormat("{0} Plugins are disabled", MsgId); |
228 | return; | 222 | return; |
@@ -278,15 +272,15 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
278 | Rest.DumpLineSize); | 272 | Rest.DumpLineSize); |
279 | } | 273 | } |
280 | 274 | ||
281 | // Load all of the handlers present in the | 275 | // Load all of the handlers present in the |
282 | // assembly | 276 | // assembly |
283 | 277 | ||
284 | // In principle, as we're an application plug-in, | 278 | // In principle, as we're an application plug-in, |
285 | // most of what needs to be done could be done using | 279 | // most of what needs to be done could be done using |
286 | // static resources, however the Open Sim plug-in | 280 | // static resources, however the Open Sim plug-in |
287 | // model makes this an instance, so that's what we | 281 | // model makes this an instance, so that's what we |
288 | // need to be. | 282 | // need to be. |
289 | // There is only one Communications manager per | 283 | // There is only one Communications manager per |
290 | // server, and by inference, only one each of the | 284 | // server, and by inference, only one each of the |
291 | // user, asset, and inventory servers. So we can cache | 285 | // user, asset, and inventory servers. So we can cache |
292 | // those using a static initializer. | 286 | // those using a static initializer. |
@@ -329,13 +323,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
329 | { | 323 | { |
330 | Rest.Log.ErrorFormat("{0} Plugin initialization has failed: {1}", MsgId, e.Message); | 324 | Rest.Log.ErrorFormat("{0} Plugin initialization has failed: {1}", MsgId, e.Message); |
331 | } | 325 | } |
332 | |||
333 | } | 326 | } |
334 | 327 | ||
335 | /// <summary> | 328 | /// <summary> |
336 | /// In the interests of efficiency, and because we cannot determine whether | 329 | /// In the interests of efficiency, and because we cannot determine whether |
337 | /// or not this instance will actually be harvested, we clobber the only | 330 | /// or not this instance will actually be harvested, we clobber the only |
338 | /// anchoring reference to the working state for this plug-in. What the | 331 | /// anchoring reference to the working state for this plug-in. What the |
339 | /// call to close does is irrelevant to this class beyond knowing that it | 332 | /// call to close does is irrelevant to this class beyond knowing that it |
340 | /// can nullify the reference when it returns. | 333 | /// can nullify the reference when it returns. |
341 | /// To make sure everything is copacetic we make sure the primary interface | 334 | /// To make sure everything is copacetic we make sure the primary interface |
@@ -344,7 +337,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
344 | 337 | ||
345 | public override void Close() | 338 | public override void Close() |
346 | { | 339 | { |
347 | |||
348 | Rest.Log.InfoFormat("{0} Plugin is terminating", MsgId); | 340 | Rest.Log.InfoFormat("{0} Plugin is terminating", MsgId); |
349 | 341 | ||
350 | try | 342 | try |
@@ -352,12 +344,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
352 | RemoveAgentHandler(Rest.Name, this); | 344 | RemoveAgentHandler(Rest.Name, this); |
353 | } | 345 | } |
354 | catch (KeyNotFoundException){} | 346 | catch (KeyNotFoundException){} |
355 | 347 | ||
356 | foreach (IRest handler in handlers) | 348 | foreach (IRest handler in handlers) |
357 | { | 349 | { |
358 | handler.Close(); | 350 | handler.Close(); |
359 | } | 351 | } |
360 | |||
361 | } | 352 | } |
362 | 353 | ||
363 | #endregion overriding methods | 354 | #endregion overriding methods |
@@ -383,7 +374,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
383 | foreach (string key in pathHandlers.Keys) | 374 | foreach (string key in pathHandlers.Keys) |
384 | { | 375 | { |
385 | Rest.Log.DebugFormat("{0} Match testing {1} against agent prefix <{2}>", MsgId, path, key); | 376 | Rest.Log.DebugFormat("{0} Match testing {1} against agent prefix <{2}>", MsgId, path, key); |
386 | 377 | ||
387 | // Note that Match will not necessarily find the handler that will | 378 | // Note that Match will not necessarily find the handler that will |
388 | // actually be used - it does no test for the "closest" fit. It | 379 | // actually be used - it does no test for the "closest" fit. It |
389 | // simply reflects that at least one possible handler exists. | 380 | // simply reflects that at least one possible handler exists. |
@@ -393,7 +384,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
393 | Rest.Log.DebugFormat("{0} Matched prefix <{1}>", MsgId, key); | 384 | Rest.Log.DebugFormat("{0} Matched prefix <{1}>", MsgId, key); |
394 | 385 | ||
395 | // This apparently odd evaluation is needed to prevent a match | 386 | // This apparently odd evaluation is needed to prevent a match |
396 | // on anything other than a URI token boundary. Otherwise we | 387 | // on anything other than a URI token boundary. Otherwise we |
397 | // may match on URL's that were not intended for this handler. | 388 | // may match on URL's that were not intended for this handler. |
398 | 389 | ||
399 | return ( path.Length == key.Length || | 390 | return ( path.Length == key.Length || |
@@ -406,9 +397,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
406 | 397 | ||
407 | foreach (string key in streamHandlers.Keys) | 398 | foreach (string key in streamHandlers.Keys) |
408 | { | 399 | { |
409 | |||
410 | Rest.Log.DebugFormat("{0} Match testing {1} against stream prefix <{2}>", MsgId, path, key); | 400 | Rest.Log.DebugFormat("{0} Match testing {1} against stream prefix <{2}>", MsgId, path, key); |
411 | 401 | ||
412 | // Note that Match will not necessarily find the handler that will | 402 | // Note that Match will not necessarily find the handler that will |
413 | // actually be used - it does no test for the "closest" fit. It | 403 | // actually be used - it does no test for the "closest" fit. It |
414 | // simply reflects that at least one possible handler exists. | 404 | // simply reflects that at least one possible handler exists. |
@@ -418,7 +408,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
418 | Rest.Log.DebugFormat("{0} Matched prefix <{1}>", MsgId, key); | 408 | Rest.Log.DebugFormat("{0} Matched prefix <{1}>", MsgId, key); |
419 | 409 | ||
420 | // This apparently odd evaluation is needed to prevent a match | 410 | // This apparently odd evaluation is needed to prevent a match |
421 | // on anything other than a URI token boundary. Otherwise we | 411 | // on anything other than a URI token boundary. Otherwise we |
422 | // may match on URL's that were not intended for this handler. | 412 | // may match on URL's that were not intended for this handler. |
423 | 413 | ||
424 | return ( path.Length == key.Length || | 414 | return ( path.Length == key.Length || |
@@ -426,7 +416,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
426 | 416 | ||
427 | } | 417 | } |
428 | } | 418 | } |
429 | |||
430 | } | 419 | } |
431 | catch (Exception e) | 420 | catch (Exception e) |
432 | { | 421 | { |
@@ -460,7 +449,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
460 | 449 | ||
461 | for (int i = 0; i < request.Headers.Count; i++) | 450 | for (int i = 0; i < request.Headers.Count; i++) |
462 | { | 451 | { |
463 | Rest.Log.DebugFormat("{0} Header [{1}] : <{2}> = <{3}>", | 452 | Rest.Log.DebugFormat("{0} Header [{1}] : <{2}> = <{3}>", |
464 | MsgId, i, request.Headers.GetKey(i), request.Headers.Get(i)); | 453 | MsgId, i, request.Headers.GetKey(i), request.Headers.Get(i)); |
465 | } | 454 | } |
466 | Rest.Log.DebugFormat("{0} URI: {1}", MsgId, request.RawUrl); | 455 | Rest.Log.DebugFormat("{0} URI: {1}", MsgId, request.RawUrl); |
@@ -486,7 +475,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
486 | Rest.Log.DebugFormat("{0} EXIT", MsgId); | 475 | Rest.Log.DebugFormat("{0} EXIT", MsgId); |
487 | 476 | ||
488 | return handled; | 477 | return handled; |
489 | |||
490 | } | 478 | } |
491 | 479 | ||
492 | #endregion interface methods | 480 | #endregion interface methods |
@@ -534,7 +522,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
534 | } | 522 | } |
535 | 523 | ||
536 | return rdata.handled; | 524 | return rdata.handled; |
537 | |||
538 | } | 525 | } |
539 | 526 | ||
540 | /// <summary> | 527 | /// <summary> |
@@ -547,13 +534,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
547 | 534 | ||
548 | public void AddStreamHandler(string httpMethod, string path, RestMethod method) | 535 | public void AddStreamHandler(string httpMethod, string path, RestMethod method) |
549 | { | 536 | { |
550 | |||
551 | if (!IsEnabled) | 537 | if (!IsEnabled) |
552 | { | 538 | { |
553 | return; | 539 | return; |
554 | } | 540 | } |
555 | 541 | ||
556 | if (!path.StartsWith(Rest.Prefix)) | 542 | if (!path.StartsWith(Rest.Prefix)) |
557 | { | 543 | { |
558 | path = String.Format("{0}{1}", Rest.Prefix, path); | 544 | path = String.Format("{0}{1}", Rest.Prefix, path); |
559 | } | 545 | } |
@@ -571,7 +557,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
571 | { | 557 | { |
572 | Rest.Log.WarnFormat("{0} Ignoring duplicate handler for {1}", MsgId, path); | 558 | Rest.Log.WarnFormat("{0} Ignoring duplicate handler for {1}", MsgId, path); |
573 | } | 559 | } |
574 | |||
575 | } | 560 | } |
576 | 561 | ||
577 | /// <summary> | 562 | /// <summary> |
@@ -586,10 +571,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
586 | 571 | ||
587 | internal bool FindPathHandler(OSHttpRequest request, OSHttpResponse response) | 572 | internal bool FindPathHandler(OSHttpRequest request, OSHttpResponse response) |
588 | { | 573 | { |
589 | |||
590 | RequestData rdata = null; | 574 | RequestData rdata = null; |
591 | string bestMatch = null; | 575 | string bestMatch = null; |
592 | 576 | ||
593 | if (!IsEnabled) | 577 | if (!IsEnabled) |
594 | { | 578 | { |
595 | return false; | 579 | return false; |
@@ -612,7 +596,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
612 | 596 | ||
613 | if (!String.IsNullOrEmpty(bestMatch)) | 597 | if (!String.IsNullOrEmpty(bestMatch)) |
614 | { | 598 | { |
615 | |||
616 | rdata = pathAllocators[bestMatch](request, response, bestMatch); | 599 | rdata = pathAllocators[bestMatch](request, response, bestMatch); |
617 | 600 | ||
618 | Rest.Log.DebugFormat("{0} Path based REST handler matched with <{1}>", MsgId, bestMatch); | 601 | Rest.Log.DebugFormat("{0} Path based REST handler matched with <{1}>", MsgId, bestMatch); |
@@ -621,7 +604,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
621 | { | 604 | { |
622 | pathHandlers[bestMatch](rdata); | 605 | pathHandlers[bestMatch](rdata); |
623 | } | 606 | } |
624 | 607 | ||
625 | // A plugin generated error indicates a request-related error | 608 | // A plugin generated error indicates a request-related error |
626 | // that has been handled by the plugin. | 609 | // that has been handled by the plugin. |
627 | 610 | ||
@@ -629,11 +612,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
629 | { | 612 | { |
630 | Rest.Log.WarnFormat("{0} Request failed: {1}", MsgId, r.Message); | 613 | Rest.Log.WarnFormat("{0} Request failed: {1}", MsgId, r.Message); |
631 | } | 614 | } |
632 | |||
633 | } | 615 | } |
634 | 616 | ||
635 | return (rdata == null) ? false : rdata.handled; | 617 | return (rdata == null) ? false : rdata.handled; |
636 | |||
637 | } | 618 | } |
638 | 619 | ||
639 | /// <summary> | 620 | /// <summary> |
@@ -643,7 +624,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
643 | 624 | ||
644 | public void AddPathHandler(RestMethodHandler mh, string path, RestMethodAllocator ra) | 625 | public void AddPathHandler(RestMethodHandler mh, string path, RestMethodAllocator ra) |
645 | { | 626 | { |
646 | |||
647 | if (!IsEnabled) | 627 | if (!IsEnabled) |
648 | { | 628 | { |
649 | return; | 629 | return; |
@@ -665,8 +645,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
665 | 645 | ||
666 | pathHandlers.Add(path, mh); | 646 | pathHandlers.Add(path, mh); |
667 | pathAllocators.Add(path, ra); | 647 | pathAllocators.Add(path, ra); |
668 | |||
669 | } | 648 | } |
670 | } | 649 | } |
671 | |||
672 | } | 650 | } |