RestRegionPlugin.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. using System;
  28. using System.Threading;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.IO;
  32. using System.Net;
  33. using System.Reflection;
  34. using System.Text.RegularExpressions;
  35. using System.Timers;
  36. using System.Xml;
  37. using System.Xml.Serialization;
  38. using libsecondlife;
  39. using Mono.Addins;
  40. using Nwc.XmlRpc;
  41. using Nini.Config;
  42. using OpenSim.Framework;
  43. using OpenSim.Framework.Console;
  44. using OpenSim.Framework.Servers;
  45. using OpenSim.Framework.Communications;
  46. using OpenSim.Region.Environment.Scenes;
  47. using OpenSim.ApplicationPlugins.Rest;
  48. [assembly : Addin]
  49. [assembly : AddinDependency("OpenSim", "0.5")]
  50. namespace OpenSim.ApplicationPlugins.Rest.Regions
  51. {
  52. [Extension("/OpenSim/Startup")]
  53. public partial class RestRegionPlugin : RestPlugin
  54. {
  55. private static XmlSerializerNamespaces _xmlNs;
  56. static RestRegionPlugin()
  57. {
  58. _xmlNs = new XmlSerializerNamespaces();
  59. _xmlNs.Add(String.Empty, String.Empty);
  60. }
  61. #region overriding properties
  62. public override string Name
  63. {
  64. get { return "REGION"; }
  65. }
  66. public override string ConfigName
  67. {
  68. get { return "RestRegionPlugin"; }
  69. }
  70. #endregion overriding properties
  71. #region overriding methods
  72. /// <summary>
  73. /// This method is called by OpenSimMain immediately after loading the
  74. /// plugin and after basic server setup, but before running any server commands.
  75. /// </summary>
  76. /// <remarks>
  77. /// Note that entries MUST be added to the active configuration files before
  78. /// the plugin can be enabled.
  79. /// </remarks>
  80. public override void Initialise(OpenSimBase openSim)
  81. {
  82. try
  83. {
  84. base.Initialise(openSim);
  85. if (!IsEnabled)
  86. {
  87. m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
  88. return;
  89. }
  90. m_log.InfoFormat("{0} REST region plugin enabled", MsgID);
  91. // add REST method handlers
  92. AddRestStreamHandler("GET", "/regions/", GetHandler);
  93. AddRestStreamHandler("POST", "/regions/", PostHandler);
  94. }
  95. catch (Exception e)
  96. {
  97. m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
  98. m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
  99. }
  100. }
  101. public override void Close()
  102. {
  103. }
  104. #endregion overriding methods
  105. }
  106. }