[Asterisk-code-review] pjsip options: contacts sometimes not being updated on reload (asterisk[master])

Kevin Harwell asteriskteam at digium.com
Wed Dec 13 16:50:57 CST 2017


Kevin Harwell has submitted this change and it was merged. ( https://gerrit.asterisk.org/7489 )

Change subject: pjsip_options: contacts sometimes not being updated on reload
......................................................................

pjsip_options: contacts sometimes not being updated on reload

For both dynamic and static contacts it was possible that potential AOR
changes were not being applied to all contacts. This was because the qualify
and schedule code was only retrieving AOR's, and contacts with frequencies
greater than zero.

For instance the following could happen: and AOR/contact has a frequency of 5,
it then gets set to 0, and then a reload occurs. All scheduled OPTIONS are
stopped, a list of AOR's is retrieved with frequency > 0, but none are
selected since in this scenario all are 0. The contact for the one previously
set to 5 though does not get updated, so it's status remains "AVAILABLE".

This patch makes it so all contacts (static and dynamic) are selected, and
appropriately updated if need be.

ASTERISK-27467 #close

Change-Id: I7a920170f89c683af9505d4723a44fc6841decdb
---
M res/res_pjsip/pjsip_options.c
1 file changed, 10 insertions(+), 24 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Kevin Harwell: Approved for Submit



diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 662166c..ab7aa40 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -1175,32 +1175,21 @@
 	return 0;
 }
 
-/*!
- * \internal
- * \brief Unschedule all existing contacts
- */
-static int unschedule_all_cb(void *obj, void *arg, int flags)
-{
-	struct sched_data *data = obj;
-
-	AST_SCHED_DEL_UNREF(sched, data->id, ao2_ref(data, -1));
-
-	return CMP_MATCH;
-}
-
 static void qualify_and_schedule_all(void)
 {
-	struct ast_variable *var = ast_variable_new("qualify_frequency >", "0", "");
 	struct ao2_container *aors;
 	struct ao2_container *contacts;
 
-	if (!var) {
-		return;
-	}
-	aors = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(),
-		"aor", AST_RETRIEVE_FLAG_MULTIPLE, var);
+	/*
+	 * It's possible that the AOR had some of it's fields updated prior to a
+	 * reload. For instance qualifying could have been turned on or off by
+	 * setting the qualify_frequency. Due to this we have to iterate through
+	 * all contacts (static and dynamic), and not just ones where the frequency
+	 * is greater than zero, updating any contact fields with the AOR's values.
+	 */
 
-	ao2_callback(sched_qualifies, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, unschedule_all_cb, NULL);
+	aors = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(),
+		"aor", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
 
 	if (aors) {
 		ao2_callback(aors, OBJ_NODATA, qualify_and_schedule_all_cb, NULL);
@@ -1208,14 +1197,11 @@
 	}
 
 	contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(),
-		"contact", AST_RETRIEVE_FLAG_MULTIPLE, var);
+		"contact", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
 	if (contacts) {
 		ao2_callback(contacts, OBJ_NODATA, qualify_and_schedule_cb_without_aor, NULL);
 		ao2_ref(contacts, -1);
 	}
-
-	ast_variables_destroy(var);
-
 }
 
 int ast_sip_format_contact_ami(void *obj, void *arg, int flags)

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7a920170f89c683af9505d4723a44fc6841decdb
Gerrit-Change-Number: 7489
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171213/70f2f818/attachment.html>


More information about the asterisk-code-review mailing list