Main.cs 7.1 KB

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