a few changes to encoder and a few more uses

httptests
UbitUmarov 2018-01-25 08:02:45 +00:00
parent 266eabcad4
commit cdd3ef857c
2 changed files with 110 additions and 62 deletions

View File

@ -40,7 +40,7 @@ namespace OpenSim.Framework
{ {
static readonly DateTime depoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); static readonly DateTime depoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static void AddStartHeader(StringBuilder sb, bool addxmlversion = false) public static void AddStart(StringBuilder sb, bool addxmlversion = false)
{ {
if(addxmlversion) if(addxmlversion)
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd>"); // legacy llsd xml name still valid sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd>"); // legacy llsd xml name still valid
@ -48,13 +48,13 @@ namespace OpenSim.Framework
sb.Append("<llsd>"); sb.Append("<llsd>");
} }
public static void AddEndHeader(StringBuilder sb) public static void AddEnd(StringBuilder sb)
{ {
sb.Append("</llsd>"); sb.Append("</llsd>");
} }
// map == a list of key value pairs // map == a list of key value pairs
public static void AddStartMap(StringBuilder sb) public static void AddMap(StringBuilder sb)
{ {
sb.Append("<map>"); sb.Append("<map>");
} }
@ -70,7 +70,7 @@ namespace OpenSim.Framework
} }
// array == a list values // array == a list values
public static void AddStartArray(StringBuilder sb) public static void AddArray(StringBuilder sb)
{ {
sb.Append("<array>"); sb.Append("<array>");
} }
@ -99,6 +99,18 @@ namespace OpenSim.Framework
sb.Append("<boolean />"); sb.Append("<boolean />");
} }
public static void AddElem(byte e, StringBuilder sb)
{
if(e == 0)
sb.Append("<integer />");
else
{
sb.Append("<integer>");
sb.Append(e.ToString());
sb.Append("</integer>");
}
}
public static void AddElem(int e, StringBuilder sb) public static void AddElem(int e, StringBuilder sb)
{ {
if(e == 0) if(e == 0)
@ -171,7 +183,7 @@ namespace OpenSim.Framework
} }
} }
public static void AddURIElem(Uri e, StringBuilder sb) public static void AddElem(Uri e, StringBuilder sb)
{ {
if(e == null) if(e == null)
{ {
@ -218,7 +230,7 @@ namespace OpenSim.Framework
//************ key value ******************* //************ key value *******************
// assumes name is a valid llsd key // assumes name is a valid llsd key
public static void AddStartMap(string name, StringBuilder sb) public static void AddMap(string name, StringBuilder sb)
{ {
sb.Append("<key>"); sb.Append("<key>");
sb.Append(name); sb.Append(name);
@ -233,7 +245,7 @@ namespace OpenSim.Framework
} }
// array == a list values // array == a list values
public static void AddStartArray(string name, StringBuilder sb) public static void AddArray(string name, StringBuilder sb)
{ {
sb.Append("<key>"); sb.Append("<key>");
sb.Append(name); sb.Append(name);
@ -267,6 +279,22 @@ namespace OpenSim.Framework
sb.Append("<boolean />"); sb.Append("<boolean />");
} }
public static void AddElem(string name, byte e, StringBuilder sb)
{
sb.Append("<key>");
sb.Append(name);
sb.Append("</key>");
if(e == 0)
sb.Append("<integer />");
else
{
sb.Append("<integer>");
sb.Append(e.ToString());
sb.Append("</integer>");
}
}
public static void AddElem(string name, int e, StringBuilder sb) public static void AddElem(string name, int e, StringBuilder sb)
{ {
sb.Append("<key>"); sb.Append("<key>");
@ -363,7 +391,7 @@ namespace OpenSim.Framework
} }
} }
public static void AddURIElem(string name, Uri e, StringBuilder sb) public static void AddElem(string name, Uri e, StringBuilder sb)
{ {
sb.Append("<key>"); sb.Append("<key>");
sb.Append(name); sb.Append(name);

View File

@ -1376,9 +1376,15 @@ namespace OpenSim.Region.ClientStack.Linden
IOSHttpResponse httpResponse) IOSHttpResponse httpResponse)
{ {
OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
OSDMap resp = new OSDMap();
OSDArray object_ids = (OSDArray)req["object_ids"]; OSDArray object_ids = (OSDArray)req["object_ids"];
StringBuilder lsl = new StringBuilder(256);
LLSDxmlEncode.AddStart(lsl);
if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl);
else
{
LLSDxmlEncode.AddMap(lsl);
for (int i = 0 ; i < object_ids.Count ; i++) for (int i = 0 ; i < object_ids.Count ; i++)
{ {
UUID uuid = object_ids[i].AsUUID(); UUID uuid = object_ids[i].AsUUID();
@ -1386,20 +1392,21 @@ namespace OpenSim.Region.ClientStack.Linden
SceneObjectPart obj = m_Scene.GetSceneObjectPart(uuid); SceneObjectPart obj = m_Scene.GetSceneObjectPart(uuid);
if (obj != null) if (obj != null)
{ {
OSDMap object_data = new OSDMap(); LLSDxmlEncode.AddMap(uuid.ToString(),lsl);
object_data["PhysicsShapeType"] = obj.PhysicsShapeType; LLSDxmlEncode.AddElem("PhysicsShapeType", obj.PhysicsShapeType, lsl);
object_data["Density"] = obj.Density; LLSDxmlEncode.AddElem("Density", obj.Density, lsl);
object_data["Friction"] = obj.Friction; LLSDxmlEncode.AddElem("Friction", obj.Friction, lsl);
object_data["Restitution"] = obj.Restitution; LLSDxmlEncode.AddElem("Restitution", obj.Restitution, lsl);
object_data["GravityMultiplier"] = obj.GravityModifier; LLSDxmlEncode.AddElem("GravityMultiplier", obj.GravityModifier, lsl);
resp[uuid.ToString()] = object_data; LLSDxmlEncode.AddEndMap(lsl);
}
LLSDxmlEncode.AddEndMap(lsl);
} }
} }
LLSDxmlEncode.AddEnd(lsl);
string response = OSDParser.SerializeLLSDXmlString(resp); return lsl.ToString();
return response;
} }
public string GetObjectCost(string request, string path, public string GetObjectCost(string request, string path,
@ -1407,10 +1414,16 @@ namespace OpenSim.Region.ClientStack.Linden
IOSHttpResponse httpResponse) IOSHttpResponse httpResponse)
{ {
OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
OSDMap resp = new OSDMap();
OSDArray object_ids = (OSDArray)req["object_ids"]; OSDArray object_ids = (OSDArray)req["object_ids"];
StringBuilder lsl = new StringBuilder(512);
LLSDxmlEncode.AddStart(lsl);
if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl);
else
{
bool haveone = false;
LLSDxmlEncode.AddMap(lsl);
for (int i = 0; i < object_ids.Count; i++) for (int i = 0; i < object_ids.Count; i++)
{ {
UUID uuid = object_ids[i].AsUUID(); UUID uuid = object_ids[i].AsUUID();
@ -1421,6 +1434,7 @@ namespace OpenSim.Region.ClientStack.Linden
grp = part.ParentGroup; grp = part.ParentGroup;
if (grp != null) if (grp != null)
{ {
haveone = true;
float linksetCost; float linksetCost;
float linksetPhysCost; float linksetPhysCost;
float partCost; float partCost;
@ -1428,26 +1442,32 @@ namespace OpenSim.Region.ClientStack.Linden
grp.GetResourcesCosts(part,out linksetCost,out linksetPhysCost,out partCost,out partPhysCost); grp.GetResourcesCosts(part,out linksetCost,out linksetPhysCost,out partCost,out partPhysCost);
OSDMap object_data = new OSDMap(); LLSDxmlEncode.AddMap(uuid.ToString(), lsl);
object_data["linked_set_resource_cost"] = linksetCost;
object_data["resource_cost"] = partCost; LLSDxmlEncode.AddElem("linked_set_resource_cost", linksetCost, lsl);
object_data["physics_cost"] = partPhysCost; LLSDxmlEncode.AddElem("resource_cost", partCost, lsl);
object_data["linked_set_physics_cost"] = linksetPhysCost; LLSDxmlEncode.AddElem("physics_cost", partPhysCost, lsl);
object_data["resource_limiting_type"] = "legacy"; LLSDxmlEncode.AddElem("linked_set_physics_cost", linksetPhysCost, lsl);
resp[uuid.ToString()] = object_data; LLSDxmlEncode.AddElem("resource_limiting_type", "legacy", lsl);
LLSDxmlEncode.AddEndMap(lsl);
} }
} }
if(resp.Count == 0) if(!haveone)
{ {
OSDMap object_data = new OSDMap(); LLSDxmlEncode.AddMap(UUID.Zero.ToString(), lsl);
object_data["linked_set_resource_cost"] = 0; LLSDxmlEncode.AddElem("linked_set_resource_cost", 0, lsl);
object_data["resource_cost"] = 0; LLSDxmlEncode.AddElem("resource_cost", 0, lsl);
object_data["physics_cost"] = 0; LLSDxmlEncode.AddElem("physics_cost", 0, lsl);
object_data["linked_set_physics_cost"] = 0; LLSDxmlEncode.AddElem("linked_set_physics_cost", 0, lsl);
resp[UUID.Zero.ToString()] = object_data; LLSDxmlEncode.AddElem("resource_limiting_type", "legacy", lsl);
LLSDxmlEncode.AddEndMap(lsl);
} }
string response = OSDParser.SerializeLLSDXmlString(resp); LLSDxmlEncode.AddEndMap(lsl);
return response; }
LLSDxmlEncode.AddEnd(lsl);
return lsl.ToString();
} }
public string ResourceCostSelected(string request, string path, public string ResourceCostSelected(string request, string path,
@ -1825,13 +1845,13 @@ namespace OpenSim.Region.ClientStack.Linden
Dictionary<UUID,string> names = m_UserManager.GetUsersNames(ids); Dictionary<UUID,string> names = m_UserManager.GetUsersNames(ids);
StringBuilder lsl = new StringBuilder(names.Count * 256 + 256); StringBuilder lsl = new StringBuilder(names.Count * 256 + 256);
LLSDxmlEncode.AddStartHeader(lsl); LLSDxmlEncode.AddStart(lsl);
LLSDxmlEncode.AddStartMap(lsl); LLSDxmlEncode.AddMap(lsl);
if(names.Count == 0) if(names.Count == 0)
LLSDxmlEncode.AddEmpyArray("agents", lsl); LLSDxmlEncode.AddEmpyArray("agents", lsl);
else else
{ {
LLSDxmlEncode.AddStartArray("agents", lsl); LLSDxmlEncode.AddArray("agents", lsl);
foreach (KeyValuePair<UUID,string> kvp in names) foreach (KeyValuePair<UUID,string> kvp in names)
{ {
@ -1846,7 +1866,7 @@ namespace OpenSim.Region.ClientStack.Linden
if(parts[0] == "Unknown") if(parts[0] == "Unknown")
continue; continue;
LLSDxmlEncode.AddStartMap(lsl); LLSDxmlEncode.AddMap(lsl);
LLSDxmlEncode.AddElem("display_name_next_update", DateTime.UtcNow.AddDays(8), lsl); LLSDxmlEncode.AddElem("display_name_next_update", DateTime.UtcNow.AddDays(8), lsl);
LLSDxmlEncode.AddElem("display_name_expires", DateTime.UtcNow.AddMonths(1), lsl); LLSDxmlEncode.AddElem("display_name_expires", DateTime.UtcNow.AddMonths(1), lsl);
LLSDxmlEncode.AddElem("display_name", kvp.Value, lsl); LLSDxmlEncode.AddElem("display_name", kvp.Value, lsl);
@ -1861,7 +1881,7 @@ namespace OpenSim.Region.ClientStack.Linden
} }
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEndHeader(lsl); LLSDxmlEncode.AddEnd(lsl);
// Full content request // Full content request
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK; httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK;