aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
authorDiva Canto2010-02-14 16:57:02 -0800
committerDiva Canto2010-02-14 16:57:02 -0800
commitdc197856727c06b0b06488ab839409831af84865 (patch)
tree52db90cc6ae1ad2abcb6103fca0129a69bea4716 /OpenSim/Data
parentImplement the methods needed for the login service to populate the friendslist (diff)
downloadopensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.zip
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.gz
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.bz2
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.xz
Added UserAccount, Avatar and Authentication to Data.Null, so that OpenSim can run out-of-the-box. #WaitingForSQLite
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/Null/NullAuthenticationData.cs81
-rw-r--r--OpenSim/Data/Null/NullAvatarData.cs93
-rw-r--r--OpenSim/Data/Null/NullUserAccountData.cs139
-rw-r--r--OpenSim/Data/SQLite/SQLiteInventoryStore.cs67
4 files changed, 352 insertions, 28 deletions
diff --git a/OpenSim/Data/Null/NullAuthenticationData.cs b/OpenSim/Data/Null/NullAuthenticationData.cs
new file mode 100644
index 0000000..3fb3105
--- /dev/null
+++ b/OpenSim/Data/Null/NullAuthenticationData.cs
@@ -0,0 +1,81 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Data;
34
35namespace OpenSim.Data.Null
36{
37 public class NullAuthenticationData : IAuthenticationData
38 {
39 private static Dictionary<UUID, AuthenticationData> m_DataByUUID = new Dictionary<UUID, AuthenticationData>();
40 private static Dictionary<UUID, string> m_Tokens = new Dictionary<UUID, string>();
41
42 public NullAuthenticationData(string connectionString, string realm)
43 {
44 }
45
46 public AuthenticationData Get(UUID principalID)
47 {
48 if (m_DataByUUID.ContainsKey(principalID))
49 return m_DataByUUID[principalID];
50
51 return null;
52 }
53
54 public bool Store(AuthenticationData data)
55 {
56 m_DataByUUID[data.PrincipalID] = data;
57 return true;
58 }
59
60 public bool SetDataItem(UUID principalID, string item, string value)
61 {
62 // Not implemented
63 return false;
64 }
65
66 public bool SetToken(UUID principalID, string token, int lifetime)
67 {
68 m_Tokens[principalID] = token;
69 return true;
70 }
71
72 public bool CheckToken(UUID principalID, string token, int lifetime)
73 {
74 if (m_Tokens.ContainsKey(principalID))
75 return m_Tokens[principalID] == token;
76
77 return false;
78 }
79
80 }
81}
diff --git a/OpenSim/Data/Null/NullAvatarData.cs b/OpenSim/Data/Null/NullAvatarData.cs
new file mode 100644
index 0000000..c81ba43
--- /dev/null
+++ b/OpenSim/Data/Null/NullAvatarData.cs
@@ -0,0 +1,93 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Data;
34
35namespace OpenSim.Data.Null
36{
37 public class NullAvatarData : IAvatarData
38 {
39 private static Dictionary<UUID, AvatarBaseData> m_DataByUUID = new Dictionary<UUID, AvatarBaseData>();
40
41 public NullAvatarData(string connectionString, string realm)
42 {
43 }
44
45 public AvatarBaseData[] Get(string field, string val)
46 {
47 if (field == "PrincipalID")
48 {
49 UUID id = UUID.Zero;
50 if (UUID.TryParse(val, out id))
51 if (m_DataByUUID.ContainsKey(id))
52 return new AvatarBaseData[] { m_DataByUUID[id] };
53 }
54
55 // Fail
56 return new AvatarBaseData[0];
57 }
58
59 public bool Store(AvatarBaseData data)
60 {
61 m_DataByUUID[data.PrincipalID] = data;
62 return true;
63 }
64
65 public bool Delete(UUID principalID, string name)
66 {
67 if (m_DataByUUID.ContainsKey(principalID) && m_DataByUUID[principalID].Data.ContainsKey(name))
68 {
69 m_DataByUUID[principalID].Data.Remove(name);
70 return true;
71 }
72
73 return false;
74 }
75
76 public bool Delete(string field, string val)
77 {
78 if (field == "PrincipalID")
79 {
80 UUID id = UUID.Zero;
81 if (UUID.TryParse(val, out id))
82 if (m_DataByUUID.ContainsKey(id))
83 {
84 m_DataByUUID.Remove(id);
85 return true;
86 }
87 }
88
89 return false;
90 }
91
92 }
93}
diff --git a/OpenSim/Data/Null/NullUserAccountData.cs b/OpenSim/Data/Null/NullUserAccountData.cs
new file mode 100644
index 0000000..fc2c5d5
--- /dev/null
+++ b/OpenSim/Data/Null/NullUserAccountData.cs
@@ -0,0 +1,139 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Data;
34
35namespace OpenSim.Data.Null
36{
37 public class NullUserAccountData : IUserAccountData
38 {
39 private static Dictionary<UUID, UserAccountData> m_DataByUUID = new Dictionary<UUID, UserAccountData>();
40 private static Dictionary<string, UserAccountData> m_DataByName = new Dictionary<string, UserAccountData>();
41 private static Dictionary<string, UserAccountData> m_DataByEmail = new Dictionary<string, UserAccountData>();
42
43 public NullUserAccountData(string connectionString, string realm)
44 {
45 }
46
47 /// <summary>
48 /// Tries to implement the Get [] semantics, but it cuts corners like crazy.
49 /// Specifically, it relies on the knowledge that the only Gets used are
50 /// keyed on PrincipalID, Email, and FirstName+LastName.
51 /// </summary>
52 /// <param name="fields"></param>
53 /// <param name="values"></param>
54 /// <returns></returns>
55 public UserAccountData[] Get(string[] fields, string[] values)
56 {
57 List<string> fieldsLst = new List<string>(fields);
58 if (fieldsLst.Contains("PrincipalID"))
59 {
60 int i = fieldsLst.IndexOf("PrincipalID");
61 UUID id = UUID.Zero;
62 if (UUID.TryParse(values[i], out id))
63 if (m_DataByUUID.ContainsKey(id))
64 return new UserAccountData[] { m_DataByUUID[id] };
65 }
66 if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName"))
67 {
68 int findex = fieldsLst.IndexOf("FirstName");
69 int lindex = fieldsLst.IndexOf("LastName");
70 if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex]))
71 return new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] };
72 }
73 if (fieldsLst.Contains("Email"))
74 {
75 int i = fieldsLst.IndexOf("Email");
76 if (m_DataByEmail.ContainsKey(values[i]))
77 return new UserAccountData[] { m_DataByEmail[values[i]] };
78 }
79
80 // Fail
81 return new UserAccountData[0];
82 }
83
84 public bool Store(UserAccountData data)
85 {
86 if (data == null)
87 return false;
88
89 m_DataByUUID[data.PrincipalID] = data;
90 m_DataByName[data.FirstName + " " + data.LastName] = data;
91 if (data.Data.ContainsKey("Email") && data.Data["Email"] != string.Empty)
92 m_DataByEmail[data.Data["Email"]] = data;
93
94 return true;
95 }
96
97 public UserAccountData[] GetUsers(UUID scopeID, string query)
98 {
99 string[] words = query.Split(new char[] { ' ' });
100
101 for (int i = 0; i < words.Length; i++)
102 {
103 if (words[i].Length < 3)
104 {
105 if (i != words.Length - 1)
106 Array.Copy(words, i + 1, words, i, words.Length - i - 1);
107 Array.Resize(ref words, words.Length - 1);
108 }
109 }
110
111 if (words.Length == 0)
112 return new UserAccountData[0];
113
114 if (words.Length > 2)
115 return new UserAccountData[0];
116
117 List<string> lst = new List<string>(m_DataByName.Keys);
118 if (words.Length == 1)
119 {
120 lst = lst.FindAll(delegate(string s) { return s.StartsWith(words[0]); });
121 }
122 else
123 {
124 lst = lst.FindAll(delegate(string s) { return s.Contains(words[0]) || s.Contains(words[1]); });
125 }
126
127 if (lst == null || (lst != null && lst.Count == 0))
128 return new UserAccountData[0];
129
130 UserAccountData[] result = new UserAccountData[lst.Count];
131 int n = 0;
132 foreach (string key in lst)
133 result[n++] = m_DataByName[key];
134
135 return result;
136 }
137
138 }
139}
diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
index 64591fd..c058bc7 100644
--- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
+++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
@@ -46,10 +46,12 @@ namespace OpenSim.Data.SQLite
46 private const string invItemsSelect = "select * from inventoryitems"; 46 private const string invItemsSelect = "select * from inventoryitems";
47 private const string invFoldersSelect = "select * from inventoryfolders"; 47 private const string invFoldersSelect = "select * from inventoryfolders";
48 48
49 private SqliteConnection conn; 49 private static SqliteConnection conn;
50 private DataSet ds; 50 private static DataSet ds;
51 private SqliteDataAdapter invItemsDa; 51 private static SqliteDataAdapter invItemsDa;
52 private SqliteDataAdapter invFoldersDa; 52 private static SqliteDataAdapter invFoldersDa;
53
54 private static bool m_Initialized = false;
53 55
54 public void Initialise() 56 public void Initialise()
55 { 57 {
@@ -67,39 +69,44 @@ namespace OpenSim.Data.SQLite
67 /// <param name="dbconnect">connect string</param> 69 /// <param name="dbconnect">connect string</param>
68 public void Initialise(string dbconnect) 70 public void Initialise(string dbconnect)
69 { 71 {
70 if (dbconnect == string.Empty) 72 if (!m_Initialized)
71 { 73 {
72 dbconnect = "URI=file:inventoryStore.db,version=3"; 74 m_Initialized = true;
73 } 75
74 m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect); 76 if (dbconnect == string.Empty)
75 conn = new SqliteConnection(dbconnect); 77 {
78 dbconnect = "URI=file:inventoryStore.db,version=3";
79 }
80 m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect);
81 conn = new SqliteConnection(dbconnect);
76 82
77 conn.Open(); 83 conn.Open();
78 84
79 Assembly assem = GetType().Assembly; 85 Assembly assem = GetType().Assembly;
80 Migration m = new Migration(conn, assem, "InventoryStore"); 86 Migration m = new Migration(conn, assem, "InventoryStore");
81 m.Update(); 87 m.Update();
82 88
83 SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); 89 SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
84 invItemsDa = new SqliteDataAdapter(itemsSelectCmd); 90 invItemsDa = new SqliteDataAdapter(itemsSelectCmd);
85 // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); 91 // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);
86 92
87 SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn); 93 SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn);
88 invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); 94 invFoldersDa = new SqliteDataAdapter(foldersSelectCmd);
89 95
90 ds = new DataSet(); 96 ds = new DataSet();
91 97
92 ds.Tables.Add(createInventoryFoldersTable()); 98 ds.Tables.Add(createInventoryFoldersTable());
93 invFoldersDa.Fill(ds.Tables["inventoryfolders"]); 99 invFoldersDa.Fill(ds.Tables["inventoryfolders"]);
94 setupFoldersCommands(invFoldersDa, conn); 100 setupFoldersCommands(invFoldersDa, conn);
95 m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); 101 m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions");
96 102
97 ds.Tables.Add(createInventoryItemsTable()); 103 ds.Tables.Add(createInventoryItemsTable());
98 invItemsDa.Fill(ds.Tables["inventoryitems"]); 104 invItemsDa.Fill(ds.Tables["inventoryitems"]);
99 setupItemsCommands(invItemsDa, conn); 105 setupItemsCommands(invItemsDa, conn);
100 m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); 106 m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions");
101 107
102 ds.AcceptChanges(); 108 ds.AcceptChanges();
109 }
103 } 110 }
104 111
105 /// <summary> 112 /// <summary>
@@ -384,7 +391,9 @@ namespace OpenSim.Data.SQLite
384 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 391 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
385 DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; 392 DataTable inventoryFolderTable = ds.Tables["inventoryfolders"];
386 string selectExp = "agentID = '" + user + "' AND parentID = '" + UUID.Zero + "'"; 393 string selectExp = "agentID = '" + user + "' AND parentID = '" + UUID.Zero + "'";
394 m_log.DebugFormat("XXX selectExp = {0}", selectExp);
387 DataRow[] rows = inventoryFolderTable.Select(selectExp); 395 DataRow[] rows = inventoryFolderTable.Select(selectExp);
396 m_log.DebugFormat("XXX rows: {0}", rows.Length);
388 foreach (DataRow row in rows) 397 foreach (DataRow row in rows)
389 { 398 {
390 folders.Add(buildFolder(row)); 399 folders.Add(buildFolder(row));
@@ -397,9 +406,11 @@ namespace OpenSim.Data.SQLite
397 // suitably refactor. 406 // suitably refactor.
398 if (folders.Count > 0) 407 if (folders.Count > 0)
399 { 408 {
409 m_log.DebugFormat("XXX Found root folder");
400 return folders[0]; 410 return folders[0];
401 } 411 }
402 412
413 m_log.DebugFormat("XXX Root folder for {0} not found", user);
403 return null; 414 return null;
404 } 415 }
405 } 416 }