- 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:
- <message version="1" name="Credit-Control-Request" application-id="16777236" hop-by-hop-id="0" end-to-end-id="0">
- <avp name="Subscription-Id">
- <avp name="Subscription-Id-Type" data="0" alias="END_USER_E164"/>
- <avp name="Subscription-Id-Data" data="616[0-9]{6,6}"/>
- </avp>
- </message>
-
- 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 '<avp name="Subscription-Id-Data" data="616[0-9]{6,6}"/>'
- 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 = "<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}\"/>"
-
- Example 2:
- std::string pattern = "name=\"Subscription-Id\"(.)*name=\"Subscription-Id-Type\" data=\"0\"(.)*name=\"Subscription-Id-Data\" data=\"616[0-9]{6,6}\"";