diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 63 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/IStreamHandler.cs | 9 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj | 49 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build | 3 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/RestMethodEntry.cs | 27 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/RestStreamHandler.cs | 34 |
6 files changed, 116 insertions, 69 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 8fa577c..9831108 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -40,27 +40,6 @@ namespace OpenSim.Framework.Servers | |||
40 | { | 40 | { |
41 | public class BaseHttpServer | 41 | public class BaseHttpServer |
42 | { | 42 | { |
43 | protected class RestMethodEntry | ||
44 | { | ||
45 | private string m_path; | ||
46 | public string Path | ||
47 | { | ||
48 | get { return m_path; } | ||
49 | } | ||
50 | |||
51 | private RestMethod m_restMethod; | ||
52 | public RestMethod RestMethod | ||
53 | { | ||
54 | get { return m_restMethod; } | ||
55 | } | ||
56 | |||
57 | public RestMethodEntry(string path, RestMethod restMethod) | ||
58 | { | ||
59 | m_path = path; | ||
60 | m_restMethod = restMethod; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | protected Thread m_workerThread; | 43 | protected Thread m_workerThread; |
65 | protected HttpListener m_httpListener; | 44 | protected HttpListener m_httpListener; |
66 | protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); | 45 | protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); |
@@ -74,9 +53,10 @@ namespace OpenSim.Framework.Servers | |||
74 | m_port = port; | 53 | m_port = port; |
75 | } | 54 | } |
76 | 55 | ||
77 | private void AddStreamHandler(string path, IStreamHandler handler) | 56 | public void AddStreamHandler( string path, IStreamHandler handler) |
78 | { | 57 | { |
79 | m_streamHandlers.Add(path, handler); | 58 | string handlerKey = handler.HttpMethod + ":" + path; |
59 | m_streamHandlers.Add(handlerKey, handler); | ||
80 | } | 60 | } |
81 | 61 | ||
82 | public bool AddRestHandler(string method, string path, RestMethod handler) | 62 | public bool AddRestHandler(string method, string path, RestMethod handler) |
@@ -179,18 +159,12 @@ namespace OpenSim.Framework.Servers | |||
179 | { | 159 | { |
180 | string responseString = String.Empty; | 160 | string responseString = String.Empty; |
181 | 161 | ||
182 | try | 162 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); |
183 | { | ||
184 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
185 | 163 | ||
186 | string methodName = request.MethodName; | 164 | string methodName = request.MethodName; |
165 | |||
166 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
187 | 167 | ||
188 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
189 | } | ||
190 | catch | ||
191 | { | ||
192 | //Console.WriteLine(e.ToString()); | ||
193 | } | ||
194 | return responseString; | 168 | return responseString; |
195 | } | 169 | } |
196 | 170 | ||
@@ -205,12 +179,19 @@ namespace OpenSim.Framework.Servers | |||
205 | response.SendChunked = false; | 179 | response.SendChunked = false; |
206 | 180 | ||
207 | string path = request.RawUrl; | 181 | string path = request.RawUrl; |
182 | string handlerKey = request.HttpMethod + ":" + path; | ||
208 | 183 | ||
209 | IStreamHandler streamHandler; | 184 | IStreamHandler streamHandler; |
210 | 185 | ||
211 | if(TryGetStreamHandler(path, out streamHandler)) | 186 | if (TryGetStreamHandler( handlerKey, out streamHandler)) |
212 | { | 187 | { |
213 | streamHandler.Handle(path, request.InputStream, response.OutputStream ); | 188 | byte[] buffer = streamHandler.Handle(path, request.InputStream ); |
189 | request.InputStream.Close(); | ||
190 | |||
191 | response.ContentType = streamHandler.ContentType; | ||
192 | response.ContentLength64 = buffer.LongLength; | ||
193 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
194 | response.OutputStream.Close(); | ||
214 | } | 195 | } |
215 | else | 196 | else |
216 | { | 197 | { |
@@ -218,22 +199,22 @@ namespace OpenSim.Framework.Servers | |||
218 | } | 199 | } |
219 | } | 200 | } |
220 | 201 | ||
221 | private bool TryGetStreamHandler(string path, out IStreamHandler streamHandler ) | 202 | private bool TryGetStreamHandler(string handlerKey, out IStreamHandler streamHandler) |
222 | { | 203 | { |
223 | string bestMatch = null; | 204 | string bestMatch = null; |
224 | 205 | ||
225 | foreach (string pattern in m_streamHandlers.Keys) | 206 | foreach (string pattern in m_streamHandlers.Keys) |
226 | { | 207 | { |
227 | if (path.StartsWith(pattern)) | 208 | if (handlerKey.StartsWith(pattern)) |
228 | { | 209 | { |
229 | if (String.IsNullOrEmpty( bestMatch ) || pattern.Length > bestMatch.Length) | 210 | if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) |
230 | { | 211 | { |
231 | bestMatch = pattern; | 212 | bestMatch = pattern; |
232 | } | 213 | } |
233 | } | 214 | } |
234 | } | 215 | } |
235 | 216 | ||
236 | if( String.IsNullOrEmpty( bestMatch ) ) | 217 | if (String.IsNullOrEmpty(bestMatch)) |
237 | { | 218 | { |
238 | streamHandler = null; | 219 | streamHandler = null; |
239 | return false; | 220 | return false; |
diff --git a/OpenSim/Framework/Servers/IStreamHandler.cs b/OpenSim/Framework/Servers/IStreamHandler.cs index 88ae641..bc76e9c 100644 --- a/OpenSim/Framework/Servers/IStreamHandler.cs +++ b/OpenSim/Framework/Servers/IStreamHandler.cs | |||
@@ -7,6 +7,13 @@ namespace OpenSim.Framework.Servers | |||
7 | { | 7 | { |
8 | public interface IStreamHandler | 8 | public interface IStreamHandler |
9 | { | 9 | { |
10 | void Handle(string path, Stream request, Stream response); | 10 | // Handle request stream, return byte array |
11 | byte[] Handle(string path, Stream request ); | ||
12 | |||
13 | // Return response content type | ||
14 | string ContentType { get; } | ||
15 | |||
16 | // Return required http method | ||
17 | string HttpMethod { get;} | ||
11 | } | 18 | } |
12 | } | 19 | } |
diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj index 956a9bc..555bd5d 100644 --- a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.csproj | |||
@@ -1,4 +1,4 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
2 | <PropertyGroup> | 2 | <PropertyGroup> |
3 | <ProjectType>Local</ProjectType> | 3 | <ProjectType>Local</ProjectType> |
4 | <ProductVersion>8.0.50727</ProductVersion> | 4 | <ProductVersion>8.0.50727</ProductVersion> |
@@ -6,8 +6,7 @@ | |||
6 | <ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid> | 6 | <ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid> |
7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | 7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | 8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
9 | <ApplicationIcon> | 9 | <ApplicationIcon></ApplicationIcon> |
10 | </ApplicationIcon> | ||
11 | <AssemblyKeyContainerName> | 10 | <AssemblyKeyContainerName> |
12 | </AssemblyKeyContainerName> | 11 | </AssemblyKeyContainerName> |
13 | <AssemblyName>OpenSim.Framework.Servers</AssemblyName> | 12 | <AssemblyName>OpenSim.Framework.Servers</AssemblyName> |
@@ -16,11 +15,9 @@ | |||
16 | <DefaultTargetSchema>IE50</DefaultTargetSchema> | 15 | <DefaultTargetSchema>IE50</DefaultTargetSchema> |
17 | <DelaySign>false</DelaySign> | 16 | <DelaySign>false</DelaySign> |
18 | <OutputType>Library</OutputType> | 17 | <OutputType>Library</OutputType> |
19 | <AppDesignerFolder> | 18 | <AppDesignerFolder></AppDesignerFolder> |
20 | </AppDesignerFolder> | ||
21 | <RootNamespace>OpenSim.Framework.Servers</RootNamespace> | 19 | <RootNamespace>OpenSim.Framework.Servers</RootNamespace> |
22 | <StartupObject> | 20 | <StartupObject></StartupObject> |
23 | </StartupObject> | ||
24 | <FileUpgradeFlags> | 21 | <FileUpgradeFlags> |
25 | </FileUpgradeFlags> | 22 | </FileUpgradeFlags> |
26 | </PropertyGroup> | 23 | </PropertyGroup> |
@@ -31,8 +28,7 @@ | |||
31 | <ConfigurationOverrideFile> | 28 | <ConfigurationOverrideFile> |
32 | </ConfigurationOverrideFile> | 29 | </ConfigurationOverrideFile> |
33 | <DefineConstants>TRACE;DEBUG</DefineConstants> | 30 | <DefineConstants>TRACE;DEBUG</DefineConstants> |
34 | <DocumentationFile> | 31 | <DocumentationFile></DocumentationFile> |
35 | </DocumentationFile> | ||
36 | <DebugSymbols>True</DebugSymbols> | 32 | <DebugSymbols>True</DebugSymbols> |
37 | <FileAlignment>4096</FileAlignment> | 33 | <FileAlignment>4096</FileAlignment> |
38 | <Optimize>False</Optimize> | 34 | <Optimize>False</Optimize> |
@@ -41,8 +37,7 @@ | |||
41 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | 37 | <RemoveIntegerChecks>False</RemoveIntegerChecks> |
42 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | 38 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
43 | <WarningLevel>4</WarningLevel> | 39 | <WarningLevel>4</WarningLevel> |
44 | <NoWarn> | 40 | <NoWarn></NoWarn> |
45 | </NoWarn> | ||
46 | </PropertyGroup> | 41 | </PropertyGroup> |
47 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | 42 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
48 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | 43 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
@@ -51,8 +46,7 @@ | |||
51 | <ConfigurationOverrideFile> | 46 | <ConfigurationOverrideFile> |
52 | </ConfigurationOverrideFile> | 47 | </ConfigurationOverrideFile> |
53 | <DefineConstants>TRACE</DefineConstants> | 48 | <DefineConstants>TRACE</DefineConstants> |
54 | <DocumentationFile> | 49 | <DocumentationFile></DocumentationFile> |
55 | </DocumentationFile> | ||
56 | <DebugSymbols>False</DebugSymbols> | 50 | <DebugSymbols>False</DebugSymbols> |
57 | <FileAlignment>4096</FileAlignment> | 51 | <FileAlignment>4096</FileAlignment> |
58 | <Optimize>True</Optimize> | 52 | <Optimize>True</Optimize> |
@@ -61,24 +55,22 @@ | |||
61 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | 55 | <RemoveIntegerChecks>False</RemoveIntegerChecks> |
62 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | 56 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
63 | <WarningLevel>4</WarningLevel> | 57 | <WarningLevel>4</WarningLevel> |
64 | <NoWarn> | 58 | <NoWarn></NoWarn> |
65 | </NoWarn> | ||
66 | </PropertyGroup> | 59 | </PropertyGroup> |
67 | <ItemGroup> | 60 | <ItemGroup> |
68 | <Reference Include="libsecondlife.dll"> | 61 | <Reference Include="libsecondlife.dll" > |
69 | <HintPath>..\..\..\bin\libsecondlife.dll</HintPath> | 62 | <HintPath>..\..\..\bin\libsecondlife.dll</HintPath> |
70 | <Private>False</Private> | 63 | <Private>False</Private> |
71 | </Reference> | 64 | </Reference> |
72 | <Reference Include="System"> | 65 | <Reference Include="System" > |
73 | <HintPath>System.dll</HintPath> | 66 | <HintPath>System.dll</HintPath> |
74 | <Private>False</Private> | 67 | <Private>False</Private> |
75 | </Reference> | 68 | </Reference> |
76 | <Reference Include="System.Data" /> | 69 | <Reference Include="System.Xml" > |
77 | <Reference Include="System.Xml"> | ||
78 | <HintPath>System.Xml.dll</HintPath> | 70 | <HintPath>System.Xml.dll</HintPath> |
79 | <Private>False</Private> | 71 | <Private>False</Private> |
80 | </Reference> | 72 | </Reference> |
81 | <Reference Include="XMLRPC.dll"> | 73 | <Reference Include="XMLRPC.dll" > |
82 | <HintPath>..\..\..\bin\XMLRPC.dll</HintPath> | 74 | <HintPath>..\..\..\bin\XMLRPC.dll</HintPath> |
83 | <Private>False</Private> | 75 | <Private>False</Private> |
84 | </Reference> | 76 | </Reference> |
@@ -88,13 +80,13 @@ | |||
88 | <Name>OpenSim.Framework</Name> | 80 | <Name>OpenSim.Framework</Name> |
89 | <Project>{8ACA2445-0000-0000-0000-000000000000}</Project> | 81 | <Project>{8ACA2445-0000-0000-0000-000000000000}</Project> |
90 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | 82 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> |
91 | <Private>False</Private> | 83 | <Private>False</Private> |
92 | </ProjectReference> | 84 | </ProjectReference> |
93 | <ProjectReference Include="..\Console\OpenSim.Framework.Console.csproj"> | 85 | <ProjectReference Include="..\Console\OpenSim.Framework.Console.csproj"> |
94 | <Name>OpenSim.Framework.Console</Name> | 86 | <Name>OpenSim.Framework.Console</Name> |
95 | <Project>{A7CD0630-0000-0000-0000-000000000000}</Project> | 87 | <Project>{A7CD0630-0000-0000-0000-000000000000}</Project> |
96 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | 88 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> |
97 | <Private>False</Private> | 89 | <Private>False</Private> |
98 | </ProjectReference> | 90 | </ProjectReference> |
99 | </ItemGroup> | 91 | </ItemGroup> |
100 | <ItemGroup> | 92 | <ItemGroup> |
@@ -107,14 +99,21 @@ | |||
107 | <Compile Include="ILlsdMethodHandler.cs"> | 99 | <Compile Include="ILlsdMethodHandler.cs"> |
108 | <SubType>Code</SubType> | 100 | <SubType>Code</SubType> |
109 | </Compile> | 101 | </Compile> |
110 | <Compile Include="IStreamHandler.cs" /> | 102 | <Compile Include="IStreamHandler.cs"> |
103 | <SubType>Code</SubType> | ||
104 | </Compile> | ||
111 | <Compile Include="LlsdMethod.cs"> | 105 | <Compile Include="LlsdMethod.cs"> |
112 | <SubType>Code</SubType> | 106 | <SubType>Code</SubType> |
113 | </Compile> | 107 | </Compile> |
114 | <Compile Include="RestMethod.cs"> | 108 | <Compile Include="RestMethod.cs"> |
115 | <SubType>Code</SubType> | 109 | <SubType>Code</SubType> |
116 | </Compile> | 110 | </Compile> |
117 | <Compile Include="RestStreamHandler.cs" /> | 111 | <Compile Include="RestMethodEntry.cs"> |
112 | <SubType>Code</SubType> | ||
113 | </Compile> | ||
114 | <Compile Include="RestStreamHandler.cs"> | ||
115 | <SubType>Code</SubType> | ||
116 | </Compile> | ||
118 | <Compile Include="UDPServerBase.cs"> | 117 | <Compile Include="UDPServerBase.cs"> |
119 | <SubType>Code</SubType> | 118 | <SubType>Code</SubType> |
120 | </Compile> | 119 | </Compile> |
@@ -129,4 +128,4 @@ | |||
129 | <PostBuildEvent> | 128 | <PostBuildEvent> |
130 | </PostBuildEvent> | 129 | </PostBuildEvent> |
131 | </PropertyGroup> | 130 | </PropertyGroup> |
132 | </Project> \ No newline at end of file | 131 | </Project> |
diff --git a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build index 22d98dc..a3d140f 100644 --- a/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build +++ b/OpenSim/Framework/Servers/OpenSim.Framework.Servers.dll.build | |||
@@ -14,8 +14,11 @@ | |||
14 | <include name="BaseHttpServer.cs" /> | 14 | <include name="BaseHttpServer.cs" /> |
15 | <include name="CheckSumServer.cs" /> | 15 | <include name="CheckSumServer.cs" /> |
16 | <include name="ILlsdMethodHandler.cs" /> | 16 | <include name="ILlsdMethodHandler.cs" /> |
17 | <include name="IStreamHandler.cs" /> | ||
17 | <include name="LlsdMethod.cs" /> | 18 | <include name="LlsdMethod.cs" /> |
18 | <include name="RestMethod.cs" /> | 19 | <include name="RestMethod.cs" /> |
20 | <include name="RestMethodEntry.cs" /> | ||
21 | <include name="RestStreamHandler.cs" /> | ||
19 | <include name="UDPServerBase.cs" /> | 22 | <include name="UDPServerBase.cs" /> |
20 | <include name="XmlRpcMethod.cs" /> | 23 | <include name="XmlRpcMethod.cs" /> |
21 | </sources> | 24 | </sources> |
diff --git a/OpenSim/Framework/Servers/RestMethodEntry.cs b/OpenSim/Framework/Servers/RestMethodEntry.cs new file mode 100644 index 0000000..ab926e0 --- /dev/null +++ b/OpenSim/Framework/Servers/RestMethodEntry.cs | |||
@@ -0,0 +1,27 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Framework.Servers | ||
6 | { | ||
7 | public class RestMethodEntry | ||
8 | { | ||
9 | private string m_path; | ||
10 | public string Path | ||
11 | { | ||
12 | get { return m_path; } | ||
13 | } | ||
14 | |||
15 | private RestMethod m_restMethod; | ||
16 | public RestMethod RestMethod | ||
17 | { | ||
18 | get { return m_restMethod; } | ||
19 | } | ||
20 | |||
21 | public RestMethodEntry(string path, RestMethod restMethod) | ||
22 | { | ||
23 | m_path = path; | ||
24 | m_restMethod = restMethod; | ||
25 | } | ||
26 | } | ||
27 | } | ||
diff --git a/OpenSim/Framework/Servers/RestStreamHandler.cs b/OpenSim/Framework/Servers/RestStreamHandler.cs index 145a184..64d6ea3 100644 --- a/OpenSim/Framework/Servers/RestStreamHandler.cs +++ b/OpenSim/Framework/Servers/RestStreamHandler.cs | |||
@@ -7,9 +7,39 @@ namespace OpenSim.Framework.Servers | |||
7 | { | 7 | { |
8 | public class RestStreamHandler : IStreamHandler | 8 | public class RestStreamHandler : IStreamHandler |
9 | { | 9 | { |
10 | public void Handle( string path, Stream request, Stream response ) | 10 | RestMethod m_restMethod; |
11 | |||
12 | private string m_contentType; | ||
13 | public string ContentType | ||
14 | { | ||
15 | get { return m_contentType; } | ||
16 | } | ||
17 | |||
18 | private string m_httpMethod; | ||
19 | public string HttpMethod | ||
20 | { | ||
21 | get { return m_httpMethod; } | ||
22 | } | ||
23 | |||
24 | |||
25 | public byte[] Handle(string path, Stream request ) | ||
26 | { | ||
27 | Encoding encoding = Encoding.UTF8; | ||
28 | StreamReader reader = new StreamReader(request, encoding); | ||
29 | |||
30 | string requestBody = reader.ReadToEnd(); | ||
31 | reader.Close(); | ||
32 | |||
33 | string responseString = m_restMethod(requestBody, path, m_httpMethod); | ||
34 | |||
35 | return Encoding.UTF8.GetBytes(responseString); | ||
36 | } | ||
37 | |||
38 | public RestStreamHandler(RestMethod restMethod, string httpMethod, string contentType) | ||
11 | { | 39 | { |
12 | 40 | m_restMethod = restMethod; | |
41 | m_httpMethod = httpMethod; | ||
42 | m_contentType = contentType; | ||
13 | } | 43 | } |
14 | } | 44 | } |
15 | } | 45 | } |