aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authordiva2009-06-07 19:00:55 +0000
committerdiva2009-06-07 19:00:55 +0000
commit1ad237a8a757a0e6074278aff76805d01abf0c0b (patch)
treee6a697dd113aeb90c7dd92ee4d07f278d7ebf8de /OpenSim/Services
parentSkip lone ident statments or for-loop assignments (diff)
downloadopensim-SC-1ad237a8a757a0e6074278aff76805d01abf0c0b.zip
opensim-SC-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.gz
opensim-SC-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.bz2
opensim-SC-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.xz
First draft of inventory service connectors, and service implementation. No handlers yet, this is just the OUT part for now. It's not active and nothing in the simulator uses this yet. Just checking it in to start sharing with others. There are a couple of interesting software design points that could use other devs opinions.
Hopefully I added all needed files.
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs107
-rw-r--r--OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs343
-rw-r--r--OpenSim/Services/Interfaces/IInventoryService.cs118
-rw-r--r--OpenSim/Services/InventoryService/HGInventoryService.cs178
-rw-r--r--OpenSim/Services/InventoryService/InventoryService.cs544
-rw-r--r--OpenSim/Services/InventoryService/InventoryServiceBase.cs98
6 files changed, 1388 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs
new file mode 100644
index 0000000..4fc4363
--- /dev/null
+++ b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs
@@ -0,0 +1,107 @@
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 OpenSimulator 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 OpenSim.Framework;
29using OpenSim.Services.Interfaces;
30using OpenMetaverse;
31
32namespace OpenSim.Services.Connectors
33{
34 /// <summary>
35 /// Defines all operations to access a remote inventory service
36 /// using session authentication as a form of security.
37 /// </summary>
38 public interface ISessionAuthInventoryService
39 {
40 string Host
41 {
42 get;
43 }
44
45 /// <summary>
46 /// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
47 /// inventory has been received
48 /// </summary>
49 /// <param name="userID"></param>
50 /// <param name="callback"></param>
51 void GetUserInventory(string userID, UUID session_id, InventoryReceiptCallback callback);
52
53 /// <summary>
54 /// Add a new folder to the user's inventory
55 /// </summary>
56 /// <param name="folder"></param>
57 /// <returns>true if the folder was successfully added</returns>
58 bool AddFolder(string userID, InventoryFolderBase folder, UUID session_id);
59
60 /// <summary>
61 /// Update a folder in the user's inventory
62 /// </summary>
63 /// <param name="folder"></param>
64 /// <returns>true if the folder was successfully updated</returns>
65 bool UpdateFolder(string userID, InventoryFolderBase folder, UUID session_id);
66
67 /// <summary>
68 /// Move an inventory folder to a new location
69 /// </summary>
70 /// <param name="folder">A folder containing the details of the new location</param>
71 /// <returns>true if the folder was successfully moved</returns>
72 bool MoveFolder(string userID, InventoryFolderBase folder, UUID session_id);
73
74 /// <summary>
75 /// Purge an inventory folder of all its items and subfolders.
76 /// </summary>
77 /// <param name="folder"></param>
78 /// <returns>true if the folder was successfully purged</returns>
79 bool PurgeFolder(string userID, InventoryFolderBase folder, UUID session_id);
80
81 /// <summary>
82 /// Add a new item to the user's inventory
83 /// </summary>
84 /// <param name="item"></param>
85 /// <returns>true if the item was successfully added</returns>
86 bool AddItem(string userID, InventoryItemBase item, UUID session_id);
87
88 /// <summary>
89 /// Update an item in the user's inventory
90 /// </summary>
91 /// <param name="item"></param>
92 /// <returns>true if the item was successfully updated</returns>
93 bool UpdateItem(string userID, InventoryItemBase item, UUID session_id);
94
95 /// <summary>
96 /// Delete an item from the user's inventory
97 /// </summary>
98 /// <param name="item"></param>
99 /// <returns>true if the item was successfully deleted</returns>
100 bool DeleteItem(string userID, InventoryItemBase item, UUID session_id);
101
102 InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID session_id);
103
104 InventoryFolderBase QueryFolder(string userID, InventoryFolderBase item, UUID session_id);
105
106 }
107}
diff --git a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs
new file mode 100644
index 0000000..34478ae
--- /dev/null
+++ b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs
@@ -0,0 +1,343 @@
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 OpenSimulator 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 log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers.HttpServer;
36using OpenSim.Services.Interfaces;
37using OpenMetaverse;
38
39namespace OpenSim.Services.Connectors
40{
41 public class InventoryServicesConnector : ISessionAuthInventoryService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 private string m_ServerURI = String.Empty;
48
49 private Dictionary<UUID, InventoryReceiptCallback> m_RequestingInventory = new Dictionary<UUID, InventoryReceiptCallback>();
50
51 public InventoryServicesConnector()
52 {
53 }
54
55 public InventoryServicesConnector(string serverURI)
56 {
57 m_ServerURI = serverURI.TrimEnd('/');
58 }
59
60 public InventoryServicesConnector(IConfigSource source)
61 {
62 Initialise(source);
63 }
64
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig inventoryConfig = source.Configs["InventoryService"];
68 if (inventoryConfig == null)
69 {
70 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpanSim.ini");
71 throw new Exception("Inventory connector init error");
72 }
73
74 string serviceURI = inventoryConfig.GetString("InventoryServerURI",
75 String.Empty);
76
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
80 throw new Exception("Inventory connector init error");
81 }
82 m_ServerURI = serviceURI.TrimEnd('/');
83 }
84
85 #region ISessionAuthInventoryService
86
87 public string Host
88 {
89 get { return m_ServerURI; }
90 }
91
92 /// <summary>
93 /// Caller must catch eventual Exceptions.
94 /// </summary>
95 /// <param name="userID"></param>
96 /// <param name="sessionID"></param>
97 /// <param name="callback"></param>
98 public void GetUserInventory(string userIDStr, UUID sessionID, InventoryReceiptCallback callback)
99 {
100 UUID userID = UUID.Zero;
101 if (UUID.TryParse(userIDStr, out userID))
102 {
103 lock (m_RequestingInventory)
104 {
105 if (!m_RequestingInventory.ContainsKey(userID))
106 m_RequestingInventory.Add(userID, callback);
107 else
108 {
109 m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetUserInventory - ignoring repeated request for user {0}", userID);
110 return;
111 }
112 }
113
114 m_log.InfoFormat(
115 "[INVENTORY CONNECTOR]: Requesting inventory from {0}/GetInventory/ for user {1}",
116 m_ServerURI, userID);
117
118 RestSessionObjectPosterResponse<Guid, InventoryCollection> requester
119 = new RestSessionObjectPosterResponse<Guid, InventoryCollection>();
120 requester.ResponseCallback = InventoryResponse;
121
122 requester.BeginPostObject(m_ServerURI + "/GetInventory/", userID.Guid, sessionID.ToString(), userID.ToString());
123 }
124 }
125
126 public bool AddFolder(string userID, InventoryFolderBase folder, UUID sessionID)
127 {
128 try
129 {
130 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
131 "POST", m_ServerURI + "/NewFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
132 }
133 catch (Exception e)
134 {
135 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Add new inventory folder operation failed, {0} {1}",
136 e.Source, e.Message);
137 }
138
139 return false;
140 }
141
142 public bool UpdateFolder(string userID, InventoryFolderBase folder, UUID sessionID)
143 {
144 try
145 {
146 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
147 "POST", m_ServerURI + "/UpdateFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
148 }
149 catch (Exception e)
150 {
151 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Update inventory folder operation failed, {0} {1}",
152 e.Source, e.Message);
153 }
154
155 return false;
156 }
157
158 public bool MoveFolder(string userID, InventoryFolderBase folder, UUID sessionID)
159 {
160 try
161 {
162 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
163 "POST", m_ServerURI + "/MoveFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
164 }
165 catch (Exception e)
166 {
167 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory folder operation failed, {0} {1}",
168 e.Source, e.Message);
169 }
170
171 return false;
172 }
173
174 public bool PurgeFolder(string userID, InventoryFolderBase folder, UUID sessionID)
175 {
176 try
177 {
178 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
179 "POST", m_ServerURI + "/PurgeFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
180 }
181 catch (Exception e)
182 {
183 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory folder operation failed, {0} {1}",
184 e.Source, e.Message);
185 }
186
187 return false;
188 }
189
190 public bool AddItem(string userID, InventoryItemBase item, UUID sessionID)
191 {
192 try
193 {
194 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
195 "POST", m_ServerURI + "/NewItem/", item, sessionID.ToString(), item.Owner.ToString());
196 }
197 catch (Exception e)
198 {
199 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Add new inventory item operation failed, {0} {1}",
200 e.Source, e.Message);
201 }
202
203 return false;
204 }
205
206 public bool UpdateItem(string userID, InventoryItemBase item, UUID sessionID)
207 {
208 try
209 {
210 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
211 "POST", m_ServerURI + "/NewItem/", item, sessionID.ToString(), item.Owner.ToString());
212 }
213 catch (Exception e)
214 {
215 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Update new inventory item operation failed, {0} {1}",
216 e.Source, e.Message);
217 }
218
219 return false;
220 }
221
222 public bool DeleteItem(string userID, InventoryItemBase item, UUID sessionID)
223 {
224 try
225 {
226 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
227 "POST", m_ServerURI + "/DeleteItem/", item, sessionID.ToString(), item.Owner.ToString());
228 }
229 catch (Exception e)
230 {
231 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Delete inventory item operation failed, {0} {1}",
232 e.Source, e.Message);
233 }
234
235 return false;
236 }
237
238 public InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID sessionID)
239 {
240 try
241 {
242 return SynchronousRestSessionObjectPoster<InventoryItemBase, InventoryItemBase>.BeginPostObject(
243 "POST", m_ServerURI + "/QueryItem/", item, sessionID.ToString(), item.Owner.ToString());
244 }
245 catch (Exception e)
246 {
247 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Query inventory item operation failed, {0} {1}",
248 e.Source, e.Message);
249 }
250
251 return null;
252 }
253
254 public InventoryFolderBase QueryFolder(string userID, InventoryFolderBase item, UUID sessionID)
255 {
256 try
257 {
258 return SynchronousRestSessionObjectPoster<InventoryFolderBase, InventoryFolderBase>.BeginPostObject(
259 "POST", m_ServerURI + "/QueryFolder/", item, sessionID.ToString(), item.Owner.ToString());
260 }
261 catch (Exception e)
262 {
263 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Query inventory item operation failed, {0} {1}",
264 e.Source, e.Message);
265 }
266
267 return null;
268 }
269
270 #endregion
271
272 /// <summary>
273 /// Callback used by the inventory server GetInventory request
274 /// </summary>
275 /// <param name="userID"></param>
276 private void InventoryResponse(InventoryCollection response)
277 {
278 UUID userID = response.UserID;
279 InventoryReceiptCallback callback = null;
280 lock (m_RequestingInventory)
281 {
282 if (m_RequestingInventory.ContainsKey(userID))
283 {
284 callback = m_RequestingInventory[userID];
285 m_RequestingInventory.Remove(userID);
286 }
287 else
288 {
289 m_log.WarnFormat(
290 "[INVENTORY CONNECTOR]: " +
291 "Received inventory response for {0} for which we do not have a record of requesting!",
292 userID);
293 return;
294 }
295 }
296
297 m_log.InfoFormat("[INVENTORY CONNECTOR]: " +
298 "Received inventory response for user {0} containing {1} folders and {2} items",
299 userID, response.Folders.Count, response.Items.Count);
300
301 InventoryFolderImpl rootFolder = null;
302
303 ICollection<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
304 ICollection<InventoryItemBase> items = new List<InventoryItemBase>();
305
306 foreach (InventoryFolderBase folder in response.Folders)
307 {
308 if (folder.ParentID == UUID.Zero)
309 {
310 rootFolder = new InventoryFolderImpl(folder);
311 folders.Add(rootFolder);
312
313 break;
314 }
315 }
316
317 if (rootFolder != null)
318 {
319 foreach (InventoryFolderBase folder in response.Folders)
320 {
321 if (folder.ID != rootFolder.ID)
322 {
323 folders.Add(new InventoryFolderImpl(folder));
324 }
325 }
326
327 foreach (InventoryItemBase item in response.Items)
328 {
329 items.Add(item);
330 }
331 }
332 else
333 {
334 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Did not get back an inventory containing a root folder for user {0}", userID);
335 }
336
337 callback(folders, items);
338
339 }
340
341
342 }
343}
diff --git a/OpenSim/Services/Interfaces/IInventoryService.cs b/OpenSim/Services/Interfaces/IInventoryService.cs
new file mode 100644
index 0000000..9fe419f
--- /dev/null
+++ b/OpenSim/Services/Interfaces/IInventoryService.cs
@@ -0,0 +1,118 @@
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 OpenSimulator 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.Collections.Generic;
30using OpenSim.Framework;
31using OpenMetaverse;
32
33namespace OpenSim.Services.Interfaces
34{
35 /// <summary>
36 /// Callback used when a user's inventory is received from the inventory service
37 /// </summary>
38 public delegate void InventoryReceiptCallback(
39 ICollection<InventoryFolderImpl> folders, ICollection<InventoryItemBase> items);
40
41 public interface IInventoryService
42 {
43 /// <summary>
44 /// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
45 /// inventory has been received
46 /// </summary>
47 /// <param name="userID"></param>
48 /// <param name="callback"></param>
49 void GetUserInventory(UUID userID, InventoryReceiptCallback callback);
50
51 /// <summary>
52 /// Add a new folder to the user's inventory
53 /// </summary>
54 /// <param name="folder"></param>
55 /// <returns>true if the folder was successfully added</returns>
56 bool AddFolder(InventoryFolderBase folder);
57
58 /// <summary>
59 /// Update a folder in the user's inventory
60 /// </summary>
61 /// <param name="folder"></param>
62 /// <returns>true if the folder was successfully updated</returns>
63 bool UpdateFolder(InventoryFolderBase folder);
64
65 /// <summary>
66 /// Move an inventory folder to a new location
67 /// </summary>
68 /// <param name="folder">A folder containing the details of the new location</param>
69 /// <returns>true if the folder was successfully moved</returns>
70 bool MoveFolder(InventoryFolderBase folder);
71
72 /// <summary>
73 /// Purge an inventory folder of all its items and subfolders.
74 /// </summary>
75 /// <param name="folder"></param>
76 /// <returns>true if the folder was successfully purged</returns>
77 bool PurgeFolder(InventoryFolderBase folder);
78
79 /// <summary>
80 /// Add a new item to the user's inventory
81 /// </summary>
82 /// <param name="item"></param>
83 /// <returns>true if the item was successfully added</returns>
84 bool AddItem(InventoryItemBase item);
85
86 /// <summary>
87 /// Update an item in the user's inventory
88 /// </summary>
89 /// <param name="item"></param>
90 /// <returns>true if the item was successfully updated</returns>
91 bool UpdateItem(InventoryItemBase item);
92
93 /// <summary>
94 /// Delete an item from the user's inventory
95 /// </summary>
96 /// <param name="item"></param>
97 /// <returns>true if the item was successfully deleted</returns>
98 bool DeleteItem(InventoryItemBase item);
99
100 InventoryItemBase QueryItem(InventoryItemBase item);
101
102 InventoryFolderBase QueryFolder(InventoryFolderBase folder);
103
104 /// <summary>
105 /// Does the given user have an inventory structure?
106 /// </summary>
107 /// <param name="userID"></param>
108 /// <returns></returns>
109 bool HasInventoryForUser(UUID userID);
110
111 /// <summary>
112 /// Retrieve the root inventory folder for the given user.
113 /// </summary>
114 /// <param name="userID"></param>
115 /// <returns>null if no root folder was found</returns>
116 InventoryFolderBase RequestRootFolder(UUID userID);
117 }
118}
diff --git a/OpenSim/Services/InventoryService/HGInventoryService.cs b/OpenSim/Services/InventoryService/HGInventoryService.cs
new file mode 100644
index 0000000..e5e40c6
--- /dev/null
+++ b/OpenSim/Services/InventoryService/HGInventoryService.cs
@@ -0,0 +1,178 @@
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 OpenSimulator 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 log4net;
29using Nini.Config;
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Connectors;
36using OpenMetaverse;
37
38namespace OpenSim.Services.InventoryService
39{
40 public class HGInventoryService : ISessionAuthInventoryService
41 {
42 private static readonly ILog m_log =
43 LogManager.GetLogger(
44 MethodBase.GetCurrentMethod().DeclaringType);
45
46 private Dictionary<string, InventoryServicesConnector> m_connectors = new Dictionary<string, InventoryServicesConnector>();
47
48 public HGInventoryService(IConfigSource source)
49 {
50 IConfig moduleConfig = source.Configs["Modules"];
51 if (moduleConfig != null)
52 {
53
54 IConfig assetConfig = source.Configs["InventoryService"];
55 if (assetConfig == null)
56 {
57 m_log.Error("[HG INVENTORY SERVICE]: InventoryService missing from OpenSim.ini");
58 return;
59 }
60
61 m_log.Info("[HG INVENTORY SERVICE]: HG inventory service enabled");
62 }
63 }
64
65 private bool StringToUrlAndUserID(string id, out string url, out string userID)
66 {
67 url = String.Empty;
68 userID = String.Empty;
69
70 Uri assetUri;
71
72 if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
73 assetUri.Scheme == Uri.UriSchemeHttp)
74 {
75 url = "http://" + assetUri.Authority;
76 userID = assetUri.LocalPath.Trim(new char[] { '/' });
77 return true;
78 }
79
80 return false;
81 }
82 private ISessionAuthInventoryService GetConnector(string url)
83 {
84 InventoryServicesConnector connector = null;
85 lock (m_connectors)
86 {
87 if (m_connectors.ContainsKey(url))
88 {
89 connector = m_connectors[url];
90 }
91 else
92 {
93 // We're instantiating this class explicitly, but this won't
94 // work in general, because the remote grid may be running
95 // an inventory server that has a different protocol.
96 // Eventually we will want a piece of protocol asking
97 // the remote server about its kind. Definitely cool thing to do!
98 connector = new InventoryServicesConnector(url);
99 m_connectors.Add(url, connector);
100 }
101 }
102 return connector;
103 }
104
105 public string Host
106 {
107 get { return string.Empty; }
108 }
109
110 public void GetUserInventory(string id, UUID sessionID, InventoryReceiptCallback callback)
111 {
112 string url = string.Empty;
113 string userID = string.Empty;
114
115 if (StringToUrlAndUserID(id, out url, out userID))
116 {
117 ISessionAuthInventoryService connector = GetConnector(url);
118 connector.GetUserInventory(userID, sessionID, callback);
119 }
120
121 }
122
123 public bool AddFolder(string userID, InventoryFolderBase folder, UUID sessionID)
124 {
125 // TODO
126 return false;
127 }
128
129 public bool UpdateFolder(string userID, InventoryFolderBase folder, UUID sessionID)
130 {
131 // TODO
132 return false;
133 }
134
135 public bool MoveFolder(string userID, InventoryFolderBase folder, UUID sessionID)
136 {
137 // TODO
138 return false;
139 }
140
141 public bool PurgeFolder(string userID, InventoryFolderBase folder, UUID sessionID)
142 {
143 // TODO
144 return false;
145 }
146
147 public bool AddItem(string userID, InventoryItemBase item, UUID sessionID)
148 {
149 // TODO
150 return false;
151 }
152
153 public bool UpdateItem(string userID, InventoryItemBase item, UUID sessionID)
154 {
155 // TODO
156 return false;
157 }
158
159 public bool DeleteItem(string userID, InventoryItemBase item, UUID sessionID)
160 {
161 // TODO
162 return false;
163 }
164
165 public InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID sessionID)
166 {
167 // TODO
168 return null;
169 }
170
171 public InventoryFolderBase QueryFolder(string userID, InventoryFolderBase folder, UUID sessionID)
172 {
173 // TODO
174 return null;
175 }
176
177 }
178}
diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs
new file mode 100644
index 0000000..b4e2549
--- /dev/null
+++ b/OpenSim/Services/InventoryService/InventoryService.cs
@@ -0,0 +1,544 @@
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 OpenSimulator 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.Collections.Generic;
29using System.Reflection;
30using log4net;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Data;
34using OpenSim.Framework;
35using OpenSim.Services.Interfaces;
36
37namespace OpenSim.Services.InventoryService
38{
39 /// <summary>
40 /// The Inventory service reference implementation
41 /// </summary>
42 public class InventoryService : InventoryServiceBase, IInventoryService
43 {
44 private static readonly ILog m_log
45 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 public InventoryService(IConfigSource config) : base(config)
48 {
49 }
50
51 #region IInventoryServices methods
52
53 public string Host
54 {
55 get { return "default"; }
56 }
57
58 public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
59 {
60// m_log.DebugFormat("[AGENT INVENTORY]: Getting inventory skeleton for {0}", userId);
61
62 InventoryFolderBase rootFolder = RequestRootFolder(userId);
63
64 // Agent has no inventory structure yet.
65 if (null == rootFolder)
66 {
67 return null;
68 }
69
70 List<InventoryFolderBase> userFolders = new List<InventoryFolderBase>();
71
72 userFolders.Add(rootFolder);
73
74 foreach (IInventoryDataPlugin plugin in m_plugins)
75 {
76 IList<InventoryFolderBase> folders = plugin.getFolderHierarchy(rootFolder.ID);
77 userFolders.AddRange(folders);
78 }
79
80// foreach (InventoryFolderBase folder in userFolders)
81// {
82// m_log.DebugFormat("[AGENT INVENTORY]: Got folder {0} {1}", folder.name, folder.folderID);
83// }
84
85 return userFolders;
86 }
87
88 // See IInventoryServices
89 public virtual bool HasInventoryForUser(UUID userID)
90 {
91 return false;
92 }
93
94 // See IInventoryServices
95 public virtual InventoryFolderBase RequestRootFolder(UUID userID)
96 {
97 // Retrieve the first root folder we get from the list of plugins.
98 foreach (IInventoryDataPlugin plugin in m_plugins)
99 {
100 InventoryFolderBase rootFolder = plugin.getUserRootFolder(userID);
101 if (rootFolder != null)
102 return rootFolder;
103 }
104
105 // Return nothing if no plugin was able to supply a root folder
106 return null;
107 }
108
109 // See IInventoryServices
110 public bool CreateNewUserInventory(UUID user)
111 {
112 InventoryFolderBase existingRootFolder = RequestRootFolder(user);
113
114 if (null != existingRootFolder)
115 {
116 m_log.WarnFormat(
117 "[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have "
118 + "a root inventory folder with id {1}",
119 user, existingRootFolder.ID);
120 }
121 else
122 {
123 UsersInventory inven = new UsersInventory();
124 inven.CreateNewInventorySet(user);
125 AddNewInventorySet(inven);
126
127 return true;
128 }
129
130 return false;
131 }
132
133 // See IInventoryServices
134 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
135 {
136 m_log.InfoFormat("[LOCAL INVENTORY SERVICE]: Requesting inventory for user {0}", userID);
137
138 List<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
139 List<InventoryItemBase> items = new List<InventoryItemBase>();
140
141 List<InventoryFolderBase> skeletonFolders = GetInventorySkeleton(userID);
142
143 if (skeletonFolders != null)
144 {
145
146 InventoryFolderImpl rootFolder = null;
147
148 // Need to retrieve the root folder on the first pass
149 foreach (InventoryFolderBase folder in skeletonFolders)
150 {
151 if (folder.ParentID == UUID.Zero)
152 {
153 rootFolder = new InventoryFolderImpl(folder);
154 folders.Add(rootFolder);
155 items.AddRange(RequestFolderItems(rootFolder.ID));
156 break; // Only 1 root folder per user
157 }
158 }
159
160 if (rootFolder != null)
161 {
162 foreach (InventoryFolderBase folder in skeletonFolders)
163 {
164 if (folder.ID != rootFolder.ID)
165 {
166 folders.Add(new InventoryFolderImpl(folder));
167 items.AddRange(RequestFolderItems(folder.ID));
168 }
169 }
170 }
171
172 m_log.InfoFormat(
173 "[LOCAL INVENTORY SERVICE]: Received inventory response for user {0} containing {1} folders and {2} items",
174 userID, folders.Count, items.Count);
175 }
176 else
177 {
178 m_log.WarnFormat("[LOCAL INVENTORY SERVICE]: User {0} inventory not available", userID);
179 }
180
181 callback(folders, items);
182 }
183
184 public List<InventoryItemBase> GetActiveGestures(UUID userId)
185 {
186 List<InventoryItemBase> activeGestures = new List<InventoryItemBase>();
187 foreach (IInventoryDataPlugin plugin in m_plugins)
188 {
189 activeGestures.AddRange(plugin.fetchActiveGestures(userId));
190 }
191
192 return activeGestures;
193 }
194
195 #endregion
196
197 #region Methods used by GridInventoryService
198
199 public List<InventoryFolderBase> RequestSubFolders(UUID parentFolderID)
200 {
201 List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>();
202
203 foreach (IInventoryDataPlugin plugin in m_plugins)
204 {
205 inventoryList.AddRange(plugin.getInventoryFolders(parentFolderID));
206 }
207
208 return inventoryList;
209 }
210
211 public List<InventoryItemBase> RequestFolderItems(UUID folderID)
212 {
213 List<InventoryItemBase> itemsList = new List<InventoryItemBase>();
214
215 foreach (IInventoryDataPlugin plugin in m_plugins)
216 {
217 itemsList.AddRange(plugin.getInventoryInFolder(folderID));
218 }
219
220 return itemsList;
221 }
222
223 #endregion
224
225 // See IInventoryServices
226 public virtual bool AddFolder(InventoryFolderBase folder)
227 {
228 m_log.DebugFormat(
229 "[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
230
231 foreach (IInventoryDataPlugin plugin in m_plugins)
232 {
233 plugin.addInventoryFolder(folder);
234 }
235
236 // FIXME: Should return false on failure
237 return true;
238 }
239
240 // See IInventoryServices
241 public virtual bool UpdateFolder(InventoryFolderBase folder)
242 {
243 m_log.DebugFormat(
244 "[AGENT INVENTORY]: Updating folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
245
246 foreach (IInventoryDataPlugin plugin in m_plugins)
247 {
248 plugin.updateInventoryFolder(folder);
249 }
250
251 // FIXME: Should return false on failure
252 return true;
253 }
254
255 // See IInventoryServices
256 public virtual bool MoveFolder(InventoryFolderBase folder)
257 {
258 m_log.DebugFormat(
259 "[AGENT INVENTORY]: Moving folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
260
261 foreach (IInventoryDataPlugin plugin in m_plugins)
262 {
263 plugin.moveInventoryFolder(folder);
264 }
265
266 // FIXME: Should return false on failure
267 return true;
268 }
269
270 // See IInventoryServices
271 public virtual bool AddItem(InventoryItemBase item)
272 {
273 m_log.DebugFormat(
274 "[AGENT INVENTORY]: Adding item {0} {1} to folder {2}", item.Name, item.ID, item.Folder);
275
276 foreach (IInventoryDataPlugin plugin in m_plugins)
277 {
278 plugin.addInventoryItem(item);
279 }
280
281 // FIXME: Should return false on failure
282 return true;
283 }
284
285 // See IInventoryServices
286 public virtual bool UpdateItem(InventoryItemBase item)
287 {
288 m_log.InfoFormat(
289 "[AGENT INVENTORY]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder);
290
291 foreach (IInventoryDataPlugin plugin in m_plugins)
292 {
293 plugin.updateInventoryItem(item);
294 }
295
296 // FIXME: Should return false on failure
297 return true;
298 }
299
300 // See IInventoryServices
301 public virtual bool DeleteItem(InventoryItemBase item)
302 {
303 m_log.InfoFormat(
304 "[AGENT INVENTORY]: Deleting item {0} {1} from folder {2}", item.Name, item.ID, item.Folder);
305
306 foreach (IInventoryDataPlugin plugin in m_plugins)
307 {
308 plugin.deleteInventoryItem(item.ID);
309 }
310
311 // FIXME: Should return false on failure
312 return true;
313 }
314
315 public virtual InventoryItemBase QueryItem(InventoryItemBase item)
316 {
317 foreach (IInventoryDataPlugin plugin in m_plugins)
318 {
319 InventoryItemBase result = plugin.queryInventoryItem(item.ID);
320 if (result != null)
321 return result;
322 }
323
324 return null;
325 }
326
327 public virtual InventoryFolderBase QueryFolder(InventoryFolderBase item)
328 {
329 foreach (IInventoryDataPlugin plugin in m_plugins)
330 {
331 InventoryFolderBase result = plugin.queryInventoryFolder(item.ID);
332 if (result != null)
333 return result;
334 }
335
336 return null;
337 }
338
339 /// <summary>
340 /// Purge a folder of all items items and subfolders.
341 ///
342 /// FIXME: Really nasty in a sense, because we have to query the database to get information we may
343 /// already know... Needs heavy refactoring.
344 /// </summary>
345 /// <param name="folder"></param>
346 public virtual bool PurgeFolder(InventoryFolderBase folder)
347 {
348 m_log.DebugFormat(
349 "[AGENT INVENTORY]: Purging folder {0} {1} of its contents", folder.Name, folder.ID);
350
351 List<InventoryFolderBase> subFolders = RequestSubFolders(folder.ID);
352
353 foreach (InventoryFolderBase subFolder in subFolders)
354 {
355// m_log.DebugFormat("[AGENT INVENTORY]: Deleting folder {0} {1}", subFolder.Name, subFolder.ID);
356
357 foreach (IInventoryDataPlugin plugin in m_plugins)
358 {
359 plugin.deleteInventoryFolder(subFolder.ID);
360 }
361 }
362
363 List<InventoryItemBase> items = RequestFolderItems(folder.ID);
364
365 foreach (InventoryItemBase item in items)
366 {
367 DeleteItem(item);
368 }
369
370 // FIXME: Should return false on failure
371 return true;
372 }
373
374 private void AddNewInventorySet(UsersInventory inventory)
375 {
376 foreach (InventoryFolderBase folder in inventory.Folders.Values)
377 {
378 AddFolder(folder);
379 }
380 }
381
382 public InventoryItemBase GetInventoryItem(UUID itemID)
383 {
384 foreach (IInventoryDataPlugin plugin in m_plugins)
385 {
386 InventoryItemBase item = plugin.getInventoryItem(itemID);
387 if (item != null)
388 return item;
389 }
390
391 return null;
392 }
393
394 /// <summary>
395 /// Used to create a new user inventory.
396 /// </summary>
397 private class UsersInventory
398 {
399 public Dictionary<UUID, InventoryFolderBase> Folders = new Dictionary<UUID, InventoryFolderBase>();
400 public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>();
401
402 public virtual void CreateNewInventorySet(UUID user)
403 {
404 InventoryFolderBase folder = new InventoryFolderBase();
405
406 folder.ParentID = UUID.Zero;
407 folder.Owner = user;
408 folder.ID = UUID.Random();
409 folder.Name = "My Inventory";
410 folder.Type = (short)AssetType.Folder;
411 folder.Version = 1;
412 Folders.Add(folder.ID, folder);
413
414 UUID rootFolder = folder.ID;
415
416 folder = new InventoryFolderBase();
417 folder.ParentID = rootFolder;
418 folder.Owner = user;
419 folder.ID = UUID.Random();
420 folder.Name = "Animations";
421 folder.Type = (short)AssetType.Animation;
422 folder.Version = 1;
423 Folders.Add(folder.ID, folder);
424
425 folder = new InventoryFolderBase();
426 folder.ParentID = rootFolder;
427 folder.Owner = user;
428 folder.ID = UUID.Random();
429 folder.Name = "Body Parts";
430 folder.Type = (short)AssetType.Bodypart;
431 folder.Version = 1;
432 Folders.Add(folder.ID, folder);
433
434 folder = new InventoryFolderBase();
435 folder.ParentID = rootFolder;
436 folder.Owner = user;
437 folder.ID = UUID.Random();
438 folder.Name = "Calling Cards";
439 folder.Type = (short)AssetType.CallingCard;
440 folder.Version = 1;
441 Folders.Add(folder.ID, folder);
442
443 folder = new InventoryFolderBase();
444 folder.ParentID = rootFolder;
445 folder.Owner = user;
446 folder.ID = UUID.Random();
447 folder.Name = "Clothing";
448 folder.Type = (short)AssetType.Clothing;
449 folder.Version = 1;
450 Folders.Add(folder.ID, folder);
451
452 folder = new InventoryFolderBase();
453 folder.ParentID = rootFolder;
454 folder.Owner = user;
455 folder.ID = UUID.Random();
456 folder.Name = "Gestures";
457 folder.Type = (short)AssetType.Gesture;
458 folder.Version = 1;
459 Folders.Add(folder.ID, folder);
460
461 folder = new InventoryFolderBase();
462 folder.ParentID = rootFolder;
463 folder.Owner = user;
464 folder.ID = UUID.Random();
465 folder.Name = "Landmarks";
466 folder.Type = (short)AssetType.Landmark;
467 folder.Version = 1;
468 Folders.Add(folder.ID, folder);
469
470 folder = new InventoryFolderBase();
471 folder.ParentID = rootFolder;
472 folder.Owner = user;
473 folder.ID = UUID.Random();
474 folder.Name = "Lost And Found";
475 folder.Type = (short)AssetType.LostAndFoundFolder;
476 folder.Version = 1;
477 Folders.Add(folder.ID, folder);
478
479 folder = new InventoryFolderBase();
480 folder.ParentID = rootFolder;
481 folder.Owner = user;
482 folder.ID = UUID.Random();
483 folder.Name = "Notecards";
484 folder.Type = (short)AssetType.Notecard;
485 folder.Version = 1;
486 Folders.Add(folder.ID, folder);
487
488 folder = new InventoryFolderBase();
489 folder.ParentID = rootFolder;
490 folder.Owner = user;
491 folder.ID = UUID.Random();
492 folder.Name = "Objects";
493 folder.Type = (short)AssetType.Object;
494 folder.Version = 1;
495 Folders.Add(folder.ID, folder);
496
497 folder = new InventoryFolderBase();
498 folder.ParentID = rootFolder;
499 folder.Owner = user;
500 folder.ID = UUID.Random();
501 folder.Name = "Photo Album";
502 folder.Type = (short)AssetType.SnapshotFolder;
503 folder.Version = 1;
504 Folders.Add(folder.ID, folder);
505
506 folder = new InventoryFolderBase();
507 folder.ParentID = rootFolder;
508 folder.Owner = user;
509 folder.ID = UUID.Random();
510 folder.Name = "Scripts";
511 folder.Type = (short)AssetType.LSLText;
512 folder.Version = 1;
513 Folders.Add(folder.ID, folder);
514
515 folder = new InventoryFolderBase();
516 folder.ParentID = rootFolder;
517 folder.Owner = user;
518 folder.ID = UUID.Random();
519 folder.Name = "Sounds";
520 folder.Type = (short)AssetType.Sound;
521 folder.Version = 1;
522 Folders.Add(folder.ID, folder);
523
524 folder = new InventoryFolderBase();
525 folder.ParentID = rootFolder;
526 folder.Owner = user;
527 folder.ID = UUID.Random();
528 folder.Name = "Textures";
529 folder.Type = (short)AssetType.Texture;
530 folder.Version = 1;
531 Folders.Add(folder.ID, folder);
532
533 folder = new InventoryFolderBase();
534 folder.ParentID = rootFolder;
535 folder.Owner = user;
536 folder.ID = UUID.Random();
537 folder.Name = "Trash";
538 folder.Type = (short)AssetType.TrashFolder;
539 folder.Version = 1;
540 Folders.Add(folder.ID, folder);
541 }
542 }
543 }
544}
diff --git a/OpenSim/Services/InventoryService/InventoryServiceBase.cs b/OpenSim/Services/InventoryService/InventoryServiceBase.cs
new file mode 100644
index 0000000..a10e94f
--- /dev/null
+++ b/OpenSim/Services/InventoryService/InventoryServiceBase.cs
@@ -0,0 +1,98 @@
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 OpenSimulator 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.Collections.Generic;
30using System.Reflection;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenSim.Data;
34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Base;
36
37namespace OpenSim.Services.InventoryService
38{
39 public class InventoryServiceBase : ServiceBase
40 {
41 protected IInventoryDataPlugin m_Database = null;
42
43 protected List<IInventoryDataPlugin> m_plugins = new List<IInventoryDataPlugin>();
44
45 public InventoryServiceBase(IConfigSource config) : base(config)
46 {
47 IConfig assetConfig = config.Configs["InventoryService"];
48 if (assetConfig == null)
49 throw new Exception("No InventoryService configuration");
50
51 string dllName = assetConfig.GetString("StorageProvider",
52 String.Empty);
53
54 if (dllName == String.Empty)
55 throw new Exception("No StorageProvider configured");
56
57 string connString = assetConfig.GetString("ConnectionString",
58 String.Empty);
59
60 m_Database = LoadPlugin<IInventoryDataPlugin>(dllName);
61 if (m_Database == null)
62 throw new Exception("Could not find a storage interface in the given module");
63
64 m_Database.Initialise(connString);
65
66 }
67
68 #region Plugin methods
69
70 /// <summary>
71 /// Add a new inventory data plugin - plugins will be requested in the order they were added.
72 /// </summary>
73 /// <param name="plugin">The plugin that will provide data</param>
74 public void AddPlugin(IInventoryDataPlugin plugin)
75 {
76 m_plugins.Add(plugin);
77 }
78
79 /// <summary>
80 /// Adds a list of inventory data plugins, as described by `provider'
81 /// and `connect', to `m_plugins'.
82 /// </summary>
83 /// <param name="provider">
84 /// The filename of the inventory server plugin DLL.
85 /// </param>
86 /// <param name="connect">
87 /// The connection string for the storage backend.
88 /// </param>
89 public void AddPlugin(string provider, string connect)
90 {
91 m_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(provider, connect));
92 }
93
94 #endregion
95
96
97 }
98}