diff options
author | Tleiades Hax | 2007-10-13 07:26:21 +0000 |
---|---|---|
committer | Tleiades Hax | 2007-10-13 07:26:21 +0000 |
commit | 1232eb1c587ffdc06c26a1c5b1b4fa5f22848754 (patch) | |
tree | 468fb8483a2cd03e472a6988ef60f1c8ff01c07e /OpenSim/Framework | |
parent | Change 3 UserServer login messages from writeline to MainLog to help diagnose... (diff) | |
download | opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.zip opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.gz opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.bz2 opensim-SC_OLD-1232eb1c587ffdc06c26a1c5b1b4fa5f22848754.tar.xz |
Asset server implementation. Again one of these "plumbing" releases, where no real functionality has been introduced, but ground work has been made, enabling the asset server, and preparing the sim server to query the asset server.
Introduced an "IPlugin" interface, which plugins can inherit from.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/SQLAssetServer.cs | 68 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | 112 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs | 133 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLManager.cs | 92 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql | 11 | ||||
-rw-r--r-- | OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs | 23 | ||||
-rw-r--r-- | OpenSim/Framework/General/Configuration/AssetConfig.cs | 54 | ||||
-rw-r--r-- | OpenSim/Framework/General/Interfaces/IAssetProvider.cs | 3 | ||||
-rw-r--r-- | OpenSim/Framework/General/Interfaces/IPlugin.cs | 29 |
9 files changed, 392 insertions, 133 deletions
diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs index a64d195..2a38307 100644 --- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs | |||
@@ -44,16 +44,16 @@ namespace OpenSim.Framework.Communications.Caches | |||
44 | private IAssetReceiver _receiver; | 44 | private IAssetReceiver _receiver; |
45 | private BlockingQueue<ARequest> _assetRequests; | 45 | private BlockingQueue<ARequest> _assetRequests; |
46 | private Thread _localAssetServerThread; | 46 | private Thread _localAssetServerThread; |
47 | protected IAssetProvider m_plugin; | 47 | protected IAssetProvider m_assetProviderPlugin; |
48 | private object syncLock = new object(); | 48 | private object syncLock = new object(); |
49 | 49 | ||
50 | 50 | ||
51 | public SQLAssetServer() | 51 | public SQLAssetServer(string pluginName) |
52 | { | 52 | { |
53 | System.Console.WriteLine("Starting sqlite asset storage system"); | 53 | _assetRequests = new BlockingQueue<ARequest>(); |
54 | _assetRequests = new BlockingQueue<ARequest>(); | 54 | AddPlugin(pluginName); |
55 | AddPlugin("OpenSim.Framework.Data.SQLite.dll"); | 55 | |
56 | this.SetUpAssetDatabase(); | 56 | SetUpAssetDatabase(); |
57 | 57 | ||
58 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); | 58 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); |
59 | this._localAssetServerThread.IsBackground = true; | 59 | this._localAssetServerThread.IsBackground = true; |
@@ -63,7 +63,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
63 | 63 | ||
64 | public void AddPlugin(string FileName) | 64 | public void AddPlugin(string FileName) |
65 | { | 65 | { |
66 | //MainLog.Instance.Verbose("SQLAssetServer", "AssetStorage: Attempting to load " + FileName); | 66 | MainLog.Instance.Verbose("SQLAssetServer", "AssetStorage: Attempting to load " + FileName); |
67 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | 67 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); |
68 | 68 | ||
69 | foreach (Type pluginType in pluginAssembly.GetTypes()) | 69 | foreach (Type pluginType in pluginAssembly.GetTypes()) |
@@ -75,10 +75,10 @@ namespace OpenSim.Framework.Communications.Caches | |||
75 | if (typeInterface != null) | 75 | if (typeInterface != null) |
76 | { | 76 | { |
77 | IAssetProvider plug = (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | 77 | IAssetProvider plug = (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); |
78 | m_plugin = plug; | 78 | m_assetProviderPlugin = plug; |
79 | m_plugin.Initialise("AssetStorage.db", ""); | 79 | m_assetProviderPlugin.Initialise(); |
80 | 80 | ||
81 | //MainLog.Instance.Verbose("AssetStorage: Added IAssetProvider Interface"); | 81 | MainLog.Instance.Verbose("AssetStorage: Added " + m_assetProviderPlugin.Name + " " + m_assetProviderPlugin.Version); |
82 | } | 82 | } |
83 | 83 | ||
84 | typeInterface = null; | 84 | typeInterface = null; |
@@ -105,8 +105,8 @@ namespace OpenSim.Framework.Communications.Caches | |||
105 | { | 105 | { |
106 | lock (syncLock) | 106 | lock (syncLock) |
107 | { | 107 | { |
108 | m_plugin.UpdateAsset(asset); | 108 | m_assetProviderPlugin.UpdateAsset(asset); |
109 | m_plugin.CommitAssets(); | 109 | m_assetProviderPlugin.CommitAssets(); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
@@ -114,8 +114,8 @@ namespace OpenSim.Framework.Communications.Caches | |||
114 | { | 114 | { |
115 | lock (syncLock) | 115 | lock (syncLock) |
116 | { | 116 | { |
117 | m_plugin.CreateAsset(asset); | 117 | m_assetProviderPlugin.CreateAsset(asset); |
118 | m_plugin.CommitAssets(); | 118 | m_assetProviderPlugin.CommitAssets(); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
@@ -125,7 +125,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
125 | } | 125 | } |
126 | public void Close() | 126 | public void Close() |
127 | { | 127 | { |
128 | m_plugin.CommitAssets(); | 128 | m_assetProviderPlugin.CommitAssets(); |
129 | } | 129 | } |
130 | 130 | ||
131 | private void RunRequests() | 131 | private void RunRequests() |
@@ -140,7 +140,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
140 | AssetBase asset = null; | 140 | AssetBase asset = null; |
141 | lock (syncLock) | 141 | lock (syncLock) |
142 | { | 142 | { |
143 | asset = m_plugin.FetchAsset(req.AssetID); | 143 | asset = m_assetProviderPlugin.FetchAsset(req.AssetID); |
144 | } | 144 | } |
145 | if (asset != null) | 145 | if (asset != null) |
146 | { | 146 | { |
@@ -163,67 +163,67 @@ namespace OpenSim.Framework.Communications.Caches | |||
163 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); | 163 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); |
164 | Image.Name = "Bricks"; | 164 | Image.Name = "Bricks"; |
165 | this.LoadAsset(Image, true, "bricks.jp2"); | 165 | this.LoadAsset(Image, true, "bricks.jp2"); |
166 | m_plugin.CreateAsset(Image); | 166 | m_assetProviderPlugin.CreateAsset(Image); |
167 | 167 | ||
168 | Image = new AssetBase(); | 168 | Image = new AssetBase(); |
169 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); | 169 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); |
170 | Image.Name = "Plywood"; | 170 | Image.Name = "Plywood"; |
171 | this.LoadAsset(Image, true, "plywood.jp2"); | 171 | this.LoadAsset(Image, true, "plywood.jp2"); |
172 | m_plugin.CreateAsset(Image); | 172 | m_assetProviderPlugin.CreateAsset(Image); |
173 | 173 | ||
174 | Image = new AssetBase(); | 174 | Image = new AssetBase(); |
175 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); | 175 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); |
176 | Image.Name = "Rocks"; | 176 | Image.Name = "Rocks"; |
177 | this.LoadAsset(Image, true, "rocks.jp2"); | 177 | this.LoadAsset(Image, true, "rocks.jp2"); |
178 | m_plugin.CreateAsset(Image); | 178 | m_assetProviderPlugin.CreateAsset(Image); |
179 | 179 | ||
180 | Image = new AssetBase(); | 180 | Image = new AssetBase(); |
181 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); | 181 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); |
182 | Image.Name = "Granite"; | 182 | Image.Name = "Granite"; |
183 | this.LoadAsset(Image, true, "granite.jp2"); | 183 | this.LoadAsset(Image, true, "granite.jp2"); |
184 | m_plugin.CreateAsset(Image); | 184 | m_assetProviderPlugin.CreateAsset(Image); |
185 | 185 | ||
186 | Image = new AssetBase(); | 186 | Image = new AssetBase(); |
187 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); | 187 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); |
188 | Image.Name = "Hardwood"; | 188 | Image.Name = "Hardwood"; |
189 | this.LoadAsset(Image, true, "hardwood.jp2"); | 189 | this.LoadAsset(Image, true, "hardwood.jp2"); |
190 | m_plugin.CreateAsset(Image); | 190 | m_assetProviderPlugin.CreateAsset(Image); |
191 | 191 | ||
192 | Image = new AssetBase(); | 192 | Image = new AssetBase(); |
193 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); | 193 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); |
194 | Image.Name = "Prim Base Texture"; | 194 | Image.Name = "Prim Base Texture"; |
195 | this.LoadAsset(Image, true, "plywood.jp2"); | 195 | this.LoadAsset(Image, true, "plywood.jp2"); |
196 | m_plugin.CreateAsset(Image); | 196 | m_assetProviderPlugin.CreateAsset(Image); |
197 | 197 | ||
198 | Image = new AssetBase(); | 198 | Image = new AssetBase(); |
199 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); | 199 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); |
200 | Image.Name = "Map Base Texture"; | 200 | Image.Name = "Map Base Texture"; |
201 | this.LoadAsset(Image, true, "map_base.jp2"); | 201 | this.LoadAsset(Image, true, "map_base.jp2"); |
202 | m_plugin.CreateAsset(Image); | 202 | m_assetProviderPlugin.CreateAsset(Image); |
203 | 203 | ||
204 | Image = new AssetBase(); | 204 | Image = new AssetBase(); |
205 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); | 205 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); |
206 | Image.Name = "Map Texture"; | 206 | Image.Name = "Map Texture"; |
207 | this.LoadAsset(Image, true, "map1.jp2"); | 207 | this.LoadAsset(Image, true, "map1.jp2"); |
208 | m_plugin.CreateAsset(Image); | 208 | m_assetProviderPlugin.CreateAsset(Image); |
209 | 209 | ||
210 | Image = new AssetBase(); | 210 | Image = new AssetBase(); |
211 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); | 211 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); |
212 | Image.Name = "Female Body Texture"; | 212 | Image.Name = "Female Body Texture"; |
213 | this.LoadAsset(Image, true, "femalebody.jp2"); | 213 | this.LoadAsset(Image, true, "femalebody.jp2"); |
214 | m_plugin.CreateAsset(Image); | 214 | m_assetProviderPlugin.CreateAsset(Image); |
215 | 215 | ||
216 | Image = new AssetBase(); | 216 | Image = new AssetBase(); |
217 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); | 217 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); |
218 | Image.Name = "Female Bottom Texture"; | 218 | Image.Name = "Female Bottom Texture"; |
219 | this.LoadAsset(Image, true, "femalebottom.jp2"); | 219 | this.LoadAsset(Image, true, "femalebottom.jp2"); |
220 | m_plugin.CreateAsset(Image); | 220 | m_assetProviderPlugin.CreateAsset(Image); |
221 | 221 | ||
222 | Image = new AssetBase(); | 222 | Image = new AssetBase(); |
223 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); | 223 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); |
224 | Image.Name = "Female Face Texture"; | 224 | Image.Name = "Female Face Texture"; |
225 | this.LoadAsset(Image, true, "femaleface.jp2"); | 225 | this.LoadAsset(Image, true, "femaleface.jp2"); |
226 | m_plugin.CreateAsset(Image); | 226 | m_assetProviderPlugin.CreateAsset(Image); |
227 | 227 | ||
228 | Image = new AssetBase(); | 228 | Image = new AssetBase(); |
229 | Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | 229 | Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); |
@@ -231,7 +231,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
231 | Image.Type = 13; | 231 | Image.Type = 13; |
232 | Image.InvType = 13; | 232 | Image.InvType = 13; |
233 | this.LoadAsset(Image, false, "base_skin.dat"); | 233 | this.LoadAsset(Image, false, "base_skin.dat"); |
234 | m_plugin.CreateAsset(Image); | 234 | m_assetProviderPlugin.CreateAsset(Image); |
235 | 235 | ||
236 | Image = new AssetBase(); | 236 | Image = new AssetBase(); |
237 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | 237 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); |
@@ -239,7 +239,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
239 | Image.Type = 13; | 239 | Image.Type = 13; |
240 | Image.InvType = 13; | 240 | Image.InvType = 13; |
241 | this.LoadAsset(Image, false, "base_shape.dat"); | 241 | this.LoadAsset(Image, false, "base_shape.dat"); |
242 | m_plugin.CreateAsset(Image); | 242 | m_assetProviderPlugin.CreateAsset(Image); |
243 | 243 | ||
244 | Image = new AssetBase(); | 244 | Image = new AssetBase(); |
245 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | 245 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); |
@@ -247,7 +247,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
247 | Image.Type = 5; | 247 | Image.Type = 5; |
248 | Image.InvType = 18; | 248 | Image.InvType = 18; |
249 | this.LoadAsset(Image, false, "newshirt.dat"); | 249 | this.LoadAsset(Image, false, "newshirt.dat"); |
250 | m_plugin.CreateAsset(Image); | 250 | m_assetProviderPlugin.CreateAsset(Image); |
251 | 251 | ||
252 | Image = new AssetBase(); | 252 | Image = new AssetBase(); |
253 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | 253 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); |
@@ -255,7 +255,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
255 | Image.Type = 5; | 255 | Image.Type = 5; |
256 | Image.InvType = 18; | 256 | Image.InvType = 18; |
257 | this.LoadAsset(Image, false, "newpants.dat"); | 257 | this.LoadAsset(Image, false, "newpants.dat"); |
258 | m_plugin.CreateAsset(Image); | 258 | m_assetProviderPlugin.CreateAsset(Image); |
259 | 259 | ||
260 | string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); | 260 | string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); |
261 | if (File.Exists(filePath)) | 261 | if (File.Exists(filePath)) |
@@ -264,7 +264,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
264 | ReadAssetDetails(source); | 264 | ReadAssetDetails(source); |
265 | } | 265 | } |
266 | 266 | ||
267 | m_plugin.CommitAssets(); | 267 | m_assetProviderPlugin.CommitAssets(); |
268 | } | 268 | } |
269 | 269 | ||
270 | protected void ReadAssetDetails(IConfigSource source) | 270 | protected void ReadAssetDetails(IConfigSource source) |
@@ -282,7 +282,7 @@ namespace OpenSim.Framework.Communications.Caches | |||
282 | { | 282 | { |
283 | MainLog.Instance.Verbose("Creating new asset: " + newAsset.Name); | 283 | MainLog.Instance.Verbose("Creating new asset: " + newAsset.Name); |
284 | this.LoadAsset(newAsset, false, fileName); | 284 | this.LoadAsset(newAsset, false, fileName); |
285 | m_plugin.CreateAsset(newAsset); | 285 | m_assetProviderPlugin.CreateAsset(newAsset); |
286 | } | 286 | } |
287 | } | 287 | } |
288 | } | 288 | } |
diff --git a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs new file mode 100644 index 0000000..70e04b6 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | |||
@@ -0,0 +1,112 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using MySql.Data.MySqlClient; | ||
4 | |||
5 | using libsecondlife; | ||
6 | using OpenSim.Framework.Console; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Framework.Data.MySQL | ||
11 | { | ||
12 | class MySQLAssetData : IAssetProvider | ||
13 | { | ||
14 | MySQLManager _dbConnection; | ||
15 | #region IAssetProvider Members | ||
16 | |||
17 | private void UpgradeAssetsTable(string oldVersion) | ||
18 | { | ||
19 | // null as the version, indicates that the table didn't exist | ||
20 | if (oldVersion == null) | ||
21 | { | ||
22 | MainLog.Instance.Notice("ASSETS", "Creating new database tables"); | ||
23 | _dbConnection.ExecuteResourceSql("CreateAssetsTable.sql"); | ||
24 | return; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Ensure that the assets related tables exists and are at the latest version | ||
30 | /// </summary> | ||
31 | private void TestTables() | ||
32 | { | ||
33 | |||
34 | Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||
35 | |||
36 | tableList["assets"] = null; | ||
37 | _dbConnection.GetTableVersion(tableList); | ||
38 | |||
39 | UpgradeAssetsTable(tableList["assets"]); | ||
40 | |||
41 | } | ||
42 | |||
43 | public AssetBase FetchAsset(LLUUID uuid) | ||
44 | { | ||
45 | throw new Exception("The method or operation is not implemented."); | ||
46 | } | ||
47 | |||
48 | public void CreateAsset(AssetBase asset) | ||
49 | { | ||
50 | MySqlCommand cmd = new MySqlCommand("REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" + | ||
51 | "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)", _dbConnection.Connection); | ||
52 | MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); | ||
53 | p.Value = asset.FullID.GetBytes(); | ||
54 | cmd.Parameters.AddWithValue("?name", asset.Name); | ||
55 | cmd.Parameters.AddWithValue("?description", asset.Description); | ||
56 | cmd.Parameters.AddWithValue("?assetType", asset.Type); | ||
57 | cmd.Parameters.AddWithValue("?invType", asset.InvType); | ||
58 | cmd.Parameters.AddWithValue("?local", asset.Local); | ||
59 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | ||
60 | cmd.Parameters.AddWithValue("?data", asset.Data); | ||
61 | cmd.ExecuteNonQuery(); | ||
62 | } | ||
63 | |||
64 | public void UpdateAsset(AssetBase asset) | ||
65 | { | ||
66 | CreateAsset(asset); | ||
67 | } | ||
68 | |||
69 | public bool ExistsAsset(LLUUID uuid) | ||
70 | { | ||
71 | throw new Exception("The method or operation is not implemented."); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// All writes are immediately commited to the database, so this is a no-op | ||
76 | /// </summary> | ||
77 | public void CommitAssets() | ||
78 | { | ||
79 | } | ||
80 | |||
81 | #endregion | ||
82 | |||
83 | #region IPlugin Members | ||
84 | |||
85 | public void Initialise() | ||
86 | { | ||
87 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
88 | string hostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
89 | string database = GridDataMySqlFile.ParseFileReadValue("database"); | ||
90 | string username = GridDataMySqlFile.ParseFileReadValue("username"); | ||
91 | string password = GridDataMySqlFile.ParseFileReadValue("password"); | ||
92 | string pooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
93 | string port = GridDataMySqlFile.ParseFileReadValue("port"); | ||
94 | |||
95 | _dbConnection = new MySQLManager(hostname, database, username, password, pooling, port); | ||
96 | |||
97 | TestTables(); | ||
98 | } | ||
99 | |||
100 | public string Version | ||
101 | { | ||
102 | get { return _dbConnection.getVersion(); } | ||
103 | } | ||
104 | |||
105 | public string Name | ||
106 | { | ||
107 | get { return "MySQL Asset storage engine"; } | ||
108 | } | ||
109 | |||
110 | #endregion | ||
111 | } | ||
112 | } | ||
diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs index 804fd5f..6423f28 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs | |||
@@ -28,7 +28,6 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Reflection; | ||
32 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
33 | using libsecondlife; | 32 | using libsecondlife; |
34 | using OpenSim.Framework.Types; | 33 | using OpenSim.Framework.Types; |
@@ -65,41 +64,13 @@ namespace OpenSim.Framework.Data.MySQL | |||
65 | } | 64 | } |
66 | 65 | ||
67 | #region Test and initialization code | 66 | #region Test and initialization code |
68 | /// <summary> | ||
69 | /// Extract a named string resource from the embedded resources | ||
70 | /// </summary> | ||
71 | /// <param name="name">name of embedded resource</param> | ||
72 | /// <returns>string contained within the embedded resource</returns> | ||
73 | private string getResourceString(string name) | ||
74 | { | ||
75 | Assembly assem = this.GetType().Assembly; | ||
76 | string[] names = assem.GetManifestResourceNames(); | ||
77 | |||
78 | foreach(string s in names) | ||
79 | if(s.EndsWith(name)) | ||
80 | using (Stream resource = assem.GetManifestResourceStream(s)) | ||
81 | { | ||
82 | using (StreamReader resourceReader = new StreamReader(resource)) | ||
83 | { | ||
84 | string resourceString = resourceReader.ReadToEnd(); | ||
85 | return resourceString; | ||
86 | } | ||
87 | } | ||
88 | throw new Exception(string.Format("Resource '{0}' was not found", name)); | ||
89 | } | ||
90 | 67 | ||
91 | private void ExecuteResourceSql(MySqlConnection conn, string name) | 68 | private void UpgradeFoldersTable(string oldVersion) |
92 | { | ||
93 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), conn); | ||
94 | cmd.ExecuteNonQuery(); | ||
95 | } | ||
96 | |||
97 | private void UpgradeFoldersTable(MySqlConnection conn, string oldVersion) | ||
98 | { | 69 | { |
99 | // null as the version, indicates that the table didn't exist | 70 | // null as the version, indicates that the table didn't exist |
100 | if (oldVersion == null) | 71 | if (oldVersion == null) |
101 | { | 72 | { |
102 | ExecuteResourceSql(conn, "CreateFoldersTable.sql"); | 73 | database.ExecuteResourceSql("CreateFoldersTable.sql"); |
103 | return; | 74 | return; |
104 | } | 75 | } |
105 | 76 | ||
@@ -107,15 +78,15 @@ namespace OpenSim.Framework.Data.MySQL | |||
107 | if (oldVersion == "Rev. 2") | 78 | if (oldVersion == "Rev. 2") |
108 | return; | 79 | return; |
109 | 80 | ||
110 | ExecuteResourceSql(conn, "UpgradeFoldersTableToVersion2.sql"); | 81 | database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql"); |
111 | } | 82 | } |
112 | 83 | ||
113 | private void UpgradeItemsTable(MySqlConnection conn, string oldVersion) | 84 | private void UpgradeItemsTable(string oldVersion) |
114 | { | 85 | { |
115 | // null as the version, indicates that the table didn't exist | 86 | // null as the version, indicates that the table didn't exist |
116 | if (oldVersion == null) | 87 | if (oldVersion == null) |
117 | { | 88 | { |
118 | ExecuteResourceSql(conn, "CreateItemsTable.sql"); | 89 | database.ExecuteResourceSql("CreateItemsTable.sql"); |
119 | return; | 90 | return; |
120 | } | 91 | } |
121 | 92 | ||
@@ -123,7 +94,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
123 | if (oldVersion == "Rev. 2") | 94 | if (oldVersion == "Rev. 2") |
124 | return; | 95 | return; |
125 | 96 | ||
126 | ExecuteResourceSql(conn, "UpgradeItemsTableToVersion2.sql"); | 97 | database.ExecuteResourceSql("UpgradeItemsTableToVersion2.sql"); |
127 | } | 98 | } |
128 | 99 | ||
129 | private void TestTables(MySqlConnection conn) | 100 | private void TestTables(MySqlConnection conn) |
@@ -134,25 +105,10 @@ namespace OpenSim.Framework.Data.MySQL | |||
134 | tableList["inventoryfolders"] = null; | 105 | tableList["inventoryfolders"] = null; |
135 | tableList["inventoryitems"] = null; | 106 | tableList["inventoryitems"] = null; |
136 | 107 | ||
137 | MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='opensim'", conn); | 108 | database.GetTableVersion(tableList); |
138 | MySqlDataReader tables = tablesCmd.ExecuteReader(); | ||
139 | while (tables.Read()) | ||
140 | { | ||
141 | try | ||
142 | { | ||
143 | string tableName = (string)tables["TABLE_NAME"]; | ||
144 | string comment = (string)tables["TABLE_COMMENT"]; | ||
145 | tableList[tableName] = comment; | ||
146 | } | ||
147 | catch (Exception e) | ||
148 | { | ||
149 | MainLog.Instance.Error(e.ToString()); | ||
150 | } | ||
151 | } | ||
152 | tables.Close(); | ||
153 | 109 | ||
154 | UpgradeFoldersTable(conn, tableList["inventoryfolders"]); | 110 | UpgradeFoldersTable(tableList["inventoryfolders"]); |
155 | UpgradeItemsTable(conn, tableList["inventoryitems"]); | 111 | UpgradeItemsTable(tableList["inventoryitems"]); |
156 | } | 112 | } |
157 | #endregion | 113 | #endregion |
158 | 114 | ||
@@ -179,12 +135,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
179 | /// <returns>A string containing the DB provider</returns> | 135 | /// <returns>A string containing the DB provider</returns> |
180 | public string getVersion() | 136 | public string getVersion() |
181 | { | 137 | { |
182 | System.Reflection.Module module = this.GetType().Module; | 138 | return database.getVersion(); |
183 | string dllName = module.Assembly.ManifestModule.Name; | ||
184 | Version dllVersion = module.Assembly.GetName().Version; | ||
185 | |||
186 | |||
187 | return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); | ||
188 | } | 139 | } |
189 | 140 | ||
190 | /// <summary> | 141 | /// <summary> |
@@ -201,7 +152,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
201 | List<InventoryItemBase> items = new List<InventoryItemBase>(); | 152 | List<InventoryItemBase> items = new List<InventoryItemBase>(); |
202 | 153 | ||
203 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); | 154 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); |
204 | result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); | 155 | result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); |
205 | MySqlDataReader reader = result.ExecuteReader(); | 156 | MySqlDataReader reader = result.ExecuteReader(); |
206 | 157 | ||
207 | while(reader.Read()) | 158 | while(reader.Read()) |
@@ -233,8 +184,8 @@ namespace OpenSim.Framework.Data.MySQL | |||
233 | lock (database) | 184 | lock (database) |
234 | { | 185 | { |
235 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); | 186 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); |
236 | result.Parameters.Add("?uuid", user.ToStringHyphenated()); | 187 | result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated()); |
237 | result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); | 188 | result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated()); |
238 | MySqlDataReader reader = result.ExecuteReader(); | 189 | MySqlDataReader reader = result.ExecuteReader(); |
239 | 190 | ||
240 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | 191 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); |
@@ -267,13 +218,9 @@ namespace OpenSim.Framework.Data.MySQL | |||
267 | { | 218 | { |
268 | lock (database) | 219 | lock (database) |
269 | { | 220 | { |
270 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
271 | param["?uuid"] = user.ToStringHyphenated(); | ||
272 | param["?zero"] = LLUUID.Zero.ToStringHyphenated(); | ||
273 | |||
274 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); | 221 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", database.Connection); |
275 | result.Parameters.Add("?uuid", user.ToStringHyphenated()); | 222 | result.Parameters.AddWithValue("?uuid", user.ToStringHyphenated()); |
276 | result.Parameters.Add("?zero", LLUUID.Zero.ToStringHyphenated()); | 223 | result.Parameters.AddWithValue("?zero", LLUUID.Zero.ToStringHyphenated()); |
277 | 224 | ||
278 | MySqlDataReader reader = result.ExecuteReader(); | 225 | MySqlDataReader reader = result.ExecuteReader(); |
279 | 226 | ||
@@ -308,7 +255,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
308 | lock (database) | 255 | lock (database) |
309 | { | 256 | { |
310 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection); | 257 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", database.Connection); |
311 | result.Parameters.Add("?uuid", parentID.ToStringHyphenated()); | 258 | result.Parameters.AddWithValue("?uuid", parentID.ToStringHyphenated()); |
312 | MySqlDataReader reader = result.ExecuteReader(); | 259 | MySqlDataReader reader = result.ExecuteReader(); |
313 | 260 | ||
314 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | 261 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); |
@@ -378,7 +325,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
378 | Dictionary<string, string> param = new Dictionary<string, string>(); | 325 | Dictionary<string, string> param = new Dictionary<string, string>(); |
379 | 326 | ||
380 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); | 327 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", database.Connection); |
381 | result.Parameters.Add("?uuid", itemID.ToStringHyphenated()); | 328 | result.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated()); |
382 | MySqlDataReader reader = result.ExecuteReader(); | 329 | MySqlDataReader reader = result.ExecuteReader(); |
383 | 330 | ||
384 | InventoryItemBase item = null; | 331 | InventoryItemBase item = null; |
@@ -438,7 +385,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
438 | lock (database) | 385 | lock (database) |
439 | { | 386 | { |
440 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); | 387 | MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", database.Connection); |
441 | result.Parameters.Add("?uuid", folderID.ToStringHyphenated()); | 388 | result.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); |
442 | MySqlDataReader reader = result.ExecuteReader(); | 389 | MySqlDataReader reader = result.ExecuteReader(); |
443 | 390 | ||
444 | reader.Read(); | 391 | reader.Read(); |
@@ -469,19 +416,19 @@ namespace OpenSim.Framework.Data.MySQL | |||
469 | try | 416 | try |
470 | { | 417 | { |
471 | MySqlCommand result = new MySqlCommand(sql, database.Connection); | 418 | MySqlCommand result = new MySqlCommand(sql, database.Connection); |
472 | result.Parameters.Add("?inventoryID", item.inventoryID.ToStringHyphenated()); | 419 | result.Parameters.AddWithValue("?inventoryID", item.inventoryID.ToStringHyphenated()); |
473 | result.Parameters.Add("?assetID", item.assetID.ToStringHyphenated()); | 420 | result.Parameters.AddWithValue("?assetID", item.assetID.ToStringHyphenated()); |
474 | result.Parameters.Add("?assetType", item.assetType.ToString()); | 421 | result.Parameters.AddWithValue("?assetType", item.assetType.ToString()); |
475 | result.Parameters.Add("?parentFolderID", item.parentFolderID.ToStringHyphenated()); | 422 | result.Parameters.AddWithValue("?parentFolderID", item.parentFolderID.ToStringHyphenated()); |
476 | result.Parameters.Add("?avatarID", item.avatarID.ToStringHyphenated()); | 423 | result.Parameters.AddWithValue("?avatarID", item.avatarID.ToStringHyphenated()); |
477 | result.Parameters.Add("?inventoryName", item.inventoryName); | 424 | result.Parameters.AddWithValue("?inventoryName", item.inventoryName); |
478 | result.Parameters.Add("?inventoryDescription", item.inventoryDescription); | 425 | result.Parameters.AddWithValue("?inventoryDescription", item.inventoryDescription); |
479 | result.Parameters.Add("?inventoryNextPermissions", item.inventoryNextPermissions.ToString()); | 426 | result.Parameters.AddWithValue("?inventoryNextPermissions", item.inventoryNextPermissions.ToString()); |
480 | result.Parameters.Add("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString()); | 427 | result.Parameters.AddWithValue("?inventoryCurrentPermissions", item.inventoryCurrentPermissions.ToString()); |
481 | result.Parameters.Add("?invType", item.invType); | 428 | result.Parameters.AddWithValue("?invType", item.invType); |
482 | result.Parameters.Add("?creatorID", item.creatorsID.ToStringHyphenated()); | 429 | result.Parameters.AddWithValue("?creatorID", item.creatorsID.ToStringHyphenated()); |
483 | result.Parameters.Add("?inventoryBasePermissions", item.inventoryBasePermissions); | 430 | result.Parameters.AddWithValue("?inventoryBasePermissions", item.inventoryBasePermissions); |
484 | result.Parameters.Add("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); | 431 | result.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); |
485 | result.ExecuteNonQuery(); | 432 | result.ExecuteNonQuery(); |
486 | result.Dispose(); | 433 | result.Dispose(); |
487 | } | 434 | } |
@@ -509,7 +456,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
509 | try | 456 | try |
510 | { | 457 | { |
511 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection); | 458 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE inventoryID=?uuid", database.Connection); |
512 | cmd.Parameters.Add("?uuid", itemID.ToStringHyphenated()); | 459 | cmd.Parameters.AddWithValue("?uuid", itemID.ToStringHyphenated()); |
513 | cmd.ExecuteNonQuery(); | 460 | cmd.ExecuteNonQuery(); |
514 | } | 461 | } |
515 | catch (MySqlException e) | 462 | catch (MySqlException e) |
@@ -529,12 +476,12 @@ namespace OpenSim.Framework.Data.MySQL | |||
529 | sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)"; | 476 | sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)"; |
530 | 477 | ||
531 | MySqlCommand cmd = new MySqlCommand(sql, database.Connection); | 478 | MySqlCommand cmd = new MySqlCommand(sql, database.Connection); |
532 | cmd.Parameters.Add("?folderID", folder.folderID.ToStringHyphenated()); | 479 | cmd.Parameters.AddWithValue("?folderID", folder.folderID.ToStringHyphenated()); |
533 | cmd.Parameters.Add("?agentID", folder.agentID.ToStringHyphenated()); | 480 | cmd.Parameters.AddWithValue("?agentID", folder.agentID.ToStringHyphenated()); |
534 | cmd.Parameters.Add("?parentFolderID", folder.parentID.ToStringHyphenated()); | 481 | cmd.Parameters.AddWithValue("?parentFolderID", folder.parentID.ToStringHyphenated()); |
535 | cmd.Parameters.Add("?folderName", folder.name); | 482 | cmd.Parameters.AddWithValue("?folderName", folder.name); |
536 | cmd.Parameters.Add("?type", (short)folder.type); | 483 | cmd.Parameters.AddWithValue("?type", (short)folder.type); |
537 | cmd.Parameters.Add("?version", folder.version); | 484 | cmd.Parameters.AddWithValue("?version", folder.version); |
538 | 485 | ||
539 | try | 486 | try |
540 | { | 487 | { |
@@ -590,7 +537,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
590 | try | 537 | try |
591 | { | 538 | { |
592 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); | 539 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryfolders WHERE folderID=?uuid", database.Connection); |
593 | cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); | 540 | cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); |
594 | cmd.ExecuteNonQuery(); | 541 | cmd.ExecuteNonQuery(); |
595 | } | 542 | } |
596 | catch (MySqlException e) | 543 | catch (MySqlException e) |
@@ -605,7 +552,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
605 | try | 552 | try |
606 | { | 553 | { |
607 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); | 554 | MySqlCommand cmd = new MySqlCommand("DELETE FROM inventoryitems WHERE parentFolderID=?uuid", database.Connection); |
608 | cmd.Parameters.Add("?uuid", folderID.ToStringHyphenated()); | 555 | cmd.Parameters.AddWithValue("?uuid", folderID.ToStringHyphenated()); |
609 | cmd.ExecuteNonQuery(); | 556 | cmd.ExecuteNonQuery(); |
610 | } | 557 | } |
611 | catch (MySqlException e) | 558 | catch (MySqlException e) |
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs index ea174b2..d3f6976 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs | |||
@@ -26,10 +26,14 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.IO; |
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Reflection; | ||
32 | using System.Collections.Generic; | ||
31 | using libsecondlife; | 33 | using libsecondlife; |
34 | |||
32 | using MySql.Data.MySqlClient; | 35 | using MySql.Data.MySqlClient; |
36 | |||
33 | using OpenSim.Framework.Types; | 37 | using OpenSim.Framework.Types; |
34 | using OpenSim.Framework.Console; | 38 | using OpenSim.Framework.Console; |
35 | 39 | ||
@@ -114,6 +118,88 @@ namespace OpenSim.Framework.Data.MySQL | |||
114 | } | 118 | } |
115 | 119 | ||
116 | /// <summary> | 120 | /// <summary> |
121 | /// Returns the version of this DB provider | ||
122 | /// </summary> | ||
123 | /// <returns>A string containing the DB provider</returns> | ||
124 | public string getVersion() | ||
125 | { | ||
126 | System.Reflection.Module module = this.GetType().Module; | ||
127 | string dllName = module.Assembly.ManifestModule.Name; | ||
128 | Version dllVersion = module.Assembly.GetName().Version; | ||
129 | |||
130 | |||
131 | return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); | ||
132 | } | ||
133 | |||
134 | |||
135 | /// <summary> | ||
136 | /// Extract a named string resource from the embedded resources | ||
137 | /// </summary> | ||
138 | /// <param name="name">name of embedded resource</param> | ||
139 | /// <returns>string contained within the embedded resource</returns> | ||
140 | private string getResourceString(string name) | ||
141 | { | ||
142 | Assembly assem = this.GetType().Assembly; | ||
143 | string[] names = assem.GetManifestResourceNames(); | ||
144 | |||
145 | foreach (string s in names) | ||
146 | if (s.EndsWith(name)) | ||
147 | using (Stream resource = assem.GetManifestResourceStream(s)) | ||
148 | { | ||
149 | using (StreamReader resourceReader = new StreamReader(resource)) | ||
150 | { | ||
151 | string resourceString = resourceReader.ReadToEnd(); | ||
152 | return resourceString; | ||
153 | } | ||
154 | } | ||
155 | throw new Exception(string.Format("Resource '{0}' was not found", name)); | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Execute a SQL statement stored in a resource, as a string | ||
160 | /// </summary> | ||
161 | /// <param name="name"></param> | ||
162 | public void ExecuteResourceSql(string name) | ||
163 | { | ||
164 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon); | ||
165 | cmd.ExecuteNonQuery(); | ||
166 | } | ||
167 | |||
168 | /// <summary> | ||
169 | /// Given a list of tables, return the version of the tables, as seen in the database | ||
170 | /// </summary> | ||
171 | /// <param name="tableList"></param> | ||
172 | public void GetTableVersion(Dictionary<string, string> tableList) | ||
173 | { | ||
174 | lock (dbcon) | ||
175 | { | ||
176 | MySqlCommand tablesCmd = new MySqlCommand("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon); | ||
177 | tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); | ||
178 | using (MySqlDataReader tables = tablesCmd.ExecuteReader()) | ||
179 | { | ||
180 | while (tables.Read()) | ||
181 | { | ||
182 | try | ||
183 | { | ||
184 | string tableName = (string)tables["TABLE_NAME"]; | ||
185 | string comment = (string)tables["TABLE_COMMENT"]; | ||
186 | if(tableList.ContainsKey(tableName)) | ||
187 | tableList[tableName] = comment; | ||
188 | } | ||
189 | catch (Exception e) | ||
190 | { | ||
191 | MainLog.Instance.Error(e.ToString()); | ||
192 | } | ||
193 | } | ||
194 | tables.Close(); | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | |||
200 | // at some time this code should be cleaned up | ||
201 | |||
202 | /// <summary> | ||
117 | /// Runs a query with protection against SQL Injection by using parameterised input. | 203 | /// Runs a query with protection against SQL Injection by using parameterised input. |
118 | /// </summary> | 204 | /// </summary> |
119 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | 205 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> |
@@ -127,7 +213,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
127 | dbcommand.CommandText = sql; | 213 | dbcommand.CommandText = sql; |
128 | foreach (KeyValuePair<string, string> param in parameters) | 214 | foreach (KeyValuePair<string, string> param in parameters) |
129 | { | 215 | { |
130 | dbcommand.Parameters.Add(param.Key, param.Value); | 216 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
131 | } | 217 | } |
132 | 218 | ||
133 | return (IDbCommand)dbcommand; | 219 | return (IDbCommand)dbcommand; |
@@ -161,7 +247,7 @@ namespace OpenSim.Framework.Data.MySQL | |||
161 | dbcommand.CommandText = sql; | 247 | dbcommand.CommandText = sql; |
162 | foreach (KeyValuePair<string, string> param in parameters) | 248 | foreach (KeyValuePair<string, string> param in parameters) |
163 | { | 249 | { |
164 | dbcommand.Parameters.Add(param.Key, param.Value); | 250 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); |
165 | } | 251 | } |
166 | 252 | ||
167 | return (IDbCommand)dbcommand; | 253 | return (IDbCommand)dbcommand; |
diff --git a/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql b/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql new file mode 100644 index 0000000..049a3a2 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql | |||
@@ -0,0 +1,11 @@ | |||
1 | CREATE TABLE `assets` ( | ||
2 | `id` binary(16) NOT NULL, | ||
3 | `name` varchar(64) NOT NULL, | ||
4 | `description` varchar(64) NOT NULL, | ||
5 | `assetType` smallint(5) unsigned NOT NULL, | ||
6 | `invType` smallint(5) unsigned NOT NULL, | ||
7 | `local` tinyint(1) NOT NULL, | ||
8 | `temporary` tinyint(1) NOT NULL, | ||
9 | `data` longblob NOT NULL, | ||
10 | PRIMARY KEY (`id`) | ||
11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev. 1'; \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs index 4616275..922d714 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs | |||
@@ -53,7 +53,7 @@ namespace OpenSim.Framework.Data.SQLite | |||
53 | private const string assetSelect = "select * from assets"; | 53 | private const string assetSelect = "select * from assets"; |
54 | private DataSet ds; | 54 | private DataSet ds; |
55 | private SqliteDataAdapter da; | 55 | private SqliteDataAdapter da; |
56 | 56 | ||
57 | public void Initialise(string dbfile, string dbname) | 57 | public void Initialise(string dbfile, string dbname) |
58 | { | 58 | { |
59 | SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3"); | 59 | SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3"); |
@@ -275,5 +275,26 @@ namespace OpenSim.Framework.Data.SQLite | |||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | 277 | ||
278 | #region IPlugin interface | ||
279 | public string Version { | ||
280 | get | ||
281 | { | ||
282 | System.Reflection.Module module = this.GetType().Module; | ||
283 | string dllName = module.Assembly.ManifestModule.Name; | ||
284 | Version dllVersion = module.Assembly.GetName().Version; | ||
285 | |||
286 | return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | public void Initialise() | ||
291 | { | ||
292 | Initialise("AssetStorage.db", ""); | ||
293 | } | ||
294 | |||
295 | public string Name { | ||
296 | get { return "SQLite Asset storage engine"; } | ||
297 | } | ||
298 | #endregion | ||
278 | } | 299 | } |
279 | } | 300 | } |
diff --git a/OpenSim/Framework/General/Configuration/AssetConfig.cs b/OpenSim/Framework/General/Configuration/AssetConfig.cs new file mode 100644 index 0000000..e5f1c88 --- /dev/null +++ b/OpenSim/Framework/General/Configuration/AssetConfig.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Configuration | ||
6 | { | ||
7 | /// <summary> | ||
8 | /// UserConfig -- For User Server Configuration | ||
9 | /// </summary> | ||
10 | public class AssetConfig | ||
11 | { | ||
12 | public string DefaultStartupMsg = ""; | ||
13 | |||
14 | public string DatabaseProvider = ""; | ||
15 | |||
16 | public uint HttpPort = 8003; | ||
17 | |||
18 | private ConfigurationMember configMember; | ||
19 | |||
20 | public AssetConfig(string description, string filename) | ||
21 | { | ||
22 | configMember = new ConfigurationMember(filename, description, this.loadConfigurationOptions, this.handleIncomingConfiguration); | ||
23 | configMember.performConfigurationRetrieve(); | ||
24 | } | ||
25 | |||
26 | public void loadConfigurationOptions() | ||
27 | { | ||
28 | configMember.addConfigurationOption("default_startup_message", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Default Startup Message", "Welcome to OGS", false); | ||
29 | |||
30 | configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING, "DLL for database provider", "OpenSim.Framework.Data.MySQL.dll", false); | ||
31 | |||
32 | configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Http Listener port", "8003", false); | ||
33 | |||
34 | } | ||
35 | |||
36 | public bool handleIncomingConfiguration(string configuration_key, object configuration_result) | ||
37 | { | ||
38 | switch (configuration_key) | ||
39 | { | ||
40 | case "default_startup_message": | ||
41 | this.DefaultStartupMsg = (string)configuration_result; | ||
42 | break; | ||
43 | case "database_provider": | ||
44 | this.DatabaseProvider = (string)configuration_result; | ||
45 | break; | ||
46 | case "http_port": | ||
47 | HttpPort = (uint)configuration_result; | ||
48 | break; | ||
49 | } | ||
50 | |||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | } | ||
diff --git a/OpenSim/Framework/General/Interfaces/IAssetProvider.cs b/OpenSim/Framework/General/Interfaces/IAssetProvider.cs index daf9d6d..0b39d1f 100644 --- a/OpenSim/Framework/General/Interfaces/IAssetProvider.cs +++ b/OpenSim/Framework/General/Interfaces/IAssetProvider.cs | |||
@@ -6,9 +6,8 @@ using libsecondlife; | |||
6 | 6 | ||
7 | namespace OpenSim.Framework.Interfaces | 7 | namespace OpenSim.Framework.Interfaces |
8 | { | 8 | { |
9 | public interface IAssetProvider | 9 | public interface IAssetProvider : IPlugin |
10 | { | 10 | { |
11 | void Initialise(string dbfile, string dbname); | ||
12 | AssetBase FetchAsset(LLUUID uuid); | 11 | AssetBase FetchAsset(LLUUID uuid); |
13 | void CreateAsset(AssetBase asset); | 12 | void CreateAsset(AssetBase asset); |
14 | void UpdateAsset(AssetBase asset); | 13 | void UpdateAsset(AssetBase asset); |
diff --git a/OpenSim/Framework/General/Interfaces/IPlugin.cs b/OpenSim/Framework/General/Interfaces/IPlugin.cs new file mode 100644 index 0000000..ceb8b63 --- /dev/null +++ b/OpenSim/Framework/General/Interfaces/IPlugin.cs | |||
@@ -0,0 +1,29 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Interfaces | ||
6 | { | ||
7 | /// <summary> | ||
8 | /// This interface, describes a generic plugin | ||
9 | /// </summary> | ||
10 | public interface IPlugin | ||
11 | { | ||
12 | /// <summary> | ||
13 | /// Returns the plugin version | ||
14 | /// </summary> | ||
15 | /// <returns>Plugin version in MAJOR.MINOR.REVISION.BUILD format</returns> | ||
16 | string Version { get; } | ||
17 | |||
18 | /// <summary> | ||
19 | /// Returns the plugin name | ||
20 | /// </summary> | ||
21 | /// <returns>Plugin name, eg MySQL User Provider</returns> | ||
22 | string Name { get; } | ||
23 | |||
24 | /// <summary> | ||
25 | /// Initialises the plugin (artificial constructor) | ||
26 | /// </summary> | ||
27 | void Initialise(); | ||
28 | } | ||
29 | } | ||