X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=blobdiff_plain;f=include%2Fanna%2Fdiameter%2Fcodec%2FMessage.hpp;h=2ec338b1bf8e7783c74ce28ee76df3c076075132;hp=3a583ce8603f5f904c2b5389db44327ab6027858;hb=415985b3f67878c2e3cee785a0b1cb36f4eff901;hpb=227446df961ead723c8f2b04ea53d99c770a438f diff --git a/include/anna/diameter/codec/Message.hpp b/include/anna/diameter/codec/Message.hpp index 3a583ce..2ec338b 100644 --- a/include/anna/diameter/codec/Message.hpp +++ b/include/anna/diameter/codec/Message.hpp @@ -715,11 +715,12 @@ public: /** Class xml string representation - @param sortAttributes Optional normalization used to match xml representation with regexps + @param normalize Optional normalization which sorts attribute names and removes + newlines in the xml representation in order to ease regexp matching. \return XML string representation with relevant information for this instance. */ - std::string asXMLString(bool sortAttributes = false) const throw(); + std::string asXMLString(bool normalize = false) const throw(); /** Comparison operator by mean serialization @@ -732,69 +733,59 @@ public: friend bool operator == (const Message & m1, const Message & m2) throw() { return (m1.asXMLString() == m2.asXMLString()); } /** - Match a regular expression (string pattern) regarding xml string serialization for this message. - Using a complex pattern (many avps, grouped ones) it could be necessary to fix the message before - using the method in order to perform a more controlled comparison. In the same way, flags could be - ignored to simplify message xml presentation. - This powerful tool could be used to program traffic analysis and decide future behaviour (routing, - traslation, etc.). + Matchs a regular expression (string pattern) regarding xml string serialization for this message. + The message xml representation is internally normalized (attribute names are sort and newlines + are removed) in order to ease regexp matching. -
-     Examples:
+     You could use simple regular expressions.
+     For example, the pattern '' detects
+     PS charging contexts because of data suffix specification '32251@3gpp.org' for that AVP.
+     The pattern '' detects PS charging contexts
-     because of data suffix specification '32251@3gpp.org' for that AVP.
+     It would seems strange or 'creative' to use regular expressions within an hex string representation,
+     but anyway you could also do such kind of things to check non-printable data parts within the message:
+     for example, the pattern ''
+     matchs IP addresses for '10.x.10.10' where x = [0..255].
 
-     The pattern '
-        
-        
+     
+     ...
+     
+        
+        
      '
+     ...
+     
- detects MSISDN (not IMSI) equal to 606000106 + You could also extract AVP xml normalized representation in this way: - It would seems strange or 'creative' to use regular expressions within an hex string representation, - but anyway you could also do such kind of things to check non-printable data parts within the message: - for example, the pattern '' - matchs IP addresses for '10.x.10.10' where x = [0..255]. +
+     anna::diameter::codec::Message myMessage;
+     myMessage.loadXMLFile("message.xml");
+     std::string subscriptionId = myMessage.getAvp("Subscription-Id")->getAvp("Subscription-Id-Type")->asXMLString(true);
+     // Former is ''
+     
+ + And then use to match incoming messages: - 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. - - For example, imagine a 'pattern.xml' file like: - - - - - - - - Then you could do: - - anna::diameter::codec::Message patternMessage; - patternMessage.loadXMLFile("pattern.xml"); - std::string pattern = patternMessage.getAvp("Subscription-Id")->getAvp("Subscription-Id-Type")->asXMLString(); - // Former is '' - bool match = incomingMessage.isLike(pattern); - - Then, messages having MSISDN numbers starting with '616' will match the pattern. - Note, that any other message codes (and not only Credit-Control-Request ones), could pass the test... - You could also build that string manually: - - Example 1: - std::string pattern = "\n"; - 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}\""; +
+     bool match = incomingMessage.isLike(subscriptionId);
      
+ Using a complex pattern (many avps, grouped ones) is possible, indeed testing ADML engine supports 'waitfe/fc-xml' + operations which load entire diameter messages to be used as a whole regular expression (hop-by-hop, end-to-end and + Origin-State-Id avp is automatically replaced by '[0-9]+' to make possible the comparison). + + Those operations makes all the work, but if you use the API, you may take into account: + + - Respect indentation for inner Message xml representation (normally 3 spaces). + - Sort alphabetically the attribute names in every xml node. + - Remove all the newlines in the xml representation as normalization stage. + - Ignore flags and set the fix mode for the message. + \return Returns the match result */ bool isLike(const std::string &pattern) const throw();