From 2ceff87a02d9862497d1d8fa965851ae2d9c9b1b Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 11 Jul 2007 17:47:25 +0000 Subject: More work on UserProfile and inventory cache (still currently not enabled). Asset uploading over CAPS now works, and although inventory isn't really working yet, this should now at least enables texturing of prims. --- OpenSim/Framework/Servers/BinaryStreamHandler.cs | 44 ++++++++++++++++++++++++ OpenSim/Framework/Servers/RestMethod.cs | 1 + 2 files changed, 45 insertions(+) create mode 100644 OpenSim/Framework/Servers/BinaryStreamHandler.cs (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/BinaryStreamHandler.cs b/OpenSim/Framework/Servers/BinaryStreamHandler.cs new file mode 100644 index 0000000..302dbff --- /dev/null +++ b/OpenSim/Framework/Servers/BinaryStreamHandler.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace OpenSim.Framework.Servers +{ + + public class BinaryStreamHandler : BaseStreamHandler + { + BinaryMethod m_restMethod; + + override public byte[] Handle(string path, Stream request) + { + byte[] data = ReadFully(request); + string param = GetParam(path); + string responseString = m_restMethod(data, path, param); + + return Encoding.UTF8.GetBytes(responseString); + } + + public BinaryStreamHandler(string httpMethod, string path, BinaryMethod restMethod) + : base(httpMethod, path) + { + m_restMethod = restMethod; + } + + public byte[] ReadFully(Stream stream) + { + byte[] buffer = new byte[32768]; + using (MemoryStream ms = new MemoryStream()) + { + while (true) + { + int read = stream.Read(buffer, 0, buffer.Length); + if (read <= 0) + return ms.ToArray(); + ms.Write(buffer, 0, read); + } + } + } + } + +} diff --git a/OpenSim/Framework/Servers/RestMethod.cs b/OpenSim/Framework/Servers/RestMethod.cs index c6cb230..2a92fc1 100644 --- a/OpenSim/Framework/Servers/RestMethod.cs +++ b/OpenSim/Framework/Servers/RestMethod.cs @@ -28,4 +28,5 @@ namespace OpenSim.Framework.Servers { public delegate string RestMethod( string request, string path, string param ); + public delegate string BinaryMethod(byte[] data, string path, string param); } -- cgit v1.1