[Asterisk-code-review] res pjsip outbound registration: Subscribe to network chang... (asterisk[13])
George Joseph
asteriskteam at digium.com
Tue Feb 21 18:10:41 CST 2017
George Joseph has uploaded a new change for review. ( https://gerrit.asterisk.org/5055 )
Change subject: res_pjsip_outbound_registration: Subscribe to network change events
......................................................................
res_pjsip_outbound_registration: Subscribe to network change events
Outbound registration now subscribes to network change events
published by res_stun_monitor and refreshes all registrations
when an event happens. "module reload" also now actually refreshes
all subscriptions, not just those that might have changed.
ASTERISK-26808 #close
Change-Id: Iad58a9e0aa5d340477fca200bf293187a6ca5a25
---
M CHANGES
M res/res_pjsip_outbound_registration.c
2 files changed, 43 insertions(+), 6 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/5055/1
diff --git a/CHANGES b/CHANGES
index 00347f3..a53c773 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,12 @@
* Added new 'u' option to Record() application which prevents Asterisk from
truncating silence from the end of recorded files.
+res_pjsip_outbound_registration
+------------------
+ * Outbound registrations are now refreshed when res_stun_monitor detects
+ a network change event has happened. A "module reload" also now refreshes
+ all subscriptions, not just those that may have changed.
+
app_voicemail
------------------
* The 'Comedian Mail' prompts can now be overriden using the 'vm-login' and
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index da15f19..9b182a3 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -368,6 +368,9 @@
#define DEFAULT_STATE_BUCKETS 53
static AO2_GLOBAL_OBJ_STATIC(current_states);
+/*! subscription id for network change events */
+static struct stasis_subscription *network_change_sub;
+
/*! \brief hashing function for state objects */
static int registration_state_hash(const void *obj, const int flags)
{
@@ -1949,9 +1952,40 @@
.deleted = registration_deleted_observer,
};
+static int reload_module(void)
+{
+ struct ao2_container *states;
+
+ states = ao2_global_obj_ref(current_states);
+ if (!states) {
+ /* Global container has gone. Likely shutting down. */
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ ao2_callback(states, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
+ ao2_ref(states, -1);
+
+ ast_sorcery_load_object(ast_sip_get_sorcery(), "registration");
+
+ return 0;
+}
+
+static void network_change_stasis_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
+{
+ /* This callback is only concerned with network change messages from the system topic. */
+ if (stasis_message_type(message) != ast_network_change_type()) {
+ return;
+ }
+ ast_debug(3, "Received network change event\n");
+
+ reload_module();
+}
+
static int unload_module(void)
{
int remaining;
+
+ network_change_sub = stasis_unsubscribe_and_join(network_change_sub);
ast_manager_unregister("PJSIPShowRegistrationsOutbound");
ast_manager_unregister("PJSIPUnregister");
@@ -2090,13 +2124,10 @@
/* Load configuration objects */
ast_sorcery_load_object(ast_sip_get_sorcery(), "registration");
- return AST_MODULE_LOAD_SUCCESS;
-}
+ network_change_sub = stasis_subscribe(ast_system_topic(),
+ network_change_stasis_cb, NULL);
-static int reload_module(void)
-{
- ast_sorcery_reload_object(ast_sip_get_sorcery(), "registration");
- return 0;
+ return AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Outbound Registration Support",
--
To view, visit https://gerrit.asterisk.org/5055
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad58a9e0aa5d340477fca200bf293187a6ca5a25
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <gjoseph at digium.com>
More information about the asterisk-code-review
mailing list