diff options
author | UbitUmarov | 2016-07-19 18:56:32 +0100 |
---|---|---|
committer | UbitUmarov | 2016-07-19 18:56:32 +0100 |
commit | 46c55b6fa08b089961fe7fff4079295bfa24dc87 (patch) | |
tree | d9312ef006831a14c18bddf465fbe14d61b837f0 /OpenSim/Capabilities/Handlers/FetchInventory | |
parent | don't loose inventory items when there are bad folders (diff) | |
download | opensim-SC-46c55b6fa08b089961fe7fff4079295bfa24dc87.zip opensim-SC-46c55b6fa08b089961fe7fff4079295bfa24dc87.tar.gz opensim-SC-46c55b6fa08b089961fe7fff4079295bfa24dc87.tar.bz2 opensim-SC-46c55b6fa08b089961fe7fff4079295bfa24dc87.tar.xz |
some cleanup on FetchInvDescHandler
Diffstat (limited to 'OpenSim/Capabilities/Handlers/FetchInventory')
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs | 170 |
1 files changed, 22 insertions, 148 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs index 45eda57..8998b7a 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs | |||
@@ -60,7 +60,6 @@ namespace OpenSim.Capabilities.Handlers | |||
60 | m_LibraryService = libService; | 60 | m_LibraryService = libService; |
61 | m_Scene = s; | 61 | m_Scene = s; |
62 | } | 62 | } |
63 | |||
64 | 63 | ||
65 | public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 64 | public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
66 | { | 65 | { |
@@ -137,13 +136,13 @@ namespace OpenSim.Capabilities.Handlers | |||
137 | string inventoryitemstr = string.Empty; | 136 | string inventoryitemstr = string.Empty; |
138 | foreach (InventoryCollectionWithDescendents icoll in invcollSet) | 137 | foreach (InventoryCollectionWithDescendents icoll in invcollSet) |
139 | { | 138 | { |
140 | LLSDInventoryDescendents reply = ToLLSD(icoll.Collection, icoll.Descendents); | 139 | LLSDInventoryFolderContents thiscontents = contentsToLLSD(icoll.Collection, icoll.Descendents); |
141 | 140 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(thiscontents); | |
142 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); | 141 | // inventoryitemstr = inventoryitemstr.Replace("<llsd>", ""); |
143 | inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); | 142 | // inventoryitemstr = inventoryitemstr.Replace("</llsd>", ""); |
144 | inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); | 143 | // inventoryitemstr = inventoryitemstr.Substring(6,inventoryitemstr.Length - 13); |
145 | 144 | // tmpresponse.Append(inventoryitemstr); | |
146 | tmpresponse.Append(inventoryitemstr); | 145 | tmpresponse.Append(inventoryitemstr.Substring(6,inventoryitemstr.Length - 13)); |
147 | } | 146 | } |
148 | 147 | ||
149 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders)); | 148 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders)); |
@@ -236,16 +235,13 @@ namespace OpenSim.Capabilities.Handlers | |||
236 | return reply; | 235 | return reply; |
237 | } | 236 | } |
238 | 237 | ||
239 | private LLSDInventoryDescendents ToLLSD(InventoryCollection inv, int descendents) | 238 | private LLSDInventoryFolderContents contentsToLLSD(InventoryCollection inv, int descendents) |
240 | { | 239 | { |
241 | LLSDInventoryDescendents reply = new LLSDInventoryDescendents(); | ||
242 | LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents(); | 240 | LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents(); |
243 | contents.agent_id = inv.OwnerID; | 241 | contents.agent_id = inv.OwnerID; |
244 | contents.owner_id = inv.OwnerID; | 242 | contents.owner_id = inv.OwnerID; |
245 | contents.folder_id = inv.FolderID; | 243 | contents.folder_id = inv.FolderID; |
246 | 244 | ||
247 | reply.folders.Array.Add(contents); | ||
248 | |||
249 | if (inv.Folders != null) | 245 | if (inv.Folders != null) |
250 | { | 246 | { |
251 | foreach (InventoryFolderBase invFolder in inv.Folders) | 247 | foreach (InventoryFolderBase invFolder in inv.Folders) |
@@ -267,7 +263,7 @@ namespace OpenSim.Capabilities.Handlers | |||
267 | contents.descendents = descendents; | 263 | contents.descendents = descendents; |
268 | contents.version = inv.Version; | 264 | contents.version = inv.Version; |
269 | 265 | ||
270 | return reply; | 266 | return contents; |
271 | } | 267 | } |
272 | /// <summary> | 268 | /// <summary> |
273 | /// Old style. Soon to be deprecated. | 269 | /// Old style. Soon to be deprecated. |
@@ -424,108 +420,7 @@ namespace OpenSim.Capabilities.Handlers | |||
424 | itemsToReturn.Insert(0, linkedItem); | 420 | itemsToReturn.Insert(0, linkedItem); |
425 | } | 421 | } |
426 | } | 422 | } |
427 | |||
428 | // Now scan for folder links and insert the items they target and those links at the head of the return data | ||
429 | |||
430 | /* dont send contents of LinkFolders. | ||
431 | from docs seems this was never a spec | ||
432 | |||
433 | foreach (InventoryItemBase item in originalItems) | ||
434 | { | ||
435 | if (item.AssetType == (int)AssetType.LinkFolder) | ||
436 | { | ||
437 | InventoryCollection linkedFolderContents = m_InventoryService.GetFolderContent(ownerID, item.AssetID); | ||
438 | List<InventoryItemBase> links = linkedFolderContents.Items; | ||
439 | |||
440 | itemsToReturn.InsertRange(0, links); | ||
441 | |||
442 | foreach (InventoryItemBase link in linkedFolderContents.Items) | ||
443 | { | ||
444 | // Take care of genuinely broken links where the target doesn't exist | ||
445 | // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
446 | // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
447 | // rather than having to keep track of every folder requested in the recursion. | ||
448 | if (link != null) | ||
449 | { | ||
450 | // m_log.DebugFormat( | ||
451 | // "[WEB FETCH INV DESC HANDLER]: Adding item {0} {1} from folder {2} linked from {3}", | ||
452 | // link.Name, (AssetType)link.AssetType, item.AssetID, containingFolder.Name); | ||
453 | |||
454 | InventoryItemBase linkedItem | ||
455 | = m_InventoryService.GetItem(new InventoryItemBase(link.AssetID)); | ||
456 | |||
457 | if (linkedItem != null) | ||
458 | itemsToReturn.Insert(0, linkedItem); | ||
459 | } | ||
460 | } | ||
461 | } | ||
462 | } | ||
463 | */ | ||
464 | } | 423 | } |
465 | |||
466 | // foreach (InventoryItemBase item in contents.Items) | ||
467 | // { | ||
468 | // m_log.DebugFormat( | ||
469 | // "[WEB FETCH INV DESC HANDLER]: Returning item {0}, type {1}, parent {2} in {3} {4}", | ||
470 | // item.Name, (AssetType)item.AssetType, item.Folder, containingFolder.Name, containingFolder.ID); | ||
471 | // } | ||
472 | |||
473 | // ===== | ||
474 | |||
475 | // | ||
476 | // foreach (InventoryItemBase linkedItem in linkedItemsToAdd) | ||
477 | // { | ||
478 | // m_log.DebugFormat( | ||
479 | // "[WEB FETCH INV DESC HANDLER]: Inserted linked item {0} for link in folder {1} for agent {2}", | ||
480 | // linkedItem.Name, folderID, agentID); | ||
481 | // | ||
482 | // contents.Items.Add(linkedItem); | ||
483 | // } | ||
484 | // | ||
485 | // // If the folder requested contains links, then we need to send those folders first, otherwise the links | ||
486 | // // will be broken in the viewer. | ||
487 | // HashSet<UUID> linkedItemFolderIdsToSend = new HashSet<UUID>(); | ||
488 | // foreach (InventoryItemBase item in contents.Items) | ||
489 | // { | ||
490 | // if (item.AssetType == (int)AssetType.Link) | ||
491 | // { | ||
492 | // InventoryItemBase linkedItem = m_InventoryService.GetItem(new InventoryItemBase(item.AssetID)); | ||
493 | // | ||
494 | // // Take care of genuinely broken links where the target doesn't exist | ||
495 | // // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
496 | // // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
497 | // // rather than having to keep track of every folder requested in the recursion. | ||
498 | // if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) | ||
499 | // { | ||
500 | // // We don't need to send the folder if source and destination of the link are in the same | ||
501 | // // folder. | ||
502 | // if (linkedItem.Folder != containingFolder.ID) | ||
503 | // linkedItemFolderIdsToSend.Add(linkedItem.Folder); | ||
504 | // } | ||
505 | // } | ||
506 | // } | ||
507 | // | ||
508 | // foreach (UUID linkedItemFolderId in linkedItemFolderIdsToSend) | ||
509 | // { | ||
510 | // m_log.DebugFormat( | ||
511 | // "[WEB FETCH INV DESC HANDLER]: Recursively fetching folder {0} linked by item in folder {1} for agent {2}", | ||
512 | // linkedItemFolderId, folderID, agentID); | ||
513 | // | ||
514 | // int dummyVersion; | ||
515 | // InventoryCollection linkedCollection | ||
516 | // = Fetch( | ||
517 | // agentID, linkedItemFolderId, ownerID, fetchFolders, fetchItems, sortOrder, out dummyVersion); | ||
518 | // | ||
519 | // InventoryFolderBase linkedFolder = new InventoryFolderBase(linkedItemFolderId); | ||
520 | // linkedFolder.Owner = agentID; | ||
521 | // linkedFolder = m_InventoryService.GetFolder(linkedFolder); | ||
522 | // | ||
523 | //// contents.Folders.AddRange(linkedCollection.Folders); | ||
524 | // | ||
525 | // contents.Folders.Add(linkedFolder); | ||
526 | // contents.Items.AddRange(linkedCollection.Items); | ||
527 | // } | ||
528 | // } | ||
529 | } | 424 | } |
530 | } | 425 | } |
531 | else | 426 | else |
@@ -696,42 +591,21 @@ from docs seems this was never a spec | |||
696 | 591 | ||
697 | if (freq.fetch_items && contents.Items != null) | 592 | if (freq.fetch_items && contents.Items != null) |
698 | { | 593 | { |
699 | List<InventoryItemBase> itemsToReturn = contents.Items; | 594 | // viewers are lasy and want a copy of the link item sent before the link to it |
700 | 595 | ||
701 | // descendents must only include the links, not the linked items we add | 596 | // descendents must only include the links, not the linked items we add |
702 | coll.Descendents = itemsToReturn.Count; | 597 | coll.Descendents = contents.Items.Count; |
703 | 598 | ||
704 | // Add target items for links in this folder before the links themselves. | 599 | // look for item links |
705 | List<UUID> itemIDs = new List<UUID>(); | 600 | List<UUID> itemIDs = new List<UUID>(); |
706 | List<UUID> folderIDs = new List<UUID>(); | 601 | foreach (InventoryItemBase item in contents.Items) |
707 | foreach (InventoryItemBase item in itemsToReturn) | ||
708 | { | 602 | { |
709 | //m_log.DebugFormat("[XXX]: {0} {1}", item.Name, item.AssetType); | 603 | //m_log.DebugFormat("[XXX]: {0} {1}", item.Name, item.AssetType); |
710 | if (item.AssetType == (int)AssetType.Link) | 604 | if (item.AssetType == (int)AssetType.Link) |
711 | itemIDs.Add(item.AssetID); | 605 | itemIDs.Add(item.AssetID); |
712 | |||
713 | // else if (item.AssetType == (int)AssetType.LinkFolder) | ||
714 | // folderIDs.Add(item.AssetID); | ||
715 | } | ||
716 | |||
717 | //m_log.DebugFormat("[XXX]: folder {0} has {1} links and {2} linkfolders", contents.FolderID, itemIDs.Count, folderIDs.Count); | ||
718 | |||
719 | // Scan for folder links and insert the items they target and those links at the head of the return data | ||
720 | if (folderIDs.Count > 0) | ||
721 | { | ||
722 | InventoryCollection[] linkedFolders = m_InventoryService.GetMultipleFoldersContent(coll.Collection.OwnerID, folderIDs.ToArray()); | ||
723 | foreach (InventoryCollection linkedFolderContents in linkedFolders) | ||
724 | { | ||
725 | if (linkedFolderContents == null) | ||
726 | continue; | ||
727 | |||
728 | List<InventoryItemBase> links = linkedFolderContents.Items; | ||
729 | |||
730 | itemsToReturn.InsertRange(0, links); | ||
731 | |||
732 | } | ||
733 | } | 606 | } |
734 | 607 | ||
608 | // get the linked if any | ||
735 | if (itemIDs.Count > 0) | 609 | if (itemIDs.Count > 0) |
736 | { | 610 | { |
737 | InventoryItemBase[] linked = m_InventoryService.GetMultipleItems(freq.owner_id, itemIDs.ToArray()); | 611 | InventoryItemBase[] linked = m_InventoryService.GetMultipleItems(freq.owner_id, itemIDs.ToArray()); |
@@ -746,13 +620,11 @@ from docs seems this was never a spec | |||
746 | linked[i++] = m_InventoryService.GetItem(freq.owner_id, id); | 620 | linked[i++] = m_InventoryService.GetItem(freq.owner_id, id); |
747 | } | 621 | } |
748 | } | 622 | } |
749 | 623 | ||
750 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Processing folder {0}. Existing items:", freq.folder_id); | ||
751 | //foreach (InventoryItemBase item in itemsToReturn) | ||
752 | // m_log.DebugFormat("[XXX]: {0} {1} {2}", item.Name, item.AssetType, item.Folder); | ||
753 | |||
754 | if (linked != null) | 624 | if (linked != null) |
755 | { | 625 | { |
626 | List<InventoryItemBase> linkedItems = new List<InventoryItemBase>(); | ||
627 | // check for broken | ||
756 | foreach (InventoryItemBase linkedItem in linked) | 628 | foreach (InventoryItemBase linkedItem in linked) |
757 | { | 629 | { |
758 | // Take care of genuinely broken links where the target doesn't exist | 630 | // Take care of genuinely broken links where the target doesn't exist |
@@ -761,14 +633,16 @@ from docs seems this was never a spec | |||
761 | // rather than having to keep track of every folder requested in the recursion. | 633 | // rather than having to keep track of every folder requested in the recursion. |
762 | if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) | 634 | if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) |
763 | { | 635 | { |
764 | itemsToReturn.Insert(0, linkedItem); | 636 | linkedItems.Add(linkedItem); |
765 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Added {0} {1} {2}", linkedItem.Name, linkedItem.AssetType, linkedItem.Folder); | 637 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Added {0} {1} {2}", linkedItem.Name, linkedItem.AssetType, linkedItem.Folder); |
766 | } | 638 | } |
767 | } | 639 | } |
640 | // insert them | ||
641 | if(linkedItems.Count > 0) | ||
642 | contents.Items.InsertRange(0,linkedItems); | ||
768 | } | 643 | } |
769 | } | 644 | } |
770 | } | 645 | } |
771 | |||
772 | } | 646 | } |
773 | 647 | ||
774 | /// <summary> | 648 | /// <summary> |