* 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-Type
Sugilite
lbsa71 2007-07-04 11:47:32 +00:00
parent 827cccb99c
commit 9a51949cb4
9 changed files with 408 additions and 260 deletions

View File

@ -29,6 +29,17 @@ Global
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection 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 GlobalSection(ProjectConfigurationPlatforms) = postSolution
{36B72A9B-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {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 {36B72A9B-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU

View File

@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim", "OpenSim\Region\Application\OpenSim.csproj", "{438A9556-0000-0000-0000-000000000000}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Framework", "OpenSim\Framework\General\OpenSim.Framework.csproj", "{8ACA2445-0000-0000-0000-000000000000}" 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 Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection 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 GlobalSection(ProjectConfigurationPlatforms) = postSolution
{438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {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 {438A9556-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU

View File

@ -40,27 +40,6 @@ namespace OpenSim.Framework.Servers
{ {
public class BaseHttpServer 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 Thread m_workerThread;
protected HttpListener m_httpListener; protected HttpListener m_httpListener;
protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>();
@ -74,9 +53,10 @@ namespace OpenSim.Framework.Servers
m_port = port; 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) public bool AddRestHandler(string method, string path, RestMethod handler)
@ -179,18 +159,12 @@ namespace OpenSim.Framework.Servers
{ {
string responseString = String.Empty; string responseString = String.Empty;
try
{
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
string methodName = request.MethodName; string methodName = request.MethodName;
responseString = ProcessXMLRPCMethod(methodName, request); responseString = ProcessXMLRPCMethod(methodName, request);
}
catch
{
//Console.WriteLine(e.ToString());
}
return responseString; return responseString;
} }
@ -205,12 +179,19 @@ namespace OpenSim.Framework.Servers
response.SendChunked = false; response.SendChunked = false;
string path = request.RawUrl; string path = request.RawUrl;
string handlerKey = request.HttpMethod + ":" + path;
IStreamHandler streamHandler; 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 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; string bestMatch = null;
foreach (string pattern in m_streamHandlers.Keys) foreach (string pattern in m_streamHandlers.Keys)
{ {
if (path.StartsWith(pattern)) if (handlerKey.StartsWith(pattern))
{ {
if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
{ {

View File

@ -7,6 +7,13 @@ namespace OpenSim.Framework.Servers
{ {
public interface IStreamHandler 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;}
} }
} }

View File

@ -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> <PropertyGroup>
<ProjectType>Local</ProjectType> <ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion> <ProductVersion>8.0.50727</ProductVersion>
@ -6,8 +6,7 @@
<ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid> <ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon> <ApplicationIcon></ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName> <AssemblyKeyContainerName>
</AssemblyKeyContainerName> </AssemblyKeyContainerName>
<AssemblyName>OpenSim.Framework.Servers</AssemblyName> <AssemblyName>OpenSim.Framework.Servers</AssemblyName>
@ -16,11 +15,9 @@
<DefaultTargetSchema>IE50</DefaultTargetSchema> <DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign> <DelaySign>false</DelaySign>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder> <AppDesignerFolder></AppDesignerFolder>
</AppDesignerFolder>
<RootNamespace>OpenSim.Framework.Servers</RootNamespace> <RootNamespace>OpenSim.Framework.Servers</RootNamespace>
<StartupObject> <StartupObject></StartupObject>
</StartupObject>
<FileUpgradeFlags> <FileUpgradeFlags>
</FileUpgradeFlags> </FileUpgradeFlags>
</PropertyGroup> </PropertyGroup>
@ -31,8 +28,7 @@
<ConfigurationOverrideFile> <ConfigurationOverrideFile>
</ConfigurationOverrideFile> </ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants> <DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile> <DocumentationFile></DocumentationFile>
</DocumentationFile>
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize> <Optimize>False</Optimize>
@ -41,8 +37,7 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoWarn> <NoWarn></NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -51,8 +46,7 @@
<ConfigurationOverrideFile> <ConfigurationOverrideFile>
</ConfigurationOverrideFile> </ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<DocumentationFile> <DocumentationFile></DocumentationFile>
</DocumentationFile>
<DebugSymbols>False</DebugSymbols> <DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize> <Optimize>True</Optimize>
@ -61,8 +55,7 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoWarn> <NoWarn></NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="libsecondlife.dll" > <Reference Include="libsecondlife.dll" >
@ -73,7 +66,6 @@
<HintPath>System.dll</HintPath> <HintPath>System.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" > <Reference Include="System.Xml" >
<HintPath>System.Xml.dll</HintPath> <HintPath>System.Xml.dll</HintPath>
<Private>False</Private> <Private>False</Private>
@ -107,14 +99,21 @@
<Compile Include="ILlsdMethodHandler.cs"> <Compile Include="ILlsdMethodHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="IStreamHandler.cs" /> <Compile Include="IStreamHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LlsdMethod.cs"> <Compile Include="LlsdMethod.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="RestMethod.cs"> <Compile Include="RestMethod.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </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"> <Compile Include="UDPServerBase.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -14,8 +14,11 @@
<include name="BaseHttpServer.cs" /> <include name="BaseHttpServer.cs" />
<include name="CheckSumServer.cs" /> <include name="CheckSumServer.cs" />
<include name="ILlsdMethodHandler.cs" /> <include name="ILlsdMethodHandler.cs" />
<include name="IStreamHandler.cs" />
<include name="LlsdMethod.cs" /> <include name="LlsdMethod.cs" />
<include name="RestMethod.cs" /> <include name="RestMethod.cs" />
<include name="RestMethodEntry.cs" />
<include name="RestStreamHandler.cs" />
<include name="UDPServerBase.cs" /> <include name="UDPServerBase.cs" />
<include name="XmlRpcMethod.cs" /> <include name="XmlRpcMethod.cs" />
</sources> </sources>

View File

@ -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;
}
}
}

View File

@ -7,9 +7,39 @@ namespace OpenSim.Framework.Servers
{ {
public class RestStreamHandler : IStreamHandler 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;
} }
} }
} }

View File

@ -41,13 +41,13 @@ namespace OpenSim.Region.Capabilities
public class Caps public class Caps
{ {
private string httpListenerHostName; private string m_httpListenerHostName;
private int httpListenPort; private int m_httpListenPort;
private string capsObjectPath = "00001-"; private string m_capsObjectPath = "00001-";
private string requestPath = "0000/"; private string m_requestPath = "0000/";
private string mapLayerPath = "0001/"; private string m_mapLayerPath = "0001/";
private string newInventory = "0002/"; private string m_newInventory = "0002/";
private string requestTexture = "0003/"; private string m_requestTexture = "0003/";
private string eventQueue = "0100/"; private string eventQueue = "0100/";
private BaseHttpServer httpListener; private BaseHttpServer httpListener;
private LLUUID agentID; 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) public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent)
{ {
assetCache = assetCach; assetCache = assetCach;
capsObjectPath = capsPath; m_capsObjectPath = capsPath;
httpListener = httpServer; httpListener = httpServer;
httpListenerHostName = httpListen; m_httpListenerHostName = httpListen;
httpListenPort = httpPort; m_httpListenPort = httpPort;
agentID = agent; agentID = agent;
} }
@ -71,11 +71,18 @@ namespace OpenSim.Region.Capabilities
public void RegisterHandlers() public void RegisterHandlers()
{ {
Console.WriteLine("registering CAPS handlers"); Console.WriteLine("registering CAPS handlers");
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + requestPath, CapsRequest);
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + mapLayerPath, MapLayer); AddCapsHandler( httpListener, m_requestPath, CapsRequest);
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + newInventory, NewAgentInventory); AddCapsHandler( httpListener, m_mapLayerPath, MapLayer);
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + eventQueue, ProcessEventQueue); AddCapsHandler( httpListener, m_newInventory, NewAgentInventory);
httpListener.AddRestHandler("POST", "/CAPS/" + capsObjectPath + requestTexture, RequestTexture); 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> /// <summary>
@ -100,10 +107,10 @@ namespace OpenSim.Region.Capabilities
protected LLSDCapsDetails GetCapabilities() protected LLSDCapsDetails GetCapabilities()
{ {
LLSDCapsDetails caps = new LLSDCapsDetails(); 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.MapLayer = capsBaseUrl + m_mapLayerPath;
caps.NewFileAgentInventory = capsBaseUrl + newInventory; caps.NewFileAgentInventory = capsBaseUrl + m_newInventory;
return caps; return caps;
} }
@ -204,10 +211,10 @@ namespace OpenSim.Region.Capabilities
string res = ""; string res = "";
LLUUID newAsset = LLUUID.Random(); LLUUID newAsset = LLUUID.Random();
LLUUID newInvItem = 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); AssetUploader uploader = new AssetUploader(newAsset, newInvItem, uploaderPath, this.httpListener);
httpListener.AddRestHandler("POST", "/CAPS/" + uploaderPath, uploader.uploaderCaps); 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); //Console.WriteLine("uploader url is " + uploaderURL);
res += "<llsd><map>"; res += "<llsd><map>";
res += "<key>uploader</key><string>" + uploaderURL + "</string>"; res += "<key>uploader</key><string>" + uploaderURL + "</string>";