From 79106b45f24412a72c03ea3fb24f2b9020d4c033 Mon Sep 17 00:00:00 2001 From: miilic Date: Thu, 1 Oct 2015 07:59:09 -0700 Subject: [PATCH] Bug 2170 - AnimationInterface outputs improperly formed XML --- src/netanim/doc/animation.rst | 2 +- ...linknode.cc => colors-link-description.cc} | 0 ...esources_demo.cc => resources-counters.cc} | 0 src/netanim/examples/wscript | 8 +-- src/netanim/model/animation-interface.cc | 53 +++++++++++++++---- src/netanim/model/animation-interface.h | 2 +- 6 files changed, 49 insertions(+), 16 deletions(-) rename src/netanim/examples/{dynamic_linknode.cc => colors-link-description.cc} (100%) rename src/netanim/examples/{resources_demo.cc => resources-counters.cc} (100%) diff --git a/src/netanim/doc/animation.rst b/src/netanim/doc/animation.rst index 2bbc1898e..8082719d6 100644 --- a/src/netanim/doc/animation.rst +++ b/src/netanim/doc/animation.rst @@ -235,7 +235,7 @@ With the above statement, AnimationInterface sets the node size to scale by 1.5. anim.UpdateNodeCounter (89, 7, 3.4); With the above statement, AnimationInterface sets the counter with Id == 89, associated with Node 7 with the value 3.4. -The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resources_demo.cc. +The counter with Id 89 is obtained using AnimationInterface::AddNodeCounter. An example usage for this is in src/netanim/examples/resource-counters.cc. Step 2: Loading the XML in NetAnim diff --git a/src/netanim/examples/dynamic_linknode.cc b/src/netanim/examples/colors-link-description.cc similarity index 100% rename from src/netanim/examples/dynamic_linknode.cc rename to src/netanim/examples/colors-link-description.cc diff --git a/src/netanim/examples/resources_demo.cc b/src/netanim/examples/resources-counters.cc similarity index 100% rename from src/netanim/examples/resources_demo.cc rename to src/netanim/examples/resources-counters.cc diff --git a/src/netanim/examples/wscript b/src/netanim/examples/wscript index ae4131731..05a995ed4 100644 --- a/src/netanim/examples/wscript +++ b/src/netanim/examples/wscript @@ -21,10 +21,10 @@ def build(bld): ['netanim', 'internet', 'mobility', 'applications', 'uan']) obj.source = 'uan-animation.cc' - obj = bld.create_ns3_program('dynamic_linknode', + obj = bld.create_ns3_program('colors-link-description', ['netanim', 'applications', 'point-to-point-layout']) - obj.source = 'dynamic_linknode.cc' + obj.source = 'colors-link-description.cc' - obj = bld.create_ns3_program('resources_demo', + obj = bld.create_ns3_program('resources-counters', ['netanim', 'applications', 'point-to-point-layout']) - obj.source = 'resources_demo.cc' + obj.source = 'resources-counters.cc' diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index cf0f3e53f..3ad31acae 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -1997,13 +1997,46 @@ AnimationInterface::AnimXmlElement::AnimXmlElement (std::string tagName, bool em template void -AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value) +AnimationInterface::AnimXmlElement::AddAttribute (std::string attribute, T value, bool xmlEscape) { std::ostringstream oss; oss << std::setprecision (10); oss << value; m_elementString += attribute.c_str (); - m_elementString += "=\"" + oss.str () + "\" "; + if (xmlEscape) + { + m_elementString += "=\""; + std::string valueStr = oss.str (); + for (std::string::iterator it = valueStr.begin (); it != valueStr.end (); ++it) + { + switch (*it) + { + case '&': + m_elementString += "&"; + break; + case '\"': + m_elementString += """; + break; + case '\'': + m_elementString += "'"; + break; + case '<': + m_elementString += "<"; + break; + case '>': + m_elementString += ">"; + break; + default: + m_elementString += *it; + break; + } + } + m_elementString += "\" "; + } + else + { + m_elementString += "=\"" + oss.str () + "\" "; + } } void @@ -2102,7 +2135,7 @@ AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::str element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); element.AddAttribute ("fromId", fromId); element.AddAttribute ("toId", toId); - element.AddAttribute ("ld", linkDescription); + element.AddAttribute ("ld", linkDescription, true); element.CloseElement (); WriteN (element.GetElementString (), m_f); } @@ -2130,9 +2163,9 @@ AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId) lprop = m_linkProperties[p2]; } - element.AddAttribute ("fd", lprop.fromNodeDescription); - element.AddAttribute ("td", lprop.toNodeDescription); - element.AddAttribute ("ld", lprop.linkDescription); + element.AddAttribute ("fd", lprop.fromNodeDescription, true); + element.AddAttribute ("td", lprop.toNodeDescription, true); + element.AddAttribute ("ld", lprop.linkDescription, true); element.CloseElement (); WriteN (element.GetElementString (), m_f); } @@ -2143,7 +2176,7 @@ AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo) AnimXmlElement element ("rt"); element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); element.AddAttribute ("id", nodeId); - element.AddAttribute ("info", routingInfo.c_str ()); + element.AddAttribute ("info", routingInfo.c_str (), true); element.CloseElement (); WriteN (element.GetElementString (), m_routingF); } @@ -2184,7 +2217,7 @@ AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, s element.AddAttribute ("fbTx", fbTx); if (!metaInfo.empty ()) { - element.AddAttribute ("meta-info", metaInfo.c_str ()); + element.AddAttribute ("meta-info", metaInfo.c_str (), true); } element.CloseElement (); WriteN (element.GetElementString (), m_f); @@ -2212,7 +2245,7 @@ AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, d element.AddAttribute ("lbTx", lbTx); if (!metaInfo.empty ()) { - element.AddAttribute ("meta-info", metaInfo.c_str ()); + element.AddAttribute ("meta-info", metaInfo.c_str (), true); } element.AddAttribute ("tId", tId); element.AddAttribute ("fbRx", fbRx); @@ -2303,7 +2336,7 @@ AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId) element.AddAttribute ("id", nodeId); if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ()) { - element.AddAttribute ("descr", m_nodeDescriptions[nodeId]); + element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true); } element.CloseElement (); WriteN (element.GetElementString (), m_f); diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index 7ee0d8477..2648adc31 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -520,7 +520,7 @@ private: public: AnimXmlElement (std::string tagName, bool emptyElement=true); template - void AddAttribute (std::string attribute, T value); + void AddAttribute (std::string attribute, T value, bool xmlEscape=false); void Close (); void CloseElement (); void CloseTag ();