mirror of
https://github.com/opensim/opensim.git
synced 2026-08-12 04:05:42 +08:00
mantis 8762: let it be less broken
This commit is contained in:
@@ -99,8 +99,9 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
protected DefaultLLSDMethod m_defaultLlsdHandler = null; // <-- Moving away from the monolithic.. and going to /registered/
|
||||
protected Dictionary<string, LLSDMethod> m_llsdHandlers = new Dictionary<string, LLSDMethod>();
|
||||
protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>();
|
||||
// protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
|
||||
//protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
|
||||
protected ConcurrentDictionary<string, PollServiceEventArgs> m_pollHandlers = new ConcurrentDictionary<string, PollServiceEventArgs>();
|
||||
protected ConcurrentDictionary<string, PollServiceEventArgs> m_pollHandlersVarPath = new ConcurrentDictionary<string, PollServiceEventArgs>();
|
||||
protected ConcurrentDictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers = new ConcurrentDictionary<string, WebSocketRequestDelegate>();
|
||||
|
||||
protected ConcurrentDictionary<string, IRequestHandler> m_streamHandlers = new ConcurrentDictionary<string, IRequestHandler>();
|
||||
@@ -511,9 +512,16 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
return m_pollHandlers.TryAdd(args.Url, args);
|
||||
}
|
||||
|
||||
public bool AddPollServiceHTTPHandlerVarPath(PollServiceEventArgs args)
|
||||
{
|
||||
return m_pollHandlersVarPath.TryAdd(args.Url, args);
|
||||
}
|
||||
|
||||
public List<string> GetPollServiceHandlerKeys()
|
||||
{
|
||||
return new List<string>(m_pollHandlers.Keys);
|
||||
List<string> s = new List<string>(m_pollHandlers.Keys);
|
||||
s.AddRange(m_pollHandlersVarPath.Keys);
|
||||
return s;
|
||||
}
|
||||
|
||||
public bool AddLLSDHandler(string path, LLSDMethod handler)
|
||||
@@ -1058,6 +1066,23 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
if(m_pollHandlers.TryGetValue(handlerKey, out oServiceEventArgs))
|
||||
return true;
|
||||
|
||||
if(m_pollHandlersVarPath.Count > 0)
|
||||
{
|
||||
// only lsl requests should reach this, so be restrict (/lslhttp/" + urlcode.ToString()
|
||||
if (handlerKey.Length < 45)
|
||||
return false;
|
||||
|
||||
if (m_pollHandlersVarPath.TryGetValue(handlerKey, out oServiceEventArgs))
|
||||
return true;
|
||||
|
||||
int indx = handlerKey.LastIndexOf('/', handlerKey.Length - 1, 44);
|
||||
if (indx < 44) //lsl requests
|
||||
return false;
|
||||
|
||||
if(m_pollHandlersVarPath.TryGetValue(handlerKey.Substring(0, indx), out oServiceEventArgs))
|
||||
return true;
|
||||
}
|
||||
|
||||
oServiceEventArgs = null;
|
||||
return false;
|
||||
}
|
||||
@@ -2261,29 +2286,30 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
public void RemovePollServiceHTTPHandler(string httpMethod, string path)
|
||||
{
|
||||
m_pollHandlers.TryRemove(path, out PollServiceEventArgs dummy);
|
||||
if(!m_pollHandlers.TryRemove(path, out PollServiceEventArgs dummy))
|
||||
m_pollHandlersVarPath.TryRemove(path, out PollServiceEventArgs dummy2);
|
||||
}
|
||||
|
||||
public void RemovePollServiceHTTPHandler(string path)
|
||||
{
|
||||
m_pollHandlers.TryRemove(path, out PollServiceEventArgs dummy);
|
||||
if(!m_pollHandlers.TryRemove(path, out PollServiceEventArgs dummy))
|
||||
m_pollHandlersVarPath.TryRemove(path, out PollServiceEventArgs dummy2);
|
||||
}
|
||||
|
||||
// public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler)
|
||||
// {
|
||||
// lock (m_agentHandlers)
|
||||
// {
|
||||
// IHttpAgentHandler foundHandler;
|
||||
//public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler)
|
||||
//{
|
||||
// lock (m_agentHandlers)
|
||||
// {
|
||||
// IHttpAgentHandler foundHandler;
|
||||
// if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler)
|
||||
// {
|
||||
// m_agentHandlers.Remove(agent);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler)
|
||||
// {
|
||||
// m_agentHandlers.Remove(agent);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
public void RemoveXmlRPCHandler(string method)
|
||||
{
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
bool AddPollServiceHTTPHandler(string uripath, PollServiceEventArgs args);
|
||||
bool AddPollServiceHTTPHandler(PollServiceEventArgs args);
|
||||
bool AddPollServiceHTTPHandlerVarPath(PollServiceEventArgs args);
|
||||
|
||||
void RemovePollServiceHTTPHandler(string url, string path);
|
||||
void RemovePollServiceHTTPHandler(string path);
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
"Too many URLs already open" });
|
||||
return urlcode;
|
||||
}
|
||||
string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
|
||||
string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString();
|
||||
|
||||
UUID groupID = host.ParentGroup.UUID;
|
||||
UrlData urlData = new UrlData();
|
||||
@@ -268,14 +268,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
PollServiceEventArgs args
|
||||
= new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
//args.Type = PollServiceEventArgs.EventType.LslHttp;
|
||||
m_HttpServer.AddPollServiceHTTPHandler(args);
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
|
||||
// uri, itemID, host.Name, host.LocalId);
|
||||
m_HttpServer.AddPollServiceHTTPHandlerVarPath(args);
|
||||
|
||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
|
||||
//m_log.DebugFormat(
|
||||
// "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
|
||||
// uri, itemID, host.Name, host.LocalId);
|
||||
|
||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url + "/"});
|
||||
}
|
||||
|
||||
return urlcode;
|
||||
@@ -305,7 +305,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
"Too many URLs already open" });
|
||||
return urlcode;
|
||||
}
|
||||
string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";
|
||||
string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString();
|
||||
|
||||
UUID groupID = host.ParentGroup.UUID;
|
||||
UrlData urlData = new UrlData();
|
||||
@@ -333,14 +333,13 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
PollServiceEventArgs args
|
||||
= new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
//args.Type = PollServiceEventArgs.EventType.LslHttp;
|
||||
m_HttpsServer.AddPollServiceHTTPHandler(args);
|
||||
m_HttpsServer.AddPollServiceHTTPHandlerVarPath(args);
|
||||
|
||||
// m_log.DebugFormat(
|
||||
// "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
|
||||
// uri, itemID, host.Name, host.LocalId);
|
||||
|
||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
|
||||
//m_log.DebugFormat(
|
||||
// "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
|
||||
// uri, itemID, host.Name, host.LocalId);
|
||||
// keep ending / because legacy
|
||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url + "/"});
|
||||
}
|
||||
|
||||
return urlcode;
|
||||
@@ -351,7 +350,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
lock (m_UrlMap)
|
||||
{
|
||||
UrlData data;
|
||||
|
||||
url = url.TrimEnd(new char[]{'/'});
|
||||
if (!m_UrlMap.TryGetValue(url, out data))
|
||||
{
|
||||
return;
|
||||
@@ -507,9 +506,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
protected void RemoveUrl(UrlData data)
|
||||
{
|
||||
if (data.isSsl)
|
||||
m_HttpsServer.RemovePollServiceHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/");
|
||||
m_HttpsServer.RemovePollServiceHTTPHandler("", "/lslhttps/"+data.urlcode.ToString());
|
||||
else
|
||||
m_HttpServer.RemovePollServiceHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
|
||||
m_HttpServer.RemovePollServiceHTTPHandler("", "/lslhttp/"+data.urlcode.ToString());
|
||||
|
||||
if(m_countsPerSOG.TryGetValue(data.groupID, out int count))
|
||||
{
|
||||
@@ -667,46 +666,48 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
lock (request)
|
||||
{
|
||||
string uri = request.RawUrl;
|
||||
bool is_ssl = uri.Contains("lslhttps");
|
||||
if(uri.Length < 45)
|
||||
{
|
||||
request.InputStream.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
|
||||
|
||||
int pos1 = uri.IndexOf("/");// /lslhttp
|
||||
int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
|
||||
int pos3 = uri.IndexOf("/", pos2 + 1); // /lslhttp/urlcode
|
||||
|
||||
string uri_tmp = uri.Substring(0, pos3 + 1);
|
||||
//HTTP server code doesn't provide us with QueryStrings
|
||||
string uri_tmp;
|
||||
string pathInfo;
|
||||
|
||||
|
||||
pathInfo = uri.Substring(pos3);
|
||||
|
||||
UrlData url = null;
|
||||
string urlkey;
|
||||
if (!is_ssl)
|
||||
urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
|
||||
//m_UrlMap[];
|
||||
else
|
||||
urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
|
||||
|
||||
if (m_UrlMap.ContainsKey(urlkey))
|
||||
int pos = uri.IndexOf("/", 45); // /lslhttp/uuid/ <-
|
||||
if (pos >= 45)
|
||||
{
|
||||
url = m_UrlMap[urlkey];
|
||||
uri_tmp = uri.Substring(0, pos);
|
||||
pathInfo = uri.Substring(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
|
||||
request.InputStream.Dispose();
|
||||
return;
|
||||
uri_tmp = uri;
|
||||
pathInfo = string.Empty;
|
||||
}
|
||||
|
||||
string urlkey;
|
||||
if (uri.Contains("lslhttps"))
|
||||
urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
|
||||
//m_UrlMap[];
|
||||
else
|
||||
urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
|
||||
|
||||
if (!m_UrlMap.TryGetValue(urlkey, out UrlData url))
|
||||
{
|
||||
//m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
|
||||
request.InputStream.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
//for llGetHttpHeader support we need to store original URI here
|
||||
//to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
|
||||
//as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader
|
||||
|
||||
RequestData requestData = new RequestData();
|
||||
requestData.requestID = requestID;
|
||||
requestData.requestDone = false;
|
||||
@@ -738,7 +739,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
if (string.IsNullOrEmpty(key))
|
||||
sb.AppendFormat("{0}&", query[i]);
|
||||
else
|
||||
sb.AppendFormat("{0} = {1}&", key, query[i]);
|
||||
sb.AppendFormat("{0}={1}&", key, query[i]);
|
||||
}
|
||||
if (sb.Length > 1)
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
|
||||
Reference in New Issue
Block a user