Main.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 libsecondlife;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Framework.Servers;
  34. namespace OpenSim.Grid.InventoryServer
  35. {
  36. public class OpenInventory_Main : BaseOpenSimServer, conscmd_callback
  37. {
  38. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  39. private InventoryManager m_inventoryManager;
  40. private InventoryConfig m_config;
  41. private GridInventoryService m_inventoryService;
  42. public const string LogName = "INVENTORY";
  43. [STAThread]
  44. public static void Main(string[] args)
  45. {
  46. log4net.Config.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(LogName, this);
  54. MainConsole.Instance = m_console;
  55. }
  56. public void Startup()
  57. {
  58. m_log.Info("Initialising inventory manager...");
  59. m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
  60. m_inventoryService = new GridInventoryService();
  61. // m_inventoryManager = new InventoryManager();
  62. m_inventoryService.AddPlugin(m_config.DatabaseProvider);
  63. m_log.Info("[" + LogName + "]: Starting HTTP server ...");
  64. m_httpServer = new BaseHttpServer(m_config.HttpPort);
  65. AddHttpHandlers();
  66. m_httpServer.Start();
  67. m_log.Info("[" + LogName + "]: Started HTTP server");
  68. }
  69. protected void AddHttpHandlers()
  70. {
  71. m_httpServer.AddStreamHandler(
  72. new RestDeserialisehandler<Guid, InventoryCollection>(
  73. "POST", "/GetInventory/", m_inventoryService.GetUserInventory));
  74. m_httpServer.AddStreamHandler(
  75. new RestDeserialisehandler<Guid, bool>(
  76. "POST", "/CreateInventory/", m_inventoryService.CreateUsersInventory));
  77. m_httpServer.AddStreamHandler(
  78. new RestDeserialisehandler<InventoryFolderBase, bool>(
  79. "POST", "/NewFolder/", m_inventoryService.AddInventoryFolder));
  80. m_httpServer.AddStreamHandler(
  81. new RestDeserialisehandler<InventoryFolderBase, bool>(
  82. "POST", "/MoveFolder/", m_inventoryService.MoveInventoryFolder));
  83. m_httpServer.AddStreamHandler(
  84. new RestDeserialisehandler<InventoryItemBase, bool>(
  85. "POST", "/NewItem/", m_inventoryService.AddInventoryItem));
  86. m_httpServer.AddStreamHandler(
  87. new RestDeserialisehandler<InventoryItemBase, bool>(
  88. "POST", "/DeleteItem/", m_inventoryService.DeleteInvItem));
  89. // WARNING: Root folders no longer just delivers the root and immediate child folders (e.g
  90. // system folders such as Objects, Textures), but it now returns the entire inventory skeleton.
  91. // It would have been better to rename this request, but complexities in the BaseHttpServer
  92. // (e.g. any http request not found is automatically treated as an xmlrpc request) make it easier
  93. // to do this for now.
  94. m_httpServer.AddStreamHandler(
  95. new RestDeserialisehandler<Guid, List<InventoryFolderBase>>
  96. ("POST", "/RootFolders/", m_inventoryService.GetInventorySkeleton));
  97. // httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager));
  98. }
  99. private void Work()
  100. {
  101. m_console.Notice("Enter help for a list of commands\n");
  102. while (true)
  103. {
  104. m_console.Prompt();
  105. }
  106. }
  107. public override void RunCmd(string cmd, string[] cmdparams)
  108. {
  109. base.RunCmd(cmd, cmdparams);
  110. switch (cmd)
  111. {
  112. case "quit":
  113. case "add-user":
  114. m_inventoryService.CreateUsersInventory(LLUUID.Random().UUID);
  115. break;
  116. case "shutdown":
  117. m_console.Close();
  118. Environment.Exit(0);
  119. break;
  120. }
  121. }
  122. }
  123. }