public override byte[] Handle(string path, Stream requestData,
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
string body = HttpServerHandlerHelpers.ReadString(requestData).Trim();
MainConsole.Instance.TraceFormat("[WebUI]: query String: {0}", body);
string method = string.Empty;
OSDMap resp = new OSDMap();
try
{
OSDMap map = (OSDMap)OSDParser.DeserializeJson(body);
//Make sure that the person who is calling can access the web service
if (map.ContainsKey("WebPassword") && (map["WebPassword"] == m_password))
{
method = map["Method"].AsString();
if (method == "Login")
{
resp = Login(map,false);
}
else if (method == "AdminLogin")
{
resp = Login(map,true);
}
else if (APIMethods.ContainsKey(method))
{
object[] args = new object[1]{map};
resp = (OSDMap)APIMethods[method].Invoke(this, args);
}
else
{
MainConsole.Instance.TraceFormat("[WebUI] Unsupported method called ({0})", method);
}
}
else
{
MainConsole.Instance.Debug("Password does not match");
}
}
catch (Exception e)
{
MainConsole.Instance.TraceFormat("[WebUI] Exception thrown: " + e.ToString());
}
if(resp.Count == 0){
resp.Add("response", OSD.FromString("Failed"));
}
UTF8Encoding encoding = new UTF8Encoding();
httpResponse.ContentType = "application/json";
return encoding.GetBytes(OSDParser.SerializeJsonString(resp, true));
}