From 1b826b487739220503458ccc6b07ec40c54e1164 Mon Sep 17 00:00:00 2001
From: Oren Hurvitz
Date: Sun, 16 Dec 2012 09:48:37 +0200
Subject: Allow registering regions whose names are equivalent under LIKE but
not truly equal
---
OpenSim/Framework/Util.cs | 11 +++++++++++
OpenSim/Services/GridService/GridService.cs | 14 +++++++-------
OpenSim/Services/GridService/HypergridLinker.cs | 2 +-
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 4fd8a2d..f511494 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -2102,5 +2102,16 @@ namespace OpenSim.Framework
return firstName + "." + lastName + " " + "@" + uri.Authority;
}
#endregion
+
+ ///
+ /// Escapes the special characters used in "LIKE".
+ ///
+ ///
+ /// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz"
+ ///
+ public static string EscapeForLike(string str)
+ {
+ return str.Replace("_", "\\_").Replace("%", "\\%");
+ }
}
}
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index ee3b858..daebf8b 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -185,15 +185,15 @@ namespace OpenSim.Services.GridService
if (!m_AllowDuplicateNames)
{
- List dupe = m_Database.Get(regionInfos.RegionName, scopeID);
+ List dupe = m_Database.Get(Util.EscapeForLike(regionInfos.RegionName), scopeID);
if (dupe != null && dupe.Count > 0)
{
foreach (RegionData d in dupe)
{
if (d.RegionID != regionInfos.RegionID)
{
- m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register duplicate name with ID {1}.",
- regionInfos.RegionName, regionInfos.RegionID);
+ m_log.WarnFormat("[GRID SERVICE]: Region tried to register using a duplicate name. New region: {0} ({1}), existing region: {2} ({3}).",
+ regionInfos.RegionName, regionInfos.RegionID, d.RegionName, d.RegionID);
return "Duplicate region name";
}
}
@@ -359,7 +359,7 @@ namespace OpenSim.Services.GridService
public GridRegion GetRegionByName(UUID scopeID, string name)
{
- List rdatas = m_Database.Get(name, scopeID);
+ List rdatas = m_Database.Get(Util.EscapeForLike(name), scopeID);
if ((rdatas != null) && (rdatas.Count > 0))
return RegionData2RegionInfo(rdatas[0]); // get the first
@@ -377,7 +377,7 @@ namespace OpenSim.Services.GridService
{
// m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name);
- List rdatas = m_Database.Get(name + "%", scopeID);
+ List rdatas = m_Database.Get(Util.EscapeForLike(name) + "%", scopeID);
int count = 0;
List rinfos = new List();
@@ -586,7 +586,7 @@ namespace OpenSim.Services.GridService
string regionName = cmd[3];
- List regions = m_Database.Get(regionName, UUID.Zero);
+ List regions = m_Database.Get(Util.EscapeForLike(regionName), UUID.Zero);
if (regions == null || regions.Count < 1)
{
MainConsole.Instance.Output("No region with name {0} found", regionName);
@@ -716,7 +716,7 @@ namespace OpenSim.Services.GridService
return;
}
- List regions = m_Database.Get(cmd[3], UUID.Zero);
+ List regions = m_Database.Get(Util.EscapeForLike(cmd[3]), UUID.Zero);
if (regions == null || regions.Count < 1)
{
MainConsole.Instance.Output("Region not found");
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index 743d089..073197f 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -387,7 +387,7 @@ namespace OpenSim.Services.GridService
m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName);
GridRegion regInfo = null;
- List regions = m_Database.Get(mapName, m_ScopeID);
+ List regions = m_Database.Get(Util.EscapeForLike(mapName), m_ScopeID);
if (regions != null && regions.Count > 0)
{
OpenSim.Framework.RegionFlags rflags = (OpenSim.Framework.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]);
--
cgit v1.1