aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/InventoryServer/InventoryManager.cs
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/InventoryManager.cs
parent* doh II (diff)
downloadopensim-SC_OLD-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.zip
opensim-SC_OLD-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.gz
opensim-SC_OLD-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.bz2
opensim-SC_OLD-6a8d8f54e88a21e6cfd78dc7981cdeec2f18094d.tar.xz
Step one on the long march towards grid based inventory. Introduction of an InevntoryServer
Diffstat (limited to 'OpenSim/Grid/InventoryServer/InventoryManager.cs')
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryManager.cs170
1 files changed, 127 insertions, 43 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}