recover LLSD login handler

master
UbitUmarov 2020-04-27 14:34:49 +01:00
parent 6ffb5bcf23
commit 9d08f8307e
1 changed files with 66 additions and 88 deletions

View File

@ -610,22 +610,36 @@ namespace OpenSim.Framework.Servers.HttpServer
string path = request.UriPath; string path = request.UriPath;
if (path == "/") if (path == "/")
{ {
if (request.ContentType == "application/json-rpc") response.StatusCode =(int)HttpStatusCode.NotFound; // falback
switch (request.ContentType)
{ {
if (DebugLevel >= 3) case "application/json-rpc":
LogIncomingToContentTypeHandler(request); {
if (DebugLevel >= 3)
LogIncomingToContentTypeHandler(request);
HandleJsonRpcRequests(request, response); HandleJsonRpcRequests(request, response);
requestEndTick = Environment.TickCount; break;
response.Send(); }
return;
case "application/llsd+xml":
{
HandleLLSDLogin(request, response);
break;
}
default: // not sure about xmlrpc content type coerence at this point
{
if (DebugLevel >= 3)
LogIncomingToXmlRpcHandler(request);
HandleXmlRpcRequests(request, response);
break;
}
} }
if (DebugLevel >= 3) if (request.InputStream != null && request.InputStream.CanRead)
LogIncomingToXmlRpcHandler(request); request.InputStream.Dispose();
// generic login request.
HandleXmlRpcRequests(request, response);
requestEndTick = Environment.TickCount; requestEndTick = Environment.TickCount;
response.Send(); response.Send();
return; return;
@ -1209,8 +1223,6 @@ namespace OpenSim.Framework.Servers.HttpServer
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, errorMessage); xmlRpcResponse.SetFault(-32603, errorMessage);
} }
response.AddHeader("Access-Control-Allow-Origin", "*"); response.AddHeader("Access-Control-Allow-Origin", "*");
} }
else else
@ -1326,67 +1338,68 @@ namespace OpenSim.Framework.Servers.HttpServer
response.StatusCode = (int)HttpStatusCode.OK; response.StatusCode = (int)HttpStatusCode.OK;
} }
private void HandleLLSDLogin(OSHttpRequest request, OSHttpResponse response)
{
if(m_defaultLlsdHandler == null)
return;
response.StatusCode = (int)HttpStatusCode.BadRequest;
OSD llsdRequest;
try
{
llsdRequest = OSDParser.DeserializeLLSDXml(request.InputStream);
}
catch
{
return;
}
if(llsdRequest == null || !(llsdRequest is OSDMap))
return;
OSD llsdResponse = m_defaultLlsdHandler(llsdRequest, request.RemoteIPEndPoint);
if(llsdResponse != null)
{
response.ContentType = "application/llsd+xml";
response.RawBuffer = OSDParser.SerializeLLSDXmlBytes(llsdResponse);
response.StatusCode = (int)HttpStatusCode.OK;
}
}
private byte[] HandleLLSDRequests(OSHttpRequest request, OSHttpResponse response) private byte[] HandleLLSDRequests(OSHttpRequest request, OSHttpResponse response)
{ {
//m_log.Warn("[BASE HTTP SERVER]: We've figured out it's a LLSD Request"); //m_log.Warn("[BASE HTTP SERVER]: We've figured out it's a LLSD Request");
bool notfound = false; bool notfound = false;
string requestBody;
using(StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8))
requestBody= reader.ReadToEnd();
//m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody); //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody);
OSD llsdRequest = null; OSD llsdRequest = null;
OSD llsdResponse = null; OSD llsdResponse = null;
bool LegacyLLSDLoginLibOMV = (requestBody.Contains("passwd") && requestBody.Contains("mac") && requestBody.Contains("viewer_digest"));
if (requestBody.Length == 0)
// Get Request
{
requestBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd><map><key>request</key><string>get</string></map></llsd>";
}
try try
{ {
llsdRequest = OSDParser.Deserialize(requestBody); llsdRequest = OSDParser.Deserialize(request.InputStream);
} }
catch (Exception ex) catch (Exception ex)
{ {
m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message); m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
} }
if (llsdRequest != null)// && m_defaultLlsdHandler != null) if (llsdRequest != null)
{ {
if (!LegacyLLSDLoginLibOMV && TryGetLLSDHandler(request.RawUrl, out LLSDMethod llsdhandler)) if (TryGetLLSDHandler(request.RawUrl, out LLSDMethod llsdhandler))
{ {
// we found a registered llsd handler to service this request // we found a registered llsd handler to service this request
llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString()); llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString());
} }
else else
{ notfound = true;
// we didn't find a registered llsd handler to service this request
// check if we have a default llsd handler
if (m_defaultLlsdHandler != null)
{
llsdResponse = m_defaultLlsdHandler(llsdRequest, request.RemoteIPEndPoint);
}
else
{
// Oops, no handler for this.. give em the failed message
notfound = true;
}
}
} }
else else
{
notfound = true; notfound = true;
}
if(notfound) if(notfound)
{ {
response.StatusCode = (int)HttpStatusCode.NotFound; response.StatusCode = (int)HttpStatusCode.NotFound;
response.StatusDescription = "Not found";
return null; return null;
} }
@ -1395,9 +1408,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (llsdResponse.ToString() == "shutdown404!") if (llsdResponse.ToString() == "shutdown404!")
{ {
response.ContentType = "text/plain"; response.ContentType = "text/plain";
response.StatusCode = 404; response.StatusCode = (int)HttpStatusCode.NotFound;
response.StatusDescription = "Not Found";
buffer = Encoding.UTF8.GetBytes("Not found");
} }
else else
{ {
@ -1405,6 +1416,7 @@ namespace OpenSim.Framework.Servers.HttpServer
buffer = BuildLLSDResponse(request, response, llsdResponse); buffer = BuildLLSDResponse(request, response, llsdResponse);
} }
response.StatusCode = (int)HttpStatusCode.OK;
response.ContentLength64 = buffer.Length; response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8; response.ContentEncoding = Encoding.UTF8;
@ -1485,13 +1497,6 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
} }
// extra kicker to remove the default XMLRPC login case.. just in case..
if (path != "/" && bestMatch == "/" && searchquery != "/")
return false;
if (path == "/")
return false;
if (String.IsNullOrEmpty(bestMatch)) if (String.IsNullOrEmpty(bestMatch))
{ {
return false; return false;
@ -1536,10 +1541,6 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
} }
// extra kicker to remove the default XMLRPC login case.. just in case..
if (path == "/")
return false;
if (String.IsNullOrEmpty(bestMatch)) if (String.IsNullOrEmpty(bestMatch))
{ {
return false; return false;
@ -1687,42 +1688,19 @@ namespace OpenSim.Framework.Servers.HttpServer
keysvals.Add("requestvars", requestVars); keysvals.Add("requestvars", requestVars);
// keysvals.Add("form", request.Form); // keysvals.Add("form", request.Form);
if (keysvals.Contains("method")) GenericHTTPMethod requestprocessor;
bool foundHandler = TryGetHTTPHandlerPathBased(request.RawUrl, out requestprocessor);
if (foundHandler)
{ {
// m_log.Debug("[BASE HTTP SERVER]: Contains Method"); Hashtable responsedata2 = requestprocessor(keysvals);
string method = (string) keysvals["method"]; buffer = DoHTTPGruntWork(responsedata2, response);
// m_log.Debug("[BASE HTTP SERVER]: " + requestBody);
GenericHTTPMethod requestprocessor;
bool foundHandler = TryGetHTTPHandler(method, out requestprocessor);
if (foundHandler)
{
Hashtable responsedata1 = requestprocessor(keysvals);
buffer = DoHTTPGruntWork(responsedata1,response);
//SendHTML500(response); //SendHTML500(response);
}
else
{
// m_log.Warn("[BASE HTTP SERVER]: Handler Not Found");
buffer = SendHTML404(response);
}
} }
else else
{ {
GenericHTTPMethod requestprocessor;
bool foundHandler = TryGetHTTPHandlerPathBased(request.RawUrl, out requestprocessor);
if (foundHandler)
{
Hashtable responsedata2 = requestprocessor(keysvals);
buffer = DoHTTPGruntWork(responsedata2, response);
//SendHTML500(response);
}
else
{
// m_log.Warn("[BASE HTTP SERVER]: Handler Not Found2"); // m_log.Warn("[BASE HTTP SERVER]: Handler Not Found2");
buffer = SendHTML404(response); buffer = SendHTML404(response);
}
} }
return buffer; return buffer;