yeack, better not break other notecards HG; improve TestNotecardAsset()

master
UbitUmarov 2020-02-07 22:39:36 +00:00
parent c245ce3c25
commit 43fea6530f
4 changed files with 150 additions and 24 deletions

View File

@ -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<UUID> textIDs = Util.GetUUIDsOnString(ref note, indx);
if(textIDs.Count > 0)
ids.AddRange(textIDs);
}
if (ids.Count == 0)
return null;
return ids;
}

View File

@ -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<UUID> GetUUIDsOnString(ref string s, int indx)
{
var ids = new List<UUID>();
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;
}
/// <summary>
/// Is the platform Windows?
/// </summary>

View File

@ -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);

View File

@ -527,29 +527,30 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="textAsset"></param>
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<UUID> 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<UUID> ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data);
if(ids == null)
if(ids == null || ids.Count == 0)
return;
for(int i = 0; i < ids.Count; ++i)