Saturday, May 8, 2010

Kamailio 3.0.x - DYK-10 - xml processing

XML Processing in config file

See also: Kamailio 3.0.x - DYK - Table of Content

SIMPLE Presence usage increases constantly over the past years, therefore the number of XML documents flowing around is bigger and bigger. The demand of routing this SIP traffic based on content is one of the reasons Kamailio 3.0.0 added new class of pseudo-variables in config file to help with XML processing:

If you get an XML document, say in a PUBLISH, like:
     <?xml version="1.0" encoding="UTF-8"?>
<presence xmlns="urn:ietf:params:xml:ns:pidf"
entity="pres:presentity@example.com">
<tuple id="efeef223">
<status>
<basic>open</basic>
</status>
<timestamp>2003-02-01T19:15:15Z</timestamp>
</tuple>
</presence>

to get the status, then you can do:
$xml(x=>doc) = $rb;
if($xml(x=>xpath:/presence/tuple/status/basic/text())=="open")
{
# specific handling for online status
...
}
You can change the content as well:
$xml(x=>xpath:/presence/tuple/timestamp) = "2010-05-09T11:25:25Z";
Practically you can do what any XPATH operation over the XML document.

No comments:

Post a Comment