aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid
diff options
context:
space:
mode:
authorlbsa712007-07-04 14:12:32 +0000
committerlbsa712007-07-04 14:12:32 +0000
commit6a2588454a1ac4bb484ad0b9ee648e9ac156f8db (patch)
treefd4e0d33f65e36365d15d991f95d323e6d15e8b1 /OpenSim/Grid
parent* Added StreamHandler support (diff)
downloadopensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.zip
opensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.gz
opensim-SC_OLD-6a2588454a1ac4bb484ad0b9ee648e9ac156f8db.tar.bz2
opensim-SC_OLD-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/AssetHttpServer.cs125
-rw-r--r--OpenSim/Grid/AssetServer/Main.cs169
-rw-r--r--OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.csproj3
-rw-r--r--OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.exe.build1
-rw-r--r--OpenSim/Grid/GridServer/Main.cs29
-rw-r--r--OpenSim/Grid/UserServer/Main.cs4
6 files changed, 136 insertions, 195 deletions
diff --git a/OpenSim/Grid/AssetServer/AssetHttpServer.cs b/OpenSim/Grid/AssetServer/AssetHttpServer.cs
deleted file mode 100644
index 9546891..0000000
--- a/OpenSim/Grid/AssetServer/AssetHttpServer.cs
+++ /dev/null
@@ -1,125 +0,0 @@
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.Net;
31using System.Text;
32using System.Text.RegularExpressions;
33using OpenSim.Framework.Servers;
34
35namespace OpenSim.Grid.AssetServer
36{
37 /// <summary>
38 /// An HTTP server for sending assets
39 /// </summary>
40 public class AssetHttpServer :BaseHttpServer
41 {
42 /// <summary>
43 /// Creates the new asset server
44 /// </summary>
45 /// <param name="port">Port to initalise on</param>
46 public AssetHttpServer(int port)
47 : base(port)
48 {
49 }
50
51 /// <summary>
52 /// Handles an HTTP request
53 /// </summary>
54 /// <param name="stateinfo">HTTP State Info</param>
55 public override void HandleRequest(Object stateinfo)
56 {
57 try
58 {
59 HttpListenerContext context = (HttpListenerContext)stateinfo;
60
61 HttpListenerRequest request = context.Request;
62 HttpListenerResponse response = context.Response;
63
64 response.KeepAlive = false;
65 response.SendChunked = false;
66
67 Stream body = request.InputStream;
68 Encoding encoding = Encoding.UTF8;
69 StreamReader reader = new StreamReader(body, encoding);
70
71 string requestBody = reader.ReadToEnd();
72 body.Close();
73 reader.Close();
74
75 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
76 //Console.WriteLine(requestBody);
77
78 string responseString = "";
79 switch (request.ContentType)
80 {
81 case "text/xml":
82 // must be XML-RPC, so pass to the XML-RPC parser
83
84 responseString = ParseXMLRPC(requestBody);
85 responseString = Regex.Replace(responseString, "utf-16", "utf-8");
86
87 response.AddHeader("Content-type", "text/xml");
88 break;
89
90 case "application/xml":
91 // probably LLSD we hope, otherwise it should be ignored by the parser
92 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
93 response.AddHeader("Content-type", "application/xml");
94 break;
95
96 case "application/x-www-form-urlencoded":
97 // a form data POST so send to the REST parser
98 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
99 response.AddHeader("Content-type", "text/plain");
100 break;
101
102 case null:
103 // must be REST or invalid crap, so pass to the REST parser
104 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
105 response.AddHeader("Content-type", "text/plain");
106 break;
107
108 }
109
110 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
111 byte[] buffer = Windows1252Encoding.GetBytes(responseString);
112 Stream output = response.OutputStream;
113 response.SendChunked = false;
114 response.ContentLength64 = buffer.Length;
115 output.Write(buffer, 0, buffer.Length);
116 output.Close();
117 }
118 catch (Exception e)
119 {
120 Console.WriteLine(e.ToString());
121 }
122 }
123
124 }
125}
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}
diff --git a/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.csproj b/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.csproj
index caebca3..5ba4642 100644
--- a/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.csproj
+++ b/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.csproj
@@ -98,9 +98,6 @@
98 <ItemGroup> 98 <ItemGroup>
99 </ItemGroup> 99 </ItemGroup>
100 <ItemGroup> 100 <ItemGroup>
101 <Compile Include="AssetHttpServer.cs">
102 <SubType>Code</SubType>
103 </Compile>
104 <Compile Include="Main.cs"> 101 <Compile Include="Main.cs">
105 <SubType>Code</SubType> 102 <SubType>Code</SubType>
106 </Compile> 103 </Compile>
diff --git a/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.exe.build b/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.exe.build
index 88724f6..a922fe7 100644
--- a/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.exe.build
+++ b/OpenSim/Grid/AssetServer/OpenSim.Grid.AssetServer.exe.build
@@ -11,7 +11,6 @@
11 <resources prefix="OpenSim.Grid.AssetServer" dynamicprefix="true" > 11 <resources prefix="OpenSim.Grid.AssetServer" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AssetHttpServer.cs" />
15 <include name="Main.cs" /> 14 <include name="Main.cs" />
16 <include name="Properties/AssemblyInfo.cs" /> 15 <include name="Properties/AssemblyInfo.cs" />
17 </sources> 16 </sources>
diff --git a/OpenSim/Grid/GridServer/Main.cs b/OpenSim/Grid/GridServer/Main.cs
index 2e76cee..a990ff7 100644
--- a/OpenSim/Grid/GridServer/Main.cs
+++ b/OpenSim/Grid/GridServer/Main.cs
@@ -127,25 +127,16 @@ namespace OpenSim.Grid.GridServer
127 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod); 127 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
128 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod); 128 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
129 129
130 httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod); 130 httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod ));
131 httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod); 131 httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod ));
132 httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod); 132
133 httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod); 133 httpServer.AddStreamHandler( new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod ));
134 134 httpServer.AddStreamHandler( new RestStreamHandler("POST","/regions/", m_gridManager.RestSetRegionMethod ));
135 135
136 // lbsa71 : This code snippet taken from old http server. 136 //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
137 // I have no idea what this was supposed to do - looks like an infinite recursion to me. 137 //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
138 // case "regions": 138 //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
139 //// DIRTY HACK ALERT 139 //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
140 //Console.Notice("/regions/ accessed");
141 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
142 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
143 //break;
144
145 // lbsa71 : I guess these were never used?
146 //Listener.Prefixes.Add("http://+:8001/gods/");
147 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
148 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
149 140
150 httpServer.Start(); 141 httpServer.Start();
151 142
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs
index 5560e7d..30465a3 100644
--- a/OpenSim/Grid/UserServer/Main.cs
+++ b/OpenSim/Grid/UserServer/Main.cs
@@ -105,8 +105,8 @@ namespace OpenSim.Grid.UserServer
105 httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); 105 httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
106 httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); 106 httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
107 107
108 httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod); 108 httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod ));
109 109
110 httpServer.Start(); 110 httpServer.Start();
111 m_console.Status("Userserver 0.3 - Startup complete"); 111 m_console.Status("Userserver 0.3 - Startup complete");
112 } 112 }