aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs47
-rw-r--r--OpenSim/Services/HypergridService/HGInventoryService.cs6
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs748
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs62
4 files changed, 805 insertions, 58 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
index 39e983b..9d96703 100644
--- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
+++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
@@ -111,19 +111,21 @@ namespace OpenSim.Services.Connectors
111 if (ret.Count == 0) 111 if (ret.Count == 0)
112 return null; 112 return null;
113 113
114 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 114 Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
115
116 List<InventoryFolderBase> fldrs = new List<InventoryFolderBase>();
115 117
116 try 118 try
117 { 119 {
118 foreach (Object o in ret.Values) 120 foreach (Object o in folders.Values)
119 folders.Add(BuildFolder((Dictionary<string, object>)o)); 121 fldrs.Add(BuildFolder((Dictionary<string, object>)o));
120 } 122 }
121 catch (Exception e) 123 catch (Exception e)
122 { 124 {
123 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message); 125 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message);
124 } 126 }
125 127
126 return folders; 128 return fldrs;
127 } 129 }
128 130
129 public InventoryFolderBase GetRootFolder(UUID principalID) 131 public InventoryFolderBase GetRootFolder(UUID principalID)
@@ -492,12 +494,41 @@ namespace OpenSim.Services.Connectors
492 return int.Parse(ret["RESULT"].ToString()); 494 return int.Parse(ret["RESULT"].ToString());
493 } 495 }
494 496
495
496 // These are either obsolete or unused
497 //
498 public InventoryCollection GetUserInventory(UUID principalID) 497 public InventoryCollection GetUserInventory(UUID principalID)
499 { 498 {
500 return null; 499 InventoryCollection inventory = new InventoryCollection();
500 inventory.Folders = new List<InventoryFolderBase>();
501 inventory.Items = new List<InventoryItemBase>();
502 inventory.UserID = principalID;
503
504 try
505 {
506 Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY",
507 new Dictionary<string, object> {
508 { "PRINCIPAL", principalID.ToString() }
509 });
510
511 if (ret == null)
512 return null;
513 if (ret.Count == 0)
514 return null;
515
516 Dictionary<string, object> folders =
517 (Dictionary<string, object>)ret["FOLDERS"];
518 Dictionary<string, object> items =
519 (Dictionary<string, object>)ret["ITEMS"];
520
521 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
522 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
523 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
524 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
525 }
526 catch (Exception e)
527 {
528 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message);
529 }
530
531 return inventory;
501 } 532 }
502 533
503 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) 534 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)
diff --git a/OpenSim/Services/HypergridService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs
index b29d803..2e9bd40 100644
--- a/OpenSim/Services/HypergridService/HGInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGInventoryService.cs
@@ -105,6 +105,12 @@ namespace OpenSim.Services.HypergridService
105 return new List<InventoryFolderBase>(); 105 return new List<InventoryFolderBase>();
106 } 106 }
107 107
108 public override InventoryCollection GetUserInventory(UUID userID)
109 {
110 // NOGO for this inventory service
111 return null;
112 }
113
108 public override InventoryFolderBase GetRootFolder(UUID principalID) 114 public override InventoryFolderBase GetRootFolder(UUID principalID)
109 { 115 {
110 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID); 116 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index cb686e2..e65ad17 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Services.HypergridService
48 /// and it responds to GetRootFolder requests with the ID of the 48 /// and it responds to GetRootFolder requests with the ID of the
49 /// Suitcase folder, not the actual "My Inventory" folder. 49 /// Suitcase folder, not the actual "My Inventory" folder.
50 /// </summary> 50 /// </summary>
51 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService 51 public class HGSuitcaseInventoryService1 : XInventoryService, IInventoryService
52 { 52 {
53 private static readonly ILog m_log = 53 private static readonly ILog m_log =
54 LogManager.GetLogger( 54 LogManager.GetLogger(
@@ -61,7 +61,7 @@ namespace OpenSim.Services.HypergridService
61 61
62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>(); 62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
63 63
64 public HGSuitcaseInventoryService(IConfigSource config, string configName) 64 public HGSuitcaseInventoryService1(IConfigSource config, string configName)
65 : base(config, configName) 65 : base(config, configName)
66 { 66 {
67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName); 67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
@@ -104,11 +104,79 @@ namespace OpenSim.Services.HypergridService
104 return false; 104 return false;
105 } 105 }
106 106
107
108 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) 107 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
109 { 108 {
110 // NOGO for this inventory service 109 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
111 return new List<InventoryFolderBase>(); 110 XInventoryFolder root = GetRootXFolder(principalID);
111
112 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
113 if (tree == null || (tree != null && tree.Count == 0))
114 return null;
115
116 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
117 foreach (XInventoryFolder x in tree)
118 {
119 if (x.parentFolderID == suitcase.folderID)
120 x.parentFolderID = root.folderID;
121
122 folders.Add(ConvertToOpenSim(x));
123 }
124
125 SetAsRootFolder(suitcase, root);
126 folders.Add(ConvertToOpenSim(suitcase));
127
128 return folders;
129 }
130
131 public override InventoryCollection GetUserInventory(UUID userID)
132 {
133 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
134 InventoryCollection userInventory = new InventoryCollection();
135 userInventory.UserID = userID;
136 userInventory.Folders = new List<InventoryFolderBase>();
137 userInventory.Items = new List<InventoryItemBase>();
138
139 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
140 XInventoryFolder root = GetRootXFolder(userID);
141
142 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
143 if (tree == null || (tree != null && tree.Count == 0))
144 {
145 SetAsRootFolder(suitcase, root);
146 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
147 return userInventory;
148 }
149
150 List<InventoryItemBase> items;
151 foreach (XInventoryFolder f in tree)
152 {
153 // Add the items of this subfolder
154 items = GetFolderItems(userID, f.folderID);
155 if (items != null && items.Count > 0)
156 {
157 userInventory.Items.AddRange(items);
158 }
159
160 // Add the folder itself
161 if (f.parentFolderID == suitcase.folderID)
162 f.parentFolderID = root.folderID;
163 userInventory.Folders.Add(ConvertToOpenSim(f));
164 }
165
166 items = GetFolderItems(userID, suitcase.folderID);
167 if (items != null && items.Count > 0)
168 {
169 foreach (InventoryItemBase i in items)
170 i.Folder = root.folderID;
171 userInventory.Items.AddRange(items);
172 }
173
174 SetAsRootFolder(suitcase, root);
175 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
176
177 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
178 userID, userInventory.Folders.Count, userInventory.Items.Count);
179 return userInventory;
112 } 180 }
113 181
114 public override InventoryFolderBase GetRootFolder(UUID principalID) 182 public override InventoryFolderBase GetRootFolder(UUID principalID)
@@ -131,23 +199,87 @@ namespace OpenSim.Services.HypergridService
131 { 199 {
132 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); 200 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
133 // make one, and let's add it to the user's inventory as a direct child of the root folder 201 // make one, and let's add it to the user's inventory as a direct child of the root folder
202 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
134 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); 203 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
135 if (suitcase == null) 204 if (suitcase == null)
136 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); 205 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
206 suitcase.version = root.version;
207 m_Database.StoreFolder(suitcase);
137 208
209 // Create System folders
210 CreateSystemFolders(principalID, suitcase.folderID);
211 }
212 else if (suitcase.version < root.version)
213 {
214 suitcase.version = root.version;
138 m_Database.StoreFolder(suitcase); 215 m_Database.StoreFolder(suitcase);
139 } 216 }
140 217
141 // Now let's change the folder ID to match that of the real root folder 218 // Now let's change the folder ID to match that of the real root folder
142 SetAsRootFolder(suitcase, root.folderID); 219 SetAsRootFolder(suitcase, root);
143 220
144 return ConvertToOpenSim(suitcase); 221 return ConvertToOpenSim(suitcase);
145 } 222 }
146 223
224 protected void CreateSystemFolders(UUID principalID, UUID rootID)
225 {
226 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
227 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
228
229 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
230 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
231 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
232 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
233 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
234 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
235 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
236 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
237 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
238 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
239 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
240 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
241 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
242 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
243 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
244 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
245 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
246 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
247 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
248 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
249 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
250 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
251 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
252 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
253 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
254 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
255 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
256 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
257 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
258 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
259 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
260 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
261
262 }
263
147 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 264 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
148 { 265 {
149 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 266 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
150 return GetRootFolder(principalID); 267 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
268 XInventoryFolder[] folders = m_Database.GetFolders(
269 new string[] { "agentID", "type", "parentFolderID"},
270 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
271
272 if (folders.Length == 0)
273 {
274 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
275 return null;
276 }
277
278 m_log.DebugFormat(
279 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
280 folders[0].folderName, folders[0].folderID, type, principalID);
281
282 return ConvertToOpenSim(folders[0]);
151 } 283 }
152 284
153 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) 285 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
@@ -199,6 +331,7 @@ namespace OpenSim.Services.HypergridService
199 331
200 public override bool AddFolder(InventoryFolderBase folder) 332 public override bool AddFolder(InventoryFolderBase folder)
201 { 333 {
334 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
202 // Let's do a bit of sanity checking, more than the base service does 335 // Let's do a bit of sanity checking, more than the base service does
203 // make sure the given folder's parent folder exists under the suitcase tree of this user 336 // make sure the given folder's parent folder exists under the suitcase tree of this user
204 XInventoryFolder root = GetRootXFolder(folder.Owner); 337 XInventoryFolder root = GetRootXFolder(folder.Owner);
@@ -219,14 +352,37 @@ namespace OpenSim.Services.HypergridService
219 return base.AddFolder(folder); 352 return base.AddFolder(folder);
220 } 353 }
221 354
222 public bool UpdateFolder(InventoryFolderBase folder) 355 public override bool UpdateFolder(InventoryFolderBase folder)
223 { 356 {
224 XInventoryFolder root = GetRootXFolder(folder.Owner); 357 XInventoryFolder root = GetRootXFolder(folder.Owner);
225 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); 358 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
226 359
360 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
227 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase)) 361 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
362 {
363 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
228 return false; 364 return false;
365 }
366
367 if (folder.ID == root.folderID)
368 {
369 if (folder.Version <= suitcase.version)
370 {
371 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= suitcase version {1}. Ignoring.", folder.Version, suitcase.version);
372 return false;
373 }
374 if (folder.Version <= root.version)
375 {
376 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= root version {1}. Ignoring.", folder.Version, suitcase.version);
377 return false;
378 }
379 suitcase.version = root.version = folder.Version;
380 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Storing {0} type {1} version {2}", suitcase.folderName, suitcase.type, suitcase.version);
381 m_Database.StoreFolder(suitcase);
382 m_Database.StoreFolder(root);
383 }
229 384
385 // For all others
230 return base.UpdateFolder(folder); 386 return base.UpdateFolder(folder);
231 } 387 }
232 388
@@ -301,9 +457,6 @@ namespace OpenSim.Services.HypergridService
301 XInventoryFolder root = GetRootXFolder(items[0].Owner); 457 XInventoryFolder root = GetRootXFolder(items[0].Owner);
302 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); 458 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
303 459
304 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
305 return false;
306
307 foreach (InventoryItemBase it in items) 460 foreach (InventoryItemBase it in items)
308 if (it.Folder == root.folderID) 461 if (it.Folder == root.folderID)
309 { 462 {
@@ -312,6 +465,9 @@ namespace OpenSim.Services.HypergridService
312 it.Folder = suitcase.folderID; 465 it.Folder = suitcase.folderID;
313 } 466 }
314 467
468 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
469 return false;
470
315 return base.MoveItems(principalID, items); 471 return base.MoveItems(principalID, items);
316 472
317 } 473 }
@@ -322,44 +478,57 @@ namespace OpenSim.Services.HypergridService
322 return false; 478 return false;
323 } 479 }
324 480
325 public override InventoryItemBase GetItem(InventoryItemBase item) 481 public new InventoryItemBase GetItem(InventoryItemBase item)
326 { 482 {
327 InventoryItemBase it = base.GetItem(item); 483 InventoryItemBase it = base.GetItem(item);
484 if (it == null)
485 {
486 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
487 item.Name, item.ID, item.Folder);
488 return null;
489 }
328 XInventoryFolder root = GetRootXFolder(it.Owner); 490 XInventoryFolder root = GetRootXFolder(it.Owner);
329 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); 491 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
330 492 if (root == null || suitcase == null)
331 if (it != null)
332 { 493 {
333 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase)) 494 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
334 return null; 495 it.Owner);
335 496 return null;
336 if (it.Folder == suitcase.folderID) 497 }
337 it.Folder = root.folderID;
338 498
339 // UserAccount user = m_Cache.GetUser(it.CreatorId); 499 if (it.Folder == suitcase.folderID)
500 it.Folder = root.folderID;
340 501
341 // // Adjust the creator data 502 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
342 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) 503 {
343 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; 504 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
344 //} 505 it.Name, it.Folder);
506 return null;
345 } 507 }
346 508
509 // UserAccount user = m_Cache.GetUser(it.CreatorId);
510
511 // // Adjust the creator data
512 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
513 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
514 //}
515
347 return it; 516 return it;
348 } 517 }
349 518
350 public override InventoryFolderBase GetFolder(InventoryFolderBase folder) 519 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
351 { 520 {
352 InventoryFolderBase f = base.GetFolder(folder); 521 InventoryFolderBase f = base.GetFolder(folder);
353 XInventoryFolder root = GetRootXFolder(f.Owner);
354 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
355 522
356 if (f != null) 523 if (f != null)
357 { 524 {
358 if (!IsWithinSuitcaseTree(f.ID, root, suitcase)) 525 XInventoryFolder root = GetRootXFolder(f.Owner);
359 return null; 526 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
360
361 if (f.ParentID == suitcase.folderID) 527 if (f.ParentID == suitcase.folderID)
362 f.ParentID = root.folderID; 528 f.ParentID = root.folderID;
529
530 if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
531 return null;
363 } 532 }
364 533
365 return f; 534 return f;
@@ -409,20 +578,22 @@ namespace OpenSim.Services.HypergridService
409 return null; 578 return null;
410 } 579 }
411 580
412 private void SetAsRootFolder(XInventoryFolder suitcase, UUID rootID) 581 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
413 { 582 {
414 suitcase.folderID = rootID; 583 suitcase.version = root.version;
584 suitcase.folderID = root.folderID;
415 suitcase.parentFolderID = UUID.Zero; 585 suitcase.parentFolderID = UUID.Zero;
586 suitcase.type = (short)AssetType.Folder;
416 } 587 }
417 588
418 private List<XInventoryFolder> GetFolderTree(UUID root) 589 private List<XInventoryFolder> GetFolderTree(UUID folder)
419 { 590 {
420 List<XInventoryFolder> t = null; 591 List<XInventoryFolder> t = null;
421 if (m_SuitcaseTrees.TryGetValue(root, out t)) 592 if (m_SuitcaseTrees.TryGetValue(folder, out t))
422 return t; 593 return t;
423 594
424 t = GetFolderTreeRecursive(root); 595 t = GetFolderTreeRecursive(folder);
425 m_SuitcaseTrees.AddOrUpdate(root, t, 120); 596 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
426 return t; 597 return t;
427 } 598 }
428 599
@@ -447,6 +618,13 @@ namespace OpenSim.Services.HypergridService
447 618
448 } 619 }
449 620
621 /// <summary>
622 /// Return true if the folderID is a subfolder of the Suitcase or the root folder ID itself
623 /// </summary>
624 /// <param name="folderID"></param>
625 /// <param name="root"></param>
626 /// <param name="suitcase"></param>
627 /// <returns></returns>
450 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase) 628 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
451 { 629 {
452 List<XInventoryFolder> tree = new List<XInventoryFolder>(); 630 List<XInventoryFolder> tree = new List<XInventoryFolder>();
@@ -463,4 +641,502 @@ namespace OpenSim.Services.HypergridService
463 } 641 }
464 #endregion 642 #endregion
465 } 643 }
644
645 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
646 {
647 private static readonly ILog m_log =
648 LogManager.GetLogger(
649 MethodBase.GetCurrentMethod().DeclaringType);
650
651 private string m_HomeURL;
652 private IUserAccountService m_UserAccountService;
653
654 private UserAccountCache m_Cache;
655
656 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID, List<XInventoryFolder>>();
657
658 public HGSuitcaseInventoryService(IConfigSource config, string configName)
659 : base(config, configName)
660 {
661 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
662 if (configName != string.Empty)
663 m_ConfigName = configName;
664
665 if (m_Database == null)
666 m_log.WarnFormat("[XXX]: m_Database is null!");
667
668 //
669 // Try reading the [InventoryService] section, if it exists
670 //
671 IConfig invConfig = config.Configs[m_ConfigName];
672 if (invConfig != null)
673 {
674 // realm = authConfig.GetString("Realm", realm);
675 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
676 if (userAccountsDll == string.Empty)
677 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
678
679 Object[] args = new Object[] { config };
680 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
681 if (m_UserAccountService == null)
682 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
683
684 // legacy configuration [obsolete]
685 m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty);
686 // Preferred
687 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
688
689 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
690 }
691
692 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
693 }
694
695 public override bool CreateUserInventory(UUID principalID)
696 {
697 // NOGO
698 return false;
699 }
700
701 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
702 {
703 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
704 XInventoryFolder root = GetRootXFolder(principalID);
705
706 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
707 if (tree == null || (tree != null && tree.Count == 0))
708 return null;
709
710 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
711 foreach (XInventoryFolder x in tree)
712 {
713 folders.Add(ConvertToOpenSim(x));
714 }
715
716 SetAsRootFolder(suitcase, root);
717 folders.Add(ConvertToOpenSim(suitcase));
718
719 return folders;
720 }
721
722 public override InventoryCollection GetUserInventory(UUID userID)
723 {
724 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
725 InventoryCollection userInventory = new InventoryCollection();
726 userInventory.UserID = userID;
727 userInventory.Folders = new List<InventoryFolderBase>();
728 userInventory.Items = new List<InventoryItemBase>();
729
730 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
731 XInventoryFolder root = GetRootXFolder(userID);
732
733 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
734 if (tree == null || (tree != null && tree.Count == 0))
735 {
736 SetAsRootFolder(suitcase, root);
737 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
738 return userInventory;
739 }
740
741 List<InventoryItemBase> items;
742 foreach (XInventoryFolder f in tree)
743 {
744 // Add the items of this subfolder
745 items = GetFolderItems(userID, f.folderID);
746 if (items != null && items.Count > 0)
747 {
748 userInventory.Items.AddRange(items);
749 }
750
751 // Add the folder itself
752 userInventory.Folders.Add(ConvertToOpenSim(f));
753 }
754
755 items = GetFolderItems(userID, suitcase.folderID);
756 if (items != null && items.Count > 0)
757 {
758 userInventory.Items.AddRange(items);
759 }
760
761 SetAsRootFolder(suitcase, root);
762 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
763
764 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
765 userID, userInventory.Folders.Count, userInventory.Items.Count);
766 return userInventory;
767 }
768
769 public override InventoryFolderBase GetRootFolder(UUID principalID)
770 {
771 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
772 if (m_Database == null)
773 m_log.ErrorFormat("[XXX]: m_Database is NULL!");
774
775 // Let's find out the local root folder
776 XInventoryFolder root = GetRootXFolder(principalID); ;
777 if (root == null)
778 {
779 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
780 }
781
782 // Warp! Root folder for travelers is the suitcase folder
783 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
784
785 if (suitcase == null)
786 {
787 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
788 // make one, and let's add it to the user's inventory as a direct child of the root folder
789 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
790 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
791 if (suitcase == null)
792 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
793 m_Database.StoreFolder(suitcase);
794
795 // Create System folders
796 CreateSystemFolders(principalID, suitcase.folderID);
797 }
798
799 SetAsRootFolder(suitcase, root);
800
801 return ConvertToOpenSim(suitcase);
802 }
803
804 protected void CreateSystemFolders(UUID principalID, UUID rootID)
805 {
806 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
807 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
808
809 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
810 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
811 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
812 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
813 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
814 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
815 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
816 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
817 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
818 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
819 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
820 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
821 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
822 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
823 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
824 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
825 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
826 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
827 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
828 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
829 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
830 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
831 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
832 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
833 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
834 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
835 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
836 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
837 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
838 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
839 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
840 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
841
842 }
843
844 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
845 {
846 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
847 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
848 XInventoryFolder[] folders = m_Database.GetFolders(
849 new string[] { "agentID", "type", "parentFolderID" },
850 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
851
852 if (folders.Length == 0)
853 {
854 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
855 return null;
856 }
857
858 m_log.DebugFormat(
859 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
860 folders[0].folderName, folders[0].folderID, type, principalID);
861
862 return ConvertToOpenSim(folders[0]);
863 }
864
865 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
866 {
867 InventoryCollection coll = null;
868 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
869
870 if (!IsWithinSuitcaseTree(folderID, suitcase))
871 return new InventoryCollection();
872
873 coll = base.GetFolderContent(principalID, folderID);
874
875 if (coll == null)
876 {
877 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
878 coll = new InventoryCollection();
879 }
880 return coll;
881 }
882
883 public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
884 {
885 // Let's do a bit of sanity checking, more than the base service does
886 // make sure the given folder exists under the suitcase tree of this user
887 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
888
889 if (!IsWithinSuitcaseTree(folderID, suitcase))
890 return new List<InventoryItemBase>();
891
892 return base.GetFolderItems(principalID, folderID);
893 }
894
895 public override bool AddFolder(InventoryFolderBase folder)
896 {
897 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
898 // Let's do a bit of sanity checking, more than the base service does
899 // make sure the given folder's parent folder exists under the suitcase tree of this user
900 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
901
902 if (!IsWithinSuitcaseTree(folder.ParentID, suitcase))
903 return false;
904
905 // OK, it's legit
906 return base.AddFolder(folder);
907 }
908
909 public override bool UpdateFolder(InventoryFolderBase folder)
910 {
911 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
912
913 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
914 if (!IsWithinSuitcaseTree(folder.ID, suitcase))
915 {
916 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
917 return false;
918 }
919
920 // For all others
921 return base.UpdateFolder(folder);
922 }
923
924 public override bool MoveFolder(InventoryFolderBase folder)
925 {
926 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
927
928 if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase))
929 return false;
930
931 return base.MoveFolder(folder);
932 }
933
934 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
935 {
936 // NOGO
937 return false;
938 }
939
940 public override bool PurgeFolder(InventoryFolderBase folder)
941 {
942 // NOGO
943 return false;
944 }
945
946 public override bool AddItem(InventoryItemBase item)
947 {
948 // Let's do a bit of sanity checking, more than the base service does
949 // make sure the given folder's parent folder exists under the suitcase tree of this user
950 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
951
952 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
953 return false;
954
955 // OK, it's legit
956 return base.AddItem(item);
957
958 }
959
960 public override bool UpdateItem(InventoryItemBase item)
961 {
962 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
963
964 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
965 return false;
966
967 return base.UpdateItem(item);
968 }
969
970 public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
971 {
972 // Principal is b0rked. *sigh*
973
974 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
975
976 if (!IsWithinSuitcaseTree(items[0].Folder, suitcase))
977 return false;
978
979 return base.MoveItems(principalID, items);
980
981 }
982
983 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
984 {
985 return false;
986 }
987
988 public new InventoryItemBase GetItem(InventoryItemBase item)
989 {
990 InventoryItemBase it = base.GetItem(item);
991 if (it == null)
992 {
993 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
994 item.Name, item.ID, item.Folder);
995 return null;
996 }
997 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
998 if (suitcase == null)
999 {
1000 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
1001 it.Owner);
1002 return null;
1003 }
1004
1005 if (!IsWithinSuitcaseTree(it.Folder, suitcase))
1006 {
1007 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
1008 it.Name, it.Folder);
1009 return null;
1010 }
1011
1012 // UserAccount user = m_Cache.GetUser(it.CreatorId);
1013
1014 // // Adjust the creator data
1015 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
1016 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
1017 //}
1018
1019 return it;
1020 }
1021
1022 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
1023 {
1024 InventoryFolderBase f = base.GetFolder(folder);
1025
1026 if (f != null)
1027 {
1028 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
1029
1030 if (!IsWithinSuitcaseTree(f.ID, suitcase))
1031 return null;
1032 }
1033
1034 return f;
1035 }
1036
1037 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
1038 //{
1039 //}
1040
1041 //public int GetAssetPermissions(UUID principalID, UUID assetID)
1042 //{
1043 //}
1044
1045 #region Auxiliary functions
1046 private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
1047 {
1048 XInventoryFolder[] folders = m_Database.GetFolders(
1049 new string[] { "agentID", "folderID" },
1050 new string[] { userID.ToString(), folderID.ToString() });
1051
1052 if (folders.Length == 0)
1053 return null;
1054
1055 return folders[0];
1056 }
1057
1058 private XInventoryFolder GetRootXFolder(UUID principalID)
1059 {
1060 XInventoryFolder[] folders = m_Database.GetFolders(
1061 new string[] { "agentID", "folderName", "type" },
1062 new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
1063
1064 if (folders != null && folders.Length > 0)
1065 return folders[0];
1066 return null;
1067 }
1068
1069 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
1070 {
1071 // Warp! Root folder for travelers
1072 XInventoryFolder[] folders = m_Database.GetFolders(
1073 new string[] { "agentID", "type" },
1074 new string[] { principalID.ToString(), "100" }); // This is a special folder type...
1075
1076 if (folders != null && folders.Length > 0)
1077 return folders[0];
1078 return null;
1079 }
1080
1081 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
1082 {
1083 suitcase.type = (short)AssetType.Folder;
1084 }
1085
1086 private List<XInventoryFolder> GetFolderTree(UUID folder)
1087 {
1088 List<XInventoryFolder> t = null;
1089 if (m_SuitcaseTrees.TryGetValue(folder, out t))
1090 return t;
1091
1092 t = GetFolderTreeRecursive(folder);
1093 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
1094 return t;
1095 }
1096
1097 private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
1098 {
1099 List<XInventoryFolder> tree = new List<XInventoryFolder>();
1100 XInventoryFolder[] folders = m_Database.GetFolders(
1101 new string[] { "parentFolderID" },
1102 new string[] { root.ToString() });
1103
1104 if (folders == null || (folders != null && folders.Length == 0))
1105 return tree; // empty tree
1106 else
1107 {
1108 foreach (XInventoryFolder f in folders)
1109 {
1110 tree.Add(f);
1111 tree.AddRange(GetFolderTreeRecursive(f.folderID));
1112 }
1113 return tree;
1114 }
1115
1116 }
1117
1118 /// <summary>
1119 /// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself
1120 /// </summary>
1121 /// <param name="folderID"></param>
1122 /// <param name="root"></param>
1123 /// <param name="suitcase"></param>
1124 /// <returns></returns>
1125 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase)
1126 {
1127 List<XInventoryFolder> tree = new List<XInventoryFolder>();
1128 tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
1129 tree.AddRange(GetFolderTree(suitcase.folderID));
1130 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
1131 {
1132 if (fl.folderID == folderID) return true;
1133 else return false;
1134 });
1135
1136 if (f == null) return false;
1137 else return true;
1138 }
1139 #endregion
1140 }
1141
466} 1142}
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
index 7b2c3a6..0e7a358 100644
--- a/OpenSim/Services/InventoryService/XInventoryService.cs
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -40,9 +40,9 @@ namespace OpenSim.Services.InventoryService
40{ 40{
41 public class XInventoryService : ServiceBase, IInventoryService 41 public class XInventoryService : ServiceBase, IInventoryService
42 { 42 {
43// private static readonly ILog m_log = 43 private static readonly ILog m_log =
44// LogManager.GetLogger( 44 LogManager.GetLogger(
45// MethodBase.GetCurrentMethod().DeclaringType); 45 MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected IXInventoryData m_Database; 47 protected IXInventoryData m_Database;
48 protected bool m_AllowDelete = true; 48 protected bool m_AllowDelete = true;
@@ -113,7 +113,7 @@ namespace OpenSim.Services.InventoryService
113 result = true; 113 result = true;
114 } 114 }
115 115
116 XInventoryFolder[] sysFolders = GetSystemFolders(principalID); 116 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootFolder.ID);
117 117
118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; })) 118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations"); 119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations");
@@ -163,13 +163,13 @@ namespace OpenSim.Services.InventoryService
163 return newFolder; 163 return newFolder;
164 } 164 }
165 165
166 protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID) 166 protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID, UUID rootID)
167 { 167 {
168// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID); 168// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID);
169 169
170 XInventoryFolder[] allFolders = m_Database.GetFolders( 170 XInventoryFolder[] allFolders = m_Database.GetFolders(
171 new string[] { "agentID" }, 171 new string[] { "agentID", "parentFolderID" },
172 new string[] { principalID.ToString() }); 172 new string[] { principalID.ToString(), rootID.ToString() });
173 173
174 XInventoryFolder[] sysFolders = Array.FindAll( 174 XInventoryFolder[] sysFolders = Array.FindAll(
175 allFolders, 175 allFolders,
@@ -301,16 +301,26 @@ namespace OpenSim.Services.InventoryService
301 301
302 public virtual bool AddFolder(InventoryFolderBase folder) 302 public virtual bool AddFolder(InventoryFolderBase folder)
303 { 303 {
304 //m_log.DebugFormat("[XINVENTORY]: Add folder {0} type {1} in parent {2}", folder.Name, folder.Type, folder.ParentID);
304 InventoryFolderBase check = GetFolder(folder); 305 InventoryFolderBase check = GetFolder(folder);
305 if (check != null) 306 if (check != null)
306 return false; 307 return false;
307 308
308 XInventoryFolder xFolder = ConvertFromOpenSim(folder); 309 if (folder.Type == (short)AssetType.Folder || folder.Type == (short)AssetType.Unknown ||
309 return m_Database.StoreFolder(xFolder); 310 GetFolderForType(folder.Owner, (AssetType)(folder.Type)) == null)
311 {
312 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
313 return m_Database.StoreFolder(xFolder);
314 }
315 else
316 m_log.DebugFormat("[XINVENTORY]: Folder {0} of type {1} already exists", folder.Name, folder.Type);
317
318 return false;
310 } 319 }
311 320
312 public virtual bool UpdateFolder(InventoryFolderBase folder) 321 public virtual bool UpdateFolder(InventoryFolderBase folder)
313 { 322 {
323 //m_log.DebugFormat("[XINVENTORY]: Update folder {0} {1} ({2})", folder.Name, folder.Type, folder.ID);
314 XInventoryFolder xFolder = ConvertFromOpenSim(folder); 324 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
315 InventoryFolderBase check = GetFolder(folder); 325 InventoryFolderBase check = GetFolder(folder);
316 if (check == null) 326 if (check == null)
@@ -319,9 +329,13 @@ namespace OpenSim.Services.InventoryService
319 if (check.Type != -1 || xFolder.type != -1) 329 if (check.Type != -1 || xFolder.type != -1)
320 { 330 {
321 if (xFolder.version < check.Version) 331 if (xFolder.version < check.Version)
332 {
333 //m_log.DebugFormat("[XINVENTORY]: {0} < {1} can't do", xFolder.version, check.Version);
322 return false; 334 return false;
335 }
323 check.Version = (ushort)xFolder.version; 336 check.Version = (ushort)xFolder.version;
324 xFolder = ConvertFromOpenSim(check); 337 xFolder = ConvertFromOpenSim(check);
338 //m_log.DebugFormat("[XINVENTORY]: Storing {0} {1} {2}", xFolder.folderName, xFolder.version, xFolder.type);
325 return m_Database.StoreFolder(xFolder); 339 return m_Database.StoreFolder(xFolder);
326 } 340 }
327 341
@@ -499,13 +513,30 @@ namespace OpenSim.Services.InventoryService
499 return m_Database.GetAssetPermissions(principalID, assetID); 513 return m_Database.GetAssetPermissions(principalID, assetID);
500 } 514 }
501 515
502 // CM never needed those. Left unimplemented. 516 public virtual InventoryCollection GetUserInventory(UUID userID)
503 // Obsolete in core
504 //
505 public InventoryCollection GetUserInventory(UUID userID)
506 { 517 {
507 return null; 518 InventoryCollection userInventory = new InventoryCollection();
519 userInventory.UserID = userID;
520 userInventory.Folders = new List<InventoryFolderBase>();
521 userInventory.Items = new List<InventoryItemBase>();
522
523 List<InventoryFolderBase> skel = GetInventorySkeleton(userID);
524 if (skel != null)
525 {
526 foreach (InventoryFolderBase f in skel)
527 {
528 InventoryCollection c = GetFolderContent(userID, f.ID);
529 if (c != null && c.Items != null && c.Items.Count > 0)
530 userInventory.Items.AddRange(c.Items);
531 if (c != null && c.Folders != null && c.Folders.Count > 0)
532 userInventory.Folders.AddRange(c.Folders);
533 }
534 }
535 m_log.DebugFormat("[XINVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
536 userID, userInventory.Folders.Count, userInventory.Items.Count);
537 return userInventory;
508 } 538 }
539
509 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) 540 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
510 { 541 {
511 } 542 }
@@ -525,6 +556,9 @@ namespace OpenSim.Services.InventoryService
525 556
526 newFolder.ParentID = folder.parentFolderID; 557 newFolder.ParentID = folder.parentFolderID;
527 newFolder.Type = (short)folder.type; 558 newFolder.Type = (short)folder.type;
559 // Viewer can't understand anything that's not in it's LLFolderType enum
560 if (newFolder.Type == 100)
561 newFolder.Type = -1;
528 newFolder.Version = (ushort)folder.version; 562 newFolder.Version = (ushort)folder.version;
529 newFolder.Name = folder.folderName; 563 newFolder.Name = folder.folderName;
530 newFolder.Owner = folder.agentID; 564 newFolder.Owner = folder.agentID;