aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Cache/SQLAssetServer.cs68
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLAssetData.cs112
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs133
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLManager.cs92
-rw-r--r--OpenSim/Framework/Data.MySQL/Resources/CreateAssetsTable.sql11
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs23
-rw-r--r--OpenSim/Framework/General/Configuration/AssetConfig.cs54
-rw-r--r--OpenSim/Framework/General/Interfaces/IAssetProvider.cs3
-rw-r--r--OpenSim/Framework/General/Interfaces/IPlugin.cs29
-rw-r--r--OpenSim/Grid/AssetServer/Main.cs193
-rw-r--r--OpenSim/Region/Application/OpenSimMain.cs2
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs1
12 files changed, 415 insertions, 306 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 @@
1using System;
2using System.Collections.Generic;
3using MySql.Data.MySqlClient;
4
5using libsecondlife;
6using OpenSim.Framework.Console;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Types;
9
10namespace 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 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Data; 30using System.Data;
31using System.Reflection;
32using System.Collections.Generic; 31using System.Collections.Generic;
33using libsecondlife; 32using libsecondlife;
34using OpenSim.Framework.Types; 33using 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*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.IO;
30using System.Data; 30using System.Data;
31using System.Reflection;
32using System.Collections.Generic;
31using libsecondlife; 33using libsecondlife;
34
32using MySql.Data.MySqlClient; 35using MySql.Data.MySqlClient;
36
33using OpenSim.Framework.Types; 37using OpenSim.Framework.Types;
34using OpenSim.Framework.Console; 38using 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 @@
1CREATE 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 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace 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
7namespace OpenSim.Framework.Interfaces 7namespace 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 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace 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}
diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs
index 6bdb9da..9272f24 100644
--- a/OpenSim/Grid/AssetServer/Main.cs
+++ b/OpenSim/Grid/AssetServer/Main.cs
@@ -28,14 +28,21 @@
28 28
29using System; 29using System;
30using System.IO; 30using System.IO;
31using System.Text; 31
32using Db4objects.Db4o;
33using libsecondlife; 32using libsecondlife;
34using OpenSim.Framework.Console; 33using OpenSim.Framework.Console;
35using OpenSim.Framework.Types;
36using OpenSim.Framework.Servers; 34using OpenSim.Framework.Servers;
35using OpenSim.Framework.Configuration;
36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38 38using OpenSim.Framework.Communications.Caches;
39/*
40using System.Text;
41using Db4objects.Db4o;
42using OpenSim.Framework.Types;
43using OpenSim.Framework.Utilities;
44using OpenSim.Framework.Communications.Caches;
45*/
39namespace OpenSim.Grid.AssetServer 46namespace OpenSim.Grid.AssetServer
40{ 47{
41 /// <summary> 48 /// <summary>
@@ -43,11 +50,11 @@ namespace OpenSim.Grid.AssetServer
43 /// </summary> 50 /// </summary>
44 public class OpenAsset_Main : conscmd_callback 51 public class OpenAsset_Main : conscmd_callback
45 { 52 {
46 private IObjectContainer db;
47
48 public static OpenAsset_Main assetserver; 53 public static OpenAsset_Main assetserver;
49 54
50 private LogBase m_console; 55 private LogBase m_console;
56 private AssetConfig m_config;
57 private IAssetServer m_assetServer;
51 58
52 [STAThread] 59 [STAThread]
53 public static void Main(string[] args) 60 public static void Main(string[] args)
@@ -82,8 +89,10 @@ namespace OpenSim.Grid.AssetServer
82 89
83 public void Startup() 90 public void Startup()
84 { 91 {
92 m_config = new AssetConfig("ASSET SERVER", (Path.Combine(Util.configDir(), "AssetServer_Config.xml")));
93
85 m_console.Verbose("ASSET", "Setting up asset DB"); 94 m_console.Verbose("ASSET", "Setting up asset DB");
86 setupDB(); 95 setupDB(m_config);
87 96
88 m_console.Verbose("ASSET", "Starting HTTP process"); 97 m_console.Verbose("ASSET", "Starting HTTP process");
89 BaseHttpServer httpServer = new BaseHttpServer(8003); 98 BaseHttpServer httpServer = new BaseHttpServer(8003);
@@ -97,180 +106,22 @@ namespace OpenSim.Grid.AssetServer
97 106
98 public byte[] GetAssetData(LLUUID assetID, bool isTexture) 107 public byte[] GetAssetData(LLUUID assetID, bool isTexture)
99 { 108 {
100 bool found = false; 109 return null;
101 AssetStorage foundAsset = null;
102
103 IObjectSet result = db.Get(new AssetStorage(assetID));
104 if (result.Count > 0)
105 {
106 foundAsset = (AssetStorage)result.Next();
107 found = true;
108 }
109
110 if (found)
111 {
112 return foundAsset.Data;
113 }
114 else
115 {
116 return null;
117 }
118 } 110 }
119 111
120 public void setupDB() 112 public void setupDB(AssetConfig config)
121 { 113 {
122 string yappath=(Path.Combine(Util.dataDir(),"gridassets.yap"));
123 bool yapfile = File.Exists(yappath);
124 try 114 try
125 { 115 {
126 db = Db4oFactory.OpenFile(yappath); 116 m_assetServer = new SQLAssetServer(config.DatabaseProvider);
127 MainLog.Instance.Verbose("storage", "Main.cs:setupDB() - creation");
128 } 117 }
129 catch (Exception e) 118 catch (Exception e)
130 { 119 {
131 db.Close(); 120 MainLog.Instance.Warn("ASSET", "setupDB() - Exception occured");
132 MainLog.Instance.Warn("storage", "Main.cs:setupDB() - Exception occured"); 121 MainLog.Instance.Warn("ASSET", e.ToString());
133 MainLog.Instance.Warn("storage", e.ToString());
134 }
135 if (!yapfile)
136 {
137 this.LoadDB();
138 } 122 }
139 } 123 }
140 124
141 public void LoadDB()
142 {
143 try
144 {
145
146 Console.WriteLine("setting up Asset database");
147
148 AssetBase Image = new AssetBase();
149 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
150 Image.Name = "Bricks";
151 this.LoadAsset(Image, true, "bricks.jp2");
152 AssetStorage store = new AssetStorage();
153 store.Data = Image.Data;
154 store.Name = Image.Name;
155 store.UUID = Image.FullID;
156 db.Set(store);
157 db.Commit();
158
159 Image = new AssetBase();
160 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002");
161 Image.Name = "Plywood";
162 this.LoadAsset(Image, true, "plywood.jp2");
163 store = new AssetStorage();
164 store.Data = Image.Data;
165 store.Name = Image.Name;
166 store.UUID = Image.FullID;
167 db.Set(store);
168 db.Commit();
169
170 Image = new AssetBase();
171 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003");
172 Image.Name = "Rocks";
173 this.LoadAsset(Image, true, "rocks.jp2");
174 store = new AssetStorage();
175 store.Data = Image.Data;
176 store.Name = Image.Name;
177 store.UUID = Image.FullID;
178 db.Set(store);
179 db.Commit();
180
181 Image = new AssetBase();
182 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004");
183 Image.Name = "Granite";
184 this.LoadAsset(Image, true, "granite.jp2");
185 store = new AssetStorage();
186 store.Data = Image.Data;
187 store.Name = Image.Name;
188 store.UUID = Image.FullID;
189 db.Set(store);
190 db.Commit();
191
192 Image = new AssetBase();
193 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005");
194 Image.Name = "Hardwood";
195 this.LoadAsset(Image, true, "hardwood.jp2");
196 store = new AssetStorage();
197 store.Data = Image.Data;
198 store.Name = Image.Name;
199 store.UUID = Image.FullID;
200 db.Set(store);
201 db.Commit();
202
203 Image = new AssetBase();
204 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
205 Image.Name = "Prim Base Texture";
206 this.LoadAsset(Image, true, "plywood.jp2");
207 store = new AssetStorage();
208 store.Data = Image.Data;
209 store.Name = Image.Name;
210 store.UUID = Image.FullID;
211 db.Set(store);
212 db.Commit();
213
214 Image = new AssetBase();
215 Image.FullID = new LLUUID("13371337-1337-1337-1337-133713371337");
216 Image.Name = "Peaches";
217 this.LoadAsset(Image, true, "peaches.jp2");
218 store = new AssetStorage();
219 store.Data = Image.Data;
220 store.Name = Image.Name;
221 store.UUID = Image.FullID;
222 db.Set(store);
223 db.Commit();
224
225 Image = new AssetBase();
226 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
227 Image.Name = "Shape";
228 this.LoadAsset(Image, false, "base_shape.dat");
229 store = new AssetStorage();
230 store.Data = Image.Data;
231 store.Name = Image.Name;
232 store.UUID = Image.FullID;
233 db.Set(store);
234 db.Commit();
235 }
236 catch (Exception e)
237 {
238 Console.WriteLine(e.Message);
239 }
240 }
241
242 private void LoadAsset(AssetBase info, bool image, string filename)
243 {
244
245
246 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
247 string fileName = Path.Combine(dataPath, filename);
248 FileInfo fInfo = new FileInfo(fileName);
249 long numBytes = fInfo.Length;
250 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
251 byte[] idata = new byte[numBytes];
252 BinaryReader br = new BinaryReader(fStream);
253 idata = br.ReadBytes((int)numBytes);
254 br.Close();
255 fStream.Close();
256 info.Data = idata;
257 //info.loaded=true;
258 }
259
260 public void CreateAsset(LLUUID assetId, byte[] assetData)
261 {
262 AssetBase asset = new AssetBase();
263 asset.Name = "";
264 asset.FullID = assetId;
265 asset.Data = assetData;
266
267 AssetStorage store = new AssetStorage();
268 store.Data = asset.Data;
269 store.Name = asset.Name;
270 store.UUID = asset.FullID;
271 db.Set(store);
272 db.Commit();
273 }
274 125
275 public void RunCmd(string cmd, string[] cmdparams) 126 public void RunCmd(string cmd, string[] cmdparams)
276 { 127 {
@@ -339,7 +190,7 @@ namespace OpenSim.Grid.AssetServer
339 190
340 byte[] assetData = memoryStream.ToArray(); 191 byte[] assetData = memoryStream.ToArray();
341 192
342 m_assetManager.CreateAsset(assetId, assetData); 193// m_assetManager.CreateAsset(assetId, assetData);
343 } 194 }
344 } 195 }
345 196
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs
index 08b499d..20152d8 100644
--- a/OpenSim/Region/Application/OpenSimMain.cs
+++ b/OpenSim/Region/Application/OpenSimMain.cs
@@ -283,7 +283,7 @@ namespace OpenSim
283 } 283 }
284 else 284 else
285 { 285 {
286 assetServer = new SQLAssetServer(); 286 assetServer = new SQLAssetServer("OpenSim.Framework.Data.SQLite.dll");
287 } 287 }
288 assetServer.SetServerInfo(m_networkServersInfo.AssetURL, m_networkServersInfo.AssetSendKey); 288 assetServer.SetServerInfo(m_networkServersInfo.AssetURL, m_networkServersInfo.AssetSendKey);
289 m_assetCache = new AssetCache(assetServer); 289 m_assetCache = new AssetCache(assetServer);
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index e9ac642..e0661f8 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -30,7 +30,6 @@ using System.Threading;
30using System.Collections.Generic; 30using System.Collections.Generic;
31 31
32using libsecondlife; 32using libsecondlife;
33using libsecondlife.Utilities;
34 33
35using Axiom.Math; 34using Axiom.Math;
36using Ode.NET; 35using Ode.NET;