got tired of creating stringbuilders

httptests
UbitUmarov 2018-01-25 09:06:39 +00:00
parent cdd3ef857c
commit 98019031df
2 changed files with 43 additions and 28 deletions

View File

@ -48,11 +48,28 @@ namespace OpenSim.Framework
sb.Append("<llsd>"); sb.Append("<llsd>");
} }
// got tired of creating a stringbuilder all the time;
public static StringBuilder Start(int size = 256, bool addxmlversion = false)
{
StringBuilder sb = new StringBuilder(size);
if(addxmlversion)
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd>"); // legacy llsd xml name still valid
else
sb.Append("<llsd>");
return sb;
}
public static void AddEnd(StringBuilder sb) public static void AddEnd(StringBuilder sb)
{ {
sb.Append("</llsd>"); sb.Append("</llsd>");
} }
public static string End(StringBuilder sb)
{
sb.Append("</llsd>");
return sb.ToString();
}
// map == a list of key value pairs // map == a list of key value pairs
public static void AddMap(StringBuilder sb) public static void AddMap(StringBuilder sb)
{ {
@ -452,7 +469,6 @@ namespace OpenSim.Framework
{ {
int i; int i;
char c; char c;
String t;
int len = s.Length; int len = s.Length;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)

View File

@ -1378,8 +1378,8 @@ namespace OpenSim.Region.ClientStack.Linden
OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
OSDArray object_ids = (OSDArray)req["object_ids"]; OSDArray object_ids = (OSDArray)req["object_ids"];
StringBuilder lsl = new StringBuilder(256); StringBuilder lsl = LLSDxmlEncode.Start();
LLSDxmlEncode.AddStart(lsl);
if(object_ids.Count == 0) if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl); LLSDxmlEncode.AddEmpyMap(lsl);
else else
@ -1405,8 +1405,8 @@ namespace OpenSim.Region.ClientStack.Linden
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
} }
} }
LLSDxmlEncode.AddEnd(lsl);
return lsl.ToString(); return LLSDxmlEncode.End(lsl);
} }
public string GetObjectCost(string request, string path, public string GetObjectCost(string request, string path,
@ -1416,8 +1416,8 @@ namespace OpenSim.Region.ClientStack.Linden
OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
OSDArray object_ids = (OSDArray)req["object_ids"]; OSDArray object_ids = (OSDArray)req["object_ids"];
StringBuilder lsl = new StringBuilder(512); StringBuilder lsl = LLSDxmlEncode.Start(512);
LLSDxmlEncode.AddStart(lsl);
if(object_ids.Count == 0) if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl); LLSDxmlEncode.AddEmpyMap(lsl);
else else
@ -1466,8 +1466,7 @@ namespace OpenSim.Region.ClientStack.Linden
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
} }
LLSDxmlEncode.AddEnd(lsl); return LLSDxmlEncode.End(lsl);
return lsl.ToString();
} }
public string ResourceCostSelected(string request, string path, public string ResourceCostSelected(string request, string path,
@ -1475,8 +1474,6 @@ 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();
float phys=0; float phys=0;
float stream=0; float stream=0;
@ -1527,16 +1524,21 @@ namespace OpenSim.Region.ClientStack.Linden
} }
} }
OSDMap object_data = new OSDMap(); StringBuilder lsl = LLSDxmlEncode.Start();
LLSDxmlEncode.AddMap(lsl);
object_data["physics"] = phys; LLSDxmlEncode.AddMap("selected", lsl);
object_data["streaming"] = stream;
object_data["simulation"] = simul; LLSDxmlEncode.AddElem("physics", phys, lsl);
LLSDxmlEncode.AddElem("streaming", stream, lsl);
LLSDxmlEncode.AddElem("simulation", simul, lsl);
LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEndMap(lsl);
resp["selected"] = object_data;
// resp["transaction_id"] = "undef"; // resp["transaction_id"] = "undef";
string response = OSDParser.SerializeLLSDXmlString(resp); return LLSDxmlEncode.End(lsl);
return response;
} }
public string UpdateAgentInformation(string request, string path, public string UpdateAgentInformation(string request, string path,
@ -1839,13 +1841,17 @@ namespace OpenSim.Region.ClientStack.Linden
return ""; return "";
} }
// Full content request
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK;
//httpResponse.ContentLength = ??;
httpResponse.ContentType = "application/llsd+xml";
NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
string[] ids = query.GetValues("ids"); string[] ids = query.GetValues("ids");
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 = LLSDxmlEncode.Start(names.Count * 256 + 256);
LLSDxmlEncode.AddStart(lsl);
LLSDxmlEncode.AddMap(lsl); LLSDxmlEncode.AddMap(lsl);
if(names.Count == 0) if(names.Count == 0)
LLSDxmlEncode.AddEmpyArray("agents", lsl); LLSDxmlEncode.AddEmpyArray("agents", lsl);
@ -1881,14 +1887,7 @@ namespace OpenSim.Region.ClientStack.Linden
} }
LLSDxmlEncode.AddEndMap(lsl); LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddEnd(lsl); return LLSDxmlEncode.End(lsl);;
// Full content request
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK;
//httpResponse.ContentLength = ??;
httpResponse.ContentType = "application/llsd+xml";
return lsl.ToString();
} }
} }