[svn-commits] file: trunk r430180 - in /trunk: ./ channels/pjsip/ funcs/ include/asterisk/ ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 5 11:53:48 CST 2015


Author: file
Date: Mon Jan  5 11:53:42 2015
New Revision: 430180

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=430180
Log:
pjsip: Add 'PJSIP_AOR' and 'PJSIP_CONTACT' dialplan functions.

The PJSIP_AOR dialplan function allows inspection of configured AORs including
what contacts are currently bound to them.

The PJSIP_CONTACT dialplan function allows inspection of contacts in existence.
These can include both externally added (by way of registration) or permanent
ones.

ASTERISK-24341
Reported by: xrobau

Review: https://reviewboard.asterisk.org/r/4308/
........

Merged revisions 430179 from http://svn.asterisk.org/svn/asterisk/branches/13

Added:
    trunk/funcs/func_pjsip_aor.c
      - copied unchanged from r430179, branches/13/funcs/func_pjsip_aor.c
    trunk/funcs/func_pjsip_contact.c
      - copied unchanged from r430179, branches/13/funcs/func_pjsip_contact.c
Modified:
    trunk/   (props changed)
    trunk/channels/pjsip/dialplan_functions.c
    trunk/include/asterisk/res_pjsip.h
    trunk/include/asterisk/res_pjsip_session.h
    trunk/res/res_pjsip/location.c
    trunk/res/res_pjsip_session.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/channels/pjsip/dialplan_functions.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/pjsip/dialplan_functions.c?view=diff&rev=430180&r1=430179&r2=430180
==============================================================================
--- trunk/channels/pjsip/dialplan_functions.c (original)
+++ trunk/channels/pjsip/dialplan_functions.c Mon Jan  5 11:53:42 2015
@@ -298,6 +298,18 @@
 			Use the <replaceable>PJSIP_ENDPOINT</replaceable> function to obtain
 			further endpoint related information.</para>
 		</enum>
+		<enum name="contact">
+			<para>R/O The name of the contact associated with this channel.
+			Use the <replaceable>PJSIP_CONTACT</replaceable> function to obtain
+			further contact related information. Note this may not be present and if so
+			is only available on outgoing legs.</para>
+		</enum>
+		<enum name="aor">
+			<para>R/O The name of the AOR associated with this channel.
+			Use the <replaceable>PJSIP_AOR</replaceable> function to obtain
+			further AOR related information. Note this may not be present and if so
+			is only available on outgoing legs.</para>
+		</enum>
 		<enum name="pjsip">
 			<para>R/O Obtain information about the current PJSIP channel and its
 			session.</para>
@@ -671,6 +683,28 @@
 			return -1;
 		}
 		snprintf(func_args->buf, func_args->len, "%s", ast_sorcery_object_get_id(pvt->session->endpoint));
+	} else if (!strcmp(func_args->param, "contact")) {
+		struct ast_sip_channel_pvt *pvt = ast_channel_tech_pvt(func_args->chan);
+
+		if (!pvt) {
+			ast_log(AST_LOG_WARNING, "Channel %s has no pvt!\n", ast_channel_name(func_args->chan));
+			return -1;
+		}
+		if (!pvt->session || !pvt->session->contact) {
+			return 0;
+		}
+		snprintf(func_args->buf, func_args->len, "%s", ast_sorcery_object_get_id(pvt->session->contact));
+	} else if (!strcmp(func_args->param, "aor")) {
+		struct ast_sip_channel_pvt *pvt = ast_channel_tech_pvt(func_args->chan);
+
+		if (!pvt) {
+			ast_log(AST_LOG_WARNING, "Channel %s has no pvt!\n", ast_channel_name(func_args->chan));
+			return -1;
+		}
+		if (!pvt->session || !pvt->session->aor) {
+			return 0;
+		}
+		snprintf(func_args->buf, func_args->len, "%s", ast_sorcery_object_get_id(pvt->session->aor));
 	} else if (!strcmp(func_args->param, "pjsip")) {
 		func_args->ret = channel_read_pjsip(func_args->chan, func_args->type,
 		                                    func_args->field, func_args->buf,

Modified: trunk/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip.h?view=diff&rev=430180&r1=430179&r2=430180
==============================================================================
--- trunk/include/asterisk/res_pjsip.h (original)
+++ trunk/include/asterisk/res_pjsip.h Mon Jan  5 11:53:42 2015
@@ -918,6 +918,16 @@
 struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list);
 
 /*!
+ * \brief Retrieve the first bound contact AND the AOR chosen from a list of AORs
+ *
+ * \param aor_list A comma-separated list of AOR names
+ * \param aor The chosen AOR
+ * \param contact The chosen contact
+ */
+ void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor,
+	struct ast_sip_contact **contact);
+
+/*!
  * \brief Retrieve a named contact
  *
  * \param contact_name Name of the contact

Modified: trunk/include/asterisk/res_pjsip_session.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip_session.h?view=diff&rev=430180&r1=430179&r2=430180
==============================================================================
--- trunk/include/asterisk/res_pjsip_session.h (original)
+++ trunk/include/asterisk/res_pjsip_session.h Mon Jan  5 11:53:42 2015
@@ -107,6 +107,8 @@
 	char exten[AST_MAX_EXTENSION];
 	/*! The endpoint with which Asterisk is communicating */
 	struct ast_sip_endpoint *endpoint;
+	/*! The AOR associated with this session */
+	struct ast_sip_aor *aor;
 	/*! The contact associated with this session */
 	struct ast_sip_contact *contact;
 	/*! The PJSIP details of the session, which includes the dialog */

Modified: trunk/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/location.c?view=diff&rev=430180&r1=430179&r2=430180
==============================================================================
--- trunk/res/res_pjsip/location.c (original)
+++ trunk/res/res_pjsip/location.c Mon Jan  5 11:53:42 2015
@@ -144,30 +144,46 @@
 	return contacts;
 }
 
-struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
+void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor,
+	struct ast_sip_contact **contact)
 {
 	char *aor_name;
 	char *rest;
-	struct ast_sip_contact *contact = NULL;
 
 	/* If the location is still empty we have nowhere to go */
 	if (ast_strlen_zero(aor_list) || !(rest = ast_strdupa(aor_list))) {
 		ast_log(LOG_WARNING, "Unable to determine contacts from empty aor list\n");
-		return NULL;
-	}
+		return;
+	}
+
+	*aor = NULL;
+	*contact = NULL;
 
 	while ((aor_name = strsep(&rest, ","))) {
-		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
-
-		if (!aor) {
+		*aor = ast_sip_location_retrieve_aor(aor_name);
+
+		if (!(*aor)) {
 			continue;
 		}
-		contact = ast_sip_location_retrieve_first_aor_contact(aor);
+		*contact = ast_sip_location_retrieve_first_aor_contact(*aor);
 		/* If a valid contact is available use its URI for dialing */
-		if (contact) {
+		if (*contact) {
 			break;
 		}
-	}
+
+		ao2_ref(*aor, -1);
+		*aor = NULL;
+	}
+}
+
+struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
+{
+	struct ast_sip_aor *aor;
+	struct ast_sip_contact *contact;
+
+	ast_sip_location_retrieve_contact_and_aor_from_list(aor_list, &aor, &contact);
+
+	ao2_cleanup(aor);
 
 	return contact;
 }

Modified: trunk/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_session.c?view=diff&rev=430180&r1=430179&r2=430180
==============================================================================
--- trunk/res/res_pjsip_session.c (original)
+++ trunk/res/res_pjsip_session.c Mon Jan  5 11:53:42 2015
@@ -956,6 +956,7 @@
 	}
 	ast_party_id_free(&session->id);
 	ao2_cleanup(session->endpoint);
+	ao2_cleanup(session->aor);
 	ao2_cleanup(session->contact);
 	ao2_cleanup(session->req_caps);
 	ao2_cleanup(session->direct_media_cap);
@@ -1213,6 +1214,7 @@
 	struct ast_format_cap *req_caps)
 {
 	const char *uri = NULL;
+	RAII_VAR(struct ast_sip_aor *, found_aor, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_sip_contact *, found_contact, NULL, ao2_cleanup);
 	pjsip_timer_setting timer;
 	pjsip_dialog *dlg;
@@ -1223,7 +1225,7 @@
 	if (location || !contact) {
 		location = S_OR(location, endpoint->aors);
 
-		found_contact = ast_sip_location_retrieve_contact_from_aor_list(location);
+		ast_sip_location_retrieve_contact_and_aor_from_list(location, &found_aor, &found_contact);
 		if (!found_contact || ast_strlen_zero(found_contact->uri)) {
 			uri = location;
 		} else {
@@ -1264,6 +1266,7 @@
 		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
 		return NULL;
 	}
+	session->aor = ao2_bump(found_aor);
 	ast_party_id_copy(&session->id, &endpoint->id.self);
 
 	if (ast_format_cap_count(req_caps)) {




More information about the svn-commits mailing list