[asterisk-commits] file: branch file/pjsip-subscription-persistence r415657 - /team/file/pjsip-s...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 10 09:11:19 CDT 2014
Author: file
Date: Tue Jun 10 09:11:13 2014
New Revision: 415657
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=415657
Log:
Recreate subscriptions once the system is fully booted.
Modified:
team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c
Modified: team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c?view=diff&rev=415657&r1=415656&r2=415657
==============================================================================
--- team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c (original)
+++ team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c Tue Jun 10 09:11:13 2014
@@ -459,6 +459,7 @@
if (!expires_header) {
expires_header = pjsip_expires_hdr_create(pool, 0);
if (!expires_header) {
+ ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
return 0;
}
pjsip_msg_add_hdr(rdata.msg_info.msg, (pjsip_hdr*)expires_header);
@@ -467,12 +468,13 @@
handler = subscription_get_handler_from_rdata(&rdata);
if (!handler) {
- /* This may eventually get a handler once everything is loaded */
+ ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
return 0;
}
generator = subscription_get_generator_from_rdata(&rdata, handler);
if (!generator) {
+ ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
return 0;
}
@@ -492,7 +494,7 @@
return 0;
}
-/*! \brief Function which loads and recreates persisted subscriptions upon startup */
+/*! \brief Function which loads and recreates persisted subscriptions upon startup when the system is fully booted */
static int subscription_persistence_load(void *data)
{
struct ao2_container *persisted_subscriptions = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(),
@@ -512,6 +514,33 @@
ao2_ref(persisted_subscriptions, -1);
return 0;
+}
+
+/*! \brief Event callback which fires subscription persistence recreation when the system is fully booted */
+static void subscription_persistence_event_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
+{
+ struct ast_json_payload *payload;
+ const char *type;
+
+ if (stasis_message_type(message) != ast_manager_get_generic_type()) {
+ return;
+ }
+
+ payload = stasis_message_data(message);
+ type = ast_json_string_get(ast_json_object_get(payload->json, "type"));
+
+ /* This subscription only responds to the FullyBooted event so that all modules have been loaded when we
+ * recreate SIP subscriptions.
+ */
+ if (strcmp(type, "FullyBooted")) {
+ return;
+ }
+
+ /* This has to be here so the subscription is recreated when the body generator is available */
+ ast_sip_push_task(NULL, subscription_persistence_load, NULL);
+
+ /* Once the system is fully booted we don't care anymore */
+ stasis_unsubscribe(sub);
}
static void add_subscription(struct ast_sip_subscription *obj)
@@ -1015,9 +1044,6 @@
pjsip_evsub_register_pkg(&pubsub_module, &event, DEFAULT_EXPIRES, i, accept);
sub_add_handler(handler);
-
- /* This has to be here so the subscription is recreated when the body generator is available */
- ast_sip_push_task_synchronous(NULL, subscription_persistence_load, NULL);
return 0;
}
@@ -1876,6 +1902,8 @@
ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "",
persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0);
+ stasis_subscribe(ast_manager_get_topic(), subscription_persistence_event_cb, NULL);
+
ast_manager_register_xml(AMI_SHOW_SUBSCRIPTIONS_INBOUND, EVENT_FLAG_SYSTEM,
ami_show_subscriptions_inbound);
ast_manager_register_xml(AMI_SHOW_SUBSCRIPTIONS_OUTBOUND, EVENT_FLAG_SYSTEM,
More information about the asterisk-commits
mailing list