From d96701a0e42f7ea31337e2242cba592c2fcc3a8b Mon Sep 17 00:00:00 2001
From: Dr Scofield
Date: Fri, 15 Aug 2008 07:45:23 +0000
Subject: From: Richard Alimi <ralimi@us.ibm.com>

The following patch allows an asset to be added via the REST interface.


---
 .../Rest/Inventory/RestAssetServices.cs            | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
index 70957f5..b4eb7db 100644
--- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAssetServices.cs
@@ -168,6 +168,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
                     DoGet(rdata);
                     break;
                 case "put" :
+                    DoPut(rdata);
+                    break;
                 case "post" :
                 case "delete" :
                 default :
@@ -240,6 +242,48 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
 
         }
 
+        private void DoPut(AssetRequestData rdata)
+        {
+            Rest.Log.DebugFormat("{0} REST Asset handler, Method = <{1}> ENTRY", MsgId, rdata.method);
+
+            // The only parameter we accept is an LLUUID for
+            // the asset
+
+            if (rdata.parameters.Length == 1)
+            {
+                rdata.initXmlReader();
+                XmlReader xml = rdata.reader;
+
+                if (!xml.ReadToFollowing("Asset"))
+                {
+                    Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path);
+                    rdata.Fail(Rest.HttpStatusCodeBadRequest, 
+                               Rest.HttpStatusDescBadRequest);
+                }
+
+                AssetBase asset = new AssetBase();
+                asset.ID = rdata.parameters[0];
+                asset.Name = xml.GetAttribute("name");
+                asset.Description = xml.GetAttribute("desc");
+                asset.Type = SByte.Parse(xml.GetAttribute("type"));
+                asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0;
+                asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0;
+                asset.Data = (new System.Text.ASCIIEncoding()).GetBytes(Rest.Base64ToString(xml.ReadElementContentAsString("Asset", "")));
+
+                Rest.AssetServices.AddAsset(asset);
+            }
+            else
+            {
+                Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
+                rdata.Fail(Rest.HttpStatusCodeNotFound, 
+                           Rest.HttpStatusDescNotFound);
+            }
+
+            rdata.Complete();
+            rdata.Respond("Asset " + rdata.method + ": Normal completion");
+
+        }
+
         internal class AssetRequestData : RequestData
         {
             internal AssetRequestData(OSHttpRequest request, OSHttpResponse response, string prefix)
-- 
cgit v1.1