split the Upload* caps per asset type. We will need that one day. move uploadtaskscript to simpleh
parent
7a8a7c7168
commit
3a21d4de1e
|
@ -3693,7 +3693,20 @@ namespace OpenSim.Framework
|
|||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
public static void SaveAssetToFile(string filename, byte[] data)
|
||||
{
|
||||
string assetPath = "UserAssets";
|
||||
if (!Directory.Exists(assetPath))
|
||||
{
|
||||
Directory.CreateDirectory(assetPath);
|
||||
}
|
||||
FileStream fs = File.Create(Path.Combine(assetPath, filename));
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
bw.Write(data);
|
||||
bw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/* don't like this code
|
||||
public class DoubleQueue<T> where T:class
|
||||
|
@ -3858,5 +3871,6 @@ namespace OpenSim.Framework
|
|||
rng.GetBytes(buff);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,10 +266,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
m_HostCapsObj.RegisterSimpleHandler("ResourceCostSelected",
|
||||
new SimpleOSDMapHandler("POST", GetNewCapPath(), ResourceCostSelected));
|
||||
|
||||
IRequestHandler req = new RestStreamHandler(
|
||||
"POST", GetNewCapPath(), ScriptTaskInventory, "UpdateScript", null);
|
||||
m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req);
|
||||
m_HostCapsObj.RegisterHandler("UpdateScriptTask", req);
|
||||
|
||||
|
||||
if(m_AllowCapHomeLocation)
|
||||
{
|
||||
|
@ -304,23 +301,37 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>(
|
||||
"POST", GetNewCapPath(), NewAgentInventoryRequest, "NewFileAgentInventory", null));
|
||||
|
||||
if(ItemUpdatedCall != null)
|
||||
SimpleOSDMapHandler oreq;
|
||||
if (ItemUpdatedCall != null)
|
||||
{
|
||||
// we have a single "do it all" method
|
||||
var oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateInventoryItemAsset);
|
||||
|
||||
// first also sets the http handler, others only register the cap, using it
|
||||
// first sets the http handler, others only register the cap, using it
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateNotecardItemAsset);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateNotecardAgentInventory", oreq, true);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateNotecardTaskInventory", oreq, false); // a object inv
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateAnimSetAgentInventory", oreq, false);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgentInventory", oreq, false);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgent", oreq, false);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateSettingsAgentInventory", oreq, false);
|
||||
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateAnimSetItemAsset);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateAnimSetAgentInventory", oreq, true);
|
||||
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateScriptItemAsset);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgent", oreq, true);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgentInventory", oreq, false); //legacy
|
||||
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateSettingsItemAsset);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateSettingsAgentInventory", oreq, true);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateSettingsTaskInventory", oreq, false); // a object inv
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateGestureAgentInventory", oreq, false);
|
||||
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateGestureItemAsset);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateGestureAgentInventory", oreq, true);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateGestureTaskInventory", oreq, false);
|
||||
}
|
||||
|
||||
if (TaskScriptUpdatedCall != null)
|
||||
{
|
||||
oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateScriptTaskInventory);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptTask", oreq, true);
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateScriptTaskInventory", oreq, true); //legacy
|
||||
}
|
||||
|
||||
m_HostCapsObj.RegisterSimpleHandler("UpdateAgentInformation",
|
||||
new SimpleStreamHandler(GetNewCapPath(), UpdateAgentInformation));
|
||||
|
||||
|
@ -400,7 +411,6 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
List<string> validCaps = new List<string>();
|
||||
|
||||
foreach (OSD c in capsRequested)
|
||||
|
@ -419,98 +429,6 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
//m_log.DebugFormat("[CAPS] CapsRequest {0}", result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the script task update handler. Provides a URL to which the client can upload a new asset.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="httpRequest">HTTP request header object</param>
|
||||
/// <param name="httpResponse">HTTP response header object</param>
|
||||
/// <returns></returns>
|
||||
public string ScriptTaskInventory(string request, string path, string param,
|
||||
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||
{
|
||||
try
|
||||
{
|
||||
//m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
|
||||
//m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);
|
||||
|
||||
Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
|
||||
LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
|
||||
LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest);
|
||||
|
||||
string uploaderPath = GetNewCapPath();
|
||||
|
||||
TaskInventoryScriptUpdater uploader =
|
||||
new TaskInventoryScriptUpdater(
|
||||
llsdUpdateRequest.item_id,
|
||||
llsdUpdateRequest.task_id,
|
||||
llsdUpdateRequest.is_script_running,
|
||||
uploaderPath,
|
||||
m_HostCapsObj.HttpListener,
|
||||
m_dumpAssetsToFile);
|
||||
uploader.OnUpLoad += TaskScriptUpdated;
|
||||
|
||||
m_HostCapsObj.HttpListener.AddStreamHandler(
|
||||
new BinaryStreamHandler(
|
||||
"POST", uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null));
|
||||
|
||||
string protocol = m_HostCapsObj.SSLCaps ? "https://" : "http://";
|
||||
|
||||
string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath;
|
||||
|
||||
LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
|
||||
uploadResponse.uploader = uploaderURL;
|
||||
uploadResponse.state = "upload";
|
||||
|
||||
// m_log.InfoFormat("[CAPS]: " +
|
||||
// "ScriptTaskInventory response: {0}",
|
||||
// LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
|
||||
|
||||
return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[CAPS]: " + e.ToString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when new asset data for an agent inventory item update has been uploaded.
|
||||
/// </summary>
|
||||
/// <param name="itemID">Item to update</param>
|
||||
/// <param name="primID">Prim containing item to update</param>
|
||||
/// <param name="isScriptRunning">Signals whether the script to update is currently running</param>
|
||||
/// <param name="data">New asset data</param>
|
||||
public void TaskScriptUpdated(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors)
|
||||
{
|
||||
if (TaskScriptUpdatedCall != null)
|
||||
{
|
||||
ArrayList e = TaskScriptUpdatedCall(m_HostCapsObj.AgentID, itemID, primID, isScriptRunning, data);
|
||||
foreach (Object item in e)
|
||||
errors.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when new asset data for an agent inventory item update has been uploaded.
|
||||
/// </summary>
|
||||
/// <param name="itemID">Item to update</param>
|
||||
/// <param name="data">New asset data</param>
|
||||
/// <returns></returns>
|
||||
public UUID ItemUpdated(UUID itemID, UUID objectID, byte[] data)
|
||||
{
|
||||
if (ItemUpdatedCall != null)
|
||||
{
|
||||
return ItemUpdatedCall(m_HostCapsObj.AgentID, itemID, objectID, data);
|
||||
}
|
||||
|
||||
return UUID.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -2292,118 +2210,4 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This class is a callback invoked when a client sends asset data to
|
||||
/// a task inventory script update url
|
||||
/// </summary>
|
||||
public class TaskInventoryScriptUpdater
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public event UpdateTaskScript OnUpLoad;
|
||||
|
||||
private UpdateTaskScript handlerUpdateTaskScript = null;
|
||||
|
||||
private string uploaderPath = String.Empty;
|
||||
private UUID inventoryItemID;
|
||||
private UUID primID;
|
||||
private bool isScriptRunning;
|
||||
private IHttpServer httpListener;
|
||||
private bool m_dumpAssetToFile;
|
||||
|
||||
public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, int isScriptRunning,
|
||||
string path, IHttpServer httpServer, bool dumpAssetToFile)
|
||||
{
|
||||
m_dumpAssetToFile = dumpAssetToFile;
|
||||
|
||||
this.inventoryItemID = inventoryItemID;
|
||||
this.primID = primID;
|
||||
|
||||
// This comes in over the packet as an integer, but actually appears to be treated as a bool
|
||||
this.isScriptRunning = (0 == isScriptRunning ? false : true);
|
||||
|
||||
uploaderPath = path;
|
||||
httpListener = httpServer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public string uploaderCaps(byte[] data, string path, string param)
|
||||
{
|
||||
try
|
||||
{
|
||||
// m_log.InfoFormat("[CAPS]: " +
|
||||
// "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
|
||||
// data, path, param));
|
||||
|
||||
string res = String.Empty;
|
||||
LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();
|
||||
|
||||
ArrayList errors = new ArrayList();
|
||||
handlerUpdateTaskScript = OnUpLoad;
|
||||
if (handlerUpdateTaskScript != null)
|
||||
{
|
||||
handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data, ref errors);
|
||||
}
|
||||
|
||||
uploadComplete.new_asset = inventoryItemID;
|
||||
uploadComplete.compiled = errors.Count > 0 ? false : true;
|
||||
uploadComplete.state = "complete";
|
||||
uploadComplete.errors = new OpenSim.Framework.Capabilities.OSDArray();
|
||||
uploadComplete.errors.Array = errors;
|
||||
|
||||
res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
|
||||
|
||||
httpListener.RemoveStreamHandler("POST", uploaderPath);
|
||||
|
||||
if (m_dumpAssetToFile)
|
||||
{
|
||||
SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
|
||||
}
|
||||
|
||||
// m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[CAPS]: " + e.ToString());
|
||||
}
|
||||
|
||||
// XXX Maybe this should be some meaningful error packet
|
||||
return null;
|
||||
}
|
||||
|
||||
///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)
|
||||
{
|
||||
string assetPath = "UserAssets";
|
||||
if (!Directory.Exists(assetPath))
|
||||
{
|
||||
Directory.CreateDirectory(assetPath);
|
||||
}
|
||||
FileStream fs = File.Create(Path.Combine(assetPath, filename));
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
bw.Write(data);
|
||||
bw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.StructuredData;
|
||||
|
@ -18,14 +21,32 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
|
||||
public partial class BunchOfCaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Called by the items updates handler. Provides a URL to which the client can upload a new asset.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public void UpdateInventoryItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
public void UpdateNotecardItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
UpdateInventoryItemAsset(httpRequest, httpResponse, map, (byte)AssetType.Notecard);
|
||||
}
|
||||
|
||||
public void UpdateAnimSetItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
//UpdateInventoryItemAsset(httpRequest, httpResponse, map, CustomInventoryType.AnimationSet);
|
||||
}
|
||||
|
||||
public void UpdateScriptItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
UpdateInventoryItemAsset(httpRequest, httpResponse, map, (byte)AssetType.LSLText);
|
||||
}
|
||||
|
||||
public void UpdateSettingsItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
UpdateInventoryItemAsset(httpRequest, httpResponse, map, (byte)AssetType.Settings);
|
||||
}
|
||||
|
||||
public void UpdateGestureItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
UpdateInventoryItemAsset(httpRequest, httpResponse, map, (byte)AssetType.Gesture);
|
||||
}
|
||||
|
||||
private void UpdateInventoryItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map, byte atype, bool taskSript = false)
|
||||
{
|
||||
m_log.Debug("[CAPS]: UpdateInventoryItemAsset Request in region: " + m_regionName + "\n");
|
||||
|
||||
|
@ -76,43 +97,173 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
|
||||
string uploaderPath = GetNewCapPath();
|
||||
|
||||
ItemUpdater uploader = new ItemUpdater(itemID, objectID, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
|
||||
uploader.OnUpLoad += ItemUpdated;
|
||||
|
||||
m_HostCapsObj.HttpListener.AddStreamHandler(
|
||||
new BinaryStreamHandler(
|
||||
"POST", uploaderPath, uploader.uploaderCaps, "UpdateInventoryItemAsset", null));
|
||||
|
||||
string protocol = m_HostCapsObj.SSLCaps ? "https://" : "http://";
|
||||
|
||||
string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath;
|
||||
|
||||
LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
|
||||
uploadResponse.uploader = uploaderURL;
|
||||
uploadResponse.state = "upload";
|
||||
|
||||
ItemUpdater uploader = new ItemUpdater(itemID, objectID, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
|
||||
uploader.remoteAdress = httpRequest.RemoteIPEndPoint.Address;
|
||||
|
||||
uploader.OnUpLoad += ItemUpdated;
|
||||
|
||||
var uploaderHandler = new SimpleBinaryHandler("POST", uploaderPath, uploader.process);
|
||||
|
||||
uploaderHandler.MaxDataSize = 10000000; // change per asset type?
|
||||
|
||||
m_HostCapsObj.HttpListener.AddSimpleStreamHandler(uploaderHandler);
|
||||
|
||||
// m_log.InfoFormat("[CAPS]: UpdateAgentInventoryAsset response: {0}",
|
||||
// LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
|
||||
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when new asset data for an inventory item update has been uploaded.
|
||||
/// </summary>
|
||||
/// <param name="itemID">Item to update</param>
|
||||
/// <param name="data">New asset data</param>
|
||||
/// <returns></returns>
|
||||
public UUID ItemUpdated(UUID itemID, UUID objectID, byte[] data)
|
||||
{
|
||||
if (ItemUpdatedCall != null)
|
||||
{
|
||||
return ItemUpdatedCall(m_HostCapsObj.AgentID, itemID, objectID, data);
|
||||
}
|
||||
return UUID.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the script task update handler. Provides a URL to which the client can upload a new asset.
|
||||
/// </summary>
|
||||
/// <param name="httpRequest">HTTP request header object</param>
|
||||
/// <param name="httpResponse">HTTP response header object</param>
|
||||
/// <returns></returns>
|
||||
public void UpdateScriptTaskInventory(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map)
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.OK;
|
||||
|
||||
try
|
||||
{
|
||||
//m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
|
||||
//m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);
|
||||
|
||||
UUID itemID = UUID.Zero;
|
||||
UUID objectID = UUID.Zero;
|
||||
bool is_script_running = false;
|
||||
OSD tmp;
|
||||
try
|
||||
{
|
||||
if (map.TryGetValue("item_id", out tmp))
|
||||
itemID = tmp;
|
||||
if (map.TryGetValue("task_id", out tmp))
|
||||
objectID = tmp;
|
||||
if (map.TryGetValue("is_script_running", out tmp))
|
||||
is_script_running = tmp;
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (itemID == UUID.Zero || objectID == UUID.Zero)
|
||||
{
|
||||
LLSDAssetUploadError error = new LLSDAssetUploadError();
|
||||
error.message = "failed to recode request";
|
||||
error.identifier = UUID.Zero;
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error));
|
||||
return;
|
||||
}
|
||||
|
||||
SceneObjectPart sop = m_Scene.GetSceneObjectPart(objectID);
|
||||
if (sop == null)
|
||||
{
|
||||
LLSDAssetUploadError error = new LLSDAssetUploadError();
|
||||
error.message = "object not found";
|
||||
error.identifier = UUID.Zero;
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_Scene.Permissions.CanEditObjectInventory(objectID, m_AgentID))
|
||||
{
|
||||
LLSDAssetUploadError error = new LLSDAssetUploadError();
|
||||
error.message = "No permissions to edit objec";
|
||||
error.identifier = UUID.Zero;
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_Scene.Permissions.CanEditScript(itemID, objectID, m_AgentID))
|
||||
{
|
||||
LLSDAssetUploadError error = new LLSDAssetUploadError();
|
||||
error.message = "No permissions to edit script";
|
||||
error.identifier = UUID.Zero;
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error));
|
||||
return;
|
||||
}
|
||||
|
||||
string uploaderPath = GetNewCapPath();
|
||||
string protocol = m_HostCapsObj.SSLCaps ? "https://" : "http://";
|
||||
string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath;
|
||||
LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
|
||||
uploadResponse.uploader = uploaderURL;
|
||||
uploadResponse.state = "upload";
|
||||
|
||||
TaskInventoryScriptUpdater uploader = new TaskInventoryScriptUpdater(itemID, objectID, is_script_running,
|
||||
uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
|
||||
uploader.remoteAdress = httpRequest.RemoteIPEndPoint.Address;
|
||||
uploader.OnUpLoad += TaskScriptUpdated;
|
||||
|
||||
var uploaderHandler = new SimpleBinaryHandler("POST", uploaderPath, uploader.process);
|
||||
|
||||
uploaderHandler.MaxDataSize = 10000000; // change per asset type?
|
||||
|
||||
m_HostCapsObj.HttpListener.AddSimpleStreamHandler(uploaderHandler);
|
||||
|
||||
// m_log.InfoFormat("[CAPS]: " +
|
||||
// "ScriptTaskInventory response: {0}",
|
||||
// LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
|
||||
|
||||
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[UpdateScriptTaskInventory]: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when new asset data for an agent inventory item update has been uploaded.
|
||||
/// </summary>
|
||||
/// <param name="itemID">Item to update</param>
|
||||
/// <param name="primID">Prim containing item to update</param>
|
||||
/// <param name="isScriptRunning">Signals whether the script to update is currently running</param>
|
||||
/// <param name="data">New asset data</param>
|
||||
public void TaskScriptUpdated(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors)
|
||||
{
|
||||
if (TaskScriptUpdatedCall != null)
|
||||
{
|
||||
ArrayList e = TaskScriptUpdatedCall(m_HostCapsObj.AgentID, itemID, primID, isScriptRunning, data);
|
||||
foreach (Object item in e)
|
||||
errors.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This class is a callback invoked when a client sends asset data to
|
||||
/// an agent inventory notecard update url
|
||||
/// </summary>
|
||||
public class ItemUpdater
|
||||
{
|
||||
public event UpdateItem OnUpLoad;
|
||||
|
||||
private UpdateItem handlerUpdateItem = null;
|
||||
|
||||
public event UpdateItem OnUpLoad = null;
|
||||
private string uploaderPath = String.Empty;
|
||||
private UUID inventoryItemID;
|
||||
private UUID objectID;
|
||||
private IHttpServer httpListener;
|
||||
private bool m_dumpAssetToFile;
|
||||
public IPAddress remoteAdress;
|
||||
|
||||
public ItemUpdater(UUID inventoryItem, UUID objectid, string path, IHttpServer httpServer, bool dumpAssetToFile)
|
||||
{
|
||||
|
@ -131,54 +282,131 @@ namespace OpenSim.Region.ClientStack.Linden
|
|||
/// <param name="path"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public string uploaderCaps(byte[] data, string path, string param)
|
||||
public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
|
||||
{
|
||||
httpListener.RemoveStreamHandler("POST", uploaderPath);
|
||||
httpListener.RemoveSimpleStreamHandler(uploaderPath);
|
||||
|
||||
if (!request.RemoteIPEndPoint.Address.Equals(remoteAdress))
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
return;
|
||||
}
|
||||
|
||||
UUID inv = inventoryItemID;
|
||||
string res = String.Empty;
|
||||
|
||||
UUID assetID = UUID.Zero;
|
||||
handlerUpdateItem = OnUpLoad;
|
||||
if (handlerUpdateItem != null)
|
||||
assetID = handlerUpdateItem(inv, objectID, data);
|
||||
if (OnUpLoad == null)
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.Gone;
|
||||
return;
|
||||
}
|
||||
|
||||
UUID assetID = OnUpLoad(inventoryItemID, objectID, data);
|
||||
|
||||
if (assetID == UUID.Zero)
|
||||
{
|
||||
LLSDAssetUploadError uperror = new LLSDAssetUploadError();
|
||||
uperror.message = "Failed to update inventory item asset";
|
||||
uperror.identifier = inv;
|
||||
uperror.identifier = inventoryItemID;
|
||||
res = LLSDHelpers.SerialiseLLSDReply(uperror);
|
||||
}
|
||||
else
|
||||
{
|
||||
LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
|
||||
uploadComplete.new_asset = assetID.ToString();
|
||||
uploadComplete.new_inventory_item = inv;
|
||||
uploadComplete.new_inventory_item = inventoryItemID;
|
||||
uploadComplete.state = "complete";
|
||||
res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
|
||||
}
|
||||
|
||||
if (m_dumpAssetToFile)
|
||||
{
|
||||
SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
|
||||
Util.SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
|
||||
}
|
||||
|
||||
return res;
|
||||
response.StatusCode = (int)HttpStatusCode.OK;
|
||||
response.RawBuffer = Encoding.UTF8.GetBytes(res);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is a callback invoked when a client sends asset data to
|
||||
/// a task inventory script update url
|
||||
/// </summary>
|
||||
public class TaskInventoryScriptUpdater
|
||||
{
|
||||
public event UpdateTaskScript OnUpLoad;
|
||||
private string m_uploaderPath = String.Empty;
|
||||
private UUID m_inventoryItemID;
|
||||
private UUID m_primID;
|
||||
private bool m_isScriptRunning;
|
||||
private IHttpServer m_httpListener;
|
||||
private bool m_dumpAssetToFile;
|
||||
public IPAddress remoteAdress;
|
||||
|
||||
public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, bool isScriptRunning,
|
||||
string path, IHttpServer httpServer, bool dumpAssetToFile)
|
||||
{
|
||||
m_dumpAssetToFile = dumpAssetToFile;
|
||||
|
||||
m_inventoryItemID = inventoryItemID;
|
||||
m_primID = primID;
|
||||
|
||||
m_isScriptRunning = isScriptRunning;
|
||||
|
||||
m_uploaderPath = path;
|
||||
m_httpListener = httpServer;
|
||||
}
|
||||
|
||||
private static void SaveAssetToFile(string filename, byte[] data)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public void process(IOSHttpRequest request, IOSHttpResponse response, byte[] data)
|
||||
{
|
||||
string assetPath = "UserAssets";
|
||||
if (!Directory.Exists(assetPath))
|
||||
m_httpListener.RemoveSimpleStreamHandler(m_uploaderPath);
|
||||
if(OnUpLoad == null)
|
||||
{
|
||||
Directory.CreateDirectory(assetPath);
|
||||
response.StatusCode = (int)HttpStatusCode.Gone;
|
||||
return;
|
||||
}
|
||||
|
||||
response.StatusCode = (int)HttpStatusCode.OK;
|
||||
|
||||
try
|
||||
{
|
||||
string res = String.Empty;
|
||||
LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();
|
||||
|
||||
ArrayList errors = new ArrayList();
|
||||
OnUpLoad?.Invoke(m_inventoryItemID, m_primID, m_isScriptRunning, data, ref errors);
|
||||
|
||||
uploadComplete.new_asset = m_inventoryItemID;
|
||||
uploadComplete.compiled = errors.Count > 0 ? false : true;
|
||||
uploadComplete.state = "complete";
|
||||
uploadComplete.errors = new OpenSim.Framework.Capabilities.OSDArray();
|
||||
uploadComplete.errors.Array = errors;
|
||||
|
||||
res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
|
||||
|
||||
if (m_dumpAssetToFile)
|
||||
{
|
||||
Util.SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
|
||||
}
|
||||
|
||||
// m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
|
||||
response.RawBuffer = Encoding.UTF8.GetBytes(res);
|
||||
}
|
||||
catch
|
||||
{
|
||||
LLSDAssetUploadError error = new LLSDAssetUploadError();
|
||||
error.message = "could not compile script";
|
||||
error.identifier = UUID.Zero;
|
||||
response.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error));
|
||||
return;
|
||||
}
|
||||
FileStream fs = File.Create(Path.Combine(assetPath, filename));
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
bw.Write(data);
|
||||
bw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue