From 336665e03532cf9d7a1ad65d5071e7050bf6ecd0 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Sun, 22 May 2011 16:51:03 -0700
Subject: More on HG Friends. Added Delete(string, string) across the board.
 Added security to friendship identifiers so that they can safely be deleted
 across worlds. Had to change Get(string) to use LIKE because the secret in
 the identifier is not always known -- affects only HG visitors. BOTTOM LINE
 SO FAR: HG friendships established and deleted safely across grids, local
 rights working but not (yet?) being transmitted back.

---
 OpenSim/Data/IFriendsData.cs             |  1 +
 OpenSim/Data/MSSQL/MSSQLFriendsData.cs   |  5 +++++
 OpenSim/Data/MySQL/MySQLFriendsData.cs   | 17 +++++++++++++----
 OpenSim/Data/Null/NullFriendsData.cs     |  7 ++++++-
 OpenSim/Data/SQLite/SQLiteFriendsData.cs |  5 +++++
 5 files changed, 30 insertions(+), 5 deletions(-)

(limited to 'OpenSim/Data')

diff --git a/OpenSim/Data/IFriendsData.cs b/OpenSim/Data/IFriendsData.cs
index 52e7f14..3fdf87b 100644
--- a/OpenSim/Data/IFriendsData.cs
+++ b/OpenSim/Data/IFriendsData.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Data
     {
         bool Store(FriendsData data);
         bool Delete(UUID ownerID, string friend);
+        bool Delete(string ownerID, string friend);
         FriendsData[] GetFriends(UUID principalID);
         FriendsData[] GetFriends(string principalID);
     }
diff --git a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
index ba1b085..0b178f1 100644
--- a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
@@ -52,6 +52,11 @@ namespace OpenSim.Data.MSSQL
 
         public bool Delete(UUID principalID, string friend)
         {
+            return Delete(principalID.ToString(), friend);
+        }
+
+        public bool Delete(string principalID, string friend)
+        {
             using (SqlConnection conn = new SqlConnection(m_ConnectionString))
             using (SqlCommand cmd = new SqlCommand())
             {
diff --git a/OpenSim/Data/MySQL/MySQLFriendsData.cs b/OpenSim/Data/MySQL/MySQLFriendsData.cs
index 69fac9d..130ba5e 100644
--- a/OpenSim/Data/MySQL/MySQLFriendsData.cs
+++ b/OpenSim/Data/MySQL/MySQLFriendsData.cs
@@ -44,6 +44,11 @@ namespace OpenSim.Data.MySQL
 
         public bool Delete(UUID principalID, string friend)
         {
+            return Delete(principalID.ToString(), friend);
+        }
+
+        public bool Delete(string principalID, string friend)
+        {
             MySqlCommand cmd = new MySqlCommand();
 
             cmd.CommandText = String.Format("delete from {0} where PrincipalID = ?PrincipalID and Friend = ?Friend", m_Realm);
@@ -57,16 +62,20 @@ namespace OpenSim.Data.MySQL
 
         public FriendsData[] GetFriends(UUID principalID)
         {
-            return GetFriends(principalID.ToString());
+            MySqlCommand cmd = new MySqlCommand();
+
+            cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID", m_Realm);
+            cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
+
+            return DoQuery(cmd);
         }
 
         public FriendsData[] GetFriends(string principalID)
         {
             MySqlCommand cmd = new MySqlCommand();
 
-            cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID", m_Realm);
-            cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
-
+            cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID LIKE ?PrincipalID", m_Realm);
+            cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString() + '%');
             return DoQuery(cmd);
         }
     }
diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs
index 2bfdc7a..d90788a 100644
--- a/OpenSim/Data/Null/NullFriendsData.cs
+++ b/OpenSim/Data/Null/NullFriendsData.cs
@@ -77,7 +77,12 @@ namespace OpenSim.Data.Null
             return true;
         }
 
-        public bool Delete(UUID userID, string friendID)
+        public bool Delete(UUID principalID, string friend)
+        {
+            return Delete(principalID.ToString(), friend);
+        }
+
+        public bool Delete(string userID, string friendID)
         {
             List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); });
             if (lst != null)
diff --git a/OpenSim/Data/SQLite/SQLiteFriendsData.cs b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
index d925412..b14c348 100644
--- a/OpenSim/Data/SQLite/SQLiteFriendsData.cs
+++ b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
@@ -64,6 +64,11 @@ namespace OpenSim.Data.SQLite
 
         public bool Delete(UUID principalID, string friend)
         {
+            return Delete(principalID.ToString(), friend);
+        }
+
+        public bool Delete(string principalID, string friend)
+        {
             SqliteCommand cmd = new SqliteCommand();
 
             cmd.CommandText = String.Format("delete from {0} where PrincipalID = :PrincipalID and Friend = :Friend", m_Realm);
-- 
cgit v1.1