add timeouts and placehold for future code

master
UbitUmarov 2020-04-29 10:39:36 +01:00
parent 3a21d4de1e
commit 7b5934ea26
1 changed files with 67 additions and 17 deletions

View File

@ -4,6 +4,7 @@ using System.Collections;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Timers;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
@ -103,8 +104,8 @@ namespace OpenSim.Region.ClientStack.Linden
uploadResponse.uploader = uploaderURL; uploadResponse.uploader = uploaderURL;
uploadResponse.state = "upload"; uploadResponse.state = "upload";
ItemUpdater uploader = new ItemUpdater(itemID, objectID, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); ItemUpdater uploader = new ItemUpdater(itemID, objectID, atype, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
uploader.remoteAdress = httpRequest.RemoteIPEndPoint.Address; uploader.m_remoteAdress = httpRequest.RemoteIPEndPoint.Address;
uploader.OnUpLoad += ItemUpdated; uploader.OnUpLoad += ItemUpdated;
@ -248,6 +249,11 @@ namespace OpenSim.Region.ClientStack.Linden
errors.Add(item); errors.Add(item);
} }
} }
static public bool ValidateAssetData(byte assetType, byte[] data)
{
return true;
}
} }
@ -258,21 +264,35 @@ namespace OpenSim.Region.ClientStack.Linden
public class ItemUpdater public class ItemUpdater
{ {
public event UpdateItem OnUpLoad = null; public event UpdateItem OnUpLoad = null;
private string uploaderPath = String.Empty; private string m_uploaderPath = String.Empty;
private UUID inventoryItemID; private UUID m_inventoryItemID;
private UUID objectID; private UUID m_objectID;
private IHttpServer httpListener; private IHttpServer m_httpListener;
private bool m_dumpAssetToFile; private bool m_dumpAssetToFile;
public IPAddress remoteAdress; public IPAddress m_remoteAdress;
private byte m_assetType;
private Timer m_timeout;
public ItemUpdater(UUID inventoryItem, UUID objectid, string path, IHttpServer httpServer, bool dumpAssetToFile) public ItemUpdater(UUID inventoryItem, UUID objectid,byte aType, string path, IHttpServer httpServer, bool dumpAssetToFile)
{ {
m_dumpAssetToFile = dumpAssetToFile; m_dumpAssetToFile = dumpAssetToFile;
inventoryItemID = inventoryItem; m_inventoryItemID = inventoryItem;
objectID = objectid; m_objectID = objectid;
uploaderPath = path; m_uploaderPath = path;
httpListener = httpServer; m_httpListener = httpServer;
m_assetType = aType;
m_timeout = new Timer();
m_timeout.Elapsed += Timeout;
m_timeout.Interval = 1000;
m_timeout.Start();
}
private void Timeout(Object source, ElapsedEventArgs e)
{
m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
m_timeout.Dispose();
} }
/// <summary> /// <summary>
@ -284,9 +304,12 @@ namespace OpenSim.Region.ClientStack.Linden
/// <returns></returns> /// <returns></returns>
public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data) public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
{ {
httpListener.RemoveSimpleStreamHandler(uploaderPath); m_timeout.Stop();
m_timeout.Dispose();
if (!request.RemoteIPEndPoint.Address.Equals(remoteAdress)) m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
if (!request.RemoteIPEndPoint.Address.Equals(m_remoteAdress))
{ {
response.StatusCode = (int)HttpStatusCode.Unauthorized; response.StatusCode = (int)HttpStatusCode.Unauthorized;
return; return;
@ -300,20 +323,26 @@ namespace OpenSim.Region.ClientStack.Linden
return; return;
} }
UUID assetID = OnUpLoad(inventoryItemID, objectID, data); if (!BunchOfCaps.ValidateAssetData(m_assetType, data))
{
response.StatusCode = (int)HttpStatusCode.BadRequest;
return;
}
UUID assetID = OnUpLoad(m_inventoryItemID, m_objectID, data);
if (assetID == UUID.Zero) if (assetID == UUID.Zero)
{ {
LLSDAssetUploadError uperror = new LLSDAssetUploadError(); LLSDAssetUploadError uperror = new LLSDAssetUploadError();
uperror.message = "Failed to update inventory item asset"; uperror.message = "Failed to update inventory item asset";
uperror.identifier = inventoryItemID; uperror.identifier = m_inventoryItemID;
res = LLSDHelpers.SerialiseLLSDReply(uperror); res = LLSDHelpers.SerialiseLLSDReply(uperror);
} }
else else
{ {
LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
uploadComplete.new_asset = assetID.ToString(); uploadComplete.new_asset = assetID.ToString();
uploadComplete.new_inventory_item = inventoryItemID; uploadComplete.new_inventory_item = m_inventoryItemID;
uploadComplete.state = "complete"; uploadComplete.state = "complete";
res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
} }
@ -342,6 +371,7 @@ namespace OpenSim.Region.ClientStack.Linden
private IHttpServer m_httpListener; private IHttpServer m_httpListener;
private bool m_dumpAssetToFile; private bool m_dumpAssetToFile;
public IPAddress remoteAdress; public IPAddress remoteAdress;
private Timer m_timeout;
public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, bool isScriptRunning, public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, bool isScriptRunning,
string path, IHttpServer httpServer, bool dumpAssetToFile) string path, IHttpServer httpServer, bool dumpAssetToFile)
@ -355,6 +385,17 @@ namespace OpenSim.Region.ClientStack.Linden
m_uploaderPath = path; m_uploaderPath = path;
m_httpListener = httpServer; m_httpListener = httpServer;
m_timeout = new Timer();
m_timeout.Elapsed += Timeout;
m_timeout.Interval = 1000;
m_timeout.Start();
}
private void Timeout(Object source, ElapsedEventArgs e)
{
m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
m_timeout.Dispose();
} }
/// <summary> /// <summary>
@ -366,6 +407,9 @@ namespace OpenSim.Region.ClientStack.Linden
/// <returns></returns> /// <returns></returns>
public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data) public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
{ {
m_timeout.Stop();
m_timeout.Dispose();
m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath); m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
if(OnUpLoad == null) if(OnUpLoad == null)
{ {
@ -373,6 +417,12 @@ namespace OpenSim.Region.ClientStack.Linden
return; return;
} }
if (!BunchOfCaps.ValidateAssetData((byte)AssetType.LSLText, data))
{
response.StatusCode = (int)HttpStatusCode.BadRequest;
return;
}
response.StatusCode = (int)HttpStatusCode.OK; response.StatusCode = (int)HttpStatusCode.OK;
try try