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:
void ast_sip_subscription_set_persistence_data(struct ast_sip_subscription *subscription, struct ast_json *persistence_data); const struct ast_json *ast_sip_subscription_get_persistence_data(const struct ast_sip_subscription *subscription);
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!