Main.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 OpenSimulator 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.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using log4net;
  32. using log4net.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications.Services;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. namespace OpenSim.Grid.InventoryServer
  40. {
  41. public class OpenInventory_Main : BaseOpenSimServer
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private GridInventoryService m_inventoryService;
  45. //private HGInventoryService m_directInventoryService;
  46. public const string LogName = "INVENTORY";
  47. public static void Main(string[] args)
  48. {
  49. XmlConfigurator.Configure();
  50. OpenInventory_Main theServer = new OpenInventory_Main();
  51. theServer.Startup();
  52. theServer.Work();
  53. }
  54. public OpenInventory_Main()
  55. {
  56. m_console = new LocalConsole("Inventory");
  57. MainConsole.Instance = m_console;
  58. }
  59. protected override void StartupSpecific()
  60. {
  61. InventoryConfig config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
  62. m_inventoryService = new GridInventoryService(config.UserServerURL);
  63. m_inventoryService.DoLookup = config.SessionLookUp;
  64. m_inventoryService.AddPlugin(config.DatabaseProvider, config.DatabaseConnect);
  65. m_log.Info("[" + LogName + "]: Starting HTTP server ...");
  66. m_httpServer = new BaseHttpServer(config.HttpPort);
  67. AddHttpHandlers(config.RegionAccessToAgentsInventory);
  68. m_httpServer.Start();
  69. m_log.Info("[" + LogName + "]: Started HTTP server");
  70. new HGInventoryService(m_inventoryService, config.AssetServerURL, config.UserServerURL, m_httpServer, config.InventoryServerURL);
  71. base.StartupSpecific();
  72. m_console.Commands.AddCommand("inventoryserver", false, "add user",
  73. "add user",
  74. "Add a random user inventory", HandleAddUser);
  75. }
  76. protected void AddHttpHandlers(bool regionAccess)
  77. {
  78. if (regionAccess)
  79. {
  80. m_httpServer.AddStreamHandler(
  81. new RestDeserialiseSecureHandler<Guid, InventoryCollection>(
  82. "POST", "/GetInventory/", m_inventoryService.GetUserInventory, m_inventoryService.CheckAuthSession));
  83. m_httpServer.AddStreamHandler(
  84. new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
  85. "POST", "/UpdateFolder/", m_inventoryService.UpdateFolder, m_inventoryService.CheckAuthSession));
  86. m_httpServer.AddStreamHandler(
  87. new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
  88. "POST", "/MoveFolder/", m_inventoryService.MoveFolder, m_inventoryService.CheckAuthSession));
  89. m_httpServer.AddStreamHandler(
  90. new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
  91. "POST", "/PurgeFolder/", m_inventoryService.PurgeFolder, m_inventoryService.CheckAuthSession));
  92. m_httpServer.AddStreamHandler(
  93. new RestDeserialiseSecureHandler<InventoryItemBase, bool>(
  94. "POST", "/DeleteItem/", m_inventoryService.DeleteItem, m_inventoryService.CheckAuthSession));
  95. m_httpServer.AddStreamHandler(
  96. new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>(
  97. "POST", "/QueryItem/", m_inventoryService.QueryItem, m_inventoryService.CheckAuthSession));
  98. m_httpServer.AddStreamHandler(
  99. new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryFolderBase>(
  100. "POST", "/QueryFolder/", m_inventoryService.QueryFolder, m_inventoryService.CheckAuthSession));
  101. }
  102. m_httpServer.AddStreamHandler(
  103. new RestDeserialiseTrustedHandler<Guid, bool>(
  104. "POST", "/CreateInventory/", m_inventoryService.CreateUsersInventory, m_inventoryService.CheckTrustSource));
  105. m_httpServer.AddStreamHandler(
  106. new RestDeserialiseSecureHandler<InventoryFolderBase, bool>(
  107. "POST", "/NewFolder/", m_inventoryService.AddFolder, m_inventoryService.CheckAuthSession));
  108. m_httpServer.AddStreamHandler(
  109. new RestDeserialiseTrustedHandler<InventoryFolderBase, bool>(
  110. "POST", "/CreateFolder/", m_inventoryService.AddFolder, m_inventoryService.CheckTrustSource));
  111. m_httpServer.AddStreamHandler(
  112. new RestDeserialiseSecureHandler<InventoryItemBase, bool>(
  113. "POST", "/NewItem/", m_inventoryService.AddItem, m_inventoryService.CheckAuthSession));
  114. m_httpServer.AddStreamHandler(
  115. new RestDeserialiseTrustedHandler<InventoryItemBase, bool>(
  116. "POST", "/AddNewItem/", m_inventoryService.AddItem, m_inventoryService.CheckTrustSource));
  117. m_httpServer.AddStreamHandler(
  118. new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>>(
  119. "POST", "/GetItems/", m_inventoryService.GetFolderItems, m_inventoryService.CheckTrustSource));
  120. // for persistent active gestures
  121. m_httpServer.AddStreamHandler(
  122. new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>>
  123. ("POST", "/ActiveGestures/", m_inventoryService.GetActiveGestures, m_inventoryService.CheckTrustSource));
  124. // WARNING: Root folders no longer just delivers the root and immediate child folders (e.g
  125. // system folders such as Objects, Textures), but it now returns the entire inventory skeleton.
  126. // It would have been better to rename this request, but complexities in the BaseHttpServer
  127. // (e.g. any http request not found is automatically treated as an xmlrpc request) make it easier
  128. // to do this for now.
  129. m_httpServer.AddStreamHandler(
  130. new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>>
  131. ("POST", "/RootFolders/", m_inventoryService.GetInventorySkeleton, m_inventoryService.CheckTrustSource));
  132. }
  133. private void Work()
  134. {
  135. m_console.Output("Enter help for a list of commands\n");
  136. while (true)
  137. {
  138. m_console.Prompt();
  139. }
  140. }
  141. private void HandleAddUser(string module, string[] args)
  142. {
  143. m_inventoryService.CreateUsersInventory(UUID.Random().Guid);
  144. }
  145. }
  146. }