aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorTleiades Hax2007-10-26 11:46:27 +0000
committerTleiades Hax2007-10-26 11:46:27 +0000
commit5e7dba726896fcb84882b53952651742926e6efb (patch)
treea396337e721912fd954e8a66e26d16c375d7bab4 /OpenSim
parentadd my set-eol-style script. Can be run on Linux (diff)
downloadopensim-SC_OLD-5e7dba726896fcb84882b53952651742926e6efb.zip
opensim-SC_OLD-5e7dba726896fcb84882b53952651742926e6efb.tar.gz
opensim-SC_OLD-5e7dba726896fcb84882b53952651742926e6efb.tar.bz2
opensim-SC_OLD-5e7dba726896fcb84882b53952651742926e6efb.tar.xz
Very early first implementation of grid based assets.
Run this on a major grid, and weep
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs11
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs36
-rw-r--r--OpenSim/Framework/Communications/Cache/GridAssetClient.cs160
-rw-r--r--OpenSim/Framework/Communications/RestClient/GenericAsyncResult.cs2
-rw-r--r--OpenSim/Framework/Communications/RestClient/RestClient.cs101
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLAssetData.cs30
-rw-r--r--OpenSim/Framework/General/Types/AssetBase.cs2
-rw-r--r--OpenSim/Grid/AssetServer/Main.cs170
-rw-r--r--OpenSim/Grid/AssetServer/RestService.cs109
-rw-r--r--OpenSim/Region/Application/OpenSimMain.cs4
10 files changed, 511 insertions, 114 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 271934f..95183ad 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -36,6 +36,7 @@ using libsecondlife.Packets;
36using OpenSim.Framework.Interfaces; 36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Types; 37using OpenSim.Framework.Types;
38using OpenSim.Framework.Utilities; 38using OpenSim.Framework.Utilities;
39using OpenSim.Framework.Console;
39 40
40namespace OpenSim.Framework.Communications.Cache 41namespace OpenSim.Framework.Communications.Cache
41{ 42{
@@ -319,17 +320,19 @@ namespace OpenSim.Framework.Communications.Cache
319 320
320 public void AssetNotFound(LLUUID assetID) 321 public void AssetNotFound(LLUUID assetID)
321 { 322 {
322 /*
323 if (this.RequestedTextures.ContainsKey(assetID)) 323 if (this.RequestedTextures.ContainsKey(assetID))
324 { 324 {
325 MainLog.Instance.Warn("ASSET CACHE", "sending image not found for {0}", assetID);
325 AssetRequest req = this.RequestedTextures[assetID]; 326 AssetRequest req = this.RequestedTextures[assetID];
326 ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket(); 327 ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket();
327 notFound.ImageID.ID = assetID; 328 notFound.ImageID.ID = assetID;
328 req.RequestUser.OutPacket(notFound); 329 req.RequestUser.OutPacket(notFound);
329 //Console.WriteLine("sending image not found for " + assetID);
330
331 this.RequestedTextures.Remove(assetID); 330 this.RequestedTextures.Remove(assetID);
332 }*/ 331 }
332 else
333 {
334 MainLog.Instance.Error("ASSET CACHE", "Cound not send image not found for {0}", assetID);
335 }
333 } 336 }
334 337
335 #region Assets 338 #region Assets
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index a3ec346..53efa16 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -108,23 +108,23 @@ namespace OpenSim.Framework.Communications.Cache
108 public virtual List<AssetBase> GetDefaultAssets() 108 public virtual List<AssetBase> GetDefaultAssets()
109 { 109 {
110 List<AssetBase> assets = new List<AssetBase>(); 110 List<AssetBase> assets = new List<AssetBase>();
111 111 // These assets have been moved into the OpenSimAssetSet.XML file
112 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000001", "Bricks", "bricks.jp2")); 112 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000001", "Bricks", "bricks.jp2"));
113 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000002", "Plywood", "plywood.jp2")); 113 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000002", "Plywood", "plywood.jp2"));
114 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000003", "Rocks", "rocks.jp2")); 114 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000003", "Rocks", "rocks.jp2"));
115 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000004", "Granite", "granite.jp2")); 115 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000004", "Granite", "granite.jp2"));
116 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000005", "Hardwood", "hardwood.jp2")); 116 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000005", "Hardwood", "hardwood.jp2"));
117 assets.Add(CreateImageAsset("00000000-0000-0000-5005-000000000005", "Prim Base Texture", "plywood.jp2")); 117 //assets.Add(CreateImageAsset("00000000-0000-1111-5005-000000000005", "Prim Base Texture", "plywood.jp2"));
118 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000006", "Map Base Texture", "map_base.jp2")); 118 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000006", "Map Base Texture", "map_base.jp2"));
119 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000007", "Map Texture", "map1.jp2")); 119 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000007", "Map Texture", "map1.jp2"));
120 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000010", "Female Body Texture", "femalebody.jp2")); 120 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000010", "Female Body Texture", "femalebody.jp2"));
121 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000011", "Female Bottom Texture", "femalebottom.jp2")); 121 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000011", "Female Bottom Texture", "femalebottom.jp2"));
122 assets.Add(CreateImageAsset("00000000-0000-0000-9999-000000000012", "Female Face Texture", "femaleface.jp2")); 122 //assets.Add(CreateImageAsset("00000000-0000-1111-9999-000000000012", "Female Face Texture", "femaleface.jp2"));
123 123
124 assets.Add(CreateAsset("77c41e39-38f9-f75a-024e-585989bbabbb", "Skin", "base_skin.dat", false)); 124 //assets.Add(CreateAsset("77c41e39-38f9-f75a-024e-585989bbabbb", "Skin", "base_skin.dat", false));
125 assets.Add(CreateAsset("66c41e39-38f9-f75a-024e-585989bfab73", "Shape", "base_shape.dat", false)); 125 //assets.Add(CreateAsset("66c41e39-38f9-f75a-024e-585989bfab73", "Shape", "base_shape.dat", false));
126 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111110", "Shirt", "newshirt.dat", false)); 126 //assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111110", "Shirt", "newshirt.dat", false));
127 assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111120", "Shirt", "newpants.dat", false)); 127 //assets.Add(CreateAsset("00000000-38f9-1111-024e-222222111120", "Shirt", "newpants.dat", false));
128 128
129 return assets; 129 return assets;
130 } 130 }
@@ -185,4 +185,4 @@ namespace OpenSim.Framework.Communications.Cache
185 } 185 }
186 } 186 }
187 } 187 }
188} \ No newline at end of file 188}
diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
new file mode 100644
index 0000000..fc77431
--- /dev/null
+++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
@@ -0,0 +1,160 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.IO;
30using System.Threading;
31using System.Reflection;
32using System.Xml.Serialization;
33
34using libsecondlife;
35
36using Nini.Config;
37using OpenSim.Framework.Console;
38using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Types;
40using OpenSim.Framework.Utilities;
41using OpenSim.Framework.Communications;
42
43namespace OpenSim.Framework.Communications.Cache
44{
45 public class GridAssetClient : IAssetServer
46 {
47 private string _assetServerUrl;
48 private IAssetReceiver _receiver;
49
50 public GridAssetClient(string serverUrl)
51 {
52 _assetServerUrl = serverUrl;
53 }
54
55 #region IAssetServer Members
56
57 public void SetReceiver(IAssetReceiver receiver)
58 {
59 _receiver = receiver;
60 }
61
62 public void FetchAsset(LLUUID assetID, bool isTexture)
63 {
64 Stream s = null;
65 try
66 {
67
68 MainLog.Instance.Debug("ASSETCACHE", "Querying for {0}", assetID.ToString());
69
70 RestClient rc = new RestClient(_assetServerUrl);
71 rc.AddResourcePath("assets");
72 rc.AddResourcePath(assetID.ToString());
73 if (isTexture)
74 rc.AddQueryParameter("texture");
75
76 rc.RequestMethod = "GET";
77 s = rc.Request();
78
79 if (s.Length > 0)
80 {
81 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
82 AssetBase asset = (AssetBase)xs.Deserialize(s);
83
84 _receiver.AssetReceived(asset, isTexture);
85 }
86 else
87 {
88 MainLog.Instance.Debug("ASSETCACHE", "Asset not found {0}", assetID.ToString());
89 _receiver.AssetNotFound(assetID);
90 }
91 }
92 catch (Exception e)
93 {
94 MainLog.Instance.Error("ASSETCACHE", e.Message);
95 MainLog.Instance.Error("ASSETCACHE", e.StackTrace);
96 }
97 }
98
99 public void UpdateAsset(AssetBase asset)
100 {
101 throw new Exception("The method or operation is not implemented.");
102 }
103
104 public void StoreAndCommitAsset(AssetBase asset)
105 {
106 try
107 {
108 MemoryStream s = new MemoryStream();
109
110 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
111 xs.Serialize(s, asset);
112 RestClient rc = new RestClient(_assetServerUrl);
113 rc.AddResourcePath("assets");
114 rc.RequestMethod = "POST";
115 rc.Request(s);
116 }
117 catch (Exception e)
118 {
119 MainLog.Instance.Error("ASSETS", e.Message);
120 }
121 }
122
123 public void Close()
124 {
125 throw new Exception("The method or operation is not implemented.");
126 }
127
128 public void LoadAsset(AssetBase info, bool image, string filename)
129 {
130 throw new Exception("The method or operation is not implemented.");
131 }
132
133 public System.Collections.Generic.List<AssetBase> GetDefaultAssets()
134 {
135 throw new Exception("The method or operation is not implemented.");
136 }
137
138 public AssetBase CreateImageAsset(string assetIdStr, string name, string filename)
139 {
140 throw new Exception("The method or operation is not implemented.");
141 }
142
143 public void ForEachDefaultAsset(Action<AssetBase> action)
144 {
145 throw new Exception("The method or operation is not implemented.");
146 }
147
148 public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
149 {
150 throw new Exception("The method or operation is not implemented.");
151 }
152
153 public void ForEachXmlAsset(Action<AssetBase> action)
154 {
155 throw new Exception("The method or operation is not implemented.");
156 }
157
158 #endregion
159 }
160}
diff --git a/OpenSim/Framework/Communications/RestClient/GenericAsyncResult.cs b/OpenSim/Framework/Communications/RestClient/GenericAsyncResult.cs
index 55456ae..c821fa4 100644
--- a/OpenSim/Framework/Communications/RestClient/GenericAsyncResult.cs
+++ b/OpenSim/Framework/Communications/RestClient/GenericAsyncResult.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.Threading; 4using System.Threading;
5 5
6namespace OpenSim.Framework.RestClient 6namespace OpenSim.Framework.Communications
7{ 7{
8 internal class SimpleAsyncResult : IAsyncResult 8 internal class SimpleAsyncResult : IAsyncResult
9 { 9 {
diff --git a/OpenSim/Framework/Communications/RestClient/RestClient.cs b/OpenSim/Framework/Communications/RestClient/RestClient.cs
index 25fc61a..392669f 100644
--- a/OpenSim/Framework/Communications/RestClient/RestClient.cs
+++ b/OpenSim/Framework/Communications/RestClient/RestClient.cs
@@ -6,7 +6,9 @@ using System.Text;
6using System.Collections.Generic; 6using System.Collections.Generic;
7using System.Threading; 7using System.Threading;
8 8
9namespace OpenSim.Framework.RestClient 9using OpenSim.Framework.Console;
10
11namespace OpenSim.Framework.Communications
10{ 12{
11 /// <summary> 13 /// <summary>
12 /// Implementation of a generic REST client 14 /// Implementation of a generic REST client
@@ -25,8 +27,11 @@ namespace OpenSim.Framework.RestClient
25 /// other threads to execute, while it waits for a response from the web-service. RestClient it self, can be 27 /// other threads to execute, while it waits for a response from the web-service. RestClient it self, can be
26 /// invoked by the caller in either synchroneous mode or asynchroneous mode. 28 /// invoked by the caller in either synchroneous mode or asynchroneous mode.
27 /// </remarks> 29 /// </remarks>
28 public class RestClient 30 public class RestClient
29 { 31 {
32
33 string realuri;
34 #region member variables
30 /// <summary> 35 /// <summary>
31 /// The base Uri of the web-service e.g. http://www.google.com 36 /// The base Uri of the web-service e.g. http://www.google.com
32 /// </summary> 37 /// </summary>
@@ -55,7 +60,7 @@ namespace OpenSim.Framework.RestClient
55 /// <summary> 60 /// <summary>
56 /// MemoryStream representing the resultiong resource 61 /// MemoryStream representing the resultiong resource
57 /// </summary> 62 /// </summary>
58 MemoryStream _resource; 63 Stream _resource;
59 64
60 /// <summary> 65 /// <summary>
61 /// WebRequest object, held as a member variable 66 /// WebRequest object, held as a member variable
@@ -89,6 +94,9 @@ namespace OpenSim.Framework.RestClient
89 /// </summary> 94 /// </summary>
90 private Exception _asyncException; 95 private Exception _asyncException;
91 96
97 #endregion member variables
98
99 #region constructors
92 /// <summary> 100 /// <summary>
93 /// Instantiate a new RestClient 101 /// Instantiate a new RestClient
94 /// </summary> 102 /// </summary>
@@ -100,8 +108,12 @@ namespace OpenSim.Framework.RestClient
100 _resource = new MemoryStream(); 108 _resource = new MemoryStream();
101 _request = null; 109 _request = null;
102 _response = null; 110 _response = null;
111 _lock = new object();
103 } 112 }
104 113
114 object _lock;
115 #endregion constructors
116
105 /// <summary> 117 /// <summary>
106 /// Add a path element to the query, e.g. assets 118 /// Add a path element to the query, e.g. assets
107 /// </summary> 119 /// </summary>
@@ -125,6 +137,15 @@ namespace OpenSim.Framework.RestClient
125 } 137 }
126 138
127 /// <summary> 139 /// <summary>
140 /// Add a query parameter to the Url
141 /// </summary>
142 /// <param name="name">Name of the parameter, e.g. min</param>
143 public void AddQueryParameter(string name)
144 {
145 _parameterElements.Add(HttpUtility.UrlEncode(name), null);
146 }
147
148 /// <summary>
128 /// Web-Request method, e.g. GET, PUT, POST, DELETE 149 /// Web-Request method, e.g. GET, PUT, POST, DELETE
129 /// </summary> 150 /// </summary>
130 public string RequestMethod 151 public string RequestMethod
@@ -185,9 +206,10 @@ namespace OpenSim.Framework.RestClient
185 sb.Append(kv.Value); 206 sb.Append(kv.Value);
186 } 207 }
187 } 208 }
209 realuri = sb.ToString();
188 return new Uri(sb.ToString()); 210 return new Uri(sb.ToString());
189 } 211 }
190 212 #region Async communications with server
191 /// <summary> 213 /// <summary>
192 /// Async method, invoked when a block of data has been received from the service 214 /// Async method, invoked when a block of data has been received from the service
193 /// </summary> 215 /// </summary>
@@ -199,7 +221,6 @@ namespace OpenSim.Framework.RestClient
199 Stream s = (Stream)ar.AsyncState; 221 Stream s = (Stream)ar.AsyncState;
200 int read = s.EndRead(ar); 222 int read = s.EndRead(ar);
201 223
202 // Read the HTML page and then print it to the console.
203 if (read > 0) 224 if (read > 0)
204 { 225 {
205 _resource.Write(_readbuf, 0, read); 226 _resource.Write(_readbuf, 0, read);
@@ -207,7 +228,6 @@ namespace OpenSim.Framework.RestClient
207 228
208 // TODO! Implement timeout, without killing the server 229 // TODO! Implement timeout, without killing the server
209 //ThreadPool.RegisterWaitForSingleObject(asynchronousResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); 230 //ThreadPool.RegisterWaitForSingleObject(asynchronousResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
210 return;
211 } 231 }
212 else 232 else
213 { 233 {
@@ -261,32 +281,83 @@ namespace OpenSim.Framework.RestClient
261 } 281 }
262 } 282 }
263 } 283 }
284 #endregion Async communications with server
264 285
265 /// <summary> 286 /// <summary>
266 /// Perform synchroneous request 287 /// Perform synchroneous request
267 /// </summary> 288 /// </summary>
268 public Stream Request() 289 public Stream Request()
269 { 290 {
291 lock (_lock)
292 {
293 _request = (HttpWebRequest)WebRequest.Create(buildUri());
294 _request.KeepAlive = false;
295 _request.ContentType = "application/xml";
296 _request.Timeout = 200000;
297 _asyncException = null;
298
299// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
300 _response = (HttpWebResponse)_request.GetResponse();
301 Stream src = _response.GetResponseStream();
302 int length = src.Read(_readbuf, 0, BufferSize);
303 while(length > 0)
304 {
305 _resource.Write(_readbuf, 0, length);
306 length = src.Read(_readbuf, 0, BufferSize);
307 }
308
309
310 // TODO! Implement timeout, without killing the server
311 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
312 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
313
314// _allDone.WaitOne();
315 if (_response != null)
316 _response.Close();
317 if (_asyncException != null)
318 throw _asyncException;
319
320 if (_resource != null)
321 {
322 _resource.Flush();
323 _resource.Seek(0, SeekOrigin.Begin);
324 }
325
326 return _resource;
327 }
328 }
329
330 public Stream Request(Stream src)
331 {
270 _request = (HttpWebRequest)WebRequest.Create(buildUri()); 332 _request = (HttpWebRequest)WebRequest.Create(buildUri());
271 _request.KeepAlive = false; 333 _request.KeepAlive = false;
272 _request.ContentType = "text/html"; 334 _request.ContentType = "application/xml";
273 _request.Timeout = 200; 335 _request.Timeout = 900000;
336 _request.Method = RequestMethod;
274 _asyncException = null; 337 _asyncException = null;
338 _request.ContentLength = src.Length;
275 339
276 IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); 340 src.Seek(0, SeekOrigin.Begin);
341 Stream dst = _request.GetRequestStream();
342 byte[] buf = new byte[1024];
343 int length = src.Read(buf,0, 1024);
344 while (length > 0)
345 {
346 dst.Write(buf, 0, length);
347 length = src.Read(buf, 0, 1024);
348 }
349 _response = (HttpWebResponse)_request.GetResponse();
350
351// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request);
277 352
278 // TODO! Implement timeout, without killing the server 353 // TODO! Implement timeout, without killing the server
279 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted 354 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
280 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); 355 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true);
281 356
282 _allDone.WaitOne(); 357 return null;
283 if(_response != null)
284 _response.Close();
285 if (_asyncException != null)
286 throw _asyncException;
287 return _resource;
288 } 358 }
289 359
360
290 #region Async Invocation 361 #region Async Invocation
291 public IAsyncResult BeginRequest(AsyncCallback callback, object state) 362 public IAsyncResult BeginRequest(AsyncCallback callback, object state)
292 { 363 {
diff --git a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
index a8f0fdb..0112474 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
@@ -71,22 +71,24 @@ namespace OpenSim.Framework.Data.MySQL
71 public AssetBase FetchAsset(LLUUID assetID) 71 public AssetBase FetchAsset(LLUUID assetID)
72 { 72 {
73 AssetBase asset = null; 73 AssetBase asset = null;
74 74 lock (_dbConnection)
75 MySqlCommand cmd = new MySqlCommand("SELECT name, description, assetType, invType, local, temporary, data FROM assets WHERE id=?id", _dbConnection.Connection);
76 MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
77 p.Value = assetID.GetBytes();
78 using (MySqlDataReader dbReader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
79 { 75 {
80 if (dbReader.Read()) 76 MySqlCommand cmd = new MySqlCommand("SELECT name, description, assetType, invType, local, temporary, data FROM assets WHERE id=?id", _dbConnection.Connection);
77 MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
78 p.Value = assetID.GetBytes();
79 using (MySqlDataReader dbReader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
81 { 80 {
82 asset = new AssetBase(); 81 if (dbReader.Read())
83 asset.Data = (byte[])dbReader["data"]; 82 {
84 asset.Description = (string)dbReader["description"]; 83 asset = new AssetBase();
85 asset.FullID = assetID; 84 asset.Data = (byte[])dbReader["data"];
86 asset.InvType = (sbyte)dbReader["invType"]; 85 asset.Description = (string)dbReader["description"];
87 asset.Local = ((sbyte)dbReader["local"]) != 0 ? true : false; 86 asset.FullID = assetID;
88 asset.Name = (string)dbReader["name"]; 87 asset.InvType = (sbyte)dbReader["invType"];
89 asset.Type = (sbyte)dbReader["assetType"]; 88 asset.Local = ((sbyte)dbReader["local"]) != 0 ? true : false;
89 asset.Name = (string)dbReader["name"];
90 asset.Type = (sbyte)dbReader["assetType"];
91 }
90 } 92 }
91 } 93 }
92 return asset; 94 return asset;
diff --git a/OpenSim/Framework/General/Types/AssetBase.cs b/OpenSim/Framework/General/Types/AssetBase.cs
index 628724d..c34887c 100644
--- a/OpenSim/Framework/General/Types/AssetBase.cs
+++ b/OpenSim/Framework/General/Types/AssetBase.cs
@@ -25,10 +25,12 @@
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System;
28using libsecondlife; 29using libsecondlife;
29 30
30namespace OpenSim.Framework.Types 31namespace OpenSim.Framework.Types
31{ 32{
33 [Serializable]
32 public class AssetBase 34 public class AssetBase
33 { 35 {
34 public byte[] Data; 36 public byte[] Data;
diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs
index 9f1f9a2..dabacd4 100644
--- a/OpenSim/Grid/AssetServer/Main.cs
+++ b/OpenSim/Grid/AssetServer/Main.cs
@@ -28,15 +28,18 @@
28 28
29using System; 29using System;
30using System.IO; 30using System.IO;
31using System.Reflection;
31 32
32using libsecondlife; 33using libsecondlife;
34using Nini.Config;
35
36using OpenSim.Framework.Types;
33using OpenSim.Framework.Communications.Cache; 37using OpenSim.Framework.Communications.Cache;
34using OpenSim.Framework.Configuration; 38using OpenSim.Framework.Configuration;
35using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Configuration;
38using OpenSim.Framework.Interfaces; 40using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Utilities; 41using OpenSim.Framework.Utilities;
42using OpenSim.Framework.Servers;
40 43
41/* 44/*
42using System.Text; 45using System.Text;
@@ -57,7 +60,7 @@ namespace OpenSim.Grid.AssetServer
57 public static OpenAsset_Main assetserver; 60 public static OpenAsset_Main assetserver;
58 61
59 private LogBase m_console; 62 private LogBase m_console;
60 private IAssetServer m_assetServer; 63 private IAssetProvider m_assetProvider;
61 64
62 [STAThread] 65 [STAThread]
63 public static void Main(string[] args) 66 public static void Main(string[] args)
@@ -97,11 +100,14 @@ namespace OpenSim.Grid.AssetServer
97 m_console.Verbose("ASSET", "Setting up asset DB"); 100 m_console.Verbose("ASSET", "Setting up asset DB");
98 setupDB(m_config); 101 setupDB(m_config);
99 102
103 m_console.Verbose("ASSET", "Loading default asset set..");
104 LoadDefaultAssets();
105
100 m_console.Verbose("ASSET", "Starting HTTP process"); 106 m_console.Verbose("ASSET", "Starting HTTP process");
101 BaseHttpServer httpServer = new BaseHttpServer((int)m_config.HttpPort); 107 BaseHttpServer httpServer = new BaseHttpServer((int)m_config.HttpPort);
102 108
103 httpServer.AddStreamHandler(new GetAssetStreamHandler(this)); 109 httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider));
104 httpServer.AddStreamHandler(new PostAssetStreamHandler( this )); 110 httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider));
105 111
106 httpServer.Start(); 112 httpServer.Start();
107 } 113 }
@@ -111,14 +117,49 @@ namespace OpenSim.Grid.AssetServer
111 return null; 117 return null;
112 } 118 }
113 119
120
121 public IAssetProvider LoadDatabasePlugin(string FileName)
122 {
123 MainLog.Instance.Verbose("ASSET SERVER", "LoadDatabasePlugin: Attempting to load " + FileName);
124 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
125 IAssetProvider assetPlugin = null;
126 foreach (Type pluginType in pluginAssembly.GetTypes())
127 {
128 if (!pluginType.IsAbstract)
129 {
130 Type typeInterface = pluginType.GetInterface("IAssetProvider", true);
131
132 if (typeInterface != null)
133 {
134 IAssetProvider plug = (IAssetProvider)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
135 assetPlugin = plug;
136 assetPlugin.Initialise();
137
138 MainLog.Instance.Verbose("ASSET SERVER", "Added " + assetPlugin.Name + " " + assetPlugin.Version);
139 break;
140 }
141
142 typeInterface = null;
143 }
144 }
145
146 pluginAssembly = null;
147 return assetPlugin;
148 }
149
114 public void setupDB(AssetConfig config) 150 public void setupDB(AssetConfig config)
115 { 151 {
116 try 152 try
117 { 153 {
118 SQLAssetServer assetServer = new SQLAssetServer(config.DatabaseProvider ); 154 m_assetProvider = LoadDatabasePlugin(config.DatabaseProvider);
119 assetServer.LoadDefaultAssets(); 155 if (m_assetProvider == null)
156 {
157 MainLog.Instance.Error("ASSET", "Failed to load a database plugin, server halting");
158 Environment.Exit(-1);
159 }
160// assetServer.LoadDefaultAssets();
120 161
121 m_assetServer = assetServer; 162// m_assetServer = assetServer;
122 } 163 }
123 catch (Exception e) 164 catch (Exception e)
124 { 165 {
@@ -127,84 +168,89 @@ namespace OpenSim.Grid.AssetServer
127 } 168 }
128 } 169 }
129 170
130 public void RunCmd(string cmd, string[] cmdparams) 171 public void LoadAsset(AssetBase info, bool image, string filename)
131 { 172 {
132 switch (cmd) 173 //should request Asset from storage manager
133 { 174 //but for now read from file
134 case "help":
135 m_console.Notice("shutdown - shutdown this asset server (USE CAUTION!)");
136 break;
137
138 case "shutdown":
139 m_console.Close();
140 Environment.Exit(0);
141 break;
142 }
143 }
144 175
145 public void Show(string ShowWhat) 176 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
146 { 177 string fileName = Path.Combine(dataPath, filename);
178 FileInfo fInfo = new FileInfo(fileName);
179 long numBytes = fInfo.Length;
180 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
181 byte[] idata = new byte[numBytes];
182 BinaryReader br = new BinaryReader(fStream);
183 idata = br.ReadBytes((int)numBytes);
184 br.Close();
185 fStream.Close();
186 info.Data = idata;
187 //info.loaded=true;
147 } 188 }
148 }
149 189
150 public class GetAssetStreamHandler : BaseStreamHandler 190 public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
151 {
152 OpenAsset_Main m_assetManager;
153
154 override public byte[] Handle(string path, Stream request)
155 { 191 {
156 string param = GetParam(path); 192 AssetBase asset = new AssetBase(
193 new LLUUID(assetIdStr),
194 name
195 );
157 196
158 byte[] assetdata = m_assetManager.GetAssetData(new LLUUID(param), false); 197 if (!String.IsNullOrEmpty(filename))
159 if (assetdata != null)
160 { 198 {
161 return assetdata; 199 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename);
200
201 LoadAsset(asset, isImage, filename);
162 } 202 }
163 else 203 else
164 { 204 {
165 return new byte[]{}; 205 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name);
166 } 206 }
167 }
168 207
169 public GetAssetStreamHandler(OpenAsset_Main assetManager) : base("/assets/", "GET") 208 return asset;
170 {
171 m_assetManager = assetManager;
172 } 209 }
173 }
174
175 public class PostAssetStreamHandler : BaseStreamHandler
176 {
177 OpenAsset_Main m_assetManager;
178 210
179 override public byte[] Handle(string path, Stream request) 211 public void LoadDefaultAssets()
180 { 212 {
181 string param = GetParam(path); 213 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
182 LLUUID assetId = new LLUUID(param); 214 if (File.Exists(filePath))
183 byte[] txBuffer = new byte[4096];
184
185 using( BinaryReader binReader = new BinaryReader( request ) )
186 { 215 {
187 using (MemoryStream memoryStream = new MemoryStream(4096)) 216 XmlConfigSource source = new XmlConfigSource(filePath);
217
218 for (int i = 0; i < source.Configs.Count; i++)
188 { 219 {
189 int count; 220 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated());
190 while ((count = binReader.Read(txBuffer, 0, 4096)) > 0) 221 string name = source.Configs[i].GetString("name", "");
191 { 222 sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0);
192 memoryStream.Write(txBuffer, 0, count); 223 sbyte invType = (sbyte)source.Configs[i].GetInt("inventoryType", 0);
193 } 224 string fileName = source.Configs[i].GetString("fileName", "");
225
226 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false);
194 227
195 byte[] assetData = memoryStream.ToArray(); 228 newAsset.Type = type;
229 newAsset.InvType = invType;
196 230
197// m_assetManager.CreateAsset(assetId, assetData); 231 m_assetProvider.CreateAsset(newAsset);
198 } 232 }
199 } 233 }
200
201 return new byte[]{};
202 } 234 }
203 235
204 public PostAssetStreamHandler( OpenAsset_Main assetManager ) 236
205 : base("/assets/", "POST") 237 public void RunCmd(string cmd, string[] cmdparams)
238 {
239 switch (cmd)
240 {
241 case "help":
242 m_console.Notice("shutdown - shutdown this asset server (USE CAUTION!)");
243 break;
244
245 case "shutdown":
246 m_console.Close();
247 Environment.Exit(0);
248 break;
249 }
250 }
251
252 public void Show(string ShowWhat)
206 { 253 {
207 m_assetManager = assetManager;
208 } 254 }
209 } 255 }
210} 256}
diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs
new file mode 100644
index 0000000..88a1668
--- /dev/null
+++ b/OpenSim/Grid/AssetServer/RestService.cs
@@ -0,0 +1,109 @@
1using System;
2using System.IO;
3using System.Xml;
4using System.Xml.Serialization;
5using System.Text;
6
7using libsecondlife;
8using OpenSim.Framework.Types;
9using OpenSim.Framework.Servers;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Console;
12
13namespace OpenSim.Grid.AssetServer
14{
15 public class GetAssetStreamHandler : BaseStreamHandler
16 {
17 OpenAsset_Main m_assetManager;
18 IAssetProvider m_assetProvider;
19
20 override public byte[] Handle(string path, Stream request)
21 {
22 string param = GetParam(path);
23 byte[] result = new byte[] { };
24 try {
25
26 string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
27
28 if (p.Length > 0)
29 {
30 LLUUID assetID;
31 bool isTexture = false;
32 LLUUID.TryParse(p[0], out assetID);
33 if (p.Length > 1)
34 {
35 if (string.Compare(p[1], "texture", true) == 0)
36 isTexture = true;
37 }
38
39
40 AssetBase asset = m_assetProvider.FetchAsset(assetID);
41 if (asset != null)
42 {
43 MainLog.Instance.Debug("REST", "GET:/asset found {0}, {1}", assetID, asset.Name);
44
45 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
46 MemoryStream ms = new MemoryStream();
47 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
48 xw.Formatting = Formatting.Indented;
49 xs.Serialize(xw, asset);
50 xw.Flush();
51
52 ms.Seek(0, SeekOrigin.Begin);
53 StreamReader sr = new StreamReader(ms);
54
55 result = ms.GetBuffer();
56 Array.Resize<byte>(ref result, (int)ms.Length);
57 }
58 else
59 {
60 MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID);
61 }
62 }
63 }
64 catch (Exception e)
65 {
66 MainLog.Instance.Error(e.ToString());
67 }
68 return result;
69 }
70
71 public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
72 : base("GET", "/assets" )
73 {
74 m_assetManager = assetManager;
75 m_assetProvider = assetProvider;
76 }
77 }
78
79 public class PostAssetStreamHandler : BaseStreamHandler
80 {
81 OpenAsset_Main m_assetManager;
82 IAssetProvider m_assetProvider;
83
84 override public byte[] Handle(string path, Stream request)
85 {
86 string param = GetParam(path);
87
88 LLUUID assetId;
89 if(param.Length > 0)
90 LLUUID.TryParse(param, out assetId);
91 byte[] txBuffer = new byte[4096];
92
93 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
94 AssetBase asset = (AssetBase)xs.Deserialize(request);
95
96 MainLog.Instance.Verbose("REST", "StoreAndCommitAsset {0}", asset.FullID);
97 m_assetProvider.CreateAsset(asset);
98
99 return new byte[] { };
100 }
101
102 public PostAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
103 : base("POST", "/assets")
104 {
105 m_assetManager = assetManager;
106 m_assetProvider = assetProvider;
107 }
108 }
109}
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs
index 55913a8..f550ee2 100644
--- a/OpenSim/Region/Application/OpenSimMain.cs
+++ b/OpenSim/Region/Application/OpenSimMain.cs
@@ -301,6 +301,10 @@ namespace OpenSim
301 { 301 {
302 assetServer = new LocalAssetServer(); 302 assetServer = new LocalAssetServer();
303 } 303 }
304 else if (m_assetStorage == "grid")
305 {
306 assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
307 }
304 else 308 else
305 { 309 {
306 SQLAssetServer sqlAssetServer = new SQLAssetServer(standaloneAssetPlugin); 310 SQLAssetServer sqlAssetServer = new SQLAssetServer(standaloneAssetPlugin);