RestRegionPlugin.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #region overriding properties
  57. public override string Name
  58. {
  59. get { return "REGION"; }
  60. }
  61. public override string ConfigName
  62. {
  63. get { return "RestRegionPlugin"; }
  64. }
  65. #endregion overriding properties
  66. #region overriding methods
  67. /// <summary>
  68. /// This method is called by OpenSimMain immediately after loading the
  69. /// plugin and after basic server setup, but before running any server commands.
  70. /// </summary>
  71. /// <remarks>
  72. /// Note that entries MUST be added to the active configuration files before
  73. /// the plugin can be enabled.
  74. /// </remarks>
  75. public override void Initialise(OpenSimMain openSim)
  76. {
  77. try
  78. {
  79. base.Initialise(openSim);
  80. if (!IsEnabled)
  81. {
  82. m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
  83. return;
  84. }
  85. m_log.InfoFormat("{0} REST region plugin enabled", MsgID);
  86. _xmlNs = new XmlSerializerNamespaces();
  87. _xmlNs.Add(String.Empty, String.Empty);
  88. // add REST method handlers
  89. AddRestStreamHandler("GET", "/regions/", GetHandler);
  90. AddRestStreamHandler("POST", "/regions/", PostHandler);
  91. }
  92. catch (Exception e)
  93. {
  94. m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
  95. m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
  96. }
  97. }
  98. public override void Close()
  99. {
  100. }
  101. #endregion overriding methods
  102. }
  103. }