From 201805172fe71b125391700529035835cef340a1 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Wed, 24 Sep 2008 11:39:08 +0000 Subject: cleanups, fixing REST appearance services. --- .../Rest/Inventory/RequestData.cs | 2 +- .../Rest/Inventory/RestAppearanceServices.cs | 236 +++++++++++---------- 2 files changed, 128 insertions(+), 110 deletions(-) (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory') diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs index 972d840..12caf81 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs @@ -1103,7 +1103,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory // Respond to the client's request, tag the response (for the // benefit of trace) to indicate the reason. - Respond(String.Format("Failure response: ({0}) : {1}", + Respond(String.Format("Failure response: ({0}) : {1} ", code, Rest.HttpStatusDesc[code])); // Finally initialize and the throw a RestException. All of the diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs index 82c0c2b..c375ade 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs @@ -42,9 +42,12 @@ using Nini.Config; namespace OpenSim.ApplicationPlugins.Rest.Inventory { + public class RestAppearanceServices : IRest { + private static readonly int PARM_USERID = 0; + // private static readonly int PARM_PATH = 1; private bool enabled = false; @@ -139,6 +142,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory private void DoAppearance(RequestData hdata) { + AppearanceRequestData rdata = (AppearanceRequestData) hdata; Rest.Log.DebugFormat("{0} DoAppearance ENTRY", MsgId); @@ -207,7 +211,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory // inventory. // - // Do we have at least a user agent name? if (rdata.Parameters.Length < 1) @@ -306,7 +309,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory if (rdata.userAppearance == null) { - rdata.Fail(Rest.HttpStatusCodeNoContent,"appearance data not found"); + rdata.Fail(Rest.HttpStatusCodeNoContent, + String.Format("appearance data not found for user {0} {1}", + rdata.userProfile.FirstName, rdata.userProfile.SurName)); } rdata.initXmlWriter(); @@ -331,26 +336,34 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory private void DoExtend(AppearanceRequestData rdata) { + bool created = false; bool modified = false; string newnode = String.Empty; + Rest.Log.DebugFormat("{0} POST ENTRY", MsgId); + AvatarAppearance old = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); + rdata.userAppearance = new AvatarAppearance(); - rdata.userAppearance.Owner = old.Owner; - rdata.userAppearance.Serial = old.Serial; + // Although the following behavior is admitted by HTTP I am becoming + // increasingly doubtful that it is appropriate for REST. If I attempt to + // add a new record, and it already exists, then it seems to me that the + // attempt should fail, rather than update the existing record. if (GetUserAppearance(rdata)) { modified = rdata.userAppearance != null; created = !modified; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); + // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } else { created = true; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); + // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } if (created) @@ -358,9 +371,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory newnode = String.Format("{0} {1}", rdata.userProfile.FirstName, rdata.userProfile.SurName); // Must include a location header with a URI that identifies the new resource. + rdata.AddHeader(Rest.HttpHeaderLocation,String.Format("http://{0}{1}:{2}{3}{4}", rdata.hostname,rdata.port,rdata.path,Rest.UrlPathSeparator, newnode)); rdata.Complete(Rest.HttpStatusCodeCreated); + } else { @@ -399,6 +414,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory { modified = true; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); + Rest.UserServices.UpdateUserProfile(rdata.userProfile); } if (created) @@ -703,121 +719,123 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory } - private void FormatUserAppearance(AppearanceRequestData rdata) + private void FormatPart(AppearanceRequestData rdata, string part, UUID item, UUID asset) { - - rdata.writer.WriteStartElement("Appearance"); - rdata.writer.WriteAttributeString("Height", rdata.userAppearance.AvatarHeight.ToString()); - rdata.writer.WriteAttributeString("Owner", rdata.userAppearance.Owner.ToString()); - rdata.writer.WriteAttributeString("Serial", rdata.userAppearance.Serial.ToString()); - - rdata.writer.WriteStartElement("Body"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.BodyItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.BodyAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Skin"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.SkinItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.SkinAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Hair"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.HairItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.HairAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Eyes"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.EyesItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.EyesAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Shirt"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.ShirtItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.ShirtAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Pants"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.PantsItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.PantsAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Shoes"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.ShoesItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.ShoesAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Socks"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.SocksItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.SocksAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Jacket"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.JacketItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.JacketAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Gloves"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.GlovesItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.GlovesAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("UnderShirt"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.UnderShirtItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.UnderShirtAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("UnderPants"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.UnderPantsItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.UnderPantsAsset.ToString()); - rdata.writer.WriteEndElement(); - - rdata.writer.WriteStartElement("Skirt"); - rdata.writer.WriteAttributeString("Item",rdata.userAppearance.SkirtItem.ToString()); - rdata.writer.WriteAttributeString("Asset",rdata.userAppearance.SkirtAsset.ToString()); - rdata.writer.WriteEndElement(); - - Hashtable attachments = rdata.userAppearance.GetAttachments(); - - rdata.writer.WriteStartElement("Attachments"); - - for (int i=0; i