aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/InventoryServer
diff options
context:
space:
mode:
authorTleiades Hax2007-10-30 22:42:34 +0000
committerTleiades Hax2007-10-30 22:42:34 +0000
commit6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d (patch)
tree035f881d61f4a876ebdc72672e3c50a620ae4cfd /OpenSim/Grid/InventoryServer
parent* doh II (diff)
downloadopensim-SC-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.zip
opensim-SC-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.gz
opensim-SC-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.bz2
opensim-SC-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.xz
Step one on the long march towards grid based inventory. Introduction of an InevntoryServer
Diffstat (limited to 'OpenSim/Grid/InventoryServer')
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryManager.cs170
-rw-r--r--OpenSim/Grid/InventoryServer/Main.cs55
2 files changed, 166 insertions, 59 deletions
diff --git a/OpenSim/Grid/InventoryServer/InventoryManager.cs b/OpenSim/Grid/InventoryServer/InventoryManager.cs
index 016b8bb..ca9ebf4 100644
--- a/OpenSim/Grid/InventoryServer/InventoryManager.cs
+++ b/OpenSim/Grid/InventoryServer/InventoryManager.cs
@@ -26,37 +26,36 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections; 29using System.IO;
30using System.Collections.Generic;
31using System.Text; 30using System.Text;
32using OpenGrid.Framework.Data;
33using libsecondlife;
34using System.Reflection; 31using System.Reflection;
35 32using System.Collections;
33using System.Collections.Generic;
36using System.Xml; 34using System.Xml;
37using Nwc.XmlRpc; 35using System.Xml.Serialization;
38using OpenSim.Framework.Sims; 36using libsecondlife;
39using OpenSim.Framework.Inventory;
40using OpenSim.Framework.Utilities;
41 37
42using System.Security.Cryptography; 38using OpenSim.Framework;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Servers;
43 41
44namespace OpenGridServices.InventoryServer 42namespace OpenSim.Grid.InventoryServer
45{ 43{
46 class InventoryManager 44
45 public class InventoryManager
47 { 46 {
48 Dictionary<string, IInventoryData> _plugins = new Dictionary<string, IInventoryData>(); 47 IInventoryData _databasePlugin;
49 48
50 /// <summary> 49 /// <summary>
51 /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded. 50 /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
52 /// </summary> 51 /// </summary>
53 /// <param name="FileName">The filename to the inventory server plugin DLL</param> 52 /// <param name="FileName">The filename to the inventory server plugin DLL</param>
54 public void AddPlugin(string FileName) 53 public void AddDatabasePlugin(string FileName)
55 { 54 {
56 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Attempting to load " + FileName); 55 MainLog.Instance.Verbose(OpenInventory_Main.LogName, "Invenstorage: Attempting to load " + FileName);
57 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 56 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
58 57
59 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); 58 MainLog.Instance.Verbose(OpenInventory_Main.LogName, "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
60 foreach (Type pluginType in pluginAssembly.GetTypes()) 59 foreach (Type pluginType in pluginAssembly.GetTypes())
61 { 60 {
62 if (!pluginType.IsAbstract) 61 if (!pluginType.IsAbstract)
@@ -67,8 +66,9 @@ namespace OpenGridServices.InventoryServer
67 { 66 {
68 IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 67 IInventoryData plug = (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
69 plug.Initialise(); 68 plug.Initialise();
70 this._plugins.Add(plug.getName(), plug); 69 _databasePlugin = plug;
71 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Invenstorage: Added IUserData Interface"); 70 MainLog.Instance.Verbose(OpenInventory_Main.LogName, "Invenstorage: Added IInventoryData Interface");
71 break;
72 } 72 }
73 73
74 typeInterface = null; 74 typeInterface = null;
@@ -78,48 +78,132 @@ namespace OpenGridServices.InventoryServer
78 pluginAssembly = null; 78 pluginAssembly = null;
79 } 79 }
80 80
81 public List<InventoryFolderBase> getRootFolders(LLUUID user) 81 protected static SerializableInventory loadInventoryFromXmlFile(string fileName)
82 {
83 FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
84 XmlReader reader = new XmlTextReader(fs);
85 XmlSerializer x = new XmlSerializer(typeof(SerializableInventory));
86 SerializableInventory inventory = (SerializableInventory)x.Deserialize(reader);
87 fs.Close();
88 fs.Dispose();
89 return inventory;
90 }
91
92 protected static void saveInventoryToStream(SerializableInventory inventory, Stream s)
82 { 93 {
83 foreach (KeyValuePair<string, IInventoryData> kvp in _plugins) 94 XmlTextWriter writer = new XmlTextWriter(s, Encoding.UTF8);
95 writer.Formatting = Formatting.Indented;
96 XmlSerializer x = new XmlSerializer(typeof(SerializableInventory));
97 x.Serialize(writer, inventory);
98 }
99
100 protected static bool fixupFolder(SerializableInventory.SerializableFolder f, SerializableInventory.SerializableFolder parent)
101 {
102 bool modified = false;
103
104 // ensure we have a valid folder id
105 if (f.folderID == LLUUID.Zero)
84 { 106 {
85 try 107 f.folderID = LLUUID.Random();
86 { 108 modified = true;
87 return kvp.Value.getUserRootFolders(user); 109 }
88 } 110
89 catch (Exception e) 111 // ensure we have valid agent id
90 { 112 if (f.agentID == LLUUID.Zero)
91 OpenSim.Framework.Console.MainConsole.Instance.Notice("Unable to get root folders via " + kvp.Key + " (" + e.ToString() + ")"); 113 {
92 } 114 if (parent != null)
115 f.agentID = parent.agentID;
116 else
117 f.agentID = f.folderID;
118 modified = true;
119 }
120
121 if (f.parentID == LLUUID.Zero && parent != null)
122 {
123 f.parentID = parent.folderID;
124 modified = true;
93 } 125 }
94 return null; 126
127
128 foreach (SerializableInventory.SerializableFolder child in f.SubFolders)
129 {
130 modified |= fixupFolder(child, f);
131 }
132
133 return modified;
95 } 134 }
96 135
97 public XmlRpcResponse XmlRpcInventoryRequest(XmlRpcRequest request) 136 protected static bool fixupInventory(SerializableInventory inventory)
98 { 137 {
99 XmlRpcResponse response = new XmlRpcResponse(); 138 return fixupFolder(inventory.root, null);
100 Hashtable requestData = (Hashtable)request.Params[0]; 139 }
101 140
102 Hashtable responseData = new Hashtable(); 141 public class GetInventory : BaseStreamHandler
142 {
143 private SerializableInventory _inventory;
144 private InventoryManager _manager;
145 public GetInventory(InventoryManager manager)
146 : base("GET", "/inventory")
147 {
148 _manager = manager;
103 149
104 // Stuff happens here 150 _inventory = loadInventoryFromXmlFile("Inventory_Library.xml");
151 if (fixupInventory(_inventory))
152 {
153 FileStream fs = new FileStream("Inventory_Library.xml", FileMode.Truncate, FileAccess.Write);
154 saveInventoryToStream(_inventory, fs);
155 fs.Flush();
156 fs.Close();
157 MainLog.Instance.Debug(OpenInventory_Main.LogName, "Modified");
158 }
159 }
105 160
106 if (requestData.ContainsKey("Access-type")) 161 private void CreateDefaultInventory(LLUUID userID)
107 { 162 {
108 if (requestData["access-type"] == "rootfolders") 163 }
164
165 private byte[] GetUserInventory(LLUUID userID)
166 {
167 MainLog.Instance.Notice(OpenInventory_Main.LogName, "Getting Inventory for user {0}", userID.ToStringHyphenated());
168 byte[] result = new byte[] { };
169
170 InventoryFolderBase fb = _manager._databasePlugin.getUserRootFolder(userID);
171 if (fb == null)
109 { 172 {
110// responseData["rootfolders"] = 173 MainLog.Instance.Notice(OpenInventory_Main.LogName, "Inventory not found for user {0}, creating new", userID.ToStringHyphenated());
174 CreateDefaultInventory(userID);
111 } 175 }
176
177 return result;
112 } 178 }
113 else 179
180 override public byte[] Handle(string path, Stream request)
114 { 181 {
115 responseData["error"] = "No access-type specified."; 182 byte[] result = new byte[] { };
116 }
117 183
184 string[] parms = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
185 if (parms.Length >= 1)
186 {
187 if (string.Compare(parms[1], "library", true) == 0)
188 {
118 189
119 // Stuff stops happening here 190 MemoryStream ms = new MemoryStream();
191 saveInventoryToStream(_inventory, ms);
120 192
121 response.Value = responseData; 193 result = ms.GetBuffer();
122 return response; 194 Array.Resize<byte>(ref result, (int)ms.Length);
195 }
196 else if (string.Compare(parms[1], "user", true) == 0)
197 {
198 if (parms.Length >= 2)
199 {
200 result = GetUserInventory(new LLUUID(parms[2]));
201 }
202 }
203 }
204 return result;
205 }
123 } 206 }
207
124 } 208 }
125} 209}
diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs
index 97addb0..1bc396b 100644
--- a/OpenSim/Grid/InventoryServer/Main.cs
+++ b/OpenSim/Grid/InventoryServer/Main.cs
@@ -31,48 +31,71 @@ using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using System.IO; 32using System.IO;
33using System.Text; 33using System.Text;
34
34using libsecondlife; 35using libsecondlife;
35using OpenSim.Framework.User; 36
36using OpenSim.Framework.Sims; 37using OpenSim.Framework;
37using OpenSim.Framework.Inventory;
38using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
40using OpenSim.Servers; 39using OpenSim.Framework.Servers;
41using OpenSim.Framework.Utilities; 40
41using InventoryManager = OpenSim.Grid.InventoryServer.InventoryManager;
42 42
43namespace OpenGridServices.InventoryServer 43namespace OpenSim.Grid.InventoryServer
44{ 44{
45 public class OpenInventory_Main : BaseServer, conscmd_callback 45 public class OpenInventory_Main : conscmd_callback
46 { 46 {
47 ConsoleBase m_console; 47 LogBase m_console;
48 InventoryManager m_inventoryManager; 48 InventoryManager m_inventoryManager;
49 InventoryConfig m_config;
49 50
51 public const string LogName = "INVENTORY";
52
53 [STAThread]
50 public static void Main(string[] args) 54 public static void Main(string[] args)
51 { 55 {
56 OpenInventory_Main theServer = new OpenInventory_Main();
57 theServer.Startup();
58
59 theServer.Work();
52 } 60 }
53 61
54 public OpenInventory_Main() 62 public OpenInventory_Main()
55 { 63 {
56 m_console = new ConsoleBase("opengrid-inventory-console.log", "OpenInventory", this, false); 64 m_console = new LogBase("opengrid-inventory-console.log", LogName, this, true);
57 MainConsole.Instance = m_console; 65 MainLog.Instance = m_console;
58 } 66 }
59 67
60 public void Startup() 68 public void Startup()
61 { 69 {
62 MainConsole.Instance.Notice("Initialising inventory manager..."); 70 MainLog.Instance.Notice("Initialising inventory manager...");
71 m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
72
63 m_inventoryManager = new InventoryManager(); 73 m_inventoryManager = new InventoryManager();
74 m_inventoryManager.AddDatabasePlugin(m_config.DatabaseProvider);
75 MainLog.Instance.Notice(LogName, "Starting HTTP server ...");
76 BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
64 77
65 MainConsole.Instance.Notice("Starting HTTP server"); 78 httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager));
66 BaseHttpServer httpServer = new BaseHttpServer(8004);
67 79
68 httpServer.AddXmlRPCHandler("rootfolders", m_inventoryManager.XmlRpcInventoryRequest); 80 httpServer.Start();
69 //httpServer.AddRestHandler("GET","/rootfolders/",Rest 81 MainLog.Instance.Notice(LogName, "Started HTTP server");
82 }
83
84 private void Work()
85 {
86 m_console.Notice("Enter help for a list of commands\n");
87
88 while (true)
89 {
90 m_console.MainLogPrompt();
91 }
70 } 92 }
71 93
72 public void RunCmd(string cmd, string[] cmdparams) 94 public void RunCmd(string cmd, string[] cmdparams)
73 { 95 {
74 switch (cmd) 96 switch (cmd)
75 { 97 {
98 case "quit":
76 case "shutdown": 99 case "shutdown":
77 m_console.Close(); 100 m_console.Close();
78 Environment.Exit(0); 101 Environment.Exit(0);