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.cs292
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs62
4 files changed, 280 insertions, 127 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..b6ec558 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Services.HypergridService
59 59
60 private UserAccountCache m_Cache; 60 private UserAccountCache m_Cache;
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 HGSuitcaseInventoryService(IConfigSource config, string configName)
65 : base(config, configName) 65 : base(config, configName)
@@ -104,11 +104,72 @@ 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 folders.Add(ConvertToOpenSim(x));
120 }
121
122 SetAsRootFolder(suitcase, root);
123 folders.Add(ConvertToOpenSim(suitcase));
124
125 return folders;
126 }
127
128 public override InventoryCollection GetUserInventory(UUID userID)
129 {
130 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
131 InventoryCollection userInventory = new InventoryCollection();
132 userInventory.UserID = userID;
133 userInventory.Folders = new List<InventoryFolderBase>();
134 userInventory.Items = new List<InventoryItemBase>();
135
136 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
137 XInventoryFolder root = GetRootXFolder(userID);
138
139 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
140 if (tree == null || (tree != null && tree.Count == 0))
141 {
142 SetAsRootFolder(suitcase, root);
143 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
144 return userInventory;
145 }
146
147 List<InventoryItemBase> items;
148 foreach (XInventoryFolder f in tree)
149 {
150 // Add the items of this subfolder
151 items = GetFolderItems(userID, f.folderID);
152 if (items != null && items.Count > 0)
153 {
154 userInventory.Items.AddRange(items);
155 }
156
157 // Add the folder itself
158 userInventory.Folders.Add(ConvertToOpenSim(f));
159 }
160
161 items = GetFolderItems(userID, suitcase.folderID);
162 if (items != null && items.Count > 0)
163 {
164 userInventory.Items.AddRange(items);
165 }
166
167 SetAsRootFolder(suitcase, root);
168 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
169
170 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
171 userID, userInventory.Folders.Count, userInventory.Items.Count);
172 return userInventory;
112 } 173 }
113 174
114 public override InventoryFolderBase GetRootFolder(UUID principalID) 175 public override InventoryFolderBase GetRootFolder(UUID principalID)
@@ -131,51 +192,92 @@ namespace OpenSim.Services.HypergridService
131 { 192 {
132 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); 193 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 194 // make one, and let's add it to the user's inventory as a direct child of the root folder
195 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
134 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); 196 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
135 if (suitcase == null) 197 if (suitcase == null)
136 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); 198 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
137
138 m_Database.StoreFolder(suitcase); 199 m_Database.StoreFolder(suitcase);
200
201 // Create System folders
202 CreateSystemFolders(principalID, suitcase.folderID);
139 } 203 }
140 204
141 // Now let's change the folder ID to match that of the real root folder 205 SetAsRootFolder(suitcase, root);
142 SetAsRootFolder(suitcase, root.folderID);
143 206
144 return ConvertToOpenSim(suitcase); 207 return ConvertToOpenSim(suitcase);
145 } 208 }
146 209
210 protected void CreateSystemFolders(UUID principalID, UUID rootID)
211 {
212 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
213 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
214
215 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
216 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
217 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
218 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
219 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
220 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
221 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
222 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
223 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
224 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
225 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
226 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
227 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
228 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
229 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
230 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
231 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
232 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
233 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
234 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
235 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
236 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
237 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
238 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
239 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
240 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
241 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
242 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
243 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
244 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
245 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
246 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
247
248 }
249
147 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 250 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
148 { 251 {
149 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 252 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
150 return GetRootFolder(principalID); 253 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
254 XInventoryFolder[] folders = m_Database.GetFolders(
255 new string[] { "agentID", "type", "parentFolderID" },
256 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
257
258 if (folders.Length == 0)
259 {
260 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
261 return null;
262 }
263
264 m_log.DebugFormat(
265 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
266 folders[0].folderName, folders[0].folderID, type, principalID);
267
268 return ConvertToOpenSim(folders[0]);
151 } 269 }
152 270
153 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) 271 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
154 { 272 {
155 InventoryCollection coll = null; 273 InventoryCollection coll = null;
156 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 274 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
157 XInventoryFolder root = GetRootXFolder(principalID);
158 275
159 if (!IsWithinSuitcaseTree(folderID, root, suitcase)) 276 if (!IsWithinSuitcaseTree(folderID, suitcase))
160 return new InventoryCollection(); 277 return new InventoryCollection();
161 278
162 if (folderID == root.folderID) // someone's asking for the root folder, we'll give them the suitcase 279 coll = base.GetFolderContent(principalID, folderID);
163 { 280
164 if (suitcase != null)
165 {
166 coll = base.GetFolderContent(principalID, suitcase.folderID);
167 foreach (InventoryFolderBase f in coll.Folders)
168 f.ParentID = root.folderID;
169 foreach (InventoryItemBase i in coll.Items)
170 i.Folder = root.folderID;
171 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for root folder returned content for suitcase folder");
172 }
173 }
174 else
175 {
176 coll = base.GetFolderContent(principalID, folderID);
177 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for non-root folder {0}", folderID);
178 }
179 if (coll == null) 281 if (coll == null)
180 { 282 {
181 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID); 283 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
@@ -188,10 +290,9 @@ namespace OpenSim.Services.HypergridService
188 { 290 {
189 // Let's do a bit of sanity checking, more than the base service does 291 // Let's do a bit of sanity checking, more than the base service does
190 // make sure the given folder exists under the suitcase tree of this user 292 // make sure the given folder exists under the suitcase tree of this user
191 XInventoryFolder root = GetRootXFolder(principalID);
192 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 293 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
193 294
194 if (!IsWithinSuitcaseTree(folderID, root, suitcase)) 295 if (!IsWithinSuitcaseTree(folderID, suitcase))
195 return new List<InventoryItemBase>(); 296 return new List<InventoryItemBase>();
196 297
197 return base.GetFolderItems(principalID, folderID); 298 return base.GetFolderItems(principalID, folderID);
@@ -199,52 +300,40 @@ namespace OpenSim.Services.HypergridService
199 300
200 public override bool AddFolder(InventoryFolderBase folder) 301 public override bool AddFolder(InventoryFolderBase folder)
201 { 302 {
303 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 304 // 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 305 // make sure the given folder's parent folder exists under the suitcase tree of this user
204 XInventoryFolder root = GetRootXFolder(folder.Owner);
205 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); 306 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
206 307
207 if (!IsWithinSuitcaseTree(folder.ParentID, root, suitcase)) 308 if (!IsWithinSuitcaseTree(folder.ParentID, suitcase))
208 return false; 309 return false;
209 310
210 // OK, it's legit 311 // OK, it's legit
211 // Check if it's under the Root folder directly
212 if (folder.ParentID == root.folderID)
213 {
214 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
215 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder for root folder for user {0}. Adding in suitcase instead", folder.Owner);
216 folder.ParentID = suitcase.folderID;
217 }
218
219 return base.AddFolder(folder); 312 return base.AddFolder(folder);
220 } 313 }
221 314
222 public bool UpdateFolder(InventoryFolderBase folder) 315 public override bool UpdateFolder(InventoryFolderBase folder)
223 { 316 {
224 XInventoryFolder root = GetRootXFolder(folder.Owner);
225 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); 317 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
226 318
227 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase)) 319 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
320 if (!IsWithinSuitcaseTree(folder.ID, suitcase))
321 {
322 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
228 return false; 323 return false;
324 }
229 325
326 // For all others
230 return base.UpdateFolder(folder); 327 return base.UpdateFolder(folder);
231 } 328 }
232 329
233 public override bool MoveFolder(InventoryFolderBase folder) 330 public override bool MoveFolder(InventoryFolderBase folder)
234 { 331 {
235 XInventoryFolder root = GetRootXFolder(folder.Owner);
236 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); 332 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
237 333
238 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, root, suitcase)) 334 if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase))
239 return false; 335 return false;
240 336
241 if (folder.ParentID == root.folderID)
242 {
243 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
244 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder to root folder for user {0}. Moving it to suitcase instead", folder.Owner);
245 folder.ParentID = suitcase.folderID;
246 }
247
248 return base.MoveFolder(folder); 337 return base.MoveFolder(folder);
249 } 338 }
250 339
@@ -264,31 +353,21 @@ namespace OpenSim.Services.HypergridService
264 { 353 {
265 // Let's do a bit of sanity checking, more than the base service does 354 // Let's do a bit of sanity checking, more than the base service does
266 // make sure the given folder's parent folder exists under the suitcase tree of this user 355 // make sure the given folder's parent folder exists under the suitcase tree of this user
267 XInventoryFolder root = GetRootXFolder(item.Owner);
268 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); 356 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
269 357
270 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase)) 358 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
271 return false; 359 return false;
272 360
273 // OK, it's legit 361 // OK, it's legit
274 // Check if it's under the Root folder directly
275 if (item.Folder == root.folderID)
276 {
277 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
278 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddItem for root folder for user {0}. Adding in suitcase instead", item.Owner);
279 item.Folder = suitcase.folderID;
280 }
281
282 return base.AddItem(item); 362 return base.AddItem(item);
283 363
284 } 364 }
285 365
286 public override bool UpdateItem(InventoryItemBase item) 366 public override bool UpdateItem(InventoryItemBase item)
287 { 367 {
288 XInventoryFolder root = GetRootXFolder(item.Owner);
289 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); 368 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
290 369
291 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase)) 370 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
292 return false; 371 return false;
293 372
294 return base.UpdateItem(item); 373 return base.UpdateItem(item);
@@ -298,68 +377,64 @@ namespace OpenSim.Services.HypergridService
298 { 377 {
299 // Principal is b0rked. *sigh* 378 // Principal is b0rked. *sigh*
300 379
301 XInventoryFolder root = GetRootXFolder(items[0].Owner);
302 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); 380 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
303 381
304 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase)) 382 if (!IsWithinSuitcaseTree(items[0].Folder, suitcase))
305 return false; 383 return false;
306 384
307 foreach (InventoryItemBase it in items)
308 if (it.Folder == root.folderID)
309 {
310 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
311 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItem to root folder for user {0}. Moving it to suitcase instead", it.Owner);
312 it.Folder = suitcase.folderID;
313 }
314
315 return base.MoveItems(principalID, items); 385 return base.MoveItems(principalID, items);
316 386
317 } 387 }
318 388
319 // Let these pass. Use inherited methods.
320 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs) 389 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
321 { 390 {
322 return false; 391 return false;
323 } 392 }
324 393
325 public override InventoryItemBase GetItem(InventoryItemBase item) 394 public new InventoryItemBase GetItem(InventoryItemBase item)
326 { 395 {
327 InventoryItemBase it = base.GetItem(item); 396 InventoryItemBase it = base.GetItem(item);
328 XInventoryFolder root = GetRootXFolder(it.Owner); 397 if (it == null)
398 {
399 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
400 item.Name, item.ID, item.Folder);
401 return null;
402 }
329 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); 403 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
330 404 if (suitcase == null)
331 if (it != null)
332 { 405 {
333 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase)) 406 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
334 return null; 407 it.Owner);
408 return null;
409 }
335 410
336 if (it.Folder == suitcase.folderID) 411 if (!IsWithinSuitcaseTree(it.Folder, suitcase))
337 it.Folder = root.folderID; 412 {
413 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
414 it.Name, it.Folder);
415 return null;
416 }
338 417
339 // UserAccount user = m_Cache.GetUser(it.CreatorId); 418 // UserAccount user = m_Cache.GetUser(it.CreatorId);
340 419
341 // // Adjust the creator data 420 // // Adjust the creator data
342 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) 421 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
343 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; 422 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
344 //} 423 //}
345 }
346 424
347 return it; 425 return it;
348 } 426 }
349 427
350 public override InventoryFolderBase GetFolder(InventoryFolderBase folder) 428 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
351 { 429 {
352 InventoryFolderBase f = base.GetFolder(folder); 430 InventoryFolderBase f = base.GetFolder(folder);
353 XInventoryFolder root = GetRootXFolder(f.Owner);
354 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
355 431
356 if (f != null) 432 if (f != null)
357 { 433 {
358 if (!IsWithinSuitcaseTree(f.ID, root, suitcase)) 434 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
359 return null;
360 435
361 if (f.ParentID == suitcase.folderID) 436 if (!IsWithinSuitcaseTree(f.ID, suitcase))
362 f.ParentID = root.folderID; 437 return null;
363 } 438 }
364 439
365 return f; 440 return f;
@@ -409,20 +484,19 @@ namespace OpenSim.Services.HypergridService
409 return null; 484 return null;
410 } 485 }
411 486
412 private void SetAsRootFolder(XInventoryFolder suitcase, UUID rootID) 487 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
413 { 488 {
414 suitcase.folderID = rootID; 489 suitcase.type = (short)AssetType.Folder;
415 suitcase.parentFolderID = UUID.Zero;
416 } 490 }
417 491
418 private List<XInventoryFolder> GetFolderTree(UUID root) 492 private List<XInventoryFolder> GetFolderTree(UUID folder)
419 { 493 {
420 List<XInventoryFolder> t = null; 494 List<XInventoryFolder> t = null;
421 if (m_SuitcaseTrees.TryGetValue(root, out t)) 495 if (m_SuitcaseTrees.TryGetValue(folder, out t))
422 return t; 496 return t;
423 497
424 t = GetFolderTreeRecursive(root); 498 t = GetFolderTreeRecursive(folder);
425 m_SuitcaseTrees.AddOrUpdate(root, t, 120); 499 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
426 return t; 500 return t;
427 } 501 }
428 502
@@ -447,10 +521,17 @@ namespace OpenSim.Services.HypergridService
447 521
448 } 522 }
449 523
450 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase) 524 /// <summary>
525 /// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself
526 /// </summary>
527 /// <param name="folderID"></param>
528 /// <param name="root"></param>
529 /// <param name="suitcase"></param>
530 /// <returns></returns>
531 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase)
451 { 532 {
452 List<XInventoryFolder> tree = new List<XInventoryFolder>(); 533 List<XInventoryFolder> tree = new List<XInventoryFolder>();
453 tree.Add(root); // Warp! the tree is the real root folder plus the children of the suitcase folder 534 tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
454 tree.AddRange(GetFolderTree(suitcase.folderID)); 535 tree.AddRange(GetFolderTree(suitcase.folderID));
455 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) 536 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
456 { 537 {
@@ -463,4 +544,5 @@ namespace OpenSim.Services.HypergridService
463 } 544 }
464 #endregion 545 #endregion
465 } 546 }
547
466} 548}
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;