[asterisk-commits] res pjsip outbound registration: Subscribe to network chang... (asterisk[14])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 28 19:05:37 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5056 )

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.

The 'pjsip send (un)register' CLI commands were updated to accept
'*all' as an argument to operate on all registrations.

The 'PJSIP(Un)Register' AMI commands were also updated to
accept '*all'.

ASTERISK-26808 #close

Change-Id: Iad58a9e0aa5d340477fca200bf293187a6ca5a25
---
M CHANGES
M res/res_pjsip_outbound_registration.c
2 files changed, 87 insertions(+), 16 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/CHANGES b/CHANGES
index 92f1bc8..7fd8203 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,14 @@
  * 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.
+   The 'pjsip send (un)register' CLI commands were updated to accept '*all'
+   as an argument to operate on all registrations.
+   The 'PJSIP(Un)Register' AMI commands were updated to also accept '*all'.
+
 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 137f3a8..683642f 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -180,12 +180,12 @@
 		<syntax>
 			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
 			<parameter name="Registration" required="true">
-				<para>The outbound registration to unregister.</para>
+				<para>The outbound registration to unregister or '*all' to unregister them all.</para>
 			</parameter>
 		</syntax>
 		<description>
 			<para>
-			Unregisters the specified outbound registration and stops future registration attempts.
+			Unregisters the specified (or all) outbound registration(s) and stops future registration attempts.
 			Call PJSIPRegister to start registration and schedule re-registrations according to configuration.
             </para>
 		</description>
@@ -197,14 +197,13 @@
 		<syntax>
 			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
 			<parameter name="Registration" required="true">
-				<para>The outbound registration to register.</para>
+				<para>The outbound registration to register or '*all' to register them all.</para>
 			</parameter>
 		</syntax>
 		<description>
 			<para>
-			Unregisters the specified outbound registration then starts registration and schedules re-registrations
+			Unregisters the specified (or all) outbound registration(s) then starts registration and schedules re-registrations
 			according to configuration.
-			future registrations.
             </para>
 		</description>
 	</manager>
@@ -378,6 +377,9 @@
 /*! \brief Default number of state container buckets */
 #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)
@@ -1458,6 +1460,26 @@
 	return 0;
 }
 
+static void unregister_all(void)
+{
+	struct ao2_container *states;
+
+	states = ao2_global_obj_ref(current_states);
+	if (!states) {
+		return;
+	}
+
+	/* Clean out all the states and let sorcery handle recreating the registrations */
+	ao2_callback(states, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
+	ao2_ref(states, -1);
+}
+
+static void reregister_all(void)
+{
+	unregister_all();
+	ast_sorcery_load_object(ast_sip_get_sorcery(), "registration");
+}
+
 static char *cli_complete_registration(const char *line, const char *word,
 				       int pos, int state)
 {
@@ -1473,6 +1495,10 @@
 	}
 
 	wordlen = strlen(word);
+	if (wordlen == 0 && ++which > state) {
+		return ast_strdup("*all");
+	}
+
 	registrations = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "registration",
 		AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
 	if (!registrations) {
@@ -1507,8 +1533,9 @@
 	case CLI_INIT:
 		e->command = "pjsip send unregister";
 		e->usage =
-			"Usage: pjsip send unregister <registration>\n"
-			"       Unregisters the specified outbound registration and stops future registration attempts.\n";
+			"Usage: pjsip send unregister <registration> | *all\n"
+			"       Unregisters the specified (or all) outbound registration(s) "
+			"and stops future registration attempts.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return cli_complete_registration(a->line, a->word, a->pos, a->n);
@@ -1519,6 +1546,12 @@
 	}
 
 	registration_name = a->argv[3];
+
+	if (strcmp(registration_name, "*all") == 0) {
+		unregister_all();
+		ast_cli(a->fd, "Unregister all queued\n");
+		return CLI_SUCCESS;
+	}
 
 	state = get_state(registration_name);
 	if (!state) {
@@ -1543,9 +1576,9 @@
 	case CLI_INIT:
 		e->command = "pjsip send register";
 		e->usage =
-			"Usage: pjsip send register <registration>\n"
-			"       Unregisters the specified outbound "
-			"registration then re-registers and re-schedules it.\n";
+			"Usage: pjsip send register <registration> | *all \n"
+			"       Unregisters the specified (or all) outbound "
+			"registration(s) then starts registration(s) and schedules re-registrations.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return cli_complete_registration(a->line, a->word, a->pos, a->n);
@@ -1556,6 +1589,12 @@
 	}
 
 	registration_name = a->argv[3];
+
+	if (strcmp(registration_name, "*all") == 0) {
+		reregister_all();
+		ast_cli(a->fd, "Re-register all queued\n");
+		return CLI_SUCCESS;
+	}
 
 	state = get_state(registration_name);
 	if (!state) {
@@ -1586,6 +1625,12 @@
 		return 0;
 	}
 
+	if (strcmp(registration_name, "*all") == 0) {
+		unregister_all();
+		astman_send_ack(s, m, "Unregistrations queued.");
+		return 0;
+	}
+
 	state = get_state(registration_name);
 	if (!state) {
 		astman_send_error(s, m, "Unable to retrieve registration entry\n");
@@ -1609,6 +1654,12 @@
 
 	if (ast_strlen_zero(registration_name)) {
 		astman_send_error(s, m, "Registration parameter missing.");
+		return 0;
+	}
+
+	if (strcmp(registration_name, "*all") == 0) {
+		reregister_all();
+		astman_send_ack(s, m, "Reregistrations queued.");
 		return 0;
 	}
 
@@ -1787,10 +1838,6 @@
 
 	ast_assert(context->output_buffer != NULL);
 
-	if (!state) {
-		return 0;
-	}
-
 	ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s  %-16s  %-16s\n",
 		id,
 		(int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
@@ -1799,8 +1846,8 @@
 		AST_VECTOR_SIZE(&registration->outbound_auths)
 			? AST_VECTOR_GET(&registration->outbound_auths, 0)
 			: "n/a",
-		sip_outbound_registration_status_str(state->client_state->status));
-	ao2_ref(state, -1);
+		(state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"));
+	ao2_cleanup(state);
 
 	if (context->show_details
 		|| (context->show_details_only_level_0 && context->indent_level == 0)) {
@@ -1960,9 +2007,22 @@
 	.deleted = registration_deleted_observer,
 };
 
+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");
+
+	reregister_all();
+}
+
 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");
@@ -2101,6 +2161,9 @@
 	/* Load configuration objects */
 	ast_sorcery_load_object(ast_sip_get_sorcery(), "registration");
 
+	network_change_sub = stasis_subscribe(ast_system_topic(),
+		network_change_stasis_cb, NULL);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/5056
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iad58a9e0aa5d340477fca200bf293187a6ca5a25
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list