From 43fea6530f0fa50c30fbbfc794eb9da4dd559969 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 7 Feb 2020 22:39:36 +0000 Subject: [PATCH] yeack, better not break other notecards HG; improve TestNotecardAsset() --- OpenSim/Framework/SLUtil.cs | 11 +- OpenSim/Framework/Util.cs | 118 ++++++++++++++++++ .../Scenes/Tests/UuidGathererTests.cs | 20 +-- .../Region/Framework/Scenes/UuidGatherer.cs | 25 ++-- 4 files changed, 150 insertions(+), 24 deletions(-) diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index e9a45b31a4..b79846f02e 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -29,7 +29,6 @@ using OpenMetaverse; using System; using System.Collections.Generic; using System.Globalization; -using System.Text.RegularExpressions; namespace OpenSim.Framework { @@ -874,7 +873,15 @@ namespace OpenSim.Framework --count; } - if(ids.Count == 0) + indx = note.IndexOf("Text length",indx); + if(indx > 0) + { + indx += 14; + List textIDs = Util.GetUUIDsOnString(ref note, indx); + if(textIDs.Count > 0) + ids.AddRange(textIDs); + } + if (ids.Count == 0) return null; return ids; } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index e0e35db874..9f36be6c16 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -719,6 +719,124 @@ namespace OpenSim.Framework } } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static bool IsHexa(char c) + { + if (c >= '0' && c <= '9') + return true; + if (c >= 'a' && c <= 'f') + return true; + if (c >= 'A' && c <= 'F') + return true; + + return false; + } + + public static List GetUUIDsOnString(ref string s, int indx) + { + var ids = new List(); + if (s.Length < 36) + return ids; + + int end = s.Length - 35; + int idbase; + int next; + int retry; + + while (indx < end) + { + for (; indx < end; ++indx) + { + if (IsHexa(s[indx])) + break; + } + if (indx == end) + break; + + idbase = indx; + for (; indx < s.Length - 26; ++indx) + { + if (!IsHexa(s[indx])) + break; + if (indx - idbase >= 8) + ++idbase; + } + + if (s[indx] != '-') + continue; + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + ++indx; + retry = indx; + + next = indx + 12; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (UUID.TryParse(s.Substring(idbase, 36), out UUID u)) + { + ids.Add(u); + } + ++indx; + } + + return ids; + } + /// /// Is the platform Windows? /// diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs index b3800d1d80..efe71e9dcf 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs @@ -42,6 +42,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests protected IAssetService m_assetService; protected UuidGatherer m_uuidGatherer; + protected static string noteBase = @"Linden text version 2\n{\nLLEmbeddedItems version 1\n +{\ncount 0\n}\nText length xxx\n"; // len does not matter on this test [SetUp] public void Init() { @@ -58,7 +60,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); AssetBase corruptAsset - = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, "CORRUPT ASSET", UUID.Zero); + = AssetHelpers.CreateAsset(corruptAssetUuid, AssetType.Notecard, noteBase + "CORRUPT ASSET", UUID.Zero); m_assetService.Store(corruptAsset); m_uuidGatherer.AddForInspection(corruptAssetUuid); @@ -87,9 +89,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests [Test] public void TestNotecardAsset() { - /* TODO fix this actually creating a valid notecard TestHelpers.InMethod(); -// TestHelpers.EnableLogging(); + // TestHelpers.EnableLogging(); UUID ownerId = TestHelpers.ParseTail(0x10); UUID embeddedId = TestHelpers.ParseTail(0x20); @@ -99,35 +100,34 @@ namespace OpenSim.Region.Framework.Scenes.Tests AssetBase ncAsset = AssetHelpers.CreateNotecardAsset( - ncAssetId, string.Format("Hello{0}World{1}", embeddedId, missingEmbeddedId)); + ncAssetId, string.Format("{0}Hello{1}World{2}", noteBase, embeddedId, missingEmbeddedId)); m_assetService.Store(ncAsset); AssetBase embeddedAsset - = AssetHelpers.CreateNotecardAsset(embeddedId, string.Format("{0} We'll meet again.", secondLevelEmbeddedId)); + = AssetHelpers.CreateNotecardAsset(embeddedId, string.Format("{0}{1} We'll meet again.", noteBase, secondLevelEmbeddedId)); m_assetService.Store(embeddedAsset); AssetBase secondLevelEmbeddedAsset - = AssetHelpers.CreateNotecardAsset(secondLevelEmbeddedId, "Don't know where, don't know when."); + = AssetHelpers.CreateNotecardAsset(secondLevelEmbeddedId, noteBase + "Don't know where, don't know when."); m_assetService.Store(secondLevelEmbeddedAsset); m_uuidGatherer.AddForInspection(ncAssetId); m_uuidGatherer.GatherAll(); -// foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys) -// System.Console.WriteLine("key : {0}", key); + // foreach (UUID key in m_uuidGatherer.GatheredUuids.Keys) + // System.Console.WriteLine("key : {0}", key); Assert.That(m_uuidGatherer.GatheredUuids.Count, Is.EqualTo(3)); Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(ncAssetId)); Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(embeddedId)); Assert.That(m_uuidGatherer.GatheredUuids.ContainsKey(secondLevelEmbeddedId)); - */ } [Test] public void TestTaskItems() { TestHelpers.InMethod(); -// TestHelpers.EnableLogging(); + // TestHelpers.EnableLogging(); UUID ownerId = TestHelpers.ParseTail(0x10); diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 05cc536565..00f3aa17cd 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -527,29 +527,30 @@ namespace OpenSim.Region.Framework.Scenes /// private void RecordTextEmbeddedAssetUuids(AssetBase textAsset) { - // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId); + // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId); string text = Utils.BytesToString(textAsset.Data); -// m_log.DebugFormat("[UUID GATHERER]: Text {0}", text); - MatchCollection uuidMatches = Util.PermissiveUUIDPattern.Matches(text); -// m_log.DebugFormat("[UUID GATHERER]: Found {0} matches in text", uuidMatches.Count); + if(text.Length < 36) + return; - foreach (Match uuidMatch in uuidMatches) + List ids = Util.GetUUIDsOnString(ref text, 0); + if (ids == null || ids.Count == 0) + return; + + for (int i = 0; i < ids.Count; ++i) { - UUID uuid = new UUID(uuidMatch.Value); - if(uuid == UUID.Zero) + if (ids[i] == UUID.Zero) continue; -// m_log.DebugFormat("[UUID GATHERER]: Recording {0} in text", uuid); - if(!UncertainAssetsUUIDs.Contains(uuid)) - UncertainAssetsUUIDs.Add(uuid); - AddForInspection(uuid); + if (!UncertainAssetsUUIDs.Contains(ids[i])) + UncertainAssetsUUIDs.Add(ids[i]); + AddForInspection(ids[i]); } } private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset) { List ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data); - if(ids == null) + if(ids == null || ids.Count == 0) return; for(int i = 0; i < ids.Count; ++i)