aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetServer/Main.cs
diff options
context:
space:
mode:
authorlbsa712007-07-04 14:12:32 +0000
committerlbsa712007-07-04 14:12:32 +0000
commit6a2588454a1ac4bb484ad0b9ee648e9ac156f8db (patch)
treefd4e0d33f65e36365d15d991f95d323e6d15e8b1 /OpenSim/Grid/AssetServer/Main.cs
parent* Added StreamHandler support (diff)
downloadopensim-SC-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.zip
opensim-SC-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.gz
opensim-SC-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.bz2
opensim-SC-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.xz
* Removed AssetHttpServer, using BaseHttpServer instead
* Removed legacy REST handling * Created two custom IStreamHandlers for asset up/download * Removed quite a lot of double and triple encodings, trying to work towards binary only and direct write into storage. * Introduced BaseStreamHandler with GetParam() and some other goodies
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/AssetServer/Main.cs169
1 files changed, 124 insertions, 45 deletions
diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs
index 112d72f..3e302d8 100644
--- a/OpenSim/Grid/AssetServer/Main.cs
+++ b/OpenSim/Grid/AssetServer/Main.cs
@@ -33,13 +33,14 @@ using Db4objects.Db4o;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
35using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Servers;
36 37
37namespace OpenSim.Grid.AssetServer 38namespace OpenSim.Grid.AssetServer
38{ 39{
39 /// <summary> 40 /// <summary>
40 /// An asset server 41 /// An asset server
41 /// </summary> 42 /// </summary>
42 public class OpenAsset_Main : conscmd_callback 43 public class OpenAsset_Main : conscmd_callback
43 { 44 {
44 private IObjectContainer db; 45 private IObjectContainer db;
45 46
@@ -76,58 +77,60 @@ namespace OpenSim.Grid.AssetServer
76 77
77 public void Startup() 78 public void Startup()
78 { 79 {
79 m_console.Verbose( "Main.cs:Startup() - Setting up asset DB"); 80 m_console.Verbose("Main.cs:Startup() - Setting up asset DB");
80 setupDB(); 81 setupDB();
81 82
82 m_console.Verbose( "Main.cs:Startup() - Starting HTTP process"); 83 m_console.Verbose("Main.cs:Startup() - Starting HTTP process");
83 AssetHttpServer httpServer = new AssetHttpServer(8003); 84 BaseHttpServer httpServer = new BaseHttpServer(8003);
84 85
86 httpServer.AddStreamHandler( new GetAssetStreamHandler(this));
87 httpServer.AddStreamHandler(new PostAssetStreamHandler( this ));
85 88
86 httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod); 89 //httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod);
87 httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod); 90 //httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod);
88 91
89 httpServer.Start(); 92 httpServer.Start();
90 93
91 } 94 }
92 95
93 public string assetPostMethod(string requestBody, string path, string param) 96 //public string AssetPostMethod(string requestBody, string path, string param)
94 { 97 //{
95 AssetBase asset = new AssetBase(); 98 // AssetBase asset = new AssetBase();
96 asset.Name = ""; 99 // asset.Name = "";
97 asset.FullID = new LLUUID(param); 100 // asset.FullID = new LLUUID(param);
98 Encoding Windows1252Encoding = Encoding.GetEncoding(1252); 101 // Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
99 byte[] buffer = Windows1252Encoding.GetBytes(requestBody); 102 // byte[] buffer = Windows1252Encoding.GetBytes(requestBody);
100 asset.Data = buffer; 103 // asset.Data = buffer;
101 AssetStorage store = new AssetStorage(); 104 // AssetStorage store = new AssetStorage();
102 store.Data = asset.Data; 105 // store.Data = asset.Data;
103 store.Name = asset.Name; 106 // store.Name = asset.Name;
104 store.UUID = asset.FullID; 107 // store.UUID = asset.FullID;
105 db.Set(store); 108 // db.Set(store);
106 db.Commit(); 109 // db.Commit();
107 return ""; 110 // return "";
108 } 111 //}
109 112
110 public string assetGetMethod(string request, string path, string param) 113 //public string AssetGetMethod(string request, string path, string param)
111 { 114 //{
112 Console.WriteLine("got a request " + param); 115 // Console.WriteLine("got a request " + param);
113 byte[] assetdata = getAssetData(new LLUUID(param), false); 116 // byte[] assetdata = GetAssetData(new LLUUID(param), false);
114 if (assetdata != null) 117 // if (assetdata != null)
115 { 118 // {
116 Encoding Windows1252Encoding = Encoding.GetEncoding(1252); 119 // Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
117 string ret = Windows1252Encoding.GetString(assetdata); 120 // string ret = Windows1252Encoding.GetString(assetdata);
118 //string ret = System.Text.Encoding.Unicode.GetString(assetdata); 121 // //string ret = System.Text.Encoding.Unicode.GetString(assetdata);
119 122
120 return ret; 123 // return ret;
121 124
122 } 125 // }
123 else 126 // else
124 { 127 // {
125 return ""; 128 // return "";
126 } 129 // }
127 130
128 } 131 //}
129 132
130 public byte[] getAssetData(LLUUID assetID, bool isTexture) 133 public byte[] GetAssetData(LLUUID assetID, bool isTexture)
131 { 134 {
132 bool found = false; 135 bool found = false;
133 AssetStorage foundAsset = null; 136 AssetStorage foundAsset = null;
@@ -155,7 +158,7 @@ namespace OpenSim.Grid.AssetServer
155 try 158 try
156 { 159 {
157 db = Db4oFactory.OpenFile("assets.yap"); 160 db = Db4oFactory.OpenFile("assets.yap");
158 MainLog.Instance.Verbose( "Main.cs:setupDB() - creation"); 161 MainLog.Instance.Verbose("Main.cs:setupDB() - creation");
159 } 162 }
160 catch (Exception e) 163 catch (Exception e)
161 { 164 {
@@ -305,6 +308,21 @@ namespace OpenSim.Grid.AssetServer
305 return config; 308 return config;
306 }*/ 309 }*/
307 310
311 public void CreateAsset(LLUUID assetId, byte[] assetData)
312 {
313 AssetBase asset = new AssetBase();
314 asset.Name = "";
315 asset.FullID = assetId;
316 asset.Data = assetData;
317
318 AssetStorage store = new AssetStorage();
319 store.Data = asset.Data;
320 store.Name = asset.Name;
321 store.UUID = asset.FullID;
322 db.Set(store);
323 db.Commit();
324 }
325
308 public void RunCmd(string cmd, string[] cmdparams) 326 public void RunCmd(string cmd, string[] cmdparams)
309 { 327 {
310 switch (cmd) 328 switch (cmd)
@@ -324,4 +342,65 @@ namespace OpenSim.Grid.AssetServer
324 { 342 {
325 } 343 }
326 } 344 }
345
346 public class GetAssetStreamHandler : BaseStreamHandler
347 {
348 OpenAsset_Main m_assetManager;
349
350 override public byte[] Handle(string path, Stream request)
351 {
352 string param = GetParam(path);
353
354 byte[] assetdata = m_assetManager.GetAssetData(new LLUUID(param), false);
355 if (assetdata != null)
356 {
357 return assetdata;
358 }
359 else
360 {
361 return new byte[]{};
362 }
363 }
364
365 public GetAssetStreamHandler(OpenAsset_Main assetManager):base( "/assets/", "GET")
366 {
367 m_assetManager = assetManager;
368 }
369 }
370
371 public class PostAssetStreamHandler : BaseStreamHandler
372 {
373 OpenAsset_Main m_assetManager;
374
375 override public byte[] Handle(string path, Stream request)
376 {
377 string param = GetParam(path);
378 LLUUID assetId = new LLUUID(param);
379 byte[] txBuffer = new byte[4096];
380
381 using( BinaryReader binReader = new BinaryReader( request ) )
382 {
383 using (MemoryStream memoryStream = new MemoryStream(4096))
384 {
385 int count;
386 while ((count = binReader.Read(txBuffer, 0, 4096)) > 0)
387 {
388 memoryStream.Write(txBuffer, 0, count);
389 }
390
391 byte[] assetData = memoryStream.ToArray();
392
393 m_assetManager.CreateAsset(assetId, assetData);
394 }
395 }
396
397 return new byte[]{};
398 }
399
400 public PostAssetStreamHandler( OpenAsset_Main assetManager )
401 : base("/assets/", "POST")
402 {
403 m_assetManager = assetManager;
404 }
405 }
327} 406}