change cap CreateInventoryCategory

master
UbitUmarov 2020-04-25 12:55:02 +01:00
parent e48d2f2c1f
commit 288dffcda1
1 changed files with 88 additions and 111 deletions

View File

@ -236,7 +236,7 @@ namespace OpenSim.Region.ClientStack.Linden
public string GetNewCapPath() public string GetNewCapPath()
{ {
return "/CAPS/" + UUID.Random(); return "/" + UUID.Random();
} }
/// <summary> /// <summary>
@ -319,18 +319,15 @@ namespace OpenSim.Region.ClientStack.Linden
m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req); m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req);
m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req); m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req);
IRequestHandler UpdateAgentInformationHandler = new RestStreamHandler( m_HostCapsObj.RegisterSimpleHandler("UpdateAgentInformation",
"POST", GetNewCapPath(), UpdateAgentInformation, "UpdateAgentInformation", null); new SimpleStreamHandler(GetNewCapPath(), UpdateAgentInformation));
m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler);
IRequestHandler CopyInventoryFromNotecardHandler = new RestStreamHandler( IRequestHandler CopyInventoryFromNotecardHandler = new RestStreamHandler(
"POST", GetNewCapPath(), CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null); "POST", GetNewCapPath(), CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null);
m_HostCapsObj.RegisterHandler("CopyInventoryFromNotecard", CopyInventoryFromNotecardHandler); m_HostCapsObj.RegisterHandler("CopyInventoryFromNotecard", CopyInventoryFromNotecardHandler);
IRequestHandler CreateInventoryCategoryHandler = new RestStreamHandler( m_HostCapsObj.RegisterSimpleHandler("CreateInventoryCategory",
"POST", GetNewCapPath(), CreateInventoryCategory, "CreateInventoryCategory", null); new SimpleStreamHandler(GetNewCapPath(), CreateInventoryCategory));
m_HostCapsObj.RegisterHandler("CreateInventoryCategory", CreateInventoryCategoryHandler);
} }
catch (Exception e) catch (Exception e)
{ {
@ -1270,109 +1267,94 @@ namespace OpenSim.Region.ClientStack.Linden
m_FileAgentInventoryState = FileAgentInventoryState.idle; m_FileAgentInventoryState = FileAgentInventoryState.idle;
} }
/// <summary> public void CreateInventoryCategory(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
///
/// </summary>
/// <param name="mapReq"></param>
/// <returns></returns>
public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq)
{
m_log.Debug("[CAPS]: MapLayer Request in region: " + m_regionName);
LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse());
return mapResponse;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected static OSDMapLayer GetOSDMapLayerResponse()
{
OSDMapLayer mapLayer = new OSDMapLayer();
mapLayer.Right = 5000;
mapLayer.Top = 5000;
mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006");
return mapLayer;
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="path"></param>
/// <param name="param"></param>
/// <returns></returns>
public string RequestTexture(string request, string path, string param)
{
m_log.Debug("texture request " + request);
// Needs implementing (added to remove compiler warning)
return String.Empty;
}
public string CreateInventoryCategory(string request, string path, string param,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{ {
if(httpRequest.HttpMethod != "POST")
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
if (m_Scene.InventoryService == null) if (m_Scene.InventoryService == null)
{ {
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.ServiceUnavailable; httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
httpResponse.StatusDescription = "Service not avaiable"; return;
return "";
} }
ScenePresence sp = m_Scene.GetScenePresence(m_AgentID); ScenePresence sp = m_Scene.GetScenePresence(m_AgentID);
if (sp == null || sp.IsDeleted) if (sp == null || sp.IsDeleted)
{ {
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.ServiceUnavailable; httpResponse.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
httpResponse.StatusDescription = "Retry later"; httpResponse.AddHeader("Retry-After", "60");
httpResponse.AddHeader("Retry-After", "30"); return;
return "";
} }
Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request)); OSDMap req;
OSD tmp;
while (true) // kinda goto try
{ {
if (!hash.Contains("folder_id") || !(hash["folder_id"] is UUID)) req = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
break; }
UUID folderID = (UUID)hash["folder_id"]; catch
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return;
}
if (!hash.Contains("parent_id") || !(hash["parent_id"] is UUID)) try
break; {
UUID parentID = (UUID)hash["parent_id"]; while (true) // kinda goto
{
if (!req.TryGetValue("folder_id", out tmp) || !(tmp is OSDUUID))
break;
UUID folderID = tmp.AsUUID();
if (!hash.Contains("name") || !(hash["name"] is string)) if(folderID == UUID.Zero)
break; break;
string folderName = (string)hash["name"];
if (!hash.Contains("type") || !(hash["type"] is int)) if (!req.TryGetValue("parent_id", out tmp) || !(tmp is OSDUUID))
break; break;
int folderType = (int)hash["type"]; UUID parentID = tmp.AsUUID();
InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, m_AgentID, (short)folderType, parentID, 1); if (!req.TryGetValue("name", out tmp) || !(tmp is OSDString))
if (!m_Scene.InventoryService.AddFolder(folder)) break;
break; string folderName = tmp.AsString();
// costly double check plus possible service changes if(string.IsNullOrEmpty(folderName))
folder = m_Scene.InventoryService.GetFolder(m_AgentID, folderID); break;
if(folder == null)
break;
StringBuilder sb = LLSDxmlEncode.Start(); if(folderName.Length > 63)
LLSDxmlEncode.AddMap(sb); folderName = folderName.Substring(0, 63);
LLSDxmlEncode.AddElem("folder_id", folder.ID, sb);
LLSDxmlEncode.AddElem("name", folder.Name, sb);
LLSDxmlEncode.AddElem("parent_id", folder.ParentID, sb);
LLSDxmlEncode.AddElem("type", folder.Type, sb);
LLSDxmlEncode.AddEndMap(sb);
string resp = LLSDxmlEncode.End(sb);
return resp; if (!req.TryGetValue("type", out tmp) || !(tmp is OSDInteger))
} break;
int folderType = tmp.AsInteger();
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, m_AgentID, (short)folderType, parentID, 1);
return ""; if (!m_Scene.InventoryService.AddFolder(folder))
break;
// costly double check plus possible service changes
folder = m_Scene.InventoryService.GetFolder(m_AgentID, folderID);
if (folder == null)
break;
StringBuilder sb = LLSDxmlEncode.Start();
LLSDxmlEncode.AddMap(sb);
LLSDxmlEncode.AddElem("folder_id", folder.ID, sb);
LLSDxmlEncode.AddElem("name", folder.Name, sb);
LLSDxmlEncode.AddElem("parent_id", folder.ParentID, sb);
LLSDxmlEncode.AddElem("type", folder.Type, sb);
LLSDxmlEncode.AddEndMap(sb);
httpResponse.RawBuffer = Encoding.UTF8.GetBytes(LLSDxmlEncode.End(sb));
httpResponse.StatusCode = (int)HttpStatusCode.OK;
return;
}
}
catch { }
m_log.Debug("[CAPS]: CreateInventoryCategory failed to process request");
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
} }
/// <summary> /// <summary>
@ -1824,16 +1806,23 @@ namespace OpenSim.Region.ClientStack.Linden
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
// resp["transaction_id"] = "undef"; // resp["transaction_id"] = "undef";
httpResponse.RawBuffer = Encoding.UTF8.GetBytes(LLSDxmlEncode.End(lsl)); httpResponse.RawBuffer = Encoding.UTF8.GetBytes(LLSDxmlEncode.End(lsl));
httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.StatusCode = (int)HttpStatusCode.OK;
} }
public string UpdateAgentInformation(string request, string path, public void UpdateAgentInformation(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
string param, IOSHttpRequest httpRequest,
IOSHttpResponse httpResponse)
{ {
// OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); if (httpRequest.HttpMethod != "POST")
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
// this is wrong now ignores request and sends same result for all
// we don't store and worse don't use that to filter contents
// OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
OSDMap resp = new OSDMap(); OSDMap resp = new OSDMap();
OSDMap accessPrefs = new OSDMap(); OSDMap accessPrefs = new OSDMap();
@ -1841,8 +1830,8 @@ namespace OpenSim.Region.ClientStack.Linden
resp["access_prefs"] = accessPrefs; resp["access_prefs"] = accessPrefs;
string response = OSDParser.SerializeLLSDXmlString(resp); httpResponse.RawBuffer = OSDParser.SerializeLLSDXmlBytes(resp);
return response; httpResponse.StatusCode = (int)HttpStatusCode.OK;
} }
public bool OSDMapTOVector3(OSDMap map, out Vector3 v) public bool OSDMapTOVector3(OSDMap map, out Vector3 v)
@ -2013,8 +2002,6 @@ namespace OpenSim.Region.ClientStack.Linden
OSDMap resp = new OSDMap(); OSDMap resp = new OSDMap();
string response;
bool fail = true; bool fail = true;
IClientAPI client = null; IClientAPI client = null;
ScenePresence sp; ScenePresence sp;
@ -2367,16 +2354,6 @@ namespace OpenSim.Region.ClientStack.Linden
httpListener.RemoveStreamHandler("POST", uploaderPath); httpListener.RemoveStreamHandler("POST", uploaderPath);
} }
///Left this in and commented in case there are unforseen issues
//private void SaveAssetToFile(string filename, byte[] data)
//{
// FileStream fs = File.Create(filename);
// BinaryWriter bw = new BinaryWriter(fs);
// bw.Write(data);
// bw.Close();
// fs.Close();
//}
private static void SaveAssetToFile(string filename, byte[] data) private static void SaveAssetToFile(string filename, byte[] data)
{ {
string assetPath = "UserAssets"; string assetPath = "UserAssets";