Allow diameter message & avp to normalize their xml representation
[anna.git] / include / anna / diameter / codec / Message.hpp
index 376fa39..3a583ce 100644 (file)
@@ -223,7 +223,8 @@ public:
   /**
   * Destructor
   */
-  ~Message();
+  virtual ~Message();
+
   // Virtual destructors are useful when you can delete an instance of a derived class through a pointer to base class:
   // This destructor is not virtual, then a pointer to base class (even pointing to a children one) will invoke this destructor, not the derived one.
   // My current solution: virtualizing method 'clear'
@@ -553,7 +554,18 @@ public:
    *
    * @param xmlPathFile Complete path file to the xml document which represents the diameter message
    */
-  void loadXML(const std::string &xmlPathFile) throw(anna::RuntimeException);
+  void loadXMLFile(const std::string &xmlPathFile) throw(anna::RuntimeException);
+
+  /**
+   * Interpret a xml string in order to create a diameter message
+   * You could apply this multiple times over the same object. A basic cleanup is done respecting the codec engine.
+   *
+   * @see functions::messageXmlDocumentFromXmlString
+   * @see fromXML
+   *
+   * @param xmlString xml representation of the diameter message
+   */
+  void loadXMLString(const std::string &xmlString) throw(anna::RuntimeException);
 
 
   // getters
@@ -703,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
@@ -747,7 +761,7 @@ public:
      for example, the pattern '<avp name="Framed-IP-Address" hex-data="0a[A-Fa-f0-9][A-Fa-f0-9]0a0a"/>'
      matchs IP addresses for '10.x.10.10' where x = [0..255].
 
-     Note that string pattern could also be generated via #loadXML and then #asXML, that is to say, you
+     Note that string pattern could also be generated via #loadXMLFile/#loadXMLString and then #asXML, thus, you
      could get patterns through xml files which act as conditional triggers over message. In that case,
      it is not possible to specify regular expressions within xml 'hex-data' fields because parser will fail
      during hexadecimal read. Normally only printable 'data' fields are used for matching issues.
@@ -763,7 +777,7 @@ public:
      Then you could do:
 
      anna::diameter::codec::Message patternMessage;
-     patternMessage.loadXML("pattern.xml");
+     patternMessage.loadXMLFile("pattern.xml");
      std::string pattern = patternMessage.getAvp("Subscription-Id")->getAvp("Subscription-Id-Type")->asXMLString();
      // Former is '<avp name="Subscription-Id-Data" data="616[0-9]{6,6}"/>'
      bool match = incomingMessage.isLike(pattern);
@@ -774,8 +788,8 @@ public:
 
      Example 1:
      std::string pattern = "<avp name=\"Subscription-Id\">\n";
-     pattern += ANNA_XML_COMPILER_TAB; pattern += "<avp name=\"Subscription-Id-Type\" data=\"0\" alias=\"END_USER_E164\"/>\n"
-     pattern += ANNA_XML_COMPILER_TAB; pattern += "<avp name=\"Subscription-Id-Data\" data=\"616[0-9]{6,6}\"/>"
+     pattern += std::string(ANNA_XML_INDENTATION_SPACES, ' '); pattern += "<avp name=\"Subscription-Id-Type\" data=\"0\" alias=\"END_USER_E164\"/>\n"
+     pattern += std::string(ANNA_XML_INDENTATION_SPACES, ' '); pattern += "<avp name=\"Subscription-Id-Data\" data=\"616[0-9]{6,6}\"/>"
 
      Example 2:
      std::string pattern = "name=\"Subscription-Id\"(.)*name=\"Subscription-Id-Type\" data=\"0\"(.)*name=\"Subscription-Id-Data\" data=\"616[0-9]{6,6}\"";