diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index cb1117a..af9b62f 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -56,7 +56,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
56 | private volatile int NotSocketErrors = 0; | 56 | private volatile int NotSocketErrors = 0; |
57 | public volatile bool HTTPDRunning = false; | 57 | public volatile bool HTTPDRunning = false; |
58 | 58 | ||
59 | protected Thread m_workerThread; | ||
60 | // protected HttpListener m_httpListener; | 59 | // protected HttpListener m_httpListener; |
61 | protected CoolHTTPListener m_httpListener2; | 60 | protected CoolHTTPListener m_httpListener2; |
62 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); | 61 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); |
@@ -66,7 +65,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
66 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); | 65 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); |
67 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); | 66 | protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); |
68 | protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); | 67 | protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); |
69 | |||
70 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = | 68 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = |
71 | new Dictionary<string, PollServiceEventArgs>(); | 69 | new Dictionary<string, PollServiceEventArgs>(); |
72 | 70 | ||
@@ -155,7 +153,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
155 | 153 | ||
156 | public List<string> GetStreamHandlerKeys() | 154 | public List<string> GetStreamHandlerKeys() |
157 | { | 155 | { |
158 | return new List<string>(m_streamHandlers.Keys); | 156 | lock (m_streamHandlers) |
157 | return new List<string>(m_streamHandlers.Keys); | ||
159 | } | 158 | } |
160 | 159 | ||
161 | private static string GetHandlerKey(string httpMethod, string path) | 160 | private static string GetHandlerKey(string httpMethod, string path) |
@@ -196,7 +195,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
196 | 195 | ||
197 | public List<string> GetXmlRpcHandlerKeys() | 196 | public List<string> GetXmlRpcHandlerKeys() |
198 | { | 197 | { |
199 | return new List<string>(m_rpcHandlers.Keys); | 198 | lock (m_rpcHandlers) |
199 | return new List<string>(m_rpcHandlers.Keys); | ||
200 | } | 200 | } |
201 | 201 | ||
202 | public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler) | 202 | public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler) |
@@ -218,10 +218,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
218 | 218 | ||
219 | public List<string> GetHTTPHandlerKeys() | 219 | public List<string> GetHTTPHandlerKeys() |
220 | { | 220 | { |
221 | return new List<string>(m_HTTPHandlers.Keys); | 221 | lock (m_HTTPHandlers) |
222 | return new List<string>(m_HTTPHandlers.Keys); | ||
222 | } | 223 | } |
223 | 224 | ||
224 | |||
225 | public bool AddPollServiceHTTPHandler(string methodName, GenericHTTPMethod handler, PollServiceEventArgs args) | 225 | public bool AddPollServiceHTTPHandler(string methodName, GenericHTTPMethod handler, PollServiceEventArgs args) |
226 | { | 226 | { |
227 | bool pollHandlerResult = false; | 227 | bool pollHandlerResult = false; |
@@ -242,10 +242,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
242 | 242 | ||
243 | public List<string> GetPollServiceHandlerKeys() | 243 | public List<string> GetPollServiceHandlerKeys() |
244 | { | 244 | { |
245 | return new List<string>(m_pollHandlers.Keys); | 245 | lock (m_pollHandlers) |
246 | return new List<string>(m_pollHandlers.Keys); | ||
246 | } | 247 | } |
247 | 248 | ||
248 | |||
249 | // Note that the agent string is provided simply to differentiate | 249 | // Note that the agent string is provided simply to differentiate |
250 | // the handlers - it is NOT required to be an actual agent header | 250 | // the handlers - it is NOT required to be an actual agent header |
251 | // value. | 251 | // value. |
@@ -266,7 +266,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
266 | 266 | ||
267 | public List<string> GetAgentHandlerKeys() | 267 | public List<string> GetAgentHandlerKeys() |
268 | { | 268 | { |
269 | return new List<string>(m_agentHandlers.Keys); | 269 | lock (m_agentHandlers) |
270 | return new List<string>(m_agentHandlers.Keys); | ||
270 | } | 271 | } |
271 | 272 | ||
272 | public bool AddLLSDHandler(string path, LLSDMethod handler) | 273 | public bool AddLLSDHandler(string path, LLSDMethod handler) |
@@ -284,7 +285,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
284 | 285 | ||
285 | public List<string> GetLLSDHandlerKeys() | 286 | public List<string> GetLLSDHandlerKeys() |
286 | { | 287 | { |
287 | return new List<string>(m_llsdHandlers.Keys); | 288 | lock (m_llsdHandlers) |
289 | return new List<string>(m_llsdHandlers.Keys); | ||
288 | } | 290 | } |
289 | 291 | ||
290 | public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler) | 292 | public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler) |
@@ -404,14 +406,14 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
404 | string requestMethod = request.HttpMethod; | 406 | string requestMethod = request.HttpMethod; |
405 | string uriString = request.RawUrl; | 407 | string uriString = request.RawUrl; |
406 | 408 | ||
407 | string reqnum = "unknown"; | 409 | // string reqnum = "unknown"; |
408 | int tickstart = Environment.TickCount; | 410 | int tickstart = Environment.TickCount; |
409 | 411 | ||
410 | try | 412 | try |
411 | { | 413 | { |
412 | // OpenSim.Framework.WebUtil.OSHeaderRequestID | 414 | // OpenSim.Framework.WebUtil.OSHeaderRequestID |
413 | if (request.Headers["opensim-request-id"] != null) | 415 | // if (request.Headers["opensim-request-id"] != null) |
414 | reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]); | 416 | // reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]); |
415 | //m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl); | 417 | //m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl); |
416 | 418 | ||
417 | Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); | 419 | Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); |
@@ -746,7 +748,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
746 | private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) | 748 | private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler) |
747 | { | 749 | { |
748 | agentHandler = null; | 750 | agentHandler = null; |
749 | try | 751 | |
752 | lock (m_agentHandlers) | ||
750 | { | 753 | { |
751 | foreach (IHttpAgentHandler handler in m_agentHandlers.Values) | 754 | foreach (IHttpAgentHandler handler in m_agentHandlers.Values) |
752 | { | 755 | { |
@@ -757,9 +760,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
757 | } | 760 | } |
758 | } | 761 | } |
759 | } | 762 | } |
760 | catch(KeyNotFoundException) | ||
761 | { | ||
762 | } | ||
763 | 763 | ||
764 | return false; | 764 | return false; |
765 | } | 765 | } |
@@ -803,9 +803,12 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
803 | 803 | ||
804 | XmlRpcMethod method; | 804 | XmlRpcMethod method; |
805 | bool methodWasFound; | 805 | bool methodWasFound; |
806 | bool keepAlive = false; | ||
806 | lock (m_rpcHandlers) | 807 | lock (m_rpcHandlers) |
807 | { | 808 | { |
808 | methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method); | 809 | methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method); |
810 | if (methodWasFound) | ||
811 | keepAlive = m_rpcHandlersKeepAlive[methodName]; | ||
809 | } | 812 | } |
810 | 813 | ||
811 | if (methodWasFound) | 814 | if (methodWasFound) |
@@ -824,7 +827,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
824 | } | 827 | } |
825 | xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] | 828 | xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] |
826 | 829 | ||
827 | |||
828 | try | 830 | try |
829 | { | 831 | { |
830 | xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); | 832 | xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); |
@@ -846,7 +848,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
846 | } | 848 | } |
847 | 849 | ||
848 | // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here | 850 | // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here |
849 | response.KeepAlive = m_rpcHandlersKeepAlive[methodName]; | 851 | response.KeepAlive = keepAlive; |
850 | } | 852 | } |
851 | else | 853 | else |
852 | { | 854 | { |
@@ -1106,7 +1108,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1106 | /// <returns>true if we have one, false if not</returns> | 1108 | /// <returns>true if we have one, false if not</returns> |
1107 | private bool DoWeHaveALLSDHandler(string path) | 1109 | private bool DoWeHaveALLSDHandler(string path) |
1108 | { | 1110 | { |
1109 | |||
1110 | string[] pathbase = path.Split('/'); | 1111 | string[] pathbase = path.Split('/'); |
1111 | string searchquery = "/"; | 1112 | string searchquery = "/"; |
1112 | 1113 | ||
@@ -1122,14 +1123,12 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1122 | 1123 | ||
1123 | string bestMatch = null; | 1124 | string bestMatch = null; |
1124 | 1125 | ||
1125 | foreach (string pattern in m_llsdHandlers.Keys) | 1126 | lock (m_llsdHandlers) |
1126 | { | 1127 | { |
1127 | 1128 | foreach (string pattern in m_llsdHandlers.Keys) | |
1128 | if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length) | ||
1129 | { | 1129 | { |
1130 | 1130 | if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length) | |
1131 | bestMatch = pattern; | 1131 | bestMatch = pattern; |
1132 | |||
1133 | } | 1132 | } |
1134 | } | 1133 | } |
1135 | 1134 | ||
@@ -1142,12 +1141,10 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1142 | 1141 | ||
1143 | if (String.IsNullOrEmpty(bestMatch)) | 1142 | if (String.IsNullOrEmpty(bestMatch)) |
1144 | { | 1143 | { |
1145 | |||
1146 | return false; | 1144 | return false; |
1147 | } | 1145 | } |
1148 | else | 1146 | else |
1149 | { | 1147 | { |
1150 | |||
1151 | return true; | 1148 | return true; |
1152 | } | 1149 | } |
1153 | } | 1150 | } |
@@ -1232,29 +1229,32 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1232 | 1229 | ||
1233 | string bestMatch = null; | 1230 | string bestMatch = null; |
1234 | 1231 | ||
1235 | foreach (string pattern in m_llsdHandlers.Keys) | 1232 | lock (m_llsdHandlers) |
1236 | { | 1233 | { |
1237 | if (searchquery.ToLower().StartsWith(pattern.ToLower())) | 1234 | foreach (string pattern in m_llsdHandlers.Keys) |
1238 | { | 1235 | { |
1239 | if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length) | 1236 | if (searchquery.ToLower().StartsWith(pattern.ToLower())) |
1240 | { | 1237 | { |
1241 | // You have to specifically register for '/' and to get it, you must specificaly request it | 1238 | if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length) |
1242 | // | 1239 | { |
1243 | if (pattern == "/" && searchquery == "/" || pattern != "/") | 1240 | // You have to specifically register for '/' and to get it, you must specificaly request it |
1244 | bestMatch = pattern; | 1241 | // |
1242 | if (pattern == "/" && searchquery == "/" || pattern != "/") | ||
1243 | bestMatch = pattern; | ||
1244 | } | ||
1245 | } | 1245 | } |
1246 | } | 1246 | } |
1247 | } | 1247 | |
1248 | 1248 | if (String.IsNullOrEmpty(bestMatch)) | |
1249 | if (String.IsNullOrEmpty(bestMatch)) | 1249 | { |
1250 | { | 1250 | llsdHandler = null; |
1251 | llsdHandler = null; | 1251 | return false; |
1252 | return false; | 1252 | } |
1253 | } | 1253 | else |
1254 | else | 1254 | { |
1255 | { | 1255 | llsdHandler = m_llsdHandlers[bestMatch]; |
1256 | llsdHandler = m_llsdHandlers[bestMatch]; | 1256 | return true; |
1257 | return true; | 1257 | } |
1258 | } | 1258 | } |
1259 | } | 1259 | } |
1260 | 1260 | ||
@@ -1793,7 +1793,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1793 | 1793 | ||
1794 | //m_log.DebugFormat("[BASE HTTP SERVER]: Removing handler key {0}", handlerKey); | 1794 | //m_log.DebugFormat("[BASE HTTP SERVER]: Removing handler key {0}", handlerKey); |
1795 | 1795 | ||
1796 | lock (m_streamHandlers) m_streamHandlers.Remove(handlerKey); | 1796 | lock (m_streamHandlers) |
1797 | m_streamHandlers.Remove(handlerKey); | ||
1797 | } | 1798 | } |
1798 | 1799 | ||
1799 | public void RemoveHTTPHandler(string httpMethod, string path) | 1800 | public void RemoveHTTPHandler(string httpMethod, string path) |
@@ -1825,17 +1826,16 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1825 | 1826 | ||
1826 | public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) | 1827 | public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) |
1827 | { | 1828 | { |
1828 | try | 1829 | lock (m_agentHandlers) |
1829 | { | 1830 | { |
1830 | if (handler == m_agentHandlers[agent]) | 1831 | IHttpAgentHandler foundHandler; |
1832 | |||
1833 | if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler) | ||
1831 | { | 1834 | { |
1832 | m_agentHandlers.Remove(agent); | 1835 | m_agentHandlers.Remove(agent); |
1833 | return true; | 1836 | return true; |
1834 | } | 1837 | } |
1835 | } | 1838 | } |
1836 | catch(KeyNotFoundException) | ||
1837 | { | ||
1838 | } | ||
1839 | 1839 | ||
1840 | return false; | 1840 | return false; |
1841 | } | 1841 | } |
@@ -1853,18 +1853,16 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1853 | 1853 | ||
1854 | public bool RemoveLLSDHandler(string path, LLSDMethod handler) | 1854 | public bool RemoveLLSDHandler(string path, LLSDMethod handler) |
1855 | { | 1855 | { |
1856 | try | 1856 | lock (m_llsdHandlers) |
1857 | { | 1857 | { |
1858 | if (handler == m_llsdHandlers[path]) | 1858 | LLSDMethod foundHandler; |
1859 | |||
1860 | if (m_llsdHandlers.TryGetValue(path, out foundHandler) && foundHandler == handler) | ||
1859 | { | 1861 | { |
1860 | m_llsdHandlers.Remove(path); | 1862 | m_llsdHandlers.Remove(path); |
1861 | return true; | 1863 | return true; |
1862 | } | 1864 | } |
1863 | } | 1865 | } |
1864 | catch (KeyNotFoundException) | ||
1865 | { | ||
1866 | // This is an exception to prevent crashing because of invalid code | ||
1867 | } | ||
1868 | 1866 | ||
1869 | return false; | 1867 | return false; |
1870 | } | 1868 | } |