aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/InventoryServer/InventoryManager.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-13 14:59:18 +0000
committerJustin Clarke Casey2008-05-13 14:59:18 +0000
commit8293be681127c6d478cefa0f470cfb2f23728fd2 (patch)
treebfdbec346fbdb935736edfa8b8e41a00a08b810e /OpenSim/Grid/InventoryServer/InventoryManager.cs
parent* As part of the region registration process, the grid service now requests t... (diff)
downloadopensim-SC_OLD-8293be681127c6d478cefa0f470cfb2f23728fd2.zip
opensim-SC_OLD-8293be681127c6d478cefa0f470cfb2f23728fd2.tar.gz
opensim-SC_OLD-8293be681127c6d478cefa0f470cfb2f23728fd2.tar.bz2
opensim-SC_OLD-8293be681127c6d478cefa0f470cfb2f23728fd2.tar.xz
* Remove old historical grid inventory code
Diffstat (limited to 'OpenSim/Grid/InventoryServer/InventoryManager.cs')
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryManager.cs207
1 files changed, 0 insertions, 207 deletions
diff --git a/OpenSim/Grid/InventoryServer/InventoryManager.cs b/OpenSim/Grid/InventoryServer/InventoryManager.cs
deleted file mode 100644
index 5c65317..0000000
--- a/OpenSim/Grid/InventoryServer/InventoryManager.cs
+++ /dev/null
@@ -1,207 +0,0 @@
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
28using System;
29using System.IO;
30using System.Reflection;
31using System.Text;
32using System.Xml;
33using System.Xml.Serialization;
34using libsecondlife;
35using log4net;
36using OpenSim.Framework;
37using OpenSim.Framework.Servers;
38
39namespace OpenSim.Grid.InventoryServer
40{
41 public class InventoryManager
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 private IInventoryData _databasePlugin;
46
47 /// <summary>
48 /// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
49 /// </summary>
50 /// <param name="FileName">The filename to the inventory server plugin DLL</param>
51 public void AddDatabasePlugin(string FileName, string dbconnect)
52 {
53 m_log.Info("[" + OpenInventory_Main.LogName + "]: Invenstorage: Attempting to load " + FileName);
54 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
55
56 m_log.Info("[" + OpenInventory_Main.LogName + "]: " +
57 "Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
58 foreach (Type pluginType in pluginAssembly.GetTypes())
59 {
60 if (!pluginType.IsAbstract)
61 {
62 Type typeInterface = pluginType.GetInterface("IInventoryData", true);
63
64 if (typeInterface != null)
65 {
66 IInventoryData plug =
67 (IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
68 plug.Initialise(dbconnect);
69 _databasePlugin = plug;
70 m_log.Info("[" + OpenInventory_Main.LogName + "]: " +
71 "Invenstorage: Added IInventoryData Interface");
72 break;
73 }
74 }
75 }
76 }
77
78 protected static SerializableInventory loadInventoryFromXmlFile(string fileName)
79 {
80 FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
81 XmlReader reader = new XmlTextReader(fs);
82 XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
83 SerializableInventory inventory = (SerializableInventory) x.Deserialize(reader);
84 fs.Close();
85 fs.Dispose();
86 return inventory;
87 }
88
89 protected static void saveInventoryToStream(SerializableInventory inventory, Stream s)
90 {
91 XmlTextWriter writer = new XmlTextWriter(s, Encoding.UTF8);
92 writer.Formatting = Formatting.Indented;
93 XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
94 x.Serialize(writer, inventory);
95 }
96
97 protected static bool fixupFolder(SerializableInventory.SerializableFolder f,
98 SerializableInventory.SerializableFolder parent)
99 {
100 bool modified = false;
101
102 // ensure we have a valid folder id
103 if (f.ID == LLUUID.Zero)
104 {
105 f.ID = LLUUID.Random();
106 modified = true;
107 }
108
109 // ensure we have valid agent id
110 if (f.Owner == LLUUID.Zero)
111 {
112 if (parent != null)
113 f.Owner = parent.Owner;
114 else
115 f.Owner = f.ID;
116 modified = true;
117 }
118
119 if (f.ParentID == LLUUID.Zero && parent != null)
120 {
121 f.ParentID = parent.ID;
122 modified = true;
123 }
124
125
126 foreach (SerializableInventory.SerializableFolder child in f.SubFolders)
127 {
128 modified |= fixupFolder(child, f);
129 }
130
131 return modified;
132 }
133
134 protected static bool fixupInventory(SerializableInventory inventory)
135 {
136 return fixupFolder(inventory.root, null);
137 }
138
139 public class GetInventory : BaseStreamHandler
140 {
141 private SerializableInventory _inventory;
142 private InventoryManager _manager;
143
144 public GetInventory(InventoryManager manager)
145 : base("GET", "/inventory")
146 {
147 _manager = manager;
148
149 _inventory = loadInventoryFromXmlFile("attic/inventory/Inventory_Library.xml");
150 if (fixupInventory(_inventory))
151 {
152 FileStream fs = new FileStream("attic/inventory/Inventory_Library.xml", FileMode.Truncate, FileAccess.Write);
153 saveInventoryToStream(_inventory, fs);
154 fs.Flush();
155 fs.Close();
156 m_log.Debug("[" + OpenInventory_Main.LogName + "]: Modified");
157 }
158 }
159
160 private void CreateDefaultInventory(LLUUID userID)
161 {
162 }
163
164 private byte[] GetUserInventory(LLUUID userID)
165 {
166 m_log.InfoFormat("[" + OpenInventory_Main.LogName + "]: Getting Inventory for user {0}", userID.ToString());
167 byte[] result = new byte[] {};
168
169 InventoryFolderBase fb = _manager._databasePlugin.getUserRootFolder(userID);
170 if (fb == null)
171 {
172 m_log.InfoFormat("[" + OpenInventory_Main.LogName + "]: Inventory not found for user {0}, creating new",
173 userID.ToString());
174 CreateDefaultInventory(userID);
175 }
176
177 return result;
178 }
179
180 public override byte[] Handle(string path, Stream request)
181 {
182 byte[] result = new byte[] {};
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 {
189 MemoryStream ms = new MemoryStream();
190 saveInventoryToStream(_inventory, ms);
191
192 result = ms.GetBuffer();
193 Array.Resize<byte>(ref result, (int) ms.Length);
194 }
195 else if (string.Compare(parms[1], "user", true) == 0)
196 {
197 if (parms.Length > 2)
198 {
199 result = GetUserInventory(new LLUUID(parms[2]));
200 }
201 }
202 }
203 return result;
204 }
205 }
206 }
207}