From: Eduardo Ramos Testillano (eramedu) Date: Sat, 2 May 2020 19:39:53 +0000 (+0200) Subject: Allow diameter message & avp to normalize their xml representation X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;ds=inline;h=227446df961ead723c8f2b04ea53d99c770a438f;p=anna.git Allow diameter message & avp to normalize their xml representation The method `asXMLString` for Message and Avp classes has now an optional bool "sortAttributes" which defaults to `false` (previous behaviour). So, you could normalize by mean sorting attribute names for nodes within xml. This does not affect to the structure because the method asXMLString just generates the representations on-demand. The new parameter is set to true when programming regexps and during TestCondition comply for diameter messages received. --- diff --git a/include/anna/diameter/codec/Avp.hpp b/include/anna/diameter/codec/Avp.hpp index c4debd2..5bffde7 100644 --- a/include/anna/diameter/codec/Avp.hpp +++ b/include/anna/diameter/codec/Avp.hpp @@ -712,9 +712,11 @@ public: /** Class xml string representation + @param sortAttributes Optional normalization used to match xml representation with regexps + \return XML string representation with relevant information for this instance. */ - std::string asXMLString() const throw(); + std::string asXMLString(bool sortAttributes = false) const throw(); /** Comparison operator by mean serialization diff --git a/include/anna/diameter/codec/Message.hpp b/include/anna/diameter/codec/Message.hpp index 41ebe0a..3a583ce 100644 --- a/include/anna/diameter/codec/Message.hpp +++ b/include/anna/diameter/codec/Message.hpp @@ -715,9 +715,11 @@ public: /** Class xml string representation + @param sortAttributes Optional normalization used to match xml representation with regexps + \return XML string representation with relevant information for this instance. */ - std::string asXMLString() const throw(); + std::string asXMLString(bool sortAttributes = false) const throw(); /** Comparison operator by mean serialization @@ -786,8 +788,8 @@ public: Example 1: std::string pattern = "\n"; - pattern += ANNA_XML_COMPILER_TAB; pattern += "\n" - pattern += ANNA_XML_COMPILER_TAB; pattern += "" + pattern += std::string(ANNA_XML_INDENTATION_SPACES, ' '); pattern += "\n" + pattern += std::string(ANNA_XML_INDENTATION_SPACES, ' '); pattern += "" Example 2: std::string pattern = "name=\"Subscription-Id\"(.)*name=\"Subscription-Id-Type\" data=\"0\"(.)*name=\"Subscription-Id-Data\" data=\"616[0-9]{6,6}\""; diff --git a/source/diameter/codec/Avp.cpp b/source/diameter/codec/Avp.cpp index 7b075cf..f0477e2 100644 --- a/source/diameter/codec/Avp.cpp +++ b/source/diameter/codec/Avp.cpp @@ -1648,9 +1648,11 @@ anna::xml::Node* Avp::asXML(anna::xml::Node* parent) const throw() { //------------------------------------------------------------------------------ //----------------------------------------------------------- Avp::asXMLString() //------------------------------------------------------------------------------ -std::string Avp::asXMLString() const throw() { +std::string Avp::asXMLString(bool sortAttributes) const throw() { anna::xml::Node root("root"); - return anna::xml::Compiler().apply(asXML(&root)); + + anna::xml::Compiler::Mode::_v mode = sortAttributes ? anna::xml::Compiler::Mode::Sort : anna::xml::Compiler::Mode::Visual; + return anna::xml::Compiler().apply(asXML(&root), mode); } diff --git a/source/diameter/codec/Message.cpp b/source/diameter/codec/Message.cpp index 31b7d14..0cf70cd 100644 --- a/source/diameter/codec/Message.cpp +++ b/source/diameter/codec/Message.cpp @@ -998,9 +998,11 @@ anna::xml::Node* Message::asXML(anna::xml::Node* parent) const throw() { //------------------------------------------------------------------------------ //------------------------------------------------------- Message::asXMLString() //------------------------------------------------------------------------------ -std::string Message::asXMLString() const throw() { +std::string Message::asXMLString(bool sortAttributes) const throw() { anna::xml::Node root("root"); - return anna::xml::Compiler().apply(asXML(&root)); + + anna::xml::Compiler::Mode::_v mode = sortAttributes ? anna::xml::Compiler::Mode::Sort : anna::xml::Compiler::Mode::Visual; + return anna::xml::Compiler().apply(asXML(&root), mode); }