[Asterisk-code-review] res pjsip: Reduce processing when a Contact is updated. (asterisk[16.0])

Joshua Colp asteriskteam at digium.com
Wed Aug 22 11:18:09 CDT 2018


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

Change subject: res_pjsip: Reduce processing when a Contact is updated.
......................................................................

res_pjsip: Reduce processing when a Contact is updated.

When a Contact is updated the only material change that qualify
support cares about is the underlying configuration for the AOR.
In this case we will update things with the new AOR information but
otherwise the callback to indicate the Contact has changed can be
ignored.

This is because it is only when a Contact is added or deleted that
material changes occur within the qualify support. An update can't
change the URI since it would result in a new Contact so it can be
ignored.

Change-Id: I2f97ebfa79969a36a97bb7b9afd5b6268cf1a07d
---
M UPGRADE.txt
M res/res_pjsip/pjsip_options.c
2 files changed, 9 insertions(+), 57 deletions(-)

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



diff --git a/UPGRADE.txt b/UPGRADE.txt
index 8b4fdf7..41e22c6 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -39,6 +39,8 @@
  - The ContactStatus and Status fields for the manager events ContactStatus
    and ContactStatusDetail are now set to "NonQualified" when a contact exists
    but has not been qualified.
+ - The ContactStatus event will no longer be sent by PJSIP when a device
+   refreshes its registration.
 
 ARI:
  - The ContactInfo event's contact_status field is now set to "NonQualified"
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index eb84c1b..f2439c4 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -2065,7 +2065,7 @@
 /*!
  * \brief Check if the contact qualify options are different than local aor qualify options
  */
-static int has_qualify_changed (struct ast_sip_contact *contact, struct sip_options_aor *aor_options)
+static int has_qualify_changed (const struct ast_sip_contact *contact, const struct sip_options_aor *aor_options)
 {
 	if (!contact) {
 	    return 0;
@@ -2186,77 +2186,27 @@
 		sip_options_contact_add_management_task, (void *) obj);
 }
 
-/*!
- * \brief Task which updates a dynamic contact to an AOR
- * \note Run by aor_options->serializer
- */
-static int sip_options_contact_update_task(void *obj)
-{
-	struct sip_options_contact_observer_task_data *task_data = obj;
-	struct ast_sip_contact_status *contact_status;
-
-	contact_status = ast_sip_get_contact_status(task_data->contact);
-	if (contact_status) {
-		switch (contact_status->status) {
-		case CREATED:
-		case UNAVAILABLE:
-		case AVAILABLE:
-		case UNKNOWN:
-			/* Refresh the ContactStatus AMI events. */
-			sip_options_contact_status_update(contact_status);
-			break;
-		case REMOVED:
-			break;
-		}
-		ao2_ref(contact_status, -1);
-	}
-
-	ao2_ref(task_data->contact, -1);
-	ao2_ref(task_data->aor_options, -1);
-	ast_free(task_data);
-	return 0;
-}
-
 /*! \brief Observer callback invoked on contact update */
 static void contact_observer_updated(const void *obj)
 {
-	struct sip_options_contact_observer_task_data *task_data;
+	const struct ast_sip_contact *contact = obj;
+	struct sip_options_aor *aor_options = ao2_find(sip_options_aors, contact->aor, OBJ_SEARCH_KEY);
 
-	task_data = ast_malloc(sizeof(*task_data));
-	if (!task_data) {
-		return;
-	}
-
-	task_data->contact = (struct ast_sip_contact *) obj;
-	task_data->aor_options = ao2_find(sip_options_aors, task_data->contact->aor,
-		OBJ_SEARCH_KEY);
-
-	if (has_qualify_changed(task_data->contact, task_data->aor_options)) {
+	if (has_qualify_changed(contact, aor_options)) {
 		struct ast_sip_aor *aor;
 
 		aor = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor",
-			task_data->contact->aor);
+			contact->aor);
 		if (aor) {
 			ast_debug(3, "AOR '%s' qualify options have been modified. Synchronize an AOR local state\n",
-				task_data->contact->aor);
+				contact->aor);
 			ast_sip_push_task_wait_serializer(management_serializer,
 				sip_options_aor_observer_modified_task, aor);
 			ao2_ref(aor, -1);
 		}
 	}
 
-	if (!task_data->aor_options) {
-		ast_free(task_data);
-		return;
-	}
-
-	ao2_ref(task_data->contact, +1);
-	if (ast_sip_push_task(task_data->aor_options->serializer,
-		sip_options_contact_update_task, task_data)) {
-		ao2_ref(task_data->contact, -1);
-		ao2_ref(task_data->aor_options, -1);
-		ast_free(task_data);
-	}
+	ao2_cleanup(aor_options);
 }
 
 /*!

-- 
To view, visit https://gerrit.asterisk.org/9966
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16.0
Gerrit-MessageType: merged
Gerrit-Change-Id: I2f97ebfa79969a36a97bb7b9afd5b6268cf1a07d
Gerrit-Change-Number: 9966
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp 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/20180822/45fa417e/attachment.html>


More information about the asterisk-code-review mailing list