[asterisk-commits] mmichelson: branch mmichelson/outbound_auth r383375 - in /team/mmichelson/out...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 19 13:42:42 CDT 2013


Author: mmichelson
Date: Tue Mar 19 13:42:40 2013
New Revision: 383375

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383375
Log:
First draft of sip_send_out_of_dialog_request() is complete.

This required the factoring out of logic that I mentioned in the
last commit.

My next step is to test that the function actually works. After that,
I can add the outbound auth stuff that needs to be there.


Modified:
    team/mmichelson/outbound_auth/include/asterisk/res_sip.h
    team/mmichelson/outbound_auth/res/res_sip.c
    team/mmichelson/outbound_auth/res/res_sip.exports.in
    team/mmichelson/outbound_auth/res/res_sip/location.c
    team/mmichelson/outbound_auth/res/res_sip_session.c

Modified: team/mmichelson/outbound_auth/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/include/asterisk/res_sip.h?view=diff&rev=383375&r1=383374&r2=383375
==============================================================================
--- team/mmichelson/outbound_auth/include/asterisk/res_sip.h (original)
+++ team/mmichelson/outbound_auth/include/asterisk/res_sip.h Tue Mar 19 13:42:40 2013
@@ -538,14 +538,32 @@
 struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name);
 
 /*!
+ * \brief Retrieve the first bound contact for an AOR
+ *
+ * \param aor Pointer to the AOR
+ * \retval NULL if no contacts available
+ * \retval non-NULL if contacts available
+ */
+struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor);
+
+/*!
  * \brief Retrieve all contacts currently available for an AOR
  *
  * \param aor Pointer to the AOR
  *
- * \param NULL if no contacts available
- * \param non-NULL if contacts available
+ * \retval NULL if no contacts available
+ * \retval non-NULL if contacts available
  */
 struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor);
+
+/*!
+ * \brief Retrieve the first bound contact from a list of AORs
+ *
+ * \param aor_list A comma-separated list of AOR names
+ * \retval NULL if no contacts available
+ * \retval non-NULL if contacts available
+ */
+struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list);
 
 /*!
  * \brief Retrieve a named contact

Modified: team/mmichelson/outbound_auth/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip.c?view=diff&rev=383375&r1=383374&r2=383375
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip.c Tue Mar 19 13:42:40 2013
@@ -481,6 +481,50 @@
 
 static int send_out_of_dialog_request(const pjsip_method *method, const struct ast_sip_body *body, struct ast_sip_endpoint *endpoint)
 {
+	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+	pj_str_t remote_uri;
+	pj_str_t from;
+	pj_pool_t *pool;
+	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
+	pjsip_tx_data *tdata;
+
+	contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
+	if (!contact || ast_strlen_zero(contact->uri)) {
+		return -1;
+	}
+
+	pj_cstr(&remote_uri, contact->uri);
+
+	if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
+		return -1;
+	}
+
+	pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound request", 256, 256);
+
+	if (!pool) {
+		return -1;
+	}
+
+	if (sip_dialog_create_from(pool, &from, NULL, &remote_uri, &selector)) {
+		pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+		return -1;
+	}
+
+	if (pjsip_endpt_create_request(ast_sip_get_pjsip_endpoint(), method, &remote_uri,
+			&from, &remote_uri, &from, NULL, -1, NULL, &tdata) != PJ_SUCCESS) {
+		pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+		return -1;
+	}
+
+	/* We can release this pool since request creation copied all the necessary
+	 * data into the outbound request's pool
+	 */
+	pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+
+	if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL) != PJ_SUCCESS) {
+		return -1;
+	}
+
 	return 0;
 }
 

Modified: team/mmichelson/outbound_auth/res/res_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip.exports.in?view=diff&rev=383375&r1=383374&r2=383375
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.exports.in (original)
+++ team/mmichelson/outbound_auth/res/res_sip.exports.in Tue Mar 19 13:42:40 2013
@@ -31,6 +31,8 @@
 		LINKER_SYMBOL_PREFIXast_sip_get_sorcery;
 		LINKER_SYMBOL_PREFIXast_sip_create_dialog;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_aor;
+		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_first_aor_contact;
+		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact_from_aor_list;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_aor_contacts;
 		LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact;
 		LINKER_SYMBOL_PREFIXast_sip_location_add_contact;

Modified: team/mmichelson/outbound_auth/res/res_sip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip/location.c?view=diff&rev=383375&r1=383374&r2=383375
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/location.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/location.c Tue Mar 19 13:42:40 2013
@@ -95,6 +95,26 @@
 	return 0;
 }
 
+/*! \brief Simple callback function which returns immediately, used to grab the first contact of an AOR */
+static int contact_find_first(void *obj, void *arg, int flags)
+{
+	return CMP_MATCH | CMP_STOP;
+}
+
+struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor)
+{
+	RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+	struct ast_sip_contact *contact;
+
+	contacts = ast_sip_location_retrieve_aor_contacts(aor);
+	if (!contacts || (ao2_container_count(contacts) == 0)) {
+		return NULL;
+	}
+
+	contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL); 
+	return contact;
+}
+
 struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
 {
 	/* Give enough space for ^ at the beginning and ;@ at the end, since that is our object naming scheme */
@@ -116,6 +136,35 @@
 	}
 
 	return contacts;
+}
+
+struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
+{
+	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;
+	}
+
+	while ((aor_name = strsep(&rest, ","))) {
+		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
+		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+
+		if (!aor) {
+			continue;
+		}
+		contact = ast_sip_location_retrieve_first_aor_contact(aor);
+		/* If a valid contact is available use its URI for dialing */
+		if (contact) {
+			break;
+		}
+	}
+
+	return contact;
 }
 
 struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name)

Modified: team/mmichelson/outbound_auth/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip_session.c?view=diff&rev=383375&r1=383374&r2=383375
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip_session.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip_session.c Tue Mar 19 13:42:40 2013
@@ -773,12 +773,6 @@
 	return session;
 }
 
-/*! \brief Simple callback function which returns immediately, used to grab the first contact of an AOR */
-static int contact_find_first(void *obj, void *arg, int flags)
-{
-	return CMP_MATCH | CMP_STOP;
-}
-
 static int session_outbound_auth(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data)
 {
 	pjsip_inv_session *inv = pjsip_dlg_get_inv_session(dlg);
@@ -791,7 +785,6 @@
 
 struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user)
 {
-	char *aor_name, *rest;
 	const char *uri = NULL;
 	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
 	pjsip_timer_setting timer;
@@ -801,33 +794,13 @@
 	pjmedia_sdp_session *offer;
 
 	/* If no location has been provided use the AOR list from the endpoint itself */
-	if (ast_strlen_zero(location)) {
-		location = endpoint->aors;
-	}
-
-	/* If the location is still empty we have nowhere to go */
-	if (ast_strlen_zero(location) || !(rest = ast_strdupa(location))) {
-		ast_log(LOG_WARNING, "No location is configured on endpoint '%s' and one was not provided\n",
-			ast_sorcery_object_get_id(endpoint));
-		return NULL;
-	}
-
-	while ((aor_name = strsep(&rest, ","))) {
-		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
-		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
-
-		/* If a valid contact is available use its URI for dialing */
-		if (aor && (contacts = ast_sip_location_retrieve_aor_contacts(aor)) &&
-			(contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL))) {
-			uri = contact->uri;
-			break;
-		}
-
-	}
-
-	/* If no URI was found using the provided AORs then use the location as provided as a last resort */
-	if (ast_strlen_zero(uri)) {
+	location = S_OR(location, endpoint->aors);
+
+	contact = ast_sip_location_retrieve_contact_from_aor_list(location);
+	if (!contact || ast_strlen_zero(contact->uri)) {
 		uri = location;
+	} else {
+		uri = contact->uri;
 	}
 
 	/* If we still have no URI to dial fail to create the session */




More information about the asterisk-commits mailing list