* Added StreamHandler support
* Implemented RestStreamHandler * Some caps functions now use it * Moved out RestMethodEntry from httpserver * The IStreamHandler interface now reports required method and Content-TypeSugilite
parent
827cccb99c
commit
9a51949cb4
|
@ -29,6 +29,17 @@ Global
|
|||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectDependencies) = postSolution
|
||||
({FD2D303D-0000-0000-0000-000000000000}).2 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({17F7F694-0000-0000-0000-000000000000}).1 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({17F7F6BE-0000-0000-0000-000000000000}).2 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({6ECC56A9-0000-0000-0000-000000000000}).1 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).4 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({60FCC3A6-0000-0000-0000-000000000000}).4 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({60FCC3A6-0000-0000-0000-000000000000}).7 = ({4B7BFD1C-0000-0000-0000-000000000000})
|
||||
({2FC96F92-0000-0000-0000-000000000000}).4 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({2FC96F92-0000-0000-0000-000000000000}).7 = ({586E2916-0000-0000-0000-000000000000})
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{36B72A9B-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{36B72A9B-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
|
|
85
OpenSim.sln
85
OpenSim.sln
|
@ -1,5 +1,5 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C# Express 2005
|
||||
# Visual Studio 2005
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim", "OpenSim\Region\Application\OpenSim.csproj", "{438A9556-0000-0000-0000-000000000000}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Framework", "OpenSim\Framework\General\OpenSim.Framework.csproj", "{8ACA2445-0000-0000-0000-000000000000}"
|
||||
|
@ -57,6 +57,89 @@ Global
|
|||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectDependencies) = postSolution
|
||||
({438A9556-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).4 = ({CB52B7E7-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).5 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).6 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).7 = ({C74E4A30-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).8 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).9 = ({586E2916-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).10 = ({61FCCDB3-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).11 = ({DC3698B2-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).12 = ({BFB5D807-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).13 = ({4806E378-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).14 = ({DCBA491C-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).15 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({438A9556-0000-0000-0000-000000000000}).16 = ({C9E0F891-0000-0000-0000-000000000000})
|
||||
({8ACA2445-0000-0000-0000-000000000000}).2 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({CB52B7E7-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({CB52B7E7-0000-0000-0000-000000000000}).2 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({FD2D303D-0000-0000-0000-000000000000}).2 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({C74E4A30-0000-0000-0000-000000000000}).0 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({2CC71860-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({2CC71860-0000-0000-0000-000000000000}).2 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).4 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).5 = ({C74E4A30-0000-0000-0000-000000000000})
|
||||
({586E2916-0000-0000-0000-000000000000}).6 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({61FCCDB3-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({39038E85-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({39038E85-0000-0000-0000-000000000000}).2 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({39038E85-0000-0000-0000-000000000000}).3 = ({61FCCDB3-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).5 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).6 = ({61FCCDB3-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).7 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({DC3698B2-0000-0000-0000-000000000000}).8 = ({C9E0F891-0000-0000-0000-000000000000})
|
||||
({BFB5D807-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({BFB5D807-0000-0000-0000-000000000000}).2 = ({CB52B7E7-0000-0000-0000-000000000000})
|
||||
({BFB5D807-0000-0000-0000-000000000000}).3 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({BFB5D807-0000-0000-0000-000000000000}).4 = ({586E2916-0000-0000-0000-000000000000})
|
||||
({4806E378-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({4806E378-0000-0000-0000-000000000000}).2 = ({CB52B7E7-0000-0000-0000-000000000000})
|
||||
({4806E378-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({4806E378-0000-0000-0000-000000000000}).4 = ({36B72A9B-0000-0000-0000-000000000000})
|
||||
({4806E378-0000-0000-0000-000000000000}).5 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).4 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).5 = ({CB52B7E7-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).6 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).7 = ({C74E4A30-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).8 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).9 = ({61FCCDB3-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).10 = ({39038E85-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).11 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({DCBA491C-0000-0000-0000-000000000000}).12 = ({C9E0F891-0000-0000-0000-000000000000})
|
||||
({241A8CDD-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({241A8CDD-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({98C7B681-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({98C7B681-0000-0000-0000-000000000000}).2 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({15B4FEF3-0000-0000-0000-000000000000}).1 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({F4FF31EB-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({F4FF31EB-0000-0000-0000-000000000000}).2 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({90620634-0000-0000-0000-000000000000}).2 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({A6D191D8-0000-0000-0000-000000000000}).1 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
({A4691E59-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({A4691E59-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({43DB702D-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({43DB702D-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({477B9270-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({477B9270-0000-0000-0000-000000000000}).2 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).2 = ({CB52B7E7-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).4 = ({2CC71860-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).5 = ({586E2916-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).6 = ({61FCCDB3-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).7 = ({39038E85-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).8 = ({DC3698B2-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).9 = ({BFB5D807-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).10 = ({DCBA491C-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).11 = ({241A8CDD-0000-0000-0000-000000000000})
|
||||
({24B12448-0000-0000-0000-000000000000}).12 = ({F4FF31EB-0000-0000-0000-000000000000})
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
|
|
|
@ -40,27 +40,6 @@ namespace OpenSim.Framework.Servers
|
|||
{
|
||||
public class BaseHttpServer
|
||||
{
|
||||
protected class RestMethodEntry
|
||||
{
|
||||
private string m_path;
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
private RestMethod m_restMethod;
|
||||
public RestMethod RestMethod
|
||||
{
|
||||
get { return m_restMethod; }
|
||||
}
|
||||
|
||||
public RestMethodEntry(string path, RestMethod restMethod)
|
||||
{
|
||||
m_path = path;
|
||||
m_restMethod = restMethod;
|
||||
}
|
||||
}
|
||||
|
||||
protected Thread m_workerThread;
|
||||
protected HttpListener m_httpListener;
|
||||
protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>();
|
||||
|
@ -74,9 +53,10 @@ namespace OpenSim.Framework.Servers
|
|||
m_port = port;
|
||||
}
|
||||
|
||||
private void AddStreamHandler(string path, IStreamHandler handler)
|
||||
public void AddStreamHandler( string path, IStreamHandler handler)
|
||||
{
|
||||
m_streamHandlers.Add(path, handler);
|
||||
string handlerKey = handler.HttpMethod + ":" + path;
|
||||
m_streamHandlers.Add(handlerKey, handler);
|
||||
}
|
||||
|
||||
public bool AddRestHandler(string method, string path, RestMethod handler)
|
||||
|
@ -179,18 +159,12 @@ namespace OpenSim.Framework.Servers
|
|||
{
|
||||
string responseString = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
|
||||
|
||||
string methodName = request.MethodName;
|
||||
|
||||
responseString = ProcessXMLRPCMethod(methodName, request);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
return responseString;
|
||||
}
|
||||
|
||||
|
@ -205,12 +179,19 @@ namespace OpenSim.Framework.Servers
|
|||
response.SendChunked = false;
|
||||
|
||||
string path = request.RawUrl;
|
||||
string handlerKey = request.HttpMethod + ":" + path;
|
||||
|
||||
IStreamHandler streamHandler;
|
||||
|
||||
if(TryGetStreamHandler(path, out streamHandler))
|
||||
if (TryGetStreamHandler( handlerKey, out streamHandler))
|
||||
{
|
||||
streamHandler.Handle(path, request.InputStream, response.OutputStream );
|
||||
byte[] buffer = streamHandler.Handle(path, request.InputStream );
|
||||
request.InputStream.Close();
|
||||
|
||||
response.ContentType = streamHandler.ContentType;
|
||||
response.ContentLength64 = buffer.LongLength;
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -218,13 +199,13 @@ namespace OpenSim.Framework.Servers
|
|||
}
|
||||
}
|
||||
|
||||
private bool TryGetStreamHandler(string path, out IStreamHandler streamHandler )
|
||||
private bool TryGetStreamHandler(string handlerKey, out IStreamHandler streamHandler)
|
||||
{
|
||||
string bestMatch = null;
|
||||
|
||||
foreach (string pattern in m_streamHandlers.Keys)
|
||||
{
|
||||
if (path.StartsWith(pattern))
|
||||
if (handlerKey.StartsWith(pattern))
|
||||
{
|
||||
if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,13 @@ namespace OpenSim.Framework.Servers
|
|||
{
|
||||
public interface IStreamHandler
|
||||
{
|
||||
void Handle(string path, Stream request, Stream response);
|
||||
// Handle request stream, return byte array
|
||||
byte[] Handle(string path, Stream request );
|
||||
|
||||
// Return response content type
|
||||
string ContentType { get; }
|
||||
|
||||
// Return required http method
|
||||
string HttpMethod { get;}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
|
@ -6,8 +6,7 @@
|
|||
<ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
<ApplicationIcon></ApplicationIcon>
|
||||
<AssemblyKeyContainerName>
|
||||
</AssemblyKeyContainerName>
|
||||
<AssemblyName>OpenSim.Framework.Servers</AssemblyName>
|
||||
|
@ -16,11 +15,9 @@
|
|||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||
<DelaySign>false</DelaySign>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>
|
||||
</AppDesignerFolder>
|
||||
<AppDesignerFolder></AppDesignerFolder>
|
||||
<RootNamespace>OpenSim.Framework.Servers</RootNamespace>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<StartupObject></StartupObject>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
</PropertyGroup>
|
||||
|
@ -31,8 +28,7 @@
|
|||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>False</Optimize>
|
||||
|
@ -41,8 +37,7 @@
|
|||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<NoWarn></NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
|
@ -51,8 +46,7 @@
|
|||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>True</Optimize>
|
||||
|
@ -61,8 +55,7 @@
|
|||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<NoWarn></NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="libsecondlife.dll" >
|
||||
|
@ -73,7 +66,6 @@
|
|||
<HintPath>System.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" >
|
||||
<HintPath>System.Xml.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
|
@ -107,14 +99,21 @@
|
|||
<Compile Include="ILlsdMethodHandler.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IStreamHandler.cs" />
|
||||
<Compile Include="IStreamHandler.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LlsdMethod.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RestMethod.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RestStreamHandler.cs" />
|
||||
<Compile Include="RestMethodEntry.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RestStreamHandler.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UDPServerBase.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
<include name="BaseHttpServer.cs" />
|
||||
<include name="CheckSumServer.cs" />
|
||||
<include name="ILlsdMethodHandler.cs" />
|
||||
<include name="IStreamHandler.cs" />
|
||||
<include name="LlsdMethod.cs" />
|
||||
<include name="RestMethod.cs" />
|
||||
<include name="RestMethodEntry.cs" />
|
||||
<include name="RestStreamHandler.cs" />
|
||||
<include name="UDPServerBase.cs" />
|
||||
<include name="XmlRpcMethod.cs" />
|
||||
</sources>
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Framework.Servers
|
||||
{
|
||||
public class RestMethodEntry
|
||||
{
|
||||
private string m_path;
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
private RestMethod m_restMethod;
|
||||
public RestMethod RestMethod
|
||||
{
|
||||
get { return m_restMethod; }
|
||||
}
|
||||
|
||||
public RestMethodEntry(string path, RestMethod restMethod)
|
||||
{
|
||||
m_path = path;
|
||||
m_restMethod = restMethod;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,9 +7,39 @@ namespace OpenSim.Framework.Servers
|
|||
{
|
||||
public class RestStreamHandler : IStreamHandler
|
||||
{
|
||||
public void Handle( string path, Stream request, Stream response )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
Encoding encoding = Encoding.UTF8;
|
||||
StreamReader reader = new StreamReader(request, encoding);
|
||||
|
||||
string requestBody = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
|
||||
string responseString = m_restMethod(requestBody, path, m_httpMethod);
|
||||
|
||||
return Encoding.UTF8.GetBytes(responseString);
|
||||
}
|
||||
|
||||
public RestStreamHandler(RestMethod restMethod, string httpMethod, string contentType)
|
||||
{
|
||||
m_restMethod = restMethod;
|
||||
m_httpMethod = httpMethod;
|
||||
m_contentType = contentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ namespace OpenSim.Region.Capabilities
|
|||
|
||||
public class Caps
|
||||
{
|
||||
private string httpListenerHostName;
|
||||
private int httpListenPort;
|
||||
private string capsObjectPath = "00001-";
|
||||
private string requestPath = "0000/";
|
||||
private string mapLayerPath = "0001/";
|
||||
private string newInventory = "0002/";
|
||||
private string requestTexture = "0003/";
|
||||
private string m_httpListenerHostName;
|
||||
private int m_httpListenPort;
|
||||
private string m_capsObjectPath = "00001-";
|
||||
private string m_requestPath = "0000/";
|
||||
private string m_mapLayerPath = "0001/";
|
||||
private string m_newInventory = "0002/";
|
||||
private string m_requestTexture = "0003/";
|
||||
private string eventQueue = "0100/";
|
||||
private BaseHttpServer httpListener;
|
||||
private LLUUID agentID;
|
||||
|
@ -58,10 +58,10 @@ namespace OpenSim.Region.Capabilities
|
|||
public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent)
|
||||
{
|
||||
assetCache = assetCach;
|
||||
capsObjectPath = capsPath;
|
||||
m_capsObjectPath = capsPath;
|
||||
httpListener = httpServer;
|
||||
httpListenerHostName = httpListen;
|
||||
httpListenPort = httpPort;
|
||||
m_httpListenerHostName = httpListen;
|
||||
m_httpListenPort = httpPort;
|
||||
agentID = agent;
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,18 @@ namespace OpenSim.Region.Capabilities
|
|||
public void RegisterHandlers()
|
||||
{
|
||||
Console.WriteLine("registering CAPS handlers");
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + requestPath, CapsRequest);
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + mapLayerPath, MapLayer);
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + newInventory, NewAgentInventory);
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + eventQueue, ProcessEventQueue);
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + requestTexture, RequestTexture);
|
||||
|
||||
AddCapsHandler( httpListener, m_requestPath, CapsRequest);
|
||||
AddCapsHandler( httpListener, m_mapLayerPath, MapLayer);
|
||||
AddCapsHandler( httpListener, m_newInventory, NewAgentInventory);
|
||||
AddCapsHandler( httpListener, eventQueue, ProcessEventQueue);
|
||||
AddCapsHandler( httpListener, m_requestTexture, RequestTexture);
|
||||
}
|
||||
|
||||
private void AddCapsHandler( BaseHttpServer httpListener, string path, RestMethod restMethod )
|
||||
{
|
||||
string capsBase = "/CAPS/" + m_capsObjectPath;
|
||||
httpListener.AddStreamHandler(capsBase + path, new RestStreamHandler(restMethod, "POST", "application/xml"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -100,10 +107,10 @@ namespace OpenSim.Region.Capabilities
|
|||
protected LLSDCapsDetails GetCapabilities()
|
||||
{
|
||||
LLSDCapsDetails caps = new LLSDCapsDetails();
|
||||
string capsBaseUrl = "http://" + httpListenerHostName + ":" + httpListenPort.ToString() + "/CAPS/" + capsObjectPath;
|
||||
string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath;
|
||||
|
||||
caps.MapLayer = capsBaseUrl + mapLayerPath;
|
||||
caps.NewFileAgentInventory = capsBaseUrl + newInventory;
|
||||
caps.MapLayer = capsBaseUrl + m_mapLayerPath;
|
||||
caps.NewFileAgentInventory = capsBaseUrl + m_newInventory;
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
@ -204,10 +211,10 @@ namespace OpenSim.Region.Capabilities
|
|||
string res = "";
|
||||
LLUUID newAsset = LLUUID.Random();
|
||||
LLUUID newInvItem = LLUUID.Random();
|
||||
string uploaderPath = capsObjectPath + Util.RandomClass.Next(5000, 8000).ToString("0000");
|
||||
string uploaderPath = m_capsObjectPath + Util.RandomClass.Next(5000, 8000).ToString("0000");
|
||||
AssetUploader uploader = new AssetUploader(newAsset, newInvItem, uploaderPath, this.httpListener);
|
||||
httpListener.AddRestHandler("POST", "/CAPS/" + uploaderPath, uploader.uploaderCaps);
|
||||
string uploaderURL = "http://" + httpListenerHostName + ":" + httpListenPort.ToString() + "/CAPS/" + uploaderPath;
|
||||
string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + uploaderPath;
|
||||
//Console.WriteLine("uploader url is " + uploaderURL);
|
||||
res += "<llsd><map>";
|
||||
res += "<key>uploader</key><string>" + uploaderURL + "</string>";
|
||||
|
|
Loading…
Reference in New Issue