[Asterisk-code-review] res pjsip registrar: Change RegistrationsInbound to send Co... (asterisk[master])

George Joseph asteriskteam at digium.com
Tue Dec 6 15:14:20 CST 2016


George Joseph has uploaded a new change for review. ( https://gerrit.asterisk.org/4563 )

Change subject: res_pjsip_registrar:  Change RegistrationsInbound to send ContactStatus
......................................................................

res_pjsip_registrar:  Change RegistrationsInbound to send ContactStatus

The PJSIPShowRegistrationsInbound AMI command was just dumping out
all AORs which was pretty useless and resource heavy since it had
to get all endpoints, then all aors for each endpoint, then all
contacts for each aor.

Now we send ContactStatusDetail events which meets the intended
purpose of the command and significantly reduces the overhead.
Also, some additional fields that were added to Contact since
the original creation of the ContactStatusDetail event have been
added to the end of the event.

ASTERISK-26644 #close

Change-Id: I2468f9d8a9d703106b530cccec20ff3874211bdb
---
M CHANGES
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_options.c
M res/res_pjsip_registrar.c
5 files changed, 83 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/4563/1

diff --git a/CHANGES b/CHANGES
index df0834d..f529f0f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -91,6 +91,20 @@
    for internal state transitions that don't change the reported public status
    state.
 
+res_pjsip_registrar
+------------------
+ * The PJSIPShowRegistrationsInbound AMI command has been changed to return
+   ContactStatusDetail events instead of just a dump of every defined AOR.
+   This is being done in the 13 branch as well as 14 and master since the
+   original behavior was unusable for the intended purpose.
+
+res_pjsip
+------------------
+ * 6 existing contact fields have been added to the end of the
+   ContactStatusDetail AMI event:
+   ID, AuthenticateQualify, OutboundProxy, Path, QualifyFrequency and
+   QualifyTimeout.  Existing fields have not been disturbed.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 14.1.0 to Asterisk 14.2.0 ------------
 ------------------------------------------------------------------------------
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 894ea76..abc2c30 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -2276,6 +2276,11 @@
 int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint,
 				struct ast_sip_ami *ami, int *count);
 
+
+int ast_sip_format_contact_ami(void *obj, void *arg, int flags);
+
+
+
 /*!
  * \brief Format auth details for AMI.
  *
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 8c2d371..144621f 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2102,10 +2102,31 @@
 					<para>Absolute time that this contact is no longer valid after</para>
 				</parameter>
 				<parameter name="ViaAddress">
-					<para>IP address:port of the last Via header in REGISTER request</para>
+					<para>IP address:port of the last Via header in REGISTER request.
+					Will only appear in the event if available.</para>
 				</parameter>
 				<parameter name="CallID">
-					<para>Content of the Call-ID header in REGISTER request</para>
+					<para>Content of the Call-ID header in REGISTER request.
+					Will only appear in the event if available.</para>
+				</parameter>
+				<parameter name="ID">
+					<para>The sorcery ID of the contact.</para>
+				</parameter>
+				<parameter name="AuthenticateQualify">
+					<para>A boolean indicating whether a qualify should be authenticated.</para>
+				</parameter>
+				<parameter name="OutboundProxy">
+					<para>The contact's outbound proxy.</para>
+				</parameter>
+				<parameter name="Path">
+					<para>The Path header received on the REGISTER.</para>
+				</parameter>
+				<parameter name="QualifyFrequency">
+					<para>The interval in seconds at which the contact will be qualified.</para>
+				</parameter>
+				<parameter name="QualifyTimeout">
+					<para>The elapsed time in decimal seconds after which an OPTIONS
+					message is sent before the contact is considered unavailable.</para>
 				</parameter>
 			</syntax>
 		</managerEventInstance>
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 09fe155..d2b812d 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -1217,7 +1217,7 @@
 
 }
 
-static int format_contact_status(void *obj, void *arg, int flags)
+int ast_sip_format_contact_ami(void *obj, void *arg, int flags)
 {
 	struct ast_sip_contact_wrapper *wrapper = obj;
 	struct ast_sip_contact *contact = wrapper->contact;
@@ -1256,7 +1256,15 @@
 		ast_str_append(&buf, 0, "RoundtripUsec: %" PRId64 "\r\n", status->rtt);
 	}
 	ast_str_append(&buf, 0, "EndpointName: %s\r\n",
-			ast_sorcery_object_get_id(endpoint));
+			endpoint ? ast_sorcery_object_get_id(endpoint) : S_OR(contact->endpoint_name, ""));
+
+	ast_str_append(&buf, 0, "ID: %s\r\n", ast_sorcery_object_get_id(contact));
+	ast_str_append(&buf, 0, "AuthenticateQualify: %d\r\n", contact->authenticate_qualify);
+	ast_str_append(&buf, 0, "OutboundProxy: %s\r\n", contact->outbound_proxy);
+	ast_str_append(&buf, 0, "Path: %s\r\n", contact->path);
+	ast_str_append(&buf, 0, "QualifyFrequency: %u\r\n", contact->qualify_frequency);
+	ast_str_append(&buf, 0, "QualifyTimeout: %.3f\r\n", contact->qualify_timeout);
+
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
 	ami->count++;
 	
@@ -1269,7 +1277,7 @@
 {
 	struct ast_sip_aor *aor = obj;
 
-	return ast_sip_for_each_contact(aor, format_contact_status, arg);
+	return ast_sip_for_each_contact(aor, ast_sip_format_contact_ami, arg);
 }
 
 static int format_ami_contact_status(const struct ast_sip_endpoint *endpoint,
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index a8d2bdc..73ecab1 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -46,11 +46,11 @@
 		<syntax />
 		<description>
 			<para>
-			In response <literal>InboundRegistrationDetail</literal> events showing configuration and status
-			information are raised for each inbound registration object.  As well as <literal>AuthDetail</literal>
-			events for each associated auth object.  Once all events are completed an
-			<literal>InboundRegistrationDetailComplete</literal> is issued.
-                        </para>
+			In response, <literal>ContactStatusDetail</literal> events showing
+			configuration and status information are raised for each inbound
+			registration (contact) object.  Once all events are completed a
+			<literal>ContactStatusDetailComplete</literal> is issued.
+            </para>
 		</description>
 	</manager>
  ***/
@@ -721,66 +721,37 @@
 	return PJ_TRUE;
 }
 
-/* function pointer to callback needs to be within the module
-   in order to avoid problems with an undefined symbol */
-static int sip_contact_to_str(void *acp, void *arg, int flags)
-{
-	return ast_sip_contact_to_str(acp, arg, flags);
-}
-
-static int ami_registrations_aor(void *obj, void *arg, int flags)
-{
-	struct ast_sip_aor *aor = obj;
-	struct ast_sip_ami *ami = arg;
-	int *count = ami->arg;
-	RAII_VAR(struct ast_str *, buf,
-		 ast_sip_create_ami_event("InboundRegistrationDetail", ami), ast_free);
-
-	if (!buf) {
-		return -1;
-	}
-
-	ast_sip_sorcery_object_to_ami(aor, &buf);
-	ast_str_append(&buf, 0, "Contacts: ");
-	ast_sip_for_each_contact(aor, sip_contact_to_str, &buf);
-	ast_str_append(&buf, 0, "\r\n");
-
-	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
-	(*count)++;
-	return 0;
-}
-
-static int ami_registrations_endpoint(void *obj, void *arg, int flags)
-{
-	struct ast_sip_endpoint *endpoint = obj;
-	return ast_sip_for_each_aor(
-		endpoint->aors, ami_registrations_aor, arg);
-}
-
-static int ami_registrations_endpoints(void *arg)
-{
-	RAII_VAR(struct ao2_container *, endpoints,
-		 ast_sip_get_endpoints(), ao2_cleanup);
-
-	if (!endpoints) {
-		return 0;
-	}
-
-	ao2_callback(endpoints, OBJ_NODATA, ami_registrations_endpoint, arg);
-	return 0;
-}
-
 static int ami_show_registrations(struct mansession *s, const struct message *m)
 {
 	int count = 0;
-	struct ast_sip_ami ami = { .s = s, .m = m, .arg = &count, .action_id = astman_get_header(m, "ActionID"), };
+	struct ast_sip_ami ami = { .s = s, .m = m, .arg = NULL, .action_id = astman_get_header(m, "ActionID"), };
+	struct ao2_container *contacts = ast_sorcery_retrieve_by_fields(
+		ast_sip_get_sorcery(), "contact", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+	struct ao2_iterator i;
+	struct ast_sip_contact *contact;
 
-	astman_send_listack(s, m, "Following are Events for each Inbound registration",
-		"start");
+	astman_send_listack(s, m, "Following are ContactStatusEvents for each Inbound "
+			    "registration", "start");
 
-	ami_registrations_endpoints(&ami);
+	if (contacts) {
+		i = ao2_iterator_init(contacts, 0);
+		while ((contact = ao2_iterator_next(&i))) {
+			struct ast_sip_contact_wrapper wrapper;
 
-	astman_send_list_complete_start(s, m, "InboundRegistrationDetailComplete", count);
+			wrapper.aor_id = contact->aor;
+			wrapper.contact = contact;
+			wrapper.contact_id = (char *)ast_sorcery_object_get_id(contact);
+
+			ast_sip_format_contact_ami(&wrapper, &ami, 0);
+			count++;
+
+			ao2_ref(contact, -1);
+		}
+		ao2_iterator_destroy(&i);
+		ao2_ref(contacts, -1);
+	}
+
+	astman_send_list_complete_start(s, m, "ContactStatusDetailComplete", count);
 	astman_send_list_complete_end(s);
 	return 0;
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2468f9d8a9d703106b530cccec20ff3874211bdb
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>



More information about the asterisk-code-review mailing list