From dc197856727c06b0b06488ab839409831af84865 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 14 Feb 2010 16:57:02 -0800 Subject: [PATCH] Added UserAccount, Avatar and Authentication to Data.Null, so that OpenSim can run out-of-the-box. #WaitingForSQLite --- OpenSim/Data/Null/NullAuthenticationData.cs | 81 ++++++++++ OpenSim/Data/Null/NullAvatarData.cs | 93 ++++++++++++ OpenSim/Data/Null/NullUserAccountData.cs | 139 ++++++++++++++++++ OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 81 +++++----- .../InventoryService/InventoryService.cs | 1 + bin/config-include/Standalone.ini | 6 + bin/config-include/StandaloneHypergrid.ini | 7 +- 7 files changed, 372 insertions(+), 36 deletions(-) create mode 100644 OpenSim/Data/Null/NullAuthenticationData.cs create mode 100644 OpenSim/Data/Null/NullAvatarData.cs create mode 100644 OpenSim/Data/Null/NullUserAccountData.cs diff --git a/OpenSim/Data/Null/NullAuthenticationData.cs b/OpenSim/Data/Null/NullAuthenticationData.cs new file mode 100644 index 0000000000..3fb3105ec5 --- /dev/null +++ b/OpenSim/Data/Null/NullAuthenticationData.cs @@ -0,0 +1,81 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Data; + +namespace OpenSim.Data.Null +{ + public class NullAuthenticationData : IAuthenticationData + { + private static Dictionary m_DataByUUID = new Dictionary(); + private static Dictionary m_Tokens = new Dictionary(); + + public NullAuthenticationData(string connectionString, string realm) + { + } + + public AuthenticationData Get(UUID principalID) + { + if (m_DataByUUID.ContainsKey(principalID)) + return m_DataByUUID[principalID]; + + return null; + } + + public bool Store(AuthenticationData data) + { + m_DataByUUID[data.PrincipalID] = data; + return true; + } + + public bool SetDataItem(UUID principalID, string item, string value) + { + // Not implemented + return false; + } + + public bool SetToken(UUID principalID, string token, int lifetime) + { + m_Tokens[principalID] = token; + return true; + } + + public bool CheckToken(UUID principalID, string token, int lifetime) + { + if (m_Tokens.ContainsKey(principalID)) + return m_Tokens[principalID] == token; + + return false; + } + + } +} diff --git a/OpenSim/Data/Null/NullAvatarData.cs b/OpenSim/Data/Null/NullAvatarData.cs new file mode 100644 index 0000000000..c81ba43e6e --- /dev/null +++ b/OpenSim/Data/Null/NullAvatarData.cs @@ -0,0 +1,93 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Data; + +namespace OpenSim.Data.Null +{ + public class NullAvatarData : IAvatarData + { + private static Dictionary m_DataByUUID = new Dictionary(); + + public NullAvatarData(string connectionString, string realm) + { + } + + public AvatarBaseData[] Get(string field, string val) + { + if (field == "PrincipalID") + { + UUID id = UUID.Zero; + if (UUID.TryParse(val, out id)) + if (m_DataByUUID.ContainsKey(id)) + return new AvatarBaseData[] { m_DataByUUID[id] }; + } + + // Fail + return new AvatarBaseData[0]; + } + + public bool Store(AvatarBaseData data) + { + m_DataByUUID[data.PrincipalID] = data; + return true; + } + + public bool Delete(UUID principalID, string name) + { + if (m_DataByUUID.ContainsKey(principalID) && m_DataByUUID[principalID].Data.ContainsKey(name)) + { + m_DataByUUID[principalID].Data.Remove(name); + return true; + } + + return false; + } + + public bool Delete(string field, string val) + { + if (field == "PrincipalID") + { + UUID id = UUID.Zero; + if (UUID.TryParse(val, out id)) + if (m_DataByUUID.ContainsKey(id)) + { + m_DataByUUID.Remove(id); + return true; + } + } + + return false; + } + + } +} diff --git a/OpenSim/Data/Null/NullUserAccountData.cs b/OpenSim/Data/Null/NullUserAccountData.cs new file mode 100644 index 0000000000..fc2c5d5de2 --- /dev/null +++ b/OpenSim/Data/Null/NullUserAccountData.cs @@ -0,0 +1,139 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Data; + +namespace OpenSim.Data.Null +{ + public class NullUserAccountData : IUserAccountData + { + private static Dictionary m_DataByUUID = new Dictionary(); + private static Dictionary m_DataByName = new Dictionary(); + private static Dictionary m_DataByEmail = new Dictionary(); + + public NullUserAccountData(string connectionString, string realm) + { + } + + /// + /// Tries to implement the Get [] semantics, but it cuts corners like crazy. + /// Specifically, it relies on the knowledge that the only Gets used are + /// keyed on PrincipalID, Email, and FirstName+LastName. + /// + /// + /// + /// + public UserAccountData[] Get(string[] fields, string[] values) + { + List fieldsLst = new List(fields); + if (fieldsLst.Contains("PrincipalID")) + { + int i = fieldsLst.IndexOf("PrincipalID"); + UUID id = UUID.Zero; + if (UUID.TryParse(values[i], out id)) + if (m_DataByUUID.ContainsKey(id)) + return new UserAccountData[] { m_DataByUUID[id] }; + } + if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName")) + { + int findex = fieldsLst.IndexOf("FirstName"); + int lindex = fieldsLst.IndexOf("LastName"); + if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex])) + return new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] }; + } + if (fieldsLst.Contains("Email")) + { + int i = fieldsLst.IndexOf("Email"); + if (m_DataByEmail.ContainsKey(values[i])) + return new UserAccountData[] { m_DataByEmail[values[i]] }; + } + + // Fail + return new UserAccountData[0]; + } + + public bool Store(UserAccountData data) + { + if (data == null) + return false; + + m_DataByUUID[data.PrincipalID] = data; + m_DataByName[data.FirstName + " " + data.LastName] = data; + if (data.Data.ContainsKey("Email") && data.Data["Email"] != string.Empty) + m_DataByEmail[data.Data["Email"]] = data; + + return true; + } + + public UserAccountData[] GetUsers(UUID scopeID, string query) + { + string[] words = query.Split(new char[] { ' ' }); + + for (int i = 0; i < words.Length; i++) + { + if (words[i].Length < 3) + { + if (i != words.Length - 1) + Array.Copy(words, i + 1, words, i, words.Length - i - 1); + Array.Resize(ref words, words.Length - 1); + } + } + + if (words.Length == 0) + return new UserAccountData[0]; + + if (words.Length > 2) + return new UserAccountData[0]; + + List lst = new List(m_DataByName.Keys); + if (words.Length == 1) + { + lst = lst.FindAll(delegate(string s) { return s.StartsWith(words[0]); }); + } + else + { + lst = lst.FindAll(delegate(string s) { return s.Contains(words[0]) || s.Contains(words[1]); }); + } + + if (lst == null || (lst != null && lst.Count == 0)) + return new UserAccountData[0]; + + UserAccountData[] result = new UserAccountData[lst.Count]; + int n = 0; + foreach (string key in lst) + result[n++] = m_DataByName[key]; + + return result; + } + + } +} diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 64591fd6f6..c058bc771b 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -46,10 +46,12 @@ namespace OpenSim.Data.SQLite private const string invItemsSelect = "select * from inventoryitems"; private const string invFoldersSelect = "select * from inventoryfolders"; - private SqliteConnection conn; - private DataSet ds; - private SqliteDataAdapter invItemsDa; - private SqliteDataAdapter invFoldersDa; + private static SqliteConnection conn; + private static DataSet ds; + private static SqliteDataAdapter invItemsDa; + private static SqliteDataAdapter invFoldersDa; + + private static bool m_Initialized = false; public void Initialise() { @@ -67,39 +69,44 @@ namespace OpenSim.Data.SQLite /// connect string public void Initialise(string dbconnect) { - if (dbconnect == string.Empty) + if (!m_Initialized) { - dbconnect = "URI=file:inventoryStore.db,version=3"; + m_Initialized = true; + + if (dbconnect == string.Empty) + { + dbconnect = "URI=file:inventoryStore.db,version=3"; + } + m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect); + conn = new SqliteConnection(dbconnect); + + conn.Open(); + + Assembly assem = GetType().Assembly; + Migration m = new Migration(conn, assem, "InventoryStore"); + m.Update(); + + SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); + invItemsDa = new SqliteDataAdapter(itemsSelectCmd); + // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); + + SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn); + invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); + + ds = new DataSet(); + + ds.Tables.Add(createInventoryFoldersTable()); + invFoldersDa.Fill(ds.Tables["inventoryfolders"]); + setupFoldersCommands(invFoldersDa, conn); + m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); + + ds.Tables.Add(createInventoryItemsTable()); + invItemsDa.Fill(ds.Tables["inventoryitems"]); + setupItemsCommands(invItemsDa, conn); + m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); + + ds.AcceptChanges(); } - m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect); - conn = new SqliteConnection(dbconnect); - - conn.Open(); - - Assembly assem = GetType().Assembly; - Migration m = new Migration(conn, assem, "InventoryStore"); - m.Update(); - - SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); - invItemsDa = new SqliteDataAdapter(itemsSelectCmd); - // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); - - SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn); - invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); - - ds = new DataSet(); - - ds.Tables.Add(createInventoryFoldersTable()); - invFoldersDa.Fill(ds.Tables["inventoryfolders"]); - setupFoldersCommands(invFoldersDa, conn); - m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); - - ds.Tables.Add(createInventoryItemsTable()); - invItemsDa.Fill(ds.Tables["inventoryitems"]); - setupItemsCommands(invItemsDa, conn); - m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); - - ds.AcceptChanges(); } /// @@ -384,7 +391,9 @@ namespace OpenSim.Data.SQLite List folders = new List(); DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; string selectExp = "agentID = '" + user + "' AND parentID = '" + UUID.Zero + "'"; + m_log.DebugFormat("XXX selectExp = {0}", selectExp); DataRow[] rows = inventoryFolderTable.Select(selectExp); + m_log.DebugFormat("XXX rows: {0}", rows.Length); foreach (DataRow row in rows) { folders.Add(buildFolder(row)); @@ -397,9 +406,11 @@ namespace OpenSim.Data.SQLite // suitably refactor. if (folders.Count > 0) { + m_log.DebugFormat("XXX Found root folder"); return folders[0]; } + m_log.DebugFormat("XXX Root folder for {0} not found", user); return null; } } diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index 781b89b983..0d6577e776 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs @@ -66,6 +66,7 @@ namespace OpenSim.Services.InventoryService // Agent has no inventory structure yet. if (null == rootFolder) { + m_log.DebugFormat("[INVENTORY SERVICE]: No root folder"); return null; } diff --git a/bin/config-include/Standalone.ini b/bin/config-include/Standalone.ini index 0c74ea44ec..bd90df4064 100644 --- a/bin/config-include/Standalone.ini +++ b/bin/config-include/Standalone.ini @@ -35,10 +35,15 @@ [AvatarService] LocalServiceModule = "OpenSim.Services.AvatarService.dll:AvatarService" + StorageProvider = "OpenSim.Data.Null.dll" [AuthorizationService] LocalServiceModule = "OpenSim.Services.AuthorizationService.dll:AuthorizationService" +[AuthenticationService] + LocalServiceModule = "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService" + StorageProvider = "OpenSim.Data.Null.dll" + [GridService] LocalServiceModule = "OpenSim.Services.GridService.dll:GridService" Realm = "regions" @@ -50,6 +55,7 @@ [UserAccountService] LocalServiceModule = "OpenSim.Services.UserAccountService.dll:UserAccountService" + StorageProvider = "OpenSim.Data.Null.dll" ;; These are for creating new accounts AuthenticationService = "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService" PresenceService = "OpenSim.Services.PresenceService.dll:PresenceService" diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index 06f189824b..a4fa5be033 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -45,6 +45,7 @@ [AvatarService] LocalServiceModule = "OpenSim.Services.AvatarService.dll:AvatarService" + StorageProvider = "OpenSim.Data.Null.dll" [LibraryService] LocalServiceModule = "OpenSim.Services.InventoryService.dll:LibraryService" @@ -56,19 +57,23 @@ [AuthenticationService] LocalServiceModule = "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService" - + StorageProvider = "OpenSim.Data.Null.dll" + [GridService] ; LocalGridServicesConnector needs this LocalServiceModule = "OpenSim.Services.GridService.dll:GridService" Realm = "regions" + StorageProvider = "OpenSim.Data.Null.dll" AllowHypergridMapSearch = true [PresenceService] LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService" + StorageProvider = "OpenSim.Data.Null.dll" [UserAccountService] LocalServiceModule = "OpenSim.Services.UserAccountService.dll:UserAccountService" + StorageProvider = "OpenSim.Data.Null.dll" ;; These are for creating new accounts by the service AuthenticationService = "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService" PresenceService = "OpenSim.Services.PresenceService.dll:PresenceService"