diff options
author | Sean Dague | 2007-07-16 15:40:11 +0000 |
---|---|---|
committer | Sean Dague | 2007-07-16 15:40:11 +0000 |
commit | 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch) | |
tree | e3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Framework/Data.SQLite | |
parent | *Trunk compiles now (diff) | |
download | opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2 opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz |
changed to native line ending encoding
Diffstat (limited to 'OpenSim/Framework/Data.SQLite')
-rw-r--r-- | OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs | 66 | ||||
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteGridData.cs | 394 | ||||
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteManager.cs | 412 |
3 files changed, 436 insertions, 436 deletions
diff --git a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs index 9de5edb..8136bc1 100644 --- a/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Data.SQLite/Properties/AssemblyInfo.cs | |||
@@ -1,33 +1,33 @@ | |||
1 | using System.Reflection; | 1 | using System.Reflection; |
2 | using System.Runtime.InteropServices; | 2 | using System.Runtime.InteropServices; |
3 | // General Information about an assembly is controlled through the following | 3 | // General Information about an assembly is controlled through the following |
4 | // set of attributes. Change these attribute values to modify the information | 4 | // set of attributes. Change these attribute values to modify the information |
5 | // associated with an assembly. | 5 | // associated with an assembly. |
6 | [assembly: AssemblyTitle("OpenSim.Framework.Data.SQLite")] | 6 | [assembly: AssemblyTitle("OpenSim.Framework.Data.SQLite")] |
7 | [assembly: AssemblyDescription("")] | 7 | [assembly: AssemblyDescription("")] |
8 | [assembly: AssemblyConfiguration("")] | 8 | [assembly: AssemblyConfiguration("")] |
9 | [assembly: AssemblyCompany("")] | 9 | [assembly: AssemblyCompany("")] |
10 | [assembly: AssemblyProduct("OpenSim.Framework.Data.SQLite")] | 10 | [assembly: AssemblyProduct("OpenSim.Framework.Data.SQLite")] |
11 | [assembly: AssemblyCopyright("Copyright © 2007")] | 11 | [assembly: AssemblyCopyright("Copyright © 2007")] |
12 | [assembly: AssemblyTrademark("")] | 12 | [assembly: AssemblyTrademark("")] |
13 | [assembly: AssemblyCulture("")] | 13 | [assembly: AssemblyCulture("")] |
14 | 14 | ||
15 | // Setting ComVisible to false makes the types in this assembly not visible | 15 | // Setting ComVisible to false makes the types in this assembly not visible |
16 | // to COM components. If you need to access a type in this assembly from | 16 | // to COM components. If you need to access a type in this assembly from |
17 | // COM, set the ComVisible attribute to true on that type. | 17 | // COM, set the ComVisible attribute to true on that type. |
18 | [assembly: ComVisible(false)] | 18 | [assembly: ComVisible(false)] |
19 | 19 | ||
20 | // The following GUID is for the ID of the typelib if this project is exposed to COM | 20 | // The following GUID is for the ID of the typelib if this project is exposed to COM |
21 | [assembly: Guid("6113d5ce-4547-49f4-9236-0dcc503457b1")] | 21 | [assembly: Guid("6113d5ce-4547-49f4-9236-0dcc503457b1")] |
22 | 22 | ||
23 | // Version information for an assembly consists of the following four values: | 23 | // Version information for an assembly consists of the following four values: |
24 | // | 24 | // |
25 | // Major Version | 25 | // Major Version |
26 | // Minor Version | 26 | // Minor Version |
27 | // Build Number | 27 | // Build Number |
28 | // Revision | 28 | // Revision |
29 | // | 29 | // |
30 | // You can specify all the values or you can default the Revision and Build Numbers | 30 | // You can specify all the values or you can default the Revision and Build Numbers |
31 | // by using the '*' as shown below: | 31 | // by using the '*' as shown below: |
32 | [assembly: AssemblyVersion("1.0.0.0")] | 32 | [assembly: AssemblyVersion("1.0.0.0")] |
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | 33 | [assembly: AssemblyFileVersion("1.0.0.0")] |
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs index 511c5f0..c1d74ae 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs | |||
@@ -1,197 +1,197 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Security.Cryptography; | 31 | using System.Security.Cryptography; |
32 | using System.Text; | 32 | using System.Text; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | 34 | ||
35 | namespace OpenSim.Framework.Data.SQLite | 35 | namespace OpenSim.Framework.Data.SQLite |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// A Grid Interface to the SQLite database | 38 | /// A Grid Interface to the SQLite database |
39 | /// </summary> | 39 | /// </summary> |
40 | public class SQLiteGridData : IGridData | 40 | public class SQLiteGridData : IGridData |
41 | { | 41 | { |
42 | /// <summary> | 42 | /// <summary> |
43 | /// A database manager | 43 | /// A database manager |
44 | /// </summary> | 44 | /// </summary> |
45 | private SQLiteManager database; | 45 | private SQLiteManager database; |
46 | 46 | ||
47 | /// <summary> | 47 | /// <summary> |
48 | /// Initialises the Grid Interface | 48 | /// Initialises the Grid Interface |
49 | /// </summary> | 49 | /// </summary> |
50 | public void Initialise() | 50 | public void Initialise() |
51 | { | 51 | { |
52 | database = new SQLiteManager("localhost", "db", "user", "password", "false"); | 52 | database = new SQLiteManager("localhost", "db", "user", "password", "false"); |
53 | } | 53 | } |
54 | 54 | ||
55 | /// <summary> | 55 | /// <summary> |
56 | /// Shuts down the grid interface | 56 | /// Shuts down the grid interface |
57 | /// </summary> | 57 | /// </summary> |
58 | public void Close() | 58 | public void Close() |
59 | { | 59 | { |
60 | database.Close(); | 60 | database.Close(); |
61 | } | 61 | } |
62 | 62 | ||
63 | /// <summary> | 63 | /// <summary> |
64 | /// Returns the name of this grid interface | 64 | /// Returns the name of this grid interface |
65 | /// </summary> | 65 | /// </summary> |
66 | /// <returns>A string containing the grid interface</returns> | 66 | /// <returns>A string containing the grid interface</returns> |
67 | public string getName() | 67 | public string getName() |
68 | { | 68 | { |
69 | return "SQLite OpenGridData"; | 69 | return "SQLite OpenGridData"; |
70 | } | 70 | } |
71 | 71 | ||
72 | /// <summary> | 72 | /// <summary> |
73 | /// Returns the version of this grid interface | 73 | /// Returns the version of this grid interface |
74 | /// </summary> | 74 | /// </summary> |
75 | /// <returns>A string containing the version</returns> | 75 | /// <returns>A string containing the version</returns> |
76 | public string getVersion() | 76 | public string getVersion() |
77 | { | 77 | { |
78 | return "0.1"; | 78 | return "0.1"; |
79 | } | 79 | } |
80 | 80 | ||
81 | /// <summary> | 81 | /// <summary> |
82 | /// Returns a list of regions within the specified ranges | 82 | /// Returns a list of regions within the specified ranges |
83 | /// </summary> | 83 | /// </summary> |
84 | /// <param name="a">minimum X coordinate</param> | 84 | /// <param name="a">minimum X coordinate</param> |
85 | /// <param name="b">minimum Y coordinate</param> | 85 | /// <param name="b">minimum Y coordinate</param> |
86 | /// <param name="c">maximum X coordinate</param> | 86 | /// <param name="c">maximum X coordinate</param> |
87 | /// <param name="d">maximum Y coordinate</param> | 87 | /// <param name="d">maximum Y coordinate</param> |
88 | /// <returns>An array of region profiles</returns> | 88 | /// <returns>An array of region profiles</returns> |
89 | public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | 89 | public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) |
90 | { | 90 | { |
91 | return null; | 91 | return null; |
92 | } | 92 | } |
93 | 93 | ||
94 | /// <summary> | 94 | /// <summary> |
95 | /// Returns a sim profile from it's location | 95 | /// Returns a sim profile from it's location |
96 | /// </summary> | 96 | /// </summary> |
97 | /// <param name="handle">Region location handle</param> | 97 | /// <param name="handle">Region location handle</param> |
98 | /// <returns>Sim profile</returns> | 98 | /// <returns>Sim profile</returns> |
99 | public SimProfileData GetProfileByHandle(ulong handle) | 99 | public SimProfileData GetProfileByHandle(ulong handle) |
100 | { | 100 | { |
101 | Dictionary<string, string> param = new Dictionary<string, string>(); | 101 | Dictionary<string, string> param = new Dictionary<string, string>(); |
102 | param["handle"] = handle.ToString(); | 102 | param["handle"] = handle.ToString(); |
103 | 103 | ||
104 | IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); | 104 | IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); |
105 | IDataReader reader = result.ExecuteReader(); | 105 | IDataReader reader = result.ExecuteReader(); |
106 | 106 | ||
107 | SimProfileData row = database.getRow(reader); | 107 | SimProfileData row = database.getRow(reader); |
108 | reader.Close(); | 108 | reader.Close(); |
109 | result.Dispose(); | 109 | result.Dispose(); |
110 | 110 | ||
111 | return row; | 111 | return row; |
112 | } | 112 | } |
113 | 113 | ||
114 | /// <summary> | 114 | /// <summary> |
115 | /// Returns a sim profile from it's UUID | 115 | /// Returns a sim profile from it's UUID |
116 | /// </summary> | 116 | /// </summary> |
117 | /// <param name="uuid">The region UUID</param> | 117 | /// <param name="uuid">The region UUID</param> |
118 | /// <returns>The sim profile</returns> | 118 | /// <returns>The sim profile</returns> |
119 | public SimProfileData GetProfileByLLUUID(LLUUID uuid) | 119 | public SimProfileData GetProfileByLLUUID(LLUUID uuid) |
120 | { | 120 | { |
121 | Dictionary<string, string> param = new Dictionary<string, string>(); | 121 | Dictionary<string, string> param = new Dictionary<string, string>(); |
122 | param["uuid"] = uuid.ToStringHyphenated(); | 122 | param["uuid"] = uuid.ToStringHyphenated(); |
123 | 123 | ||
124 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); | 124 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); |
125 | IDataReader reader = result.ExecuteReader(); | 125 | IDataReader reader = result.ExecuteReader(); |
126 | 126 | ||
127 | SimProfileData row = database.getRow(reader); | 127 | SimProfileData row = database.getRow(reader); |
128 | reader.Close(); | 128 | reader.Close(); |
129 | result.Dispose(); | 129 | result.Dispose(); |
130 | 130 | ||
131 | return row; | 131 | return row; |
132 | } | 132 | } |
133 | 133 | ||
134 | /// <summary> | 134 | /// <summary> |
135 | /// Adds a new specified region to the database | 135 | /// Adds a new specified region to the database |
136 | /// </summary> | 136 | /// </summary> |
137 | /// <param name="profile">The profile to add</param> | 137 | /// <param name="profile">The profile to add</param> |
138 | /// <returns>A dataresponse enum indicating success</returns> | 138 | /// <returns>A dataresponse enum indicating success</returns> |
139 | public DataResponse AddProfile(SimProfileData profile) | 139 | public DataResponse AddProfile(SimProfileData profile) |
140 | { | 140 | { |
141 | if (database.insertRow(profile)) | 141 | if (database.insertRow(profile)) |
142 | { | 142 | { |
143 | return DataResponse.RESPONSE_OK; | 143 | return DataResponse.RESPONSE_OK; |
144 | } | 144 | } |
145 | else | 145 | else |
146 | { | 146 | { |
147 | return DataResponse.RESPONSE_ERROR; | 147 | return DataResponse.RESPONSE_ERROR; |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | /// <summary> | 151 | /// <summary> |
152 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | 152 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. |
153 | /// </summary> | 153 | /// </summary> |
154 | /// <param name="uuid">The UUID of the challenger</param> | 154 | /// <param name="uuid">The UUID of the challenger</param> |
155 | /// <param name="handle">The attempted regionHandle of the challenger</param> | 155 | /// <param name="handle">The attempted regionHandle of the challenger</param> |
156 | /// <param name="authkey">The secret</param> | 156 | /// <param name="authkey">The secret</param> |
157 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | 157 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> |
158 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authkey) | 158 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authkey) |
159 | { | 159 | { |
160 | bool throwHissyFit = false; // Should be true by 1.0 | 160 | bool throwHissyFit = false; // Should be true by 1.0 |
161 | 161 | ||
162 | if (throwHissyFit) | 162 | if (throwHissyFit) |
163 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | 163 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); |
164 | 164 | ||
165 | SimProfileData data = GetProfileByLLUUID(uuid); | 165 | SimProfileData data = GetProfileByLLUUID(uuid); |
166 | 166 | ||
167 | return (handle == data.regionHandle && authkey == data.regionSecret); | 167 | return (handle == data.regionHandle && authkey == data.regionSecret); |
168 | } | 168 | } |
169 | 169 | ||
170 | /// <summary> | 170 | /// <summary> |
171 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | 171 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region |
172 | /// </summary> | 172 | /// </summary> |
173 | /// <remarks>This requires a security audit.</remarks> | 173 | /// <remarks>This requires a security audit.</remarks> |
174 | /// <param name="uuid"></param> | 174 | /// <param name="uuid"></param> |
175 | /// <param name="handle"></param> | 175 | /// <param name="handle"></param> |
176 | /// <param name="authhash"></param> | 176 | /// <param name="authhash"></param> |
177 | /// <param name="challenge"></param> | 177 | /// <param name="challenge"></param> |
178 | /// <returns></returns> | 178 | /// <returns></returns> |
179 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authhash, string challenge) | 179 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authhash, string challenge) |
180 | { | 180 | { |
181 | SHA512Managed HashProvider = new SHA512Managed(); | 181 | SHA512Managed HashProvider = new SHA512Managed(); |
182 | ASCIIEncoding TextProvider = new ASCIIEncoding(); | 182 | ASCIIEncoding TextProvider = new ASCIIEncoding(); |
183 | 183 | ||
184 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); | 184 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); |
185 | byte[] hash = HashProvider.ComputeHash(stream); | 185 | byte[] hash = HashProvider.ComputeHash(stream); |
186 | 186 | ||
187 | return false; | 187 | return false; |
188 | } | 188 | } |
189 | 189 | ||
190 | public ReservationData GetReservationAtPoint(uint x, uint y) | 190 | public ReservationData GetReservationAtPoint(uint x, uint y) |
191 | { | 191 | { |
192 | return null; | 192 | return null; |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | } | 197 | } |
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteManager.cs b/OpenSim/Framework/Data.SQLite/SQLiteManager.cs index c9931ab..a69611a 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteManager.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteManager.cs | |||
@@ -1,206 +1,206 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Data.SQLite; | 31 | using System.Data.SQLite; |
32 | using libsecondlife; | 32 | using libsecondlife; |
33 | 33 | ||
34 | namespace OpenSim.Framework.Data.SQLite | 34 | namespace OpenSim.Framework.Data.SQLite |
35 | { | 35 | { |
36 | class SQLiteManager | 36 | class SQLiteManager |
37 | { | 37 | { |
38 | IDbConnection dbcon; | 38 | IDbConnection dbcon; |
39 | 39 | ||
40 | /// <summary> | 40 | /// <summary> |
41 | /// Initialises and creates a new SQLite connection and maintains it. | 41 | /// Initialises and creates a new SQLite connection and maintains it. |
42 | /// </summary> | 42 | /// </summary> |
43 | /// <param name="hostname">The SQLite server being connected to</param> | 43 | /// <param name="hostname">The SQLite server being connected to</param> |
44 | /// <param name="database">The name of the SQLite database being used</param> | 44 | /// <param name="database">The name of the SQLite database being used</param> |
45 | /// <param name="username">The username logging into the database</param> | 45 | /// <param name="username">The username logging into the database</param> |
46 | /// <param name="password">The password for the user logging in</param> | 46 | /// <param name="password">The password for the user logging in</param> |
47 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> | 47 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> |
48 | public SQLiteManager(string hostname, string database, string username, string password, string cpooling) | 48 | public SQLiteManager(string hostname, string database, string username, string password, string cpooling) |
49 | { | 49 | { |
50 | try | 50 | try |
51 | { | 51 | { |
52 | string connectionString = "URI=file:GridServerSqlite.db;"; | 52 | string connectionString = "URI=file:GridServerSqlite.db;"; |
53 | dbcon = new SQLiteConnection(connectionString); | 53 | dbcon = new SQLiteConnection(connectionString); |
54 | 54 | ||
55 | dbcon.Open(); | 55 | dbcon.Open(); |
56 | } | 56 | } |
57 | catch (Exception e) | 57 | catch (Exception e) |
58 | { | 58 | { |
59 | throw new Exception("Error initialising SQLite Database: " + e.ToString()); | 59 | throw new Exception("Error initialising SQLite Database: " + e.ToString()); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | /// <summary> | 63 | /// <summary> |
64 | /// Shuts down the database connection | 64 | /// Shuts down the database connection |
65 | /// </summary> | 65 | /// </summary> |
66 | public void Close() | 66 | public void Close() |
67 | { | 67 | { |
68 | dbcon.Close(); | 68 | dbcon.Close(); |
69 | dbcon = null; | 69 | dbcon = null; |
70 | } | 70 | } |
71 | 71 | ||
72 | /// <summary> | 72 | /// <summary> |
73 | /// Runs a query with protection against SQL Injection by using parameterised input. | 73 | /// Runs a query with protection against SQL Injection by using parameterised input. |
74 | /// </summary> | 74 | /// </summary> |
75 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | 75 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
76 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | 76 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> |
77 | /// <returns>A SQLite DB Command</returns> | 77 | /// <returns>A SQLite DB Command</returns> |
78 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) | 78 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) |
79 | { | 79 | { |
80 | SQLiteCommand dbcommand = (SQLiteCommand)dbcon.CreateCommand(); | 80 | SQLiteCommand dbcommand = (SQLiteCommand)dbcon.CreateCommand(); |
81 | dbcommand.CommandText = sql; | 81 | dbcommand.CommandText = sql; |
82 | foreach (KeyValuePair<string, string> param in parameters) | 82 | foreach (KeyValuePair<string, string> param in parameters) |
83 | { | 83 | { |
84 | SQLiteParameter paramx = new SQLiteParameter(param.Key,param.Value); | 84 | SQLiteParameter paramx = new SQLiteParameter(param.Key,param.Value); |
85 | dbcommand.Parameters.Add(paramx); | 85 | dbcommand.Parameters.Add(paramx); |
86 | } | 86 | } |
87 | 87 | ||
88 | return (IDbCommand)dbcommand; | 88 | return (IDbCommand)dbcommand; |
89 | } | 89 | } |
90 | 90 | ||
91 | /// <summary> | 91 | /// <summary> |
92 | /// Reads a region row from a database reader | 92 | /// Reads a region row from a database reader |
93 | /// </summary> | 93 | /// </summary> |
94 | /// <param name="reader">An active database reader</param> | 94 | /// <param name="reader">An active database reader</param> |
95 | /// <returns>A region profile</returns> | 95 | /// <returns>A region profile</returns> |
96 | public SimProfileData getRow(IDataReader reader) | 96 | public SimProfileData getRow(IDataReader reader) |
97 | { | 97 | { |
98 | SimProfileData retval = new SimProfileData(); | 98 | SimProfileData retval = new SimProfileData(); |
99 | 99 | ||
100 | if (reader.Read()) | 100 | if (reader.Read()) |
101 | { | 101 | { |
102 | // Region Main | 102 | // Region Main |
103 | retval.regionHandle = (ulong)reader["regionHandle"]; | 103 | retval.regionHandle = (ulong)reader["regionHandle"]; |
104 | retval.regionName = (string)reader["regionName"]; | 104 | retval.regionName = (string)reader["regionName"]; |
105 | retval.UUID = new LLUUID((string)reader["uuid"]); | 105 | retval.UUID = new LLUUID((string)reader["uuid"]); |
106 | 106 | ||
107 | // Secrets | 107 | // Secrets |
108 | retval.regionRecvKey = (string)reader["regionRecvKey"]; | 108 | retval.regionRecvKey = (string)reader["regionRecvKey"]; |
109 | retval.regionSecret = (string)reader["regionSecret"]; | 109 | retval.regionSecret = (string)reader["regionSecret"]; |
110 | retval.regionSendKey = (string)reader["regionSendKey"]; | 110 | retval.regionSendKey = (string)reader["regionSendKey"]; |
111 | 111 | ||
112 | // Region Server | 112 | // Region Server |
113 | retval.regionDataURI = (string)reader["regionDataURI"]; | 113 | retval.regionDataURI = (string)reader["regionDataURI"]; |
114 | retval.regionOnline = false; // Needs to be pinged before this can be set. | 114 | retval.regionOnline = false; // Needs to be pinged before this can be set. |
115 | retval.serverIP = (string)reader["serverIP"]; | 115 | retval.serverIP = (string)reader["serverIP"]; |
116 | retval.serverPort = (uint)reader["serverPort"]; | 116 | retval.serverPort = (uint)reader["serverPort"]; |
117 | retval.serverURI = (string)reader["serverURI"]; | 117 | retval.serverURI = (string)reader["serverURI"]; |
118 | 118 | ||
119 | // Location | 119 | // Location |
120 | retval.regionLocX = (uint)((int)reader["locX"]); | 120 | retval.regionLocX = (uint)((int)reader["locX"]); |
121 | retval.regionLocY = (uint)((int)reader["locY"]); | 121 | retval.regionLocY = (uint)((int)reader["locY"]); |
122 | retval.regionLocZ = (uint)((int)reader["locZ"]); | 122 | retval.regionLocZ = (uint)((int)reader["locZ"]); |
123 | 123 | ||
124 | // Neighbours - 0 = No Override | 124 | // Neighbours - 0 = No Override |
125 | retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; | 125 | retval.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; |
126 | retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; | 126 | retval.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; |
127 | retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; | 127 | retval.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; |
128 | retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; | 128 | retval.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; |
129 | 129 | ||
130 | // Assets | 130 | // Assets |
131 | retval.regionAssetURI = (string)reader["regionAssetURI"]; | 131 | retval.regionAssetURI = (string)reader["regionAssetURI"]; |
132 | retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | 132 | retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; |
133 | retval.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | 133 | retval.regionAssetSendKey = (string)reader["regionAssetSendKey"]; |
134 | 134 | ||
135 | // Userserver | 135 | // Userserver |
136 | retval.regionUserURI = (string)reader["regionUserURI"]; | 136 | retval.regionUserURI = (string)reader["regionUserURI"]; |
137 | retval.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | 137 | retval.regionUserRecvKey = (string)reader["regionUserRecvKey"]; |
138 | retval.regionUserSendKey = (string)reader["regionUserSendKey"]; | 138 | retval.regionUserSendKey = (string)reader["regionUserSendKey"]; |
139 | } | 139 | } |
140 | else | 140 | else |
141 | { | 141 | { |
142 | throw new Exception("No rows to return"); | 142 | throw new Exception("No rows to return"); |
143 | } | 143 | } |
144 | return retval; | 144 | return retval; |
145 | } | 145 | } |
146 | 146 | ||
147 | /// <summary> | 147 | /// <summary> |
148 | /// Inserts a new region into the database | 148 | /// Inserts a new region into the database |
149 | /// </summary> | 149 | /// </summary> |
150 | /// <param name="profile">The region to insert</param> | 150 | /// <param name="profile">The region to insert</param> |
151 | /// <returns>Success?</returns> | 151 | /// <returns>Success?</returns> |
152 | public bool insertRow(SimProfileData profile) | 152 | public bool insertRow(SimProfileData profile) |
153 | { | 153 | { |
154 | string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | 154 | string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; |
155 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | 155 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; |
156 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; | 156 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; |
157 | 157 | ||
158 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; | 158 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; |
159 | sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; | 159 | sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; |
160 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; | 160 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; |
161 | 161 | ||
162 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | 162 | Dictionary<string, string> parameters = new Dictionary<string, string>(); |
163 | 163 | ||
164 | parameters["regionHandle"] = profile.regionHandle.ToString(); | 164 | parameters["regionHandle"] = profile.regionHandle.ToString(); |
165 | parameters["regionName"] = profile.regionName; | 165 | parameters["regionName"] = profile.regionName; |
166 | parameters["uuid"] = profile.UUID.ToString(); | 166 | parameters["uuid"] = profile.UUID.ToString(); |
167 | parameters["regionRecvKey"] = profile.regionRecvKey; | 167 | parameters["regionRecvKey"] = profile.regionRecvKey; |
168 | parameters["regionSendKey"] = profile.regionSendKey; | 168 | parameters["regionSendKey"] = profile.regionSendKey; |
169 | parameters["regionDataURI"] = profile.regionDataURI; | 169 | parameters["regionDataURI"] = profile.regionDataURI; |
170 | parameters["serverIP"] = profile.serverIP; | 170 | parameters["serverIP"] = profile.serverIP; |
171 | parameters["serverPort"] = profile.serverPort.ToString(); | 171 | parameters["serverPort"] = profile.serverPort.ToString(); |
172 | parameters["serverURI"] = profile.serverURI; | 172 | parameters["serverURI"] = profile.serverURI; |
173 | parameters["locX"] = profile.regionLocX.ToString(); | 173 | parameters["locX"] = profile.regionLocX.ToString(); |
174 | parameters["locY"] = profile.regionLocY.ToString(); | 174 | parameters["locY"] = profile.regionLocY.ToString(); |
175 | parameters["locZ"] = profile.regionLocZ.ToString(); | 175 | parameters["locZ"] = profile.regionLocZ.ToString(); |
176 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | 176 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); |
177 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | 177 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); |
178 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | 178 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); |
179 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | 179 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); |
180 | parameters["regionAssetURI"] = profile.regionAssetURI; | 180 | parameters["regionAssetURI"] = profile.regionAssetURI; |
181 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; | 181 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; |
182 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; | 182 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; |
183 | parameters["regionUserURI"] = profile.regionUserURI; | 183 | parameters["regionUserURI"] = profile.regionUserURI; |
184 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; | 184 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; |
185 | parameters["regionUserSendKey"] = profile.regionUserSendKey; | 185 | parameters["regionUserSendKey"] = profile.regionUserSendKey; |
186 | 186 | ||
187 | bool returnval = false; | 187 | bool returnval = false; |
188 | 188 | ||
189 | try | 189 | try |
190 | { | 190 | { |
191 | IDbCommand result = Query(sql, parameters); | 191 | IDbCommand result = Query(sql, parameters); |
192 | 192 | ||
193 | if (result.ExecuteNonQuery() == 1) | 193 | if (result.ExecuteNonQuery() == 1) |
194 | returnval = true; | 194 | returnval = true; |
195 | 195 | ||
196 | result.Dispose(); | 196 | result.Dispose(); |
197 | } | 197 | } |
198 | catch (Exception) | 198 | catch (Exception) |
199 | { | 199 | { |
200 | return false; | 200 | return false; |
201 | } | 201 | } |
202 | 202 | ||
203 | return returnval; | 203 | return returnval; |
204 | } | 204 | } |
205 | } | 205 | } |
206 | } | 206 | } |