aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors
diff options
context:
space:
mode:
authordiva2009-06-07 19:00:55 +0000
committerdiva2009-06-07 19:00:55 +0000
commit1ad237a8a757a0e6074278aff76805d01abf0c0b (patch)
treee6a697dd113aeb90c7dd92ee4d07f278d7ebf8de /OpenSim/Services/Connectors
parentSkip lone ident statments or for-loop assignments (diff)
downloadopensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.zip
opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.gz
opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.bz2
opensim-SC_OLD-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/Connectors')
-rw-r--r--OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs107
-rw-r--r--OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs343
2 files changed, 450 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}