diff options
Diffstat (limited to 'OpenSim/Framework')
9 files changed, 260 insertions, 61 deletions
diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs index 8ad7b0d..4b88923 100644 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs | |||
@@ -234,7 +234,7 @@ namespace OpenSim.Framework.Console | |||
234 | string uri = "/ReadResponses/" + sessionID.ToString() + "/"; | 234 | string uri = "/ReadResponses/" + sessionID.ToString() + "/"; |
235 | 235 | ||
236 | m_Server.AddPollServiceHTTPHandler( | 236 | m_Server.AddPollServiceHTTPHandler( |
237 | uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, sessionID,25000)); // 25 secs timeout | 237 | uri, new PollServiceEventArgs(null, uri, HasEvents, GetEvents, NoEvents, Drop, sessionID, 25000)); // 25 secs timeout |
238 | 238 | ||
239 | XmlDocument xmldoc = new XmlDocument(); | 239 | XmlDocument xmldoc = new XmlDocument(); |
240 | XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, | 240 | XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, |
@@ -425,6 +425,15 @@ namespace OpenSim.Framework.Console | |||
425 | return false; | 425 | return false; |
426 | } | 426 | } |
427 | 427 | ||
428 | private void Drop(UUID RequestID, UUID sessionID) | ||
429 | { | ||
430 | lock (m_Connections) | ||
431 | { | ||
432 | if (m_Connections.ContainsKey(sessionID)) | ||
433 | m_Connections.Remove(sessionID); | ||
434 | } | ||
435 | } | ||
436 | |||
428 | private Hashtable GetEvents(UUID RequestID, UUID sessionID) | 437 | private Hashtable GetEvents(UUID RequestID, UUID sessionID) |
429 | { | 438 | { |
430 | ConsoleConnection c = null; | 439 | ConsoleConnection c = null; |
diff --git a/OpenSim/Framework/NetworkServersInfo.cs b/OpenSim/Framework/NetworkServersInfo.cs index dfe9695..d79eb0d 100644 --- a/OpenSim/Framework/NetworkServersInfo.cs +++ b/OpenSim/Framework/NetworkServersInfo.cs | |||
@@ -37,6 +37,8 @@ namespace OpenSim.Framework | |||
37 | public bool isSandbox; | 37 | public bool isSandbox; |
38 | public bool HttpUsesSSL = false; | 38 | public bool HttpUsesSSL = false; |
39 | public string HttpSSLCN = ""; | 39 | public string HttpSSLCN = ""; |
40 | public string HttpSSLCertPath = ""; | ||
41 | public string HttpSSLCNCertPass = ""; | ||
40 | public uint httpSSLPort = 9001; | 42 | public uint httpSSLPort = 9001; |
41 | 43 | ||
42 | // "Out of band" managemnt https | 44 | // "Out of band" managemnt https |
@@ -62,6 +64,8 @@ namespace OpenSim.Framework | |||
62 | (uint)config.Configs["Network"].GetInt("http_listener_sslport", ((int)ConfigSettings.DefaultRegionHttpPort+1)); | 64 | (uint)config.Configs["Network"].GetInt("http_listener_sslport", ((int)ConfigSettings.DefaultRegionHttpPort+1)); |
63 | HttpUsesSSL = config.Configs["Network"].GetBoolean("http_listener_ssl", false); | 65 | HttpUsesSSL = config.Configs["Network"].GetBoolean("http_listener_ssl", false); |
64 | HttpSSLCN = config.Configs["Network"].GetString("http_listener_cn", "localhost"); | 66 | HttpSSLCN = config.Configs["Network"].GetString("http_listener_cn", "localhost"); |
67 | HttpSSLCertPath = config.Configs["Network"].GetString("http_listener_cert_path", HttpSSLCertPath); | ||
68 | HttpSSLCNCertPass = config.Configs["Network"].GetString("http_listener_cert_pass", HttpSSLCNCertPass); | ||
65 | 69 | ||
66 | // "Out of band management https" | 70 | // "Out of band management https" |
67 | ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false); | 71 | ssl_listener = config.Configs["Network"].GetBoolean("https_listener",false); |
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index e431042..bd8b681 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -43,10 +43,11 @@ using log4net; | |||
43 | using Nwc.XmlRpc; | 43 | using Nwc.XmlRpc; |
44 | using OpenMetaverse.StructuredData; | 44 | using OpenMetaverse.StructuredData; |
45 | using CoolHTTPListener = HttpServer.HttpListener; | 45 | using CoolHTTPListener = HttpServer.HttpListener; |
46 | using HttpListener=System.Net.HttpListener; | 46 | using HttpListener = System.Net.HttpListener; |
47 | using LogPrio=HttpServer.LogPrio; | 47 | using LogPrio = HttpServer.LogPrio; |
48 | using OpenSim.Framework.Monitoring; | 48 | using OpenSim.Framework.Monitoring; |
49 | using System.IO.Compression; | 49 | using System.IO.Compression; |
50 | using System.Security.Cryptography; | ||
50 | 51 | ||
51 | namespace OpenSim.Framework.Servers.HttpServer | 52 | namespace OpenSim.Framework.Servers.HttpServer |
52 | { | 53 | { |
@@ -110,8 +111,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
110 | protected uint m_sslport; | 111 | protected uint m_sslport; |
111 | protected bool m_ssl; | 112 | protected bool m_ssl; |
112 | private X509Certificate2 m_cert; | 113 | private X509Certificate2 m_cert; |
113 | protected bool m_firstcaps = true; | ||
114 | protected string m_SSLCommonName = ""; | 114 | protected string m_SSLCommonName = ""; |
115 | protected List<string> m_certNames = new List<string>(); | ||
116 | protected List<string> m_certIPs = new List<string>(); | ||
117 | protected string m_certCN= ""; | ||
115 | 118 | ||
116 | protected IPAddress m_listenIPAddress = IPAddress.Any; | 119 | protected IPAddress m_listenIPAddress = IPAddress.Any; |
117 | 120 | ||
@@ -148,27 +151,153 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
148 | m_port = port; | 151 | m_port = port; |
149 | } | 152 | } |
150 | 153 | ||
151 | public BaseHttpServer(uint port, bool ssl) : this (port) | 154 | private void load_cert(string CPath, string CPass) |
152 | { | 155 | { |
153 | m_ssl = ssl; | 156 | try |
157 | { | ||
158 | m_cert = new X509Certificate2(CPath, CPass); | ||
159 | X509Extension ext = m_cert.Extensions["2.5.29.17"]; | ||
160 | if(ext != null) | ||
161 | { | ||
162 | AsnEncodedData asndata = new AsnEncodedData(ext.Oid, ext.RawData); | ||
163 | string datastr = asndata.Format(true); | ||
164 | string[] lines = datastr.Split(new char[] {'\n','\r'}); | ||
165 | foreach(string s in lines) | ||
166 | { | ||
167 | if(String.IsNullOrEmpty(s)) | ||
168 | continue; | ||
169 | string[] parts = s.Split(new char[] {'='}); | ||
170 | if(String.IsNullOrEmpty(parts[0])) | ||
171 | continue; | ||
172 | string entryName = parts[0].Replace(" ",""); | ||
173 | if(entryName == "DNSName") | ||
174 | m_certNames.Add(parts[1]); | ||
175 | else if(entryName == "IPAddress") | ||
176 | m_certIPs.Add(parts[1]); | ||
177 | } | ||
178 | } | ||
179 | m_certCN = m_cert.GetNameInfo(X509NameType.SimpleName, false); | ||
180 | } | ||
181 | catch | ||
182 | { | ||
183 | throw new Exception("SSL cert load error"); | ||
184 | } | ||
154 | } | 185 | } |
155 | 186 | ||
156 | public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl) | 187 | public BaseHttpServer(uint port, bool ssl, uint sslport, string CN, string CPath, string CPass) |
157 | { | 188 | { |
158 | if (m_ssl) | 189 | m_port = port; |
190 | if (ssl) | ||
159 | { | 191 | { |
192 | if(string.IsNullOrEmpty(CPath)) | ||
193 | throw new Exception("invalid main http server cert path"); | ||
194 | |||
195 | if(Uri.CheckHostName(CN) == UriHostNameType.Unknown) | ||
196 | throw new Exception("invalid main http server CN (ExternalHostName)"); | ||
197 | |||
198 | m_certNames.Clear(); | ||
199 | m_certIPs.Clear(); | ||
200 | m_certCN= ""; | ||
201 | |||
202 | m_ssl = true; | ||
160 | m_sslport = sslport; | 203 | m_sslport = sslport; |
204 | load_cert(CPath, CPass); | ||
205 | |||
206 | if(!CheckSSLCertHost(CN)) | ||
207 | throw new Exception("invalid main http server CN (ExternalHostName)"); | ||
208 | |||
209 | m_SSLCommonName = CN; | ||
210 | |||
211 | if(m_cert.Issuer == m_cert.Subject ) | ||
212 | m_log.Warn("Self signed certificate. Clients need to allow this (some viewers debug option NoVerifySSLcert must be set to true"); | ||
161 | } | 213 | } |
214 | else | ||
215 | m_ssl = false; | ||
162 | } | 216 | } |
163 | 217 | ||
164 | public BaseHttpServer(uint port, bool ssl, string CPath, string CPass) : this (port, ssl) | 218 | public BaseHttpServer(uint port, bool ssl, string CPath, string CPass) |
165 | { | 219 | { |
166 | if (m_ssl) | 220 | m_port = port; |
221 | if (ssl) | ||
167 | { | 222 | { |
168 | m_cert = new X509Certificate2(CPath, CPass); | 223 | load_cert(CPath, CPass); |
224 | if(m_cert.Issuer == m_cert.Subject ) | ||
225 | m_log.Warn("Self signed certificate. Http clients need to allow this"); | ||
226 | m_ssl = true; | ||
227 | m_sslport = port; | ||
228 | } | ||
229 | else | ||
230 | m_ssl = false; | ||
231 | } | ||
232 | |||
233 | static bool MatchDNS (string hostname, string dns) | ||
234 | { | ||
235 | int indx = dns.IndexOf ('*'); | ||
236 | if (indx == -1) | ||
237 | return (String.Compare(hostname, dns, true, CultureInfo.InvariantCulture) == 0); | ||
238 | |||
239 | int dnslen = dns.Length; | ||
240 | dnslen--; | ||
241 | if(indx == dnslen) | ||
242 | return true; // just * ? | ||
243 | |||
244 | if(indx > dnslen - 2) | ||
245 | return false; // 2 short ? | ||
246 | |||
247 | if (dns[indx + 1] != '.') | ||
248 | return false; | ||
249 | |||
250 | int indx2 = dns.IndexOf ('*', indx + 1); | ||
251 | if (indx2 != -1) | ||
252 | return false; // there can only be one; | ||
253 | |||
254 | string end = dns.Substring(indx + 1); | ||
255 | int hostlen = hostname.Length; | ||
256 | int endlen = end.Length; | ||
257 | int length = hostlen - endlen; | ||
258 | if (length <= 0) | ||
259 | return false; | ||
260 | |||
261 | if (String.Compare(hostname, length, end, 0, endlen, true, CultureInfo.InvariantCulture) != 0) | ||
262 | return false; | ||
263 | |||
264 | if (indx == 0) | ||
265 | { | ||
266 | indx2 = hostname.IndexOf ('.'); | ||
267 | return ((indx2 == -1) || (indx2 >= length)); | ||
268 | } | ||
269 | |||
270 | string start = dns.Substring (0, indx); | ||
271 | return (String.Compare (hostname, 0, start, 0, start.Length, true, CultureInfo.InvariantCulture) == 0); | ||
272 | } | ||
273 | |||
274 | public bool CheckSSLCertHost(string hostname) | ||
275 | { | ||
276 | UriHostNameType htype = Uri.CheckHostName(hostname); | ||
277 | |||
278 | if(htype == UriHostNameType.Unknown || htype == UriHostNameType.Basic) | ||
279 | return false; | ||
280 | if(htype == UriHostNameType.Dns) | ||
281 | { | ||
282 | foreach(string name in m_certNames) | ||
283 | { | ||
284 | if(MatchDNS(hostname, name)) | ||
285 | return true; | ||
286 | } | ||
287 | if(MatchDNS(hostname, m_certCN)) | ||
288 | return true; | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | foreach(string ip in m_certIPs) | ||
293 | { | ||
294 | if (String.Compare(hostname, ip, true, CultureInfo.InvariantCulture) != 0) | ||
295 | return true; | ||
296 | } | ||
169 | } | 297 | } |
170 | } | ||
171 | 298 | ||
299 | return false; | ||
300 | } | ||
172 | /// <summary> | 301 | /// <summary> |
173 | /// Add a stream handler to the http server. If the handler already exists, then nothing happens. | 302 | /// Add a stream handler to the http server. If the handler already exists, then nothing happens. |
174 | /// </summary> | 303 | /// </summary> |
@@ -461,7 +590,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
461 | } | 590 | } |
462 | 591 | ||
463 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); | 592 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); |
464 | resp.ReuseContext = true; | 593 | // resp.ReuseContext = true; |
465 | // resp.ReuseContext = false; | 594 | // resp.ReuseContext = false; |
466 | HandleRequest(req, resp); | 595 | HandleRequest(req, resp); |
467 | 596 | ||
@@ -1804,7 +1933,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1804 | */ | 1933 | */ |
1805 | // disable this things | 1934 | // disable this things |
1806 | response.KeepAlive = false; | 1935 | response.KeepAlive = false; |
1807 | response.ReuseContext = false; | 1936 | // response.ReuseContext = false; |
1808 | 1937 | ||
1809 | // Cross-Origin Resource Sharing with simple requests | 1938 | // Cross-Origin Resource Sharing with simple requests |
1810 | if (responsedata.ContainsKey("access_control_allow_origin")) | 1939 | if (responsedata.ContainsKey("access_control_allow_origin")) |
@@ -1906,7 +2035,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1906 | 2035 | ||
1907 | public void Start() | 2036 | public void Start() |
1908 | { | 2037 | { |
1909 | Start(true); | 2038 | Start(true,true); |
1910 | } | 2039 | } |
1911 | 2040 | ||
1912 | /// <summary> | 2041 | /// <summary> |
@@ -1916,7 +2045,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1916 | /// If true then poll responses are performed asynchronsly. | 2045 | /// If true then poll responses are performed asynchronsly. |
1917 | /// Option exists to allow regression tests to perform processing synchronously. | 2046 | /// Option exists to allow regression tests to perform processing synchronously. |
1918 | /// </param> | 2047 | /// </param> |
1919 | public void Start(bool performPollResponsesAsync) | 2048 | public void Start(bool performPollResponsesAsync, bool runPool) |
1920 | { | 2049 | { |
1921 | m_log.InfoFormat( | 2050 | m_log.InfoFormat( |
1922 | "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); | 2051 | "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); |
@@ -1954,9 +2083,11 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1954 | m_httpListener2.Start(64); | 2083 | m_httpListener2.Start(64); |
1955 | 2084 | ||
1956 | // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events | 2085 | // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events |
1957 | 2086 | if(runPool) | |
1958 | PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 2, 25000); | 2087 | { |
1959 | PollServiceRequestManager.Start(); | 2088 | PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 2, 25000); |
2089 | PollServiceRequestManager.Start(); | ||
2090 | } | ||
1960 | 2091 | ||
1961 | HTTPDRunning = true; | 2092 | HTTPDRunning = true; |
1962 | 2093 | ||
diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs index f61b090..d26b68a 100644 --- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpResponse.cs | |||
@@ -118,7 +118,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
118 | /// </summary> | 118 | /// </summary> |
119 | string StatusDescription { get; set; } | 119 | string StatusDescription { get; set; } |
120 | 120 | ||
121 | bool ReuseContext { get; set; } | 121 | // bool ReuseContext { get; set; } |
122 | 122 | ||
123 | /// <summary> | 123 | /// <summary> |
124 | /// Add a header field and content to the response. | 124 | /// Add a header field and content to the response. |
diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs index ccf9c91..8456654 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpResponse.cs | |||
@@ -256,7 +256,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
256 | _httpResponse.Reason = value; | 256 | _httpResponse.Reason = value; |
257 | } | 257 | } |
258 | } | 258 | } |
259 | 259 | /* | |
260 | public bool ReuseContext | 260 | public bool ReuseContext |
261 | { | 261 | { |
262 | get | 262 | get |
@@ -275,7 +275,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | */ | |
279 | protected IHttpResponse _httpResponse; | 279 | protected IHttpResponse _httpResponse; |
280 | private IHttpClientContext _httpClientContext; | 280 | private IHttpClientContext _httpClientContext; |
281 | 281 | ||
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 3fd3bf7..a9860cc 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | |||
@@ -37,6 +37,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
37 | public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); | 37 | public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId); |
38 | 38 | ||
39 | public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); | 39 | public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); |
40 | public delegate void DropMethod(UUID requestID, UUID pId); | ||
40 | 41 | ||
41 | public class PollServiceEventArgs : EventArgs | 42 | public class PollServiceEventArgs : EventArgs |
42 | { | 43 | { |
@@ -44,6 +45,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
44 | public GetEventsMethod GetEvents; | 45 | public GetEventsMethod GetEvents; |
45 | public NoEventsMethod NoEvents; | 46 | public NoEventsMethod NoEvents; |
46 | public RequestMethod Request; | 47 | public RequestMethod Request; |
48 | public DropMethod Drop; | ||
47 | public UUID Id; | 49 | public UUID Id; |
48 | public int TimeOutms; | 50 | public int TimeOutms; |
49 | public EventType Type; | 51 | public EventType Type; |
@@ -73,13 +75,14 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
73 | RequestMethod pRequest, | 75 | RequestMethod pRequest, |
74 | string pUrl, | 76 | string pUrl, |
75 | HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, | 77 | HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents, |
76 | UUID pId, int pTimeOutms) | 78 | DropMethod pDrop, UUID pId, int pTimeOutms) |
77 | { | 79 | { |
78 | Request = pRequest; | 80 | Request = pRequest; |
79 | Url = pUrl; | 81 | Url = pUrl; |
80 | HasEvents = pHasEvents; | 82 | HasEvents = pHasEvents; |
81 | GetEvents = pGetEvents; | 83 | GetEvents = pGetEvents; |
82 | NoEvents = pNoEvents; | 84 | NoEvents = pNoEvents; |
85 | Drop = pDrop; | ||
83 | Id = pId; | 86 | Id = pId; |
84 | TimeOutms = pTimeOutms; | 87 | TimeOutms = pTimeOutms; |
85 | Type = EventType.LongPoll; | 88 | Type = EventType.LongPoll; |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index 0e4a941..6537f64 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | |||
@@ -47,8 +47,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
47 | public readonly UUID RequestID; | 47 | public readonly UUID RequestID; |
48 | public int contextHash; | 48 | public int contextHash; |
49 | 49 | ||
50 | /* | ||
50 | private void GenContextHash() | 51 | private void GenContextHash() |
51 | { | 52 | { |
53 | |||
52 | Random rnd = new Random(); | 54 | Random rnd = new Random(); |
53 | contextHash = 0; | 55 | contextHash = 0; |
54 | if (Request.Headers["remote_addr"] != null) | 56 | if (Request.Headers["remote_addr"] != null) |
@@ -62,8 +64,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
62 | } | 64 | } |
63 | else | 65 | else |
64 | contextHash += rnd.Next() & 0xffff; | 66 | contextHash += rnd.Next() & 0xffff; |
65 | } | ||
66 | 67 | ||
68 | } | ||
69 | */ | ||
67 | public PollServiceHttpRequest( | 70 | public PollServiceHttpRequest( |
68 | PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) | 71 | PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) |
69 | { | 72 | { |
@@ -72,7 +75,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
72 | Request = pRequest; | 75 | Request = pRequest; |
73 | RequestTime = System.Environment.TickCount; | 76 | RequestTime = System.Environment.TickCount; |
74 | RequestID = UUID.Random(); | 77 | RequestID = UUID.Random(); |
75 | GenContextHash(); | 78 | // GenContextHash(); |
79 | contextHash = HttpContext.contextID; | ||
76 | } | 80 | } |
77 | 81 | ||
78 | internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) | 82 | internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) |
@@ -85,7 +89,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
85 | response.SendChunked = false; | 89 | response.SendChunked = false; |
86 | response.ContentLength64 = buffer.Length; | 90 | response.ContentLength64 = buffer.Length; |
87 | response.ContentEncoding = Encoding.UTF8; | 91 | response.ContentEncoding = Encoding.UTF8; |
88 | response.ReuseContext = false; | 92 | // response.ReuseContext = false; |
89 | 93 | ||
90 | try | 94 | try |
91 | { | 95 | { |
@@ -110,7 +114,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
110 | response.SendChunked = false; | 114 | response.SendChunked = false; |
111 | response.ContentLength64 = 0; | 115 | response.ContentLength64 = 0; |
112 | response.ContentEncoding = Encoding.UTF8; | 116 | response.ContentEncoding = Encoding.UTF8; |
113 | response.ReuseContext = false; | 117 | // response.ReuseContext = false; |
114 | response.KeepAlive = false; | 118 | response.KeepAlive = false; |
115 | response.SendChunked = false; | 119 | response.SendChunked = false; |
116 | response.StatusCode = 503; | 120 | response.StatusCode = 503; |
@@ -132,8 +136,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
132 | { | 136 | { |
133 | if (b1.contextHash != b2.contextHash) | 137 | if (b1.contextHash != b2.contextHash) |
134 | return false; | 138 | return false; |
135 | bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); | 139 | // bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); |
136 | return b; | 140 | // return b; |
141 | return true; | ||
137 | } | 142 | } |
138 | 143 | ||
139 | public int GetHashCode(PollServiceHttpRequest b2) | 144 | public int GetHashCode(PollServiceHttpRequest b2) |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index ffcad0f..5b40590 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | |||
@@ -160,6 +160,19 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | public void DropByContext(PollServiceHttpRequest req) | ||
164 | { | ||
165 | Queue<PollServiceHttpRequest> ctxQeueue; | ||
166 | lock (m_bycontext) | ||
167 | { | ||
168 | if (m_bycontext.TryGetValue(req, out ctxQeueue)) | ||
169 | { | ||
170 | ctxQeueue.Clear(); | ||
171 | m_bycontext.Remove(req); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
163 | public void EnqueueInt(PollServiceHttpRequest req) | 176 | public void EnqueueInt(PollServiceHttpRequest req) |
164 | { | 177 | { |
165 | if (m_running) | 178 | if (m_running) |
@@ -263,22 +276,61 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
263 | PollServiceHttpRequest req = m_requests.Dequeue(5000); | 276 | PollServiceHttpRequest req = m_requests.Dequeue(5000); |
264 | 277 | ||
265 | Watchdog.UpdateThread(); | 278 | Watchdog.UpdateThread(); |
266 | if (req != null) | 279 | if(req == null) |
280 | continue; | ||
281 | |||
282 | try | ||
267 | { | 283 | { |
268 | try | 284 | if(!req.HttpContext.CanSend()) |
269 | { | 285 | { |
270 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) | 286 | req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); |
287 | byContextDequeue(req); | ||
288 | continue; | ||
289 | } | ||
290 | |||
291 | if(req.HttpContext.IsSending()) | ||
292 | { | ||
293 | if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) | ||
271 | { | 294 | { |
272 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); | 295 | req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); |
296 | byContextDequeue(req); | ||
297 | } | ||
298 | else | ||
299 | ReQueueEvent(req); | ||
300 | continue; | ||
301 | } | ||
273 | 302 | ||
303 | if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) | ||
304 | { | ||
305 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); | ||
306 | |||
307 | m_threadPool.QueueWorkItem(x => | ||
308 | { | ||
309 | try | ||
310 | { | ||
311 | req.DoHTTPGruntWork(m_server, responsedata); | ||
312 | byContextDequeue(req); | ||
313 | } | ||
314 | catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream | ||
315 | { | ||
316 | // Ignore it, no need to reply | ||
317 | } | ||
318 | return null; | ||
319 | }, null); | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) | ||
324 | { | ||
274 | m_threadPool.QueueWorkItem(x => | 325 | m_threadPool.QueueWorkItem(x => |
275 | { | 326 | { |
276 | try | 327 | try |
277 | { | 328 | { |
278 | req.DoHTTPGruntWork(m_server, responsedata); | 329 | req.DoHTTPGruntWork(m_server, |
330 | req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
279 | byContextDequeue(req); | 331 | byContextDequeue(req); |
280 | } | 332 | } |
281 | catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream | 333 | catch (ObjectDisposedException) |
282 | { | 334 | { |
283 | // Ignore it, no need to reply | 335 | // Ignore it, no need to reply |
284 | } | 336 | } |
@@ -287,36 +339,15 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
287 | } | 339 | } |
288 | else | 340 | else |
289 | { | 341 | { |
290 | if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) | 342 | ReQueueEvent(req); |
291 | { | ||
292 | m_threadPool.QueueWorkItem(x => | ||
293 | { | ||
294 | try | ||
295 | { | ||
296 | req.DoHTTPGruntWork(m_server, | ||
297 | req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id)); | ||
298 | byContextDequeue(req); | ||
299 | } | ||
300 | catch (ObjectDisposedException) | ||
301 | { | ||
302 | // Ignore it, no need to reply | ||
303 | } | ||
304 | return null; | ||
305 | }, null); | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | ReQueueEvent(req); | ||
310 | } | ||
311 | } | 343 | } |
312 | } | 344 | } |
313 | catch (Exception e) | 345 | } |
314 | { | 346 | catch (Exception e) |
315 | m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); | 347 | { |
316 | } | 348 | m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); |
317 | } | 349 | } |
318 | } | 350 | } |
319 | } | 351 | } |
320 | |||
321 | } | 352 | } |
322 | } | 353 | } |
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs index 57931d4..e9c284c 100644 --- a/OpenSim/Framework/Servers/MainServer.cs +++ b/OpenSim/Framework/Servers/MainServer.cs | |||
@@ -42,6 +42,7 @@ namespace OpenSim.Framework.Servers | |||
42 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | 43 | ||
44 | private static BaseHttpServer instance = null; | 44 | private static BaseHttpServer instance = null; |
45 | private static BaseHttpServer unsecureinstance = null; | ||
45 | private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); | 46 | private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); |
46 | 47 | ||
47 | /// <summary> | 48 | /// <summary> |
@@ -93,6 +94,21 @@ namespace OpenSim.Framework.Servers | |||
93 | } | 94 | } |
94 | } | 95 | } |
95 | 96 | ||
97 | |||
98 | public static BaseHttpServer ÚnSecureInstance | ||
99 | { | ||
100 | get { return unsecureinstance; } | ||
101 | |||
102 | set | ||
103 | { | ||
104 | lock (m_Servers) | ||
105 | if (!m_Servers.ContainsValue(value)) | ||
106 | throw new Exception("HTTP server must already have been registered to be set as the main instance"); | ||
107 | |||
108 | unsecureinstance = value; | ||
109 | } | ||
110 | } | ||
111 | |||
96 | /// <summary> | 112 | /// <summary> |
97 | /// Get all the registered servers. | 113 | /// Get all the registered servers. |
98 | /// </summary> | 114 | /// </summary> |