[Asterisk-code-review] res pjsip: qualify/unqualify added/deleted realtime endpoints (asterisk[14])

Alexei Gradinari asteriskteam at digium.com
Tue Aug 30 15:59:21 CDT 2016


Alexei Gradinari has uploaded a new change for review.

  https://gerrit.asterisk.org/3766

Change subject: res_pjsip: qualify/unqualify added/deleted realtime endpoints
......................................................................

res_pjsip: qualify/unqualify added/deleted realtime endpoints

If the PJSIP endpoint's AOR with the permanent contact
was deleted from the realtime storage the res_pjsip module
continues trying to qualify this contact.
The error 'Unable to find an endpoint to qualify contact'
appeares every 'qualify_frequency' seconds.
This patch deletes this contact in this case.

The PJSIP endpoint's AOR with the permanent contact
is never qualified if it is added to realtime storage
after asterisk started.
This patch adds qualifying for the AOR's permanent contacts
on the first handling of this AOR.

ASTERISK-26319 #close

Change-Id: Ib93dded9121edb113076903d1aa95402f799f8fe
---
M res/res_pjsip/pjsip_options.c
1 file changed, 40 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/3766/1

diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 5e0fc76..a282224 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -53,6 +53,9 @@
 	[REMOVED] = "Removed",
 };
 
+static void contact_deleted(const void *obj);
+static void qualify_and_schedule(struct ast_sip_contact *contact);
+
 const char *ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status)
 {
 	return status_map[status];
@@ -108,6 +111,29 @@
 	return status;
 }
 
+static int qualify_and_schedule_aor_contact(void *obj)
+{
+	struct ast_sip_contact *contact = obj;
+	struct ast_sip_aor *aor;
+
+	if (!contact || ast_strlen_zero(contact->aor) ||
+		!(aor = ast_sip_location_retrieve_aor(contact->aor))) {
+		ao2_ref(contact, -1);
+		return -1;
+	}
+
+	contact->qualify_frequency = aor->qualify_frequency;
+	contact->qualify_timeout = aor->qualify_timeout;
+	contact->authenticate_qualify = aor->authenticate_qualify;
+
+	ao2_ref(aor, -1);
+
+	qualify_and_schedule(contact);
+	ao2_ref(contact, -1);
+
+	return 0;
+}
+
 AST_MUTEX_DEFINE_STATIC(creation_lock);
 
 /*!
@@ -142,6 +168,18 @@
 			contact->uri);
 		ao2_ref(status, -1);
 		return NULL;
+	}
+
+	/* The permanent contact added after asterisk start should be qualified. */
+	if (ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED) && ast_tvzero(contact->expiration_time)) {
+		/*
+		 * The FULLY_BOOTED to filter out contacts that already existed when asterisk started.
+		 * The zero expiration_time to select only permanent contacts.
+		 */
+		ao2_ref((struct ast_sip_contact *) contact, +1);
+		if (ast_sip_push_task(NULL, qualify_and_schedule_aor_contact, (struct ast_sip_contact *) contact)) {
+			ao2_ref((struct ast_sip_contact *) contact, -1);
+		}
 	}
 
 	ast_statsd_log_string_va("PJSIP.contacts.states.%s", AST_STATSD_GAUGE,
@@ -368,8 +406,9 @@
 			endpoint_local = find_an_endpoint(contact);
 		}
 		if (!endpoint_local) {
-			ast_log(LOG_ERROR, "Unable to find an endpoint to qualify contact %s\n",
+			ast_log(LOG_WARNING, "Unable to find an endpoint to qualify contact %s. Deleting this contact\n",
 				contact->uri);
+			contact_deleted(contact);
 			return -1;
 		}
 	}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib93dded9121edb113076903d1aa95402f799f8fe
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>



More information about the asterisk-code-review mailing list