aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/OSHttpHandler.cs102
-rw-r--r--OpenSim/Framework/Servers/OSHttpServer.cs66
2 files changed, 127 insertions, 41 deletions
diff --git a/OpenSim/Framework/Servers/OSHttpHandler.cs b/OpenSim/Framework/Servers/OSHttpHandler.cs
new file mode 100644
index 0000000..c4ab81c
--- /dev/null
+++ b/OpenSim/Framework/Servers/OSHttpHandler.cs
@@ -0,0 +1,102 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text.RegularExpressions;
31
32namespace OpenSim.Framework.Servers
33{
34 /// <sumary>
35 /// Any OSHttpHandler must return one of the following results:
36 /// <list type = "table">
37 /// <listheader>
38 /// <term>result code</term>
39 /// <description>meaning</description>
40 /// </listheader>
41 /// <item>
42 /// <term>Pass</term>
43 /// <description>handler did not process the request</request>
44 /// </item>
45 /// <item>
46 /// <term>Handled</term>
47 /// <description>handler did process the request, OSHttpServer
48 /// can clean up and close the request</request>
49 /// </item>
50 /// <item>
51 /// <term>Detached</term>
52 /// <description>handler handles the request, OSHttpServer
53 /// can forget about the request and should not touch it as
54 /// the handler has taken control</request>
55 /// </item>
56 /// </list>
57 /// </summary>
58 public enum OSHttpHandlerResult
59 {
60 Pass,
61 Handled,
62 Detached,
63 }
64
65 public interface OSHttpHandler
66 {
67 /// <summary>
68 /// Regular expression used to match against path of incoming
69 /// HTTP request. If you want to match any string either use
70 /// '.*' or null. To match for the emtpy string use '^$'
71 /// </summary>
72 Regex Path
73 {
74 get;
75 }
76
77 /// <summary>
78 /// Dictionary of (header name, regular expression) tuples,
79 /// allowing us to match on HTTP header fields.
80 /// </summary>
81 Dictionary<string, Regex> Headers
82 {
83 get;
84 }
85
86 /// <summary>
87 /// Dictionary of (header name, regular expression) tuples,
88 /// allowing us to match on HTTP header fields.
89 /// </summary>
90 /// <remarks>
91 /// This feature is currently not implemented as it requires
92 /// (trivial) changes to HttpServer.HttpListener that have not
93 /// been implemented.
94 /// </remarks>
95 Regex IPEndPointWhitelist
96 {
97 get;
98 }
99
100 OSHttpHandlerResult Process(OSHttpRequest request);
101 }
102} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/OSHttpServer.cs b/OpenSim/Framework/Servers/OSHttpServer.cs
index c022062..169ce13 100644
--- a/OpenSim/Framework/Servers/OSHttpServer.cs
+++ b/OpenSim/Framework/Servers/OSHttpServer.cs
@@ -40,39 +40,6 @@ using HttpListener = HttpServer.HttpListener;
40 40
41namespace OpenSim.Framework.Servers 41namespace OpenSim.Framework.Servers
42{ 42{
43 /// <sumary>
44 /// Any OSHttpHandler must return one of the following results:
45 /// <list type = "table">
46 /// <listheader>
47 /// <term>result code</term>
48 /// <description>meaning</description>
49 /// </listheader>
50 /// <item>
51 /// <term>Pass</term>
52 /// <description>handler did not process the request</request>
53 /// </item>
54 /// <item>
55 /// <term>Handled</term>
56 /// <description>handler did process the request, OSHttpServer
57 /// can clean up and close the request</request>
58 /// </item>
59 /// <item>
60 /// <term>Detached</term>
61 /// <description>handler handles the request, OSHttpServer
62 /// can forget about the request and should not touch it as
63 /// the handler has taken control</request>
64 /// </item>
65 /// </list>
66 /// </summary>
67 public enum OSHttpHandlerResult
68 {
69 Pass,
70 Handled,
71 Detached,
72 }
73
74 public delegate OSHttpHandlerResult OSHttpHandler(OSHttpRequest request);
75
76 /// <summary> 43 /// <summary>
77 /// OSHttpServer provides an HTTP server bound to a specific 44 /// OSHttpServer provides an HTTP server bound to a specific
78 /// port. When instantiated with just address and port it uses 45 /// port. When instantiated with just address and port it uses
@@ -81,7 +48,7 @@ namespace OpenSim.Framework.Servers
81 /// </summary> 48 /// </summary>
82 public class OSHttpServer 49 public class OSHttpServer
83 { 50 {
84 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
85 52
86 // underlying HttpServer.HttpListener 53 // underlying HttpServer.HttpListener
87 protected HttpListener _listener; 54 protected HttpListener _listener;
@@ -117,6 +84,22 @@ namespace OpenSim.Framework.Servers
117 } 84 }
118 85
119 /// <summary> 86 /// <summary>
87 /// List of registered OSHttpHandlers for this OSHttpServer instance.
88 /// </summary>
89 protected List<OSHttpHandler> _httpHandlers = new List<OSHttpHandler>();
90 public List<OSHttpHandler> OSHttpHandlers
91 {
92 get
93 {
94 lock (_httpHandlers)
95 {
96 return new List<OSHttpHandler>(_httpHandlers);
97 }
98 }
99 }
100
101
102 /// <summary>
120 /// Instantiate an HTTP server. 103 /// Instantiate an HTTP server.
121 /// </summary> 104 /// </summary>
122 public OSHttpServer(IPAddress address, int port, int poolSize) 105 public OSHttpServer(IPAddress address, int port, int poolSize)
@@ -182,9 +165,6 @@ namespace OpenSim.Framework.Servers
182 } 165 }
183 } 166 }
184 167
185 protected Dictionary<OSHttpHandler, Regex> Handler2Path = new Dictionary<OSHttpHandler, Regex>();
186 protected Dictionary<OSHttpHandler, Dictionary<string, Regex>> Handler2Headers =
187 new Dictionary<OSHttpHandler, Dictionary<string, Regex>>();
188 168
189 /// <summary> 169 /// <summary>
190 /// Add an HTTP request handler. 170 /// Add an HTTP request handler.
@@ -193,13 +173,17 @@ namespace OpenSim.Framework.Servers
193 /// <param name="path">regex object for path matching</parm> 173 /// <param name="path">regex object for path matching</parm>
194 /// <param name="headers">dictionary containing header names 174 /// <param name="headers">dictionary containing header names
195 /// and regular expressions to match against header values</param> 175 /// and regular expressions to match against header values</param>
196 public void AddHandler(OSHttpHandler handler, Regex path, Dictionary<string, Regex> headers) 176 public void AddHandler(OSHttpHandler handler)
197 { 177 {
198 lock (Handler2Headers) 178 lock (_httpHandlers)
199 { 179 {
200 180 if (_httpHandlers.Contains(handler))
181 {
182 _log.DebugFormat("[OSHttpServer] attempt to add already existing handler ignored");
183 return;
184 }
185 _httpHandlers.Add(handler);
201 } 186 }
202 } 187 }
203
204 } 188 }
205} 189}