aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDr Scofield2008-07-15 13:06:30 +0000
committerDr Scofield2008-07-15 13:06:30 +0000
commit8b933e53c0c679df4b150849a8984ed6068655ad (patch)
treea07d491e7f0f49a8341ab50c617d0539e88cd2a3
parentremoves a Console.WriteLine(...) remnant. (diff)
downloadopensim-SC_OLD-8b933e53c0c679df4b150849a8984ed6068655ad.zip
opensim-SC_OLD-8b933e53c0c679df4b150849a8984ed6068655ad.tar.gz
opensim-SC_OLD-8b933e53c0c679df4b150849a8984ed6068655ad.tar.bz2
opensim-SC_OLD-8b933e53c0c679df4b150849a8984ed6068655ad.tar.xz
fixes handler scoring method. XmlRpc code path now fully working with
HttpServer. :-)
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequestPump.cs61
-rw-r--r--OpenSim/Framework/Servers/OSHttpServer.cs7
2 files changed, 61 insertions, 7 deletions
diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
index 9d0ffc1..be4c3ff 100644
--- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs
+++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
@@ -25,9 +25,12 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// #define DEBUGGING
29
28using System; 30using System;
29using System.Collections.Generic; 31using System.Collections.Generic;
30using System.Collections.Specialized; 32using System.Collections.Specialized;
33using System.Diagnostics;
31using System.IO; 34using System.IO;
32using System.Net; 35using System.Net;
33using System.Reflection; 36using System.Reflection;
@@ -36,6 +39,7 @@ using System.Threading;
36using log4net; 39using log4net;
37using HttpServer; 40using HttpServer;
38 41
42
39namespace OpenSim.Framework.Servers 43namespace OpenSim.Framework.Servers
40{ 44{
41 /// <summary> 45 /// <summary>
@@ -57,12 +61,16 @@ namespace OpenSim.Framework.Servers
57 61
58 public string EngineID 62 public string EngineID
59 { 63 {
60 get { return String.Format("{0}-{1}", _server.EngineID, _id); } 64 get { return String.Format("{0} pump {1}", _server.EngineID, _id); }
61 } 65 }
62 66
63 67
64 public OSHttpRequestPump() 68 public OSHttpRequestPump(OSHttpServer server, OSHttpRequestQueue queue, int id)
65 { 69 {
70 _server = server;
71 _queue = queue;
72 _id = id;
73
66 _engine = new Thread(new ThreadStart(Engine)); 74 _engine = new Thread(new ThreadStart(Engine));
67 _engine.Name = EngineID; 75 _engine.Name = EngineID;
68 _engine.IsBackground = true; 76 _engine.IsBackground = true;
@@ -77,9 +85,7 @@ namespace OpenSim.Framework.Servers
77 OSHttpRequestPump[] pumps = new OSHttpRequestPump[poolSize]; 85 OSHttpRequestPump[] pumps = new OSHttpRequestPump[poolSize];
78 for (int i = 0; i < pumps.Length; i++) 86 for (int i = 0; i < pumps.Length; i++)
79 { 87 {
80 pumps[i]._server = server; 88 pumps[i] = new OSHttpRequestPump(server, queue, i);
81 pumps[i]._queue = queue;
82 pumps[i]._id = i;
83 } 89 }
84 90
85 return pumps; 91 return pumps;
@@ -166,12 +172,15 @@ namespace OpenSim.Framework.Servers
166 { 172 {
167 Dictionary<OSHttpHandler, int> scoredHandlers = new Dictionary<OSHttpHandler, int>(); 173 Dictionary<OSHttpHandler, int> scoredHandlers = new Dictionary<OSHttpHandler, int>();
168 174
175 _log.DebugFormat("[{0}] MatchHandlers for {1}", EngineID, req);
169 foreach (OSHttpHandler h in handlers) 176 foreach (OSHttpHandler h in handlers)
170 { 177 {
171 Regex pathRegex = h.Path; 178 Regex pathRegex = h.Path;
172 Dictionary<string, Regex> headerRegexs = h.Headers; 179 Dictionary<string, Regex> headerRegexs = h.Headers;
173 Regex endPointsRegex = h.IPEndPointWhitelist; 180 Regex endPointsRegex = h.IPEndPointWhitelist;
174 181
182 // initial anchor
183 scoredHandlers[h] = 0;
175 184
176 // first, check whether IPEndPointWhitelist applies 185 // first, check whether IPEndPointWhitelist applies
177 // and, if it does, whether client is on that white 186 // and, if it does, whether client is on that white
@@ -218,6 +227,9 @@ namespace OpenSim.Framework.Servers
218 { 227 {
219 // no: remove the handler if it was added 228 // no: remove the handler if it was added
220 // earlier and on to the next one 229 // earlier and on to the next one
230 _LogDumpOSHttpHandler(String.Format("[{0}] dropping handler for {1}: null {2} header field",
231 EngineID, req, tag), h);
232
221 scoredHandlers.Remove(h); 233 scoredHandlers.Remove(h);
222 break; 234 break;
223 } 235 }
@@ -228,6 +240,8 @@ namespace OpenSim.Framework.Servers
228 if (!hm.Success) { 240 if (!hm.Success) {
229 // no: remove the handler if it was added 241 // no: remove the handler if it was added
230 // earlier and on to the next one 242 // earlier and on to the next one
243 _LogDumpOSHttpHandler(String.Format("[{0}] dropping handler for {1}: {2} header field content \"{3}\" does not match regex {4}",
244 EngineID, req, tag, headers[tag], headerRegexs[tag].ToString()), h);
231 scoredHandlers.Remove(h); 245 scoredHandlers.Remove(h);
232 break; 246 break;
233 } 247 }
@@ -238,11 +252,14 @@ namespace OpenSim.Framework.Servers
238 if ((null != h.ContentTypeChecker) && !h.ContentTypeChecker(req)) 252 if ((null != h.ContentTypeChecker) && !h.ContentTypeChecker(req))
239 { 253 {
240 scoredHandlers.Remove(h); 254 scoredHandlers.Remove(h);
255 _LogDumpOSHttpHandler(String.Format("[{0}] dropping handler for {1}: content checker returned false",
256 EngineID, req), h);
241 break; 257 break;
242 } 258 }
243 259
244 // ok: header matches 260 // ok: header matches
245 headersMatch++; 261 headersMatch++;
262 _LogDumpOSHttpHandler(String.Format("[{0}] MatchHandlers: found handler for {1}", EngineID, req), h);
246 continue; 263 continue;
247 } 264 }
248 // check whether h got kicked out 265 // check whether h got kicked out
@@ -251,15 +268,49 @@ namespace OpenSim.Framework.Servers
251 scoredHandlers[h] += headersMatch; 268 scoredHandlers[h] += headersMatch;
252 } 269 }
253 } 270 }
271
272 foreach (OSHttpHandler hh in scoredHandlers.Keys)
273 {
274 _LogDumpOSHttpHandler("scoredHandlers:", hh);
275 }
254 276
255 List<OSHttpHandler> matchingHandlers = new List<OSHttpHandler>(scoredHandlers.Keys); 277 List<OSHttpHandler> matchingHandlers = new List<OSHttpHandler>(scoredHandlers.Keys);
278 _LogDumpOSHttpHandlerList("before sort: ", matchingHandlers);
256 matchingHandlers.Sort(delegate(OSHttpHandler x, OSHttpHandler y) 279 matchingHandlers.Sort(delegate(OSHttpHandler x, OSHttpHandler y)
257 { 280 {
258 return scoredHandlers[x] - scoredHandlers[y]; 281 return scoredHandlers[x] - scoredHandlers[y];
259 }); 282 });
283
284 _LogDumpOSHttpHandlerList("after sort: ", matchingHandlers);
260 285
261 return matchingHandlers; 286 return matchingHandlers;
262 } 287 }
288
289 [ConditionalAttribute("DEBUGGING")]
290 private void _LogDumpOSHttpHandler(string msg, OSHttpHandler h)
291 {
292 _log.Debug(msg);
293
294 StringWriter sw = new StringWriter();
295 sw.WriteLine("{0}", h.ToString());
296 sw.WriteLine(" path regex {0}", null == h.Path ? "null": h.Path.ToString());
297 foreach (string tag in h.Headers.Keys)
298 {
299 sw.WriteLine(" header[{0}] {1}", tag, h.Headers[tag].ToString());
300 }
301 sw.WriteLine(" IP whitelist {0}", null == h.IPEndPointWhitelist ? "null" : h.IPEndPointWhitelist.ToString());
302 sw.WriteLine();
303 sw.Close();
304
305 _log.Debug(sw.ToString());
306 }
263 307
308 [ConditionalAttribute("DEBUGGING")]
309 private void _LogDumpOSHttpHandlerList(string msg, List<OSHttpHandler> l)
310 {
311 _log.DebugFormat("OSHttpHandlerList dump: {0}", msg);
312 foreach (OSHttpHandler h in l)
313 _LogDumpOSHttpHandler("OSHttpHandler", h);
314 }
264 } 315 }
265} 316}
diff --git a/OpenSim/Framework/Servers/OSHttpServer.cs b/OpenSim/Framework/Servers/OSHttpServer.cs
index 4940101..e0d26ff 100644
--- a/OpenSim/Framework/Servers/OSHttpServer.cs
+++ b/OpenSim/Framework/Servers/OSHttpServer.cs
@@ -106,8 +106,9 @@ namespace OpenSim.Framework.Servers
106 /// </summary> 106 /// </summary>
107 public OSHttpServer(IPAddress address, int port, int poolSize) 107 public OSHttpServer(IPAddress address, int port, int poolSize)
108 { 108 {
109 _engineId = String.Format("OSHttpServer [HTTP:{0}/ps:{1}]", port, poolSize); 109 _engineId = String.Format("OSHttpServer (HTTP:{0})", port);
110 _isSecure = false; 110 _isSecure = false;
111 _log.DebugFormat("[{0}] HTTP server instantiated", EngineID);
111 112
112 _listener = new HttpListener(address, port); 113 _listener = new HttpListener(address, port);
113 _queue = new OSHttpRequestQueue(); 114 _queue = new OSHttpRequestQueue();
@@ -121,6 +122,7 @@ namespace OpenSim.Framework.Servers
121 { 122 {
122 _engineId = String.Format("OSHttpServer [HTTPS:{0}/ps:{1}]", port, poolSize); 123 _engineId = String.Format("OSHttpServer [HTTPS:{0}/ps:{1}]", port, poolSize);
123 _isSecure = true; 124 _isSecure = true;
125 _log.DebugFormat("[{0}] HTTPS server instantiated", EngineID);
124 126
125 _listener = new HttpListener(address, port, certificate); 127 _listener = new HttpListener(address, port, certificate);
126 _queue = new OSHttpRequestQueue(); 128 _queue = new OSHttpRequestQueue();
@@ -176,8 +178,9 @@ namespace OpenSim.Framework.Servers
176 178
177 lock (_syncObject) Monitor.Wait(_syncObject); 179 lock (_syncObject) Monitor.Wait(_syncObject);
178 } 180 }
179 catch (Exception) 181 catch (Exception ex)
180 { 182 {
183 _log.DebugFormat("[{0}] HTTP server startup failed: {1}", EngineID, ex.ToString());
181 } 184 }
182 185
183 _log.InfoFormat("[{0}] HTTP server terminated", EngineID); 186 _log.InfoFormat("[{0}] HTTP server terminated", EngineID);