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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 19 17:04:38 CDT 2013


Author: mmichelson
Date: Tue Mar 19 17:04:35 2013
New Revision: 383398

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383398
Log:
Final cleanup for outbound auth work

* Add doxygen where necessary
* Change function names and types to be more indicative of what they do/are
* Fix memory leak for in-dialog outbound auth by using dialog pool for allocation
* Eliminate out-of-dialog processing in sip_outbound_auth.c


Modified:
    team/mmichelson/outbound_auth/include/asterisk/res_sip.h
    team/mmichelson/outbound_auth/res/res_sip.exports.in
    team/mmichelson/outbound_auth/res/res_sip/include/res_sip_private.h
    team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.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=383398&r1=383397&r2=383398
==============================================================================
--- team/mmichelson/outbound_auth/include/asterisk/res_sip.h (original)
+++ team/mmichelson/outbound_auth/include/asterisk/res_sip.h Tue Mar 19 17:04:35 2013
@@ -618,17 +618,40 @@
 int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery);
 
 /*!
- * \brief Initialize outbound authentication support
- *
- * \retval 0 Success
- * \retval non-zero Failure
- */
-int ast_sip_initialize_outbound_authentication(void);
-
-typedef int (*outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data);
-
-int ast_sip_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
-		outbound_auth_cb cb, void *user_data);
+ * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog
+ *
+ * This callback will have the created request on it. The callback's purpose is to do any extra
+ * housekeeping that needs to be done as well as to send the request out.
+ *
+ * This callback is only necessary if working with a PJSIP API that sits between the application
+ * and the dialog layer.
+ *
+ * \param dlg The dialog to which the request belongs
+ * \param tdata The created request to be sent out
+ * \param user_data Data supplied with the callback
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data);
+
+/*!
+ * \brief Set up outbound authentication on a SIP dialog
+ *
+ * This sets up the infrastructure so that all requests associated with a created dialog
+ * can be re-sent with authentication credentials if the original request is challenged.
+ *
+ * \param dlg The dialog on which requests will be authenticated
+ * \param endpoint The endpoint whom this dialog pertains to
+ * \param cb Callback to call to send requests with authentication
+ * \param user_data Data to be provided to the callback when it is called
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
+		ast_sip_dialog_outbound_auth_cb cb, void *user_data);
+
 /*!
  * \brief Initialize the distributor module
  *

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=383398&r1=383397&r2=383398
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.exports.in (original)
+++ team/mmichelson/outbound_auth/res/res_sip.exports.in Tue Mar 19 17:04:35 2013
@@ -19,7 +19,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_check_authentication;
 		LINKER_SYMBOL_PREFIXast_sip_create_auth_challenge_response;
 		LINKER_SYMBOL_PREFIXast_sip_set_outbound_authentication_credentials;
-		LINKER_SYMBOL_PREFIXast_sip_setup_outbound_authentication;
+		LINKER_SYMBOL_PREFIXast_sip_dialog_setup_outbound_authentication;
 		LINKER_SYMBOL_PREFIXast_sip_add_digest_to_challenge;
 		LINKER_SYMBOL_PREFIXast_sip_identify_endpoint;
 		LINKER_SYMBOL_PREFIXast_sip_add_header;

Modified: team/mmichelson/outbound_auth/res/res_sip/include/res_sip_private.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip/include/res_sip_private.h?view=diff&rev=383398&r1=383397&r2=383398
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/include/res_sip_private.h (original)
+++ team/mmichelson/outbound_auth/res/res_sip/include/res_sip_private.h Tue Mar 19 17:04:35 2013
@@ -40,6 +40,14 @@
 int ast_res_sip_init_options_handling(int reload);
 
 /*!
+ * \brief Initialize outbound authentication support
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_sip_initialize_outbound_authentication(void);
+
+/*!
  * \brief Get the current defined endpoints
  *
  * \retval The current endpoints loaded by res_sip

Modified: team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c?view=diff&rev=383398&r1=383397&r2=383398
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c Tue Mar 19 17:04:35 2013
@@ -23,6 +23,7 @@
 
 #include "asterisk/res_sip.h"
 #include "asterisk/module.h"
+#include "include/res_sip_private.h"
 
 static pj_bool_t outbound_auth(pjsip_rx_data *rdata);
 
@@ -33,20 +34,38 @@
 };
 
 struct outbound_auth_cb_data {
-	outbound_auth_cb cb;
+	ast_sip_dialog_outbound_auth_cb cb;
 	void *user_data;
 };
 
-static pj_bool_t dialog_outbound_auth(struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
-		pjsip_transaction *tsx, pjsip_rx_data *rdata)
+static pj_bool_t outbound_auth(pjsip_rx_data *rdata)
 {
-	struct outbound_auth_cb_data *cb_data = dlg->mod_data[outbound_auth_mod.id];
+	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	pjsip_transaction *tsx;
+	pjsip_dialog *dlg;
+	struct outbound_auth_cb_data *cb_data;
 	pjsip_tx_data *tdata;
+
+	if (rdata->msg_info.msg->line.status.code != 401 &&
+			rdata->msg_info.msg->line.status.code != 407) {
+		/* Doesn't pertain to us. Move on */
+		return PJ_FALSE;
+	}
+
+	tsx = pjsip_rdata_get_tsx(rdata);
+	dlg = pjsip_rdata_get_dlg(rdata);
+	ast_assert(dlg != NULL && tsx != NULL);
+	endpoint = ast_sip_dialog_get_endpoint(dlg);
+
+	if (!endpoint) {
+		return PJ_FALSE;
+	}
 
 	if (ast_sip_create_auth_challenge_response(endpoint, rdata, tsx, &tdata)) {
 		return PJ_FALSE;
 	}
-
+	
+	cb_data = dlg->mod_data[outbound_auth_mod.id];
 	if (cb_data) {
 		cb_data->cb(dlg, tdata, cb_data->user_data);
 		return PJ_TRUE;
@@ -56,49 +75,10 @@
 	return PJ_TRUE;
 }
 
-static pj_bool_t outbound_auth(pjsip_rx_data *rdata)
+int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
+		ast_sip_dialog_outbound_auth_cb cb, void *user_data)
 {
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
-	pjsip_transaction *tsx;
-	pjsip_dialog *dlg;
-	pjsip_auth_clt_sess auth_sess;
-	pjsip_tx_data *tdata;
-	if (rdata->msg_info.msg->line.status.code != 401 &&
-			rdata->msg_info.msg->line.status.code != 407) {
-		/* Doesn't pertain to us. Move on */
-		return PJ_FALSE;
-	}
-
-	tsx = pjsip_rdata_get_tsx(rdata);
-	dlg = pjsip_rdata_get_dlg(rdata);
-	if (dlg) {
-		endpoint = ast_sip_dialog_get_endpoint(dlg);
-		if (!endpoint) {
-			return PJ_FALSE;
-		}
-		return dialog_outbound_auth(endpoint, dlg, tsx, rdata);
-	}
-
-	/* Endpoint identification is not automatically done on responses,
-	 * so we have to do it ourselves here
-	 */
-	endpoint = ast_sip_identify_endpoint(rdata);
-	if (endpoint == NULL) {
-		ast_log(LOG_WARNING, "Cannot respond to authentication challenge because"
-				"endpoint could not be identified\n");
-		return PJ_FALSE;
-	}
-
-	ast_sip_set_outbound_authentication_credentials(&auth_sess, endpoint);
-	pjsip_auth_clt_reinit_req(&auth_sess, rdata, tsx->last_tx, &tdata);
-	pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL);
-	return PJ_TRUE;
-}
-
-int ast_sip_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
-		outbound_auth_cb cb, void *user_data)
-{
-	struct outbound_auth_cb_data *cb_data = ast_calloc(1, sizeof(*cb_data));
+	struct outbound_auth_cb_data *cb_data = PJ_POOL_ZALLOC_T(dlg->pool, struct outbound_auth_cb_data);
 	cb_data->cb = cb;
 	cb_data->user_data = user_data;
 

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=383398&r1=383397&r2=383398
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip_session.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip_session.c Tue Mar 19 17:04:35 2013
@@ -812,7 +812,7 @@
 		return NULL;
 	}
 
-	if (ast_sip_setup_outbound_authentication(dlg, endpoint, session_outbound_auth, NULL)) {
+	if (ast_sip_dialog_setup_outbound_authentication(dlg, endpoint, session_outbound_auth, NULL)) {
 		pjsip_dlg_terminate(dlg);
 		return NULL;
 	}




More information about the asterisk-commits mailing list