[OpenSIPS-Devel] [RFC] Patch for fixing PIDF aggregation

Saúl Ibarra Corretgé saul at ag-projects.com
Wed Apr 25 11:30:45 CEST 2012


Hi all,

While working with the presence modules I discovered some issues for which I created a patch (https://sourceforge.net/tracker/?func=detail&aid=3521295&group_id=232389&atid=1086410) since the diff is quite big I'll elaborate on the issues and fixes in this email.


* Ability to turn off offline PIDF generation

The presence_xml module will automatically generate a PIDF with basic status set as "closed" by building a new PIDF out of partial information taken from the previously stored PIDF in case a PUBLISH with Expires: 0 is received.

This might not always be the desired behavior, so I added a new modparam, 'generate_offline_body' (defaults to enabled, thus maintaining backwards compatibility) which will disable automatic offline PIDF generation if set to 0.


* PIDF aggregation

When a given AoR publishes several PIDFs OpenSIPS will aggregate them and deliver them as a single PIDF to watchers. The current implementation generates invalid PIDF documents (don't validate against the schema) depending on the document's structure. For example:

doc1:
...
<tuple id="abc1234">
...
</tuple>
<dm:person id="def1234">
...
</person>
<dm:device id="ghi1234">
...
</dm:device>

doc2:
...
<tuple id="zzz1234">
...
</tuple>

The resulting document would look as follows:

...
<tuple id="abc1234">
...
</tuple>
<dm:person id="def1234">
...
</person>
<dm:device id="ghi1234">
...
</dm:device>
...
<tuple id="zzz1234">
...
</tuple>


Which is wrong, because the schema specifies that <tuple> elements come before any extension, and <person> is a extension (defined by data-model).

Also, the current code will discard a full document if it finds a <tuple> element with a duplicated id. Since a document may contain an arbitrary number of <tuple> elements discarding the whole document seems too much.

In addition, all tuple, person and device elements define their "id" attribute as type "xs:ID" in the schema, which means it needs to be unique across *the whole* document in order for it to be valid. Currently there is no check for this.

In order to fix this issues I took the following approach:

- Split the code for aggregating presence and dialog documents, they can't be merged using a common function since each has a different way of doing it.
- Iterate through all stored PIDFs and keep 5 linked lists of elements: tuples, notes, persons, devices and others.
- Every time a tuple, person or device is found a check for duplicated ID is performed (among all tuples, persons and devices seen so far) and if it is duplicated then the element is discarded, but the document continues to be processed.
- After all elements in all documents have been processed a new document is created and populated with all elements from the aforementioned 5 lists in the right order.

I ran some tests with bogus documents and the aggregation was always successful now :-)

Core team: please have a look. If we merge this code and discover any issues with it in the future I do volunteer for fixing them, I'll not run away :-)


Thanks and regards,

--
Saúl Ibarra Corretgé
AG Projects






More information about the Devel mailing list