From 6a2588454a1ac4bb484ad0b9ee648e9ac156f8db Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 4 Jul 2007 14:12:32 +0000 Subject: * 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 --- OpenSim/Framework/Servers/BaseHttpServer.cs | 163 +++++++++++--------- OpenSim/Framework/Servers/BaseStreamHandler.cs | 40 +++++ OpenSim/Framework/Servers/IStreamHandler.cs | 3 + .../Servers/OpenSim.Framework.Servers.csproj | 3 + .../Servers/OpenSim.Framework.Servers.dll.build | 1 + OpenSim/Framework/Servers/RestStreamHandler.cs | 30 +--- OpenSim/Grid/AssetServer/AssetHttpServer.cs | 125 --------------- OpenSim/Grid/AssetServer/Main.cs | 169 +++++++++++++++------ .../AssetServer/OpenSim.Grid.AssetServer.csproj | 3 - .../AssetServer/OpenSim.Grid.AssetServer.exe.build | 1 - OpenSim/Grid/GridServer/Main.cs | 29 ++-- OpenSim/Grid/UserServer/Main.cs | 4 +- OpenSim/Region/Application/OpenSimMain.cs | 94 +++++++----- OpenSim/Region/Capabilities/Caps.cs | 11 +- 14 files changed, 341 insertions(+), 335 deletions(-) create mode 100644 OpenSim/Framework/Servers/BaseStreamHandler.cs delete mode 100644 OpenSim/Grid/AssetServer/AssetHttpServer.cs (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 9831108..aed538b 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -42,48 +42,56 @@ namespace OpenSim.Framework.Servers { protected Thread m_workerThread; protected HttpListener m_httpListener; - protected Dictionary m_restHandlers = new Dictionary(); + //protected Dictionary m_restHandlers = new Dictionary(); protected Dictionary m_rpcHandlers = new Dictionary(); protected Dictionary m_streamHandlers = new Dictionary(); protected int m_port; - protected bool firstcaps = true; + protected bool m_firstcaps = true; public BaseHttpServer(int port) { m_port = port; } - public void AddStreamHandler( string path, IStreamHandler handler) + public void AddStreamHandler( IStreamHandler handler) { - string handlerKey = handler.HttpMethod + ":" + path; + string httpMethod = handler.HttpMethod; + string path = handler.Path; + + string handlerKey = GetHandlerKey(httpMethod, path); m_streamHandlers.Add(handlerKey, handler); } - public bool AddRestHandler(string method, string path, RestMethod handler) + private static string GetHandlerKey(string httpMethod, string path) { - //Console.WriteLine("adding new REST handler for path " + path); - string methodKey = String.Format("{0}: {1}", method, path); - - if (!this.m_restHandlers.ContainsKey(methodKey)) - { - this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler)); - return true; - } - - //must already have a handler for that path so return false - return false; + return httpMethod + ":" + path; } - public bool RemoveRestHandler(string method, string path) - { - string methodKey = String.Format("{0}: {1}", method, path); - if (this.m_restHandlers.ContainsKey(methodKey)) - { - this.m_restHandlers.Remove(methodKey); - return true; - } - return false; - } + //public bool AddRestHandler(string method, string path, RestMethod handler) + //{ + // //Console.WriteLine("adding new REST handler for path " + path); + // string methodKey = String.Format("{0}: {1}", method, path); + + // if (!this.m_restHandlers.ContainsKey(methodKey)) + // { + // this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler)); + // return true; + // } + + // //must already have a handler for that path so return false + // return false; + //} + + //public bool RemoveRestHandler(string method, string path) + //{ + // string methodKey = String.Format("{0}: {1}", method, path); + // if (this.m_restHandlers.ContainsKey(methodKey)) + // { + // this.m_restHandlers.Remove(methodKey); + // return true; + // } + // return false; + //} public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) { @@ -119,40 +127,40 @@ namespace OpenSim.Framework.Servers return XmlRpcResponseSerializer.Singleton.Serialize(response); } - protected virtual string ParseREST(string request, string path, string method) - { - string response; + //protected virtual string ParseREST(string request, string path, string method) + //{ + // string response; - string requestKey = String.Format("{0}: {1}", method, path); + // string requestKey = String.Format("{0}: {1}", method, path); - string bestMatch = String.Empty; - foreach (string currentKey in m_restHandlers.Keys) - { - if (requestKey.StartsWith(currentKey)) - { - if (currentKey.Length > bestMatch.Length) - { - bestMatch = currentKey; - } - } - } + // string bestMatch = String.Empty; + // foreach (string currentKey in m_restHandlers.Keys) + // { + // if (requestKey.StartsWith(currentKey)) + // { + // if (currentKey.Length > bestMatch.Length) + // { + // bestMatch = currentKey; + // } + // } + // } - RestMethodEntry restMethodEntry; - if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) - { - RestMethod restMethod = restMethodEntry.RestMethod; + // RestMethodEntry restMethodEntry; + // if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) + // { + // RestMethod restMethod = restMethodEntry.RestMethod; - string param = path.Substring(restMethodEntry.Path.Length); - response = restMethod(request, path, param); + // string param = path.Substring(restMethodEntry.Path.Length); + // response = restMethod(request, path, param); - } - else - { - response = String.Empty; - } + // } + // else + // { + // response = String.Empty; + // } - return response; - } + // return response; + //} protected virtual string ParseXMLRPC(string requestBody) @@ -179,13 +187,13 @@ namespace OpenSim.Framework.Servers response.SendChunked = false; string path = request.RawUrl; - string handlerKey = request.HttpMethod + ":" + path; + string handlerKey = GetHandlerKey( request.HttpMethod, path ); IStreamHandler streamHandler; if (TryGetStreamHandler( handlerKey, out streamHandler)) { - byte[] buffer = streamHandler.Handle(path, request.InputStream ); + byte[] buffer = streamHandler.Handle(path, request.InputStream); request.InputStream.Close(); response.ContentType = streamHandler.ContentType; @@ -253,25 +261,25 @@ namespace OpenSim.Framework.Servers response.AddHeader("Content-type", "text/xml"); break; - case "application/xml": - case "application/octet-stream": - // probably LLSD we hope, otherwise it should be ignored by the parser - // responseString = ParseLLSDXML(requestBody); - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "application/xml"); - break; - - case "application/x-www-form-urlencoded": - // a form data POST so send to the REST parser - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "text/html"); - break; - - case null: - // must be REST or invalid crap, so pass to the REST parser - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "text/html"); - break; + //case "application/xml": + //case "application/octet-stream": + // // probably LLSD we hope, otherwise it should be ignored by the parser + // // responseString = ParseLLSDXML(requestBody); + // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); + // response.AddHeader("Content-type", "application/xml"); + // break; + + //case "application/x-www-form-urlencoded": + // // a form data POST so send to the REST parser + // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); + // response.AddHeader("Content-type", "text/html"); + // break; + + //case null: + // // must be REST or invalid crap, so pass to the REST parser + // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); + // response.AddHeader("Content-type", "text/html"); + // break; } @@ -318,5 +326,10 @@ namespace OpenSim.Framework.Servers } } + + public void RemoveStreamHandler(string httpMethod, string path) + { + m_streamHandlers.Remove(GetHandlerKey(httpMethod, path)); + } } } diff --git a/OpenSim/Framework/Servers/BaseStreamHandler.cs b/OpenSim/Framework/Servers/BaseStreamHandler.cs new file mode 100644 index 0000000..95e9707 --- /dev/null +++ b/OpenSim/Framework/Servers/BaseStreamHandler.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace OpenSim.Framework.Servers +{ + public abstract class BaseStreamHandler : IStreamHandler + { + public string ContentType + { + get { return "application/xml"; } + } + + private string m_httpMethod; + public string HttpMethod + { + get { return m_httpMethod; } + } + + private string m_path; + public string Path + { + get { return m_path; } + } + + protected string GetParam( string path ) + { + return path.Substring( m_path.Length ); + } + + public abstract byte[] Handle(string path, Stream request); + + protected BaseStreamHandler(string path, string httpMethod ) + { + m_httpMethod = httpMethod; + m_path = path; + } + } +} diff --git a/OpenSim/Framework/Servers/IStreamHandler.cs b/OpenSim/Framework/Servers/IStreamHandler.cs index bc76e9c..6cab40d 100644 --- a/OpenSim/Framework/Servers/IStreamHandler.cs +++ b/OpenSim/Framework/Servers/IStreamHandler.cs @@ -15,5 +15,8 @@ namespace OpenSim.Framework.Servers // Return required http method string HttpMethod { get;} + + // Return path + string Path { get; } } } diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj index 555bd5d..4eb9844 100644 --- a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj @@ -93,6 +93,9 @@ Code + + Code + Code diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build index a3d140f..5e96ef1 100644 --- a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build @@ -12,6 +12,7 @@ + diff --git a/OpenSim/Framework/Servers/RestStreamHandler.cs b/OpenSim/Framework/Servers/RestStreamHandler.cs index 64d6ea3..7ca369d 100644 --- a/OpenSim/Framework/Servers/RestStreamHandler.cs +++ b/OpenSim/Framework/Servers/RestStreamHandler.cs @@ -5,41 +5,27 @@ using System.IO; namespace OpenSim.Framework.Servers { - public class RestStreamHandler : IStreamHandler + public class RestStreamHandler : BaseStreamHandler { RestMethod m_restMethod; - private string m_contentType; - public string ContentType - { - get { return m_contentType; } - } - - private string m_httpMethod; - public string HttpMethod - { - get { return m_httpMethod; } - } - - - public byte[] Handle(string path, Stream request ) + override public byte[] Handle(string path, Stream request ) { Encoding encoding = Encoding.UTF8; - StreamReader reader = new StreamReader(request, encoding); + StreamReader streamReader = new StreamReader(request, encoding); - string requestBody = reader.ReadToEnd(); - reader.Close(); + string requestBody = streamReader.ReadToEnd(); + streamReader.Close(); - string responseString = m_restMethod(requestBody, path, m_httpMethod); + string param = GetParam(path); + string responseString = m_restMethod(requestBody, path, param ); return Encoding.UTF8.GetBytes(responseString); } - public RestStreamHandler(RestMethod restMethod, string httpMethod, string contentType) + public RestStreamHandler(string httpMethod, string path, RestMethod restMethod) : base( path, httpMethod ) { m_restMethod = restMethod; - m_httpMethod = httpMethod; - m_contentType = contentType; } } } 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 @@ -/* -* Copyright (c) Contributors, http://www.openmetaverse.org/ -* See CONTRIBUTORS.TXT for a full list of copyright holders. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the OpenSim Project nor the -* names of its contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY -* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ -using System; -using System.IO; -using System.Net; -using System.Text; -using System.Text.RegularExpressions; -using OpenSim.Framework.Servers; - -namespace OpenSim.Grid.AssetServer -{ - /// - /// An HTTP server for sending assets - /// - public class AssetHttpServer :BaseHttpServer - { - /// - /// Creates the new asset server - /// - /// Port to initalise on - public AssetHttpServer(int port) - : base(port) - { - } - - /// - /// Handles an HTTP request - /// - /// HTTP State Info - public override void HandleRequest(Object stateinfo) - { - try - { - HttpListenerContext context = (HttpListenerContext)stateinfo; - - HttpListenerRequest request = context.Request; - HttpListenerResponse response = context.Response; - - response.KeepAlive = false; - response.SendChunked = false; - - Stream body = request.InputStream; - Encoding encoding = Encoding.UTF8; - StreamReader reader = new StreamReader(body, encoding); - - string requestBody = reader.ReadToEnd(); - body.Close(); - reader.Close(); - - //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType); - //Console.WriteLine(requestBody); - - string responseString = ""; - switch (request.ContentType) - { - case "text/xml": - // must be XML-RPC, so pass to the XML-RPC parser - - responseString = ParseXMLRPC(requestBody); - responseString = Regex.Replace(responseString, "utf-16", "utf-8"); - - response.AddHeader("Content-type", "text/xml"); - break; - - case "application/xml": - // probably LLSD we hope, otherwise it should be ignored by the parser - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "application/xml"); - break; - - case "application/x-www-form-urlencoded": - // a form data POST so send to the REST parser - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "text/plain"); - break; - - case null: - // must be REST or invalid crap, so pass to the REST parser - responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); - response.AddHeader("Content-type", "text/plain"); - break; - - } - - Encoding Windows1252Encoding = Encoding.GetEncoding(1252); - byte[] buffer = Windows1252Encoding.GetBytes(responseString); - Stream output = response.OutputStream; - response.SendChunked = false; - response.ContentLength64 = buffer.Length; - output.Write(buffer, 0, buffer.Length); - output.Close(); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - } - } - - } -} 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; using libsecondlife; using OpenSim.Framework.Console; using OpenSim.Framework.Types; +using OpenSim.Framework.Servers; namespace OpenSim.Grid.AssetServer { /// /// An asset server /// - public class OpenAsset_Main : conscmd_callback + public class OpenAsset_Main : conscmd_callback { private IObjectContainer db; @@ -76,58 +77,60 @@ namespace OpenSim.Grid.AssetServer public void Startup() { - m_console.Verbose( "Main.cs:Startup() - Setting up asset DB"); + m_console.Verbose("Main.cs:Startup() - Setting up asset DB"); setupDB(); - m_console.Verbose( "Main.cs:Startup() - Starting HTTP process"); - AssetHttpServer httpServer = new AssetHttpServer(8003); + m_console.Verbose("Main.cs:Startup() - Starting HTTP process"); + BaseHttpServer httpServer = new BaseHttpServer(8003); + httpServer.AddStreamHandler( new GetAssetStreamHandler(this)); + httpServer.AddStreamHandler(new PostAssetStreamHandler( this )); - httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod); - httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod); + //httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod); + //httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod); httpServer.Start(); } - public string assetPostMethod(string requestBody, string path, string param) - { - AssetBase asset = new AssetBase(); - asset.Name = ""; - asset.FullID = new LLUUID(param); - Encoding Windows1252Encoding = Encoding.GetEncoding(1252); - byte[] buffer = Windows1252Encoding.GetBytes(requestBody); - asset.Data = buffer; - AssetStorage store = new AssetStorage(); - store.Data = asset.Data; - store.Name = asset.Name; - store.UUID = asset.FullID; - db.Set(store); - db.Commit(); - return ""; - } - - public string assetGetMethod(string request, string path, string param) - { - Console.WriteLine("got a request " + param); - byte[] assetdata = getAssetData(new LLUUID(param), false); - if (assetdata != null) - { - Encoding Windows1252Encoding = Encoding.GetEncoding(1252); - string ret = Windows1252Encoding.GetString(assetdata); - //string ret = System.Text.Encoding.Unicode.GetString(assetdata); - - return ret; - - } - else - { - return ""; - } - - } - - public byte[] getAssetData(LLUUID assetID, bool isTexture) + //public string AssetPostMethod(string requestBody, string path, string param) + //{ + // AssetBase asset = new AssetBase(); + // asset.Name = ""; + // asset.FullID = new LLUUID(param); + // Encoding Windows1252Encoding = Encoding.GetEncoding(1252); + // byte[] buffer = Windows1252Encoding.GetBytes(requestBody); + // asset.Data = buffer; + // AssetStorage store = new AssetStorage(); + // store.Data = asset.Data; + // store.Name = asset.Name; + // store.UUID = asset.FullID; + // db.Set(store); + // db.Commit(); + // return ""; + //} + + //public string AssetGetMethod(string request, string path, string param) + //{ + // Console.WriteLine("got a request " + param); + // byte[] assetdata = GetAssetData(new LLUUID(param), false); + // if (assetdata != null) + // { + // Encoding Windows1252Encoding = Encoding.GetEncoding(1252); + // string ret = Windows1252Encoding.GetString(assetdata); + // //string ret = System.Text.Encoding.Unicode.GetString(assetdata); + + // return ret; + + // } + // else + // { + // return ""; + // } + + //} + + public byte[] GetAssetData(LLUUID assetID, bool isTexture) { bool found = false; AssetStorage foundAsset = null; @@ -155,7 +158,7 @@ namespace OpenSim.Grid.AssetServer try { db = Db4oFactory.OpenFile("assets.yap"); - MainLog.Instance.Verbose( "Main.cs:setupDB() - creation"); + MainLog.Instance.Verbose("Main.cs:setupDB() - creation"); } catch (Exception e) { @@ -305,6 +308,21 @@ namespace OpenSim.Grid.AssetServer return config; }*/ + public void CreateAsset(LLUUID assetId, byte[] assetData) + { + AssetBase asset = new AssetBase(); + asset.Name = ""; + asset.FullID = assetId; + asset.Data = assetData; + + AssetStorage store = new AssetStorage(); + store.Data = asset.Data; + store.Name = asset.Name; + store.UUID = asset.FullID; + db.Set(store); + db.Commit(); + } + public void RunCmd(string cmd, string[] cmdparams) { switch (cmd) @@ -324,4 +342,65 @@ namespace OpenSim.Grid.AssetServer { } } + + public class GetAssetStreamHandler : BaseStreamHandler + { + OpenAsset_Main m_assetManager; + + override public byte[] Handle(string path, Stream request) + { + string param = GetParam(path); + + byte[] assetdata = m_assetManager.GetAssetData(new LLUUID(param), false); + if (assetdata != null) + { + return assetdata; + } + else + { + return new byte[]{}; + } + } + + public GetAssetStreamHandler(OpenAsset_Main assetManager):base( "/assets/", "GET") + { + m_assetManager = assetManager; + } + } + + public class PostAssetStreamHandler : BaseStreamHandler + { + OpenAsset_Main m_assetManager; + + override public byte[] Handle(string path, Stream request) + { + string param = GetParam(path); + LLUUID assetId = new LLUUID(param); + byte[] txBuffer = new byte[4096]; + + using( BinaryReader binReader = new BinaryReader( request ) ) + { + using (MemoryStream memoryStream = new MemoryStream(4096)) + { + int count; + while ((count = binReader.Read(txBuffer, 0, 4096)) > 0) + { + memoryStream.Write(txBuffer, 0, count); + } + + byte[] assetData = memoryStream.ToArray(); + + m_assetManager.CreateAsset(assetId, assetData); + } + } + + return new byte[]{}; + } + + public PostAssetStreamHandler( OpenAsset_Main assetManager ) + : base("/assets/", "POST") + { + m_assetManager = assetManager; + } + } } 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 @@ - - Code - Code 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 @@ - 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 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod); httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod); - httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod); - httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod); - httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod); - httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod); - - - // lbsa71 : This code snippet taken from old http server. - // I have no idea what this was supposed to do - looks like an infinite recursion to me. - // case "regions": - //// DIRTY HACK ALERT - //Console.Notice("/regions/ accessed"); - //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1])); - //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod); - //break; - - // lbsa71 : I guess these were never used? - //Listener.Prefixes.Add("http://+:8001/gods/"); - //Listener.Prefixes.Add("http://+:8001/highestuuid/"); - //Listener.Prefixes.Add("http://+:8001/uuidblocks/"); + httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod )); + httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod )); + + httpServer.AddStreamHandler( new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod )); + httpServer.AddStreamHandler( new RestStreamHandler("POST","/regions/", m_gridManager.RestSetRegionMethod )); + + //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod); + //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod); + //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod); + //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod); httpServer.Start(); 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 httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); - httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod); - + httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod )); + httpServer.Start(); m_console.Status("Userserver 0.3 - Startup complete"); } diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index eaa067b..e2486bd 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -44,6 +44,7 @@ using OpenSim.Region.ClientStack; using OpenSim.Region.Communications.Local; using OpenSim.Region.Communications.OGS1; using OpenSim.Region.Environment.Scenes; +using System.Text; namespace OpenSim { @@ -51,7 +52,7 @@ namespace OpenSim public class OpenSimMain : RegionApplicationBase, conscmd_callback { protected CommunicationsManager commsManager; - // private CheckSumServer checkServer; + // private CheckSumServer checkServer; private bool m_silent; private string m_logFilename = "region-console-" + Guid.NewGuid().ToString() + ".log"; @@ -84,10 +85,10 @@ namespace OpenSim m_log = new LogBase(m_logFilename, "Region", this, m_silent); MainLog.Instance = m_log; - m_log.Verbose( "Main.cs:Startup() - Loading configuration"); + m_log.Verbose("Main.cs:Startup() - Loading configuration"); this.serversData.InitConfig(this.m_sandbox, this.localConfig); this.localConfig.Close();//for now we can close it as no other classes read from it , but this should change - + ScenePresence.LoadTextureFile("avatar-texture.dat"); ClientView.TerrainManager = new TerrainManager(new SecondLife()); @@ -95,8 +96,8 @@ namespace OpenSim if (m_sandbox) { this.SetupLocalGridServers(); - // this.checkServer = new CheckSumServer(12036); - // this.checkServer.ServerListener(); + // this.checkServer = new CheckSumServer(12036); + // this.checkServer.ServerListener(); this.commsManager = new CommunicationsLocal(this.serversData); } else @@ -114,7 +115,7 @@ namespace OpenSim this.SetupWorld(); - m_log.Verbose( "Main.cs:Startup() - Initialising HTTP server"); + m_log.Verbose("Main.cs:Startup() - Initialising HTTP server"); @@ -124,7 +125,7 @@ namespace OpenSim } //Start http server - m_log.Verbose( "Main.cs:Startup() - Starting HTTP server"); + m_log.Verbose("Main.cs:Startup() - Starting HTTP server"); httpServer.Start(); // Start UDP servers @@ -145,7 +146,7 @@ namespace OpenSim } catch (Exception e) { - m_log.Error( e.Message + "\nSorry, could not setup local cache"); + m_log.Error(e.Message + "\nSorry, could not setup local cache"); Environment.Exit(1); } @@ -160,7 +161,7 @@ namespace OpenSim } catch (Exception e) { - m_log.Error( e.Message + "\nSorry, could not setup remote cache"); + m_log.Error(e.Message + "\nSorry, could not setup remote cache"); Environment.Exit(1); } } @@ -226,7 +227,7 @@ namespace OpenSim LocalWorld.LoadStorageDLL("OpenSim.Region.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded. LocalWorld.LoadWorldMap(); - m_log.Verbose( "Main.cs:Startup() - Starting up messaging system"); + m_log.Verbose("Main.cs:Startup() - Starting up messaging system"); LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this.m_physicsEngine); LocalWorld.PhysScene.SetTerrain(LocalWorld.Terrain.getHeights1D()); LocalWorld.LoadPrimsFromStorage(); @@ -244,21 +245,36 @@ namespace OpenSim } } - protected override void SetupHttpListener() + private class SimStatusHandler : IStreamHandler { - httpServer = new BaseHttpServer(this.serversData.HttpListenerPort); //regionData[0].IPListenPort); + public byte[] Handle(string path, Stream request) + { + return Encoding.UTF8.GetBytes("OK"); + } - if (!this.m_sandbox) + public string ContentType { + get { return "text/plain"; } + } - // we are in Grid mode so set a XmlRpc handler to handle "expect_user" calls from the user server + public string HttpMethod + { + get { return "GET"; } + } + + public string Path + { + get { return "/simstatus/"; } + } + } + protected override void SetupHttpListener() + { + httpServer = new BaseHttpServer(this.serversData.HttpListenerPort); //regionData[0].IPListenPort); - httpServer.AddRestHandler("GET", "/simstatus/", - delegate(string request, string path, string param) - { - return "OK"; - }); + if (!this.m_sandbox) + { + httpServer.AddStreamHandler( new SimStatusHandler() ); } } @@ -340,7 +356,7 @@ namespace OpenSim switch (attri) { default: - m_log.Warn( "Main.cs: SetupFromConfig() - Invalid value for PhysicsEngine attribute, terminating"); + m_log.Warn("Main.cs: SetupFromConfig() - Invalid value for PhysicsEngine attribute, terminating"); Environment.Exit(1); break; @@ -376,11 +392,11 @@ namespace OpenSim /// public virtual void Shutdown() { - m_log.Verbose( "Main.cs:Shutdown() - Closing all threads"); - m_log.Verbose( "Main.cs:Shutdown() - Killing listener thread"); - m_log.Verbose( "Main.cs:Shutdown() - Killing clients"); + m_log.Verbose("Main.cs:Shutdown() - Closing all threads"); + m_log.Verbose("Main.cs:Shutdown() - Killing listener thread"); + m_log.Verbose("Main.cs:Shutdown() - Killing clients"); // IMPLEMENT THIS - m_log.Verbose( "Main.cs:Shutdown() - Closing console and terminating"); + m_log.Verbose("Main.cs:Shutdown() - Closing console and terminating"); for (int i = 0; i < m_localWorld.Count; i++) { ((Scene)m_localWorld[i]).Close(); @@ -400,8 +416,8 @@ namespace OpenSim switch (command) { case "help": - m_log.Error( "show users - show info about connected users"); - m_log.Error( "shutdown - disconnect all clients and shutdown"); + m_log.Error("show users - show info about connected users"); + m_log.Error("shutdown - disconnect all clients and shutdown"); break; case "show": @@ -415,7 +431,7 @@ namespace OpenSim string result = ""; for (int i = 0; i < m_localWorld.Count; i++) { - if (!((Scene)m_localWorld[i]).Terrain.RunTerrainCmd(cmdparams, ref result,m_localWorld[i].RegionInfo.RegionName)) + if (!((Scene)m_localWorld[i]).Terrain.RunTerrainCmd(cmdparams, ref result, m_localWorld[i].RegionInfo.RegionName)) { m_log.Error(result); } @@ -427,7 +443,7 @@ namespace OpenSim break; default: - m_log.Error( "Unknown command"); + m_log.Error("Unknown command"); break; } } @@ -441,22 +457,22 @@ namespace OpenSim switch (ShowWhat) { case "uptime": - m_log.Error( "OpenSim has been running since " + startuptime.ToString()); - m_log.Error( "That is " + (DateTime.Now - startuptime).ToString()); + m_log.Error("OpenSim has been running since " + startuptime.ToString()); + m_log.Error("That is " + (DateTime.Now - startuptime).ToString()); break; case "users": ScenePresence TempAv; - m_log.Error( String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP","World")); + m_log.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}{6,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP", "World")); for (int i = 0; i < m_localWorld.Count; i++) { - foreach (libsecondlife.LLUUID UUID in ((Scene)m_localWorld[i]).Entities.Keys) - { - if (((Scene)m_localWorld[i]).Entities[UUID].ToString() == "OpenSim.world.Avatar") - { - TempAv = (ScenePresence)((Scene)m_localWorld[i]).Entities[UUID]; - m_log.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.AgentId, "Unknown", "Unknown"), ((Scene)m_localWorld[i]).RegionInfo.RegionName); - } - } + foreach (libsecondlife.LLUUID UUID in ((Scene)m_localWorld[i]).Entities.Keys) + { + if (((Scene)m_localWorld[i]).Entities[UUID].ToString() == "OpenSim.world.Avatar") + { + TempAv = (ScenePresence)((Scene)m_localWorld[i]).Entities[UUID]; + m_log.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}{6,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.AgentId, "Unknown", "Unknown"), ((Scene)m_localWorld[i]).RegionInfo.RegionName); + } + } } break; } diff --git a/OpenSim/Region/Capabilities/Caps.cs b/OpenSim/Region/Capabilities/Caps.cs index 0f6c471..1d07683 100644 --- a/OpenSim/Region/Capabilities/Caps.cs +++ b/OpenSim/Region/Capabilities/Caps.cs @@ -82,7 +82,7 @@ namespace OpenSim.Region.Capabilities private void AddCapsHandler( BaseHttpServer httpListener, string path, RestMethod restMethod ) { string capsBase = "/CAPS/" + m_capsObjectPath; - httpListener.AddStreamHandler(capsBase + path, new RestStreamHandler(restMethod, "POST", "application/xml")); + httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); } /// @@ -211,9 +211,11 @@ namespace OpenSim.Region.Capabilities string res = ""; LLUUID newAsset = LLUUID.Random(); LLUUID newInvItem = LLUUID.Random(); - string uploaderPath = m_capsObjectPath + Util.RandomClass.Next(5000, 8000).ToString("0000"); + string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); AssetUploader uploader = new AssetUploader(newAsset, newInvItem, uploaderPath, this.httpListener); - httpListener.AddRestHandler("POST", "/CAPS/" + uploaderPath, uploader.uploaderCaps); + + AddCapsHandler( httpListener, uploaderPath, uploader.uploaderCaps); + string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + uploaderPath; //Console.WriteLine("uploader url is " + uploaderURL); res += ""; @@ -269,7 +271,8 @@ namespace OpenSim.Region.Capabilities res += ""; // Console.WriteLine("asset " + newAssetID.ToStringHyphenated() + " , inventory item " + inv.ToStringHyphenated()); - httpListener.RemoveRestHandler("POST", "/CAPS/" + uploaderPath); + httpListener.RemoveStreamHandler("POST", "/CAPS/" + uploaderPath); + if (OnUpLoad != null) { OnUpLoad(newAssetID, inv, data); -- cgit v1.1