Search the Asterisk Blog

PJSIP Body Generator Persistence

By Joshua C. Colp

When PJSIP publish and subscribe functionality was created we knew we wanted to provide a pluggable mechanism to allow modules to easily extend and add new bodies. The result of this is what is known as body generators. Given a set of data they convert it into a format expected by a device, such as pidf+xml or dialog-info+xml. Through further development of publish and subscribe functionality we also added the ability to recreate subscriptions when Asterisk restarts. This ensures that devices don’t need to resubscribe before they start receiving updates. As soon as Asterisk restarts endpoints get a NOTIFY to update them and they are none the wiser that Asterisk has restarted.

A problem was uncovered however in that body generators may have to maintain state information. A great example is dialog-info+xml which has an incrementing version. If this is not preserved then the version starts at 0 resulting in some endpoints ignoring the received NOTIFY due to the version being too low. Great news, we’ve now added functionality to solve this!

As of Asterisk 13.31.0, 16.8.0, and 17.2.0 the publish and subscribe API has been extended to allow body generators to persist information and access it. This is done using the following API calls:

The body generator stores information using a JSON object which can contain any information it requires. This information is then persisted out with the normal subscription information and upon subscription creation the body generator can then retrieve the information and restore any state necessary. The dialog-info+xml body generator now uses this to persist the version allowing it to be restored and incremented on the NOTIFY that goes out after Asterisk restart. If you’ve had issues with dialog-info+xml and Asterisk restarts in the past I highly suggest giving the mentioned versions of Asterisk a try once they are released!

No Comments Yet

Get the conversation started!

Add to the Discussion

Your email address will not be published. Required fields are marked *

About the Author

Joshua C. Colp

Joshua Colp is a Senior Software Developer at Digium and a long time Asterisk developer. He originally started in the community submitting simple patches and grew into improving and creating new core components of Asterisk itself. He is a self-taught programmer who believes in finding the balance between doing things the way they should be done and doing what is right for the people using the software. In his spare time he enjoys smashing fax machines.

See All of Joshua C.'s Articles