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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 21 14:59:23 CDT 2013


Author: mmichelson
Date: Thu Mar 21 14:59:19 2013
New Revision: 383539

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383539
Log:
Address review board feedback.

* Remove many red blobs, including some that weren't pointed out in the reviews
* Change "challenge_response" to "create_request_with_auth"
* Remove ast_sip_set_outbound_authentication_credentials from res_sip.[ch]
* Constified endpoints in several places


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/location.c
    team/mmichelson/outbound_auth/res/res_sip/sip_options.c
    team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c
    team/mmichelson/outbound_auth/res/res_sip_outbound_authenticator_digest.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=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/include/asterisk/res_sip.h (original)
+++ team/mmichelson/outbound_auth/include/asterisk/res_sip.h Thu Mar 21 14:59:19 2013
@@ -252,7 +252,7 @@
                 /*! Musiconhold class to suggest that the other side use when placing on hold */
                 AST_STRING_FIELD(mohsuggest);
 		/*! Optional external media address to use in SDP */
-		AST_STRING_FIELD(external_media_address);       
+		AST_STRING_FIELD(external_media_address);
 	);
 	/*! Identification information for this endpoint */
 	struct ast_party_id id;
@@ -316,13 +316,13 @@
 
 /*!
  * \brief An interchangeable way of handling digest authentication for SIP.
- * 
+ *
  * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available
  * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication
  * should take place and what credentials should be used when challenging and authenticating a request.
  */
 struct ast_sip_authenticator {
-    /*! 
+    /*!
      * \brief Check if a request requires authentication
      * See ast_sip_requires_authentication for more details
      */
@@ -357,10 +357,10 @@
 	 * \retval 0 Successfully created new request
 	 * \retval -1 Failed to create a new request
 	 */
-	int (*challenge_response)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *challenge,
+	int (*create_request_with_auth)(const struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *challenge,
 			struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
 };
- 
+
 /*!
  * \brief An entity responsible for identifying the source of a SIP message
  */
@@ -386,7 +386,7 @@
  * \retval -1 Failure
  */
 int ast_sip_register_service(pjsip_module *module);
- 
+
 /*!
  * This is the opposite of ast_sip_register_service().  Unregistering a
  * service means that PJSIP will no longer call into the module any more.
@@ -395,7 +395,7 @@
  * \param module The PJSIP module to unregister
  */
 void ast_sip_unregister_service(pjsip_module *module);
- 
+
 /*!
  * \brief Register a SIP authenticator
  *
@@ -412,7 +412,7 @@
  * \retval -1 Failure
  */
 int ast_sip_register_authenticator(struct ast_sip_authenticator *auth);
- 
+
 /*!
  * \brief Unregister a SIP authenticator
  *
@@ -434,7 +434,7 @@
  * \retval -1 Failure
  */
 int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth);
- 
+
 /*!
  * \brief Unregister an outbound SIP authenticator
  *
@@ -467,7 +467,7 @@
  * \retval -1 Failure
  */
 int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier);
- 
+
 /*!
  * \brief Unregister a SIP endpoint identifier
  *
@@ -649,7 +649,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
+int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint,
 		ast_sip_dialog_outbound_auth_cb cb, void *user_data);
 
 /*!
@@ -704,7 +704,7 @@
  * Servants are where the bulk of SIP work should be performed. These threads
  * exist in order to do the work that Asterisk threads and PJSIP threads hand
  * off to them. Servant threads register themselves with PJLIB, meaning that
- * they are capable of calling PJSIP and PJLIB functions if they wish. 
+ * they are capable of calling PJSIP and PJLIB functions if they wish.
  *
  * \par Serializer
  *
@@ -843,15 +843,22 @@
  * MUST be present. If both are present, then we will assume that the message
  * is to be sent in-dialog.
  *
+ * The uri parameter can be specified if the request should be sent to an explicit
+ * URI rather than one configured on the endpoint.
+ *
  * \param method The method of the SIP request to send
  * \param dlg Optional. If specified, the dialog on which to request the message.
- * \param endpoint Optional. If specified, the request will be created out-of-dialog to the endpoint.
+ * \param endpoint Optional. If specified, the request will be created out-of-dialog
+ * to the endpoint.
+ * \param uri Optional. If specified, the request will be sent to this URI rather
+ * than one configured for the endpoint.
  * \param[out] tdata The newly-created request
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, pjsip_tx_data **tdata);
- 
+int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
+		struct ast_sip_endpoint *endpoint, const char *uri, pjsip_tx_data **tdata);
+
 /*!
  * \brief General purpose method for sending a SIP request
  *
@@ -885,7 +892,7 @@
  * \retval 0 The request does not require authentication
  */
 int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
- 
+
 /*!
  * \brief Method to determine authentication status of an incoming request
  *
@@ -905,23 +912,13 @@
 /*!
  * \brief Create a response to an authentication challenge
  *
- * This will call into an outbound authenticator's challenge_response callback
- * to create a new request with authentication credentials. See the challenge_response
+ * This will call into an outbound authenticator's create_request_with_auth callback
+ * to create a new request with authentication credentials. See the create_request_with_auth
  * callback in the \ref ast_sip_outbound_authenticator structure for details about
  * the parameters and return values.
  */
-int ast_sip_create_auth_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request);
- 
-/*!
- * \brief Set authentication credentials for outbound authentication
- *
- * \param auth_sess The client auth session to set credentials for
- * \param endpoint Endpoint from whom to get credentials
- * \retval 0 Success
- * \retval non-zero Failure
- */
-int ast_sip_set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, struct ast_sip_endpoint *endpoint);
 
 /*!
  * \brief Determine the endpoint that has sent a SIP message
@@ -936,7 +933,7 @@
  * \retval non-NULL The matching endpoint
  */
 struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata);
- 
+
 /*!
  * \brief Add a header to an outbound SIP message
  *
@@ -947,7 +944,7 @@
  * \retval -1 Failure
  */
 int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value);
- 
+
 /*!
  * \brief Add a body to an outbound SIP message
  *
@@ -960,7 +957,7 @@
  * \retval -1 Failure
  */
 int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body);
- 
+
 /*!
  * \brief Add a multipart body to an outbound SIP message
  *
@@ -973,7 +970,7 @@
  * \retval -1 Failure
  */
 int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies);
- 
+
 /*!
  * \brief Append body data to a SIP message
  *

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=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip.c Thu Mar 21 14:59:19 2013
@@ -156,49 +156,14 @@
 	ast_module_unref(ast_module_info->self);
 }
 
-int ast_sip_create_auth_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request)
 {
 	if (!registered_outbound_authenticator) {
 		ast_log(LOG_WARNING, "No SIP outbound authenticator registered. Cannot respond to authentication challenge\n");
 		return -1;
 	}
-	return registered_outbound_authenticator->challenge_response(endpoint, challenge, tsx, new_request);
-}
-
-int ast_sip_set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, struct ast_sip_endpoint *endpoint)
-{
-	struct ast_sip_auth **auths = ast_alloca(endpoint->num_outbound_auths * sizeof(*auths));
-	pjsip_cred_info *auth_creds = ast_alloca(endpoint->num_outbound_auths * sizeof(*auth_creds));
-	int res = 0;
-	int i;
-
-	if (ast_sip_retrieve_auths(endpoint->sip_outbound_auths, endpoint->num_outbound_auths, auths)) {
-		res = -1;
-		goto cleanup;
-	}
-
-	for (i = 0; i < endpoint->num_outbound_auths; ++i) {
-		pj_cstr(&auth_creds[i].realm, auths[i]->realm);
-		pj_cstr(&auth_creds[i].username, auths[i]->auth_user);
-		pj_cstr(&auth_creds[i].scheme, "digest");
-		switch (auths[i]->type) {
-		case AST_SIP_AUTH_TYPE_USER_PASS:
-			pj_cstr(&auth_creds[i].data, auths[i]->auth_pass);
-			auth_creds[i].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
-			break;
-		case AST_SIP_AUTH_TYPE_MD5:
-			pj_cstr(&auth_creds[i].data, auths[i]->md5_creds);
-			auth_creds[i].data_type = PJSIP_CRED_DATA_DIGEST;
-			break;
-		}
-	}
-
-	pjsip_auth_clt_set_credentials(auth_sess, endpoint->num_outbound_auths, auth_creds);
-
-cleanup:
-	ast_sip_cleanup_auths(auths, endpoint->num_outbound_auths);
-	return res;
+	return registered_outbound_authenticator->create_request_with_auth(endpoint, challenge, tsx, new_request);
 }
 
 struct endpoint_identifier_list {
@@ -339,11 +304,11 @@
 {
 	RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
 	const char *transport_name = endpoint->transport;
-	
+
 	if (ast_strlen_zero(transport_name)) {
 		return 0;
 	}
-	
+
 	transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name);
 
 	if (!transport || !transport->state) {
@@ -465,7 +430,8 @@
 	return 0;
 }
 
-static int create_out_of_dialog_request(const pjsip_method *method, struct ast_sip_endpoint *endpoint, pjsip_tx_data **tdata)
+static int create_out_of_dialog_request(const pjsip_method *method, struct ast_sip_endpoint *endpoint,
+		const char *uri, pjsip_tx_data **tdata)
 {
 	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
 	pj_str_t remote_uri;
@@ -473,14 +439,18 @@
 	pj_pool_t *pool;
 	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 
-	contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
-	if (!contact || ast_strlen_zero(contact->uri)) {
-		ast_log(LOG_ERROR, "Unable to retrieve contact for endpoint %s\n",
-				ast_sorcery_object_get_id(endpoint));
-		return -1;
-	}
-
-	pj_cstr(&remote_uri, contact->uri);
+	if (ast_strlen_zero(uri)) {
+		contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
+		if (!contact || ast_strlen_zero(contact->uri)) {
+			ast_log(LOG_ERROR, "Unable to retrieve contact for endpoint %s\n",
+					ast_sorcery_object_get_id(endpoint));
+			return -1;
+		}
+
+		pj_cstr(&remote_uri, contact->uri);
+	} else {
+		pj_cstr(&remote_uri, uri);
+	}
 
 	if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
 		ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport selector for endpoint %s\n",
@@ -517,7 +487,8 @@
 	return 0;
 }
 
-int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, pjsip_tx_data **tdata)
+int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
+		struct ast_sip_endpoint *endpoint, const char *uri, pjsip_tx_data **tdata)
 {
 	const pjsip_method *pmethod = get_pjsip_method(method);
 
@@ -529,7 +500,7 @@
 	if (dlg) {
 		return create_in_dialog_request(pmethod, dlg, tdata);
 	} else {
-		return create_out_of_dialog_request(pmethod, endpoint, tdata);
+		return create_out_of_dialog_request(pmethod, endpoint, uri, tdata);
 	}
 }
 
@@ -553,7 +524,7 @@
 		return;
 	}
 
-	ast_sip_create_auth_challenge_response(endpoint, challenge, tsx, &tdata);
+	ast_sip_create_request_with_auth(endpoint, challenge, tsx, &tdata);
 
 	pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL);
 }

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=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/location.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/location.c Thu Mar 21 14:59:19 2013
@@ -109,7 +109,7 @@
 		return NULL;
 	}
 
-	contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL); 
+	contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL);
 	return contact;
 }
 

Modified: team/mmichelson/outbound_auth/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip/sip_options.c?view=diff&rev=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/sip_options.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/sip_options.c Thu Mar 21 14:59:19 2013
@@ -220,7 +220,7 @@
 	pjsip_tx_data *tdata;
 	/* YAY! Send an OPTIONS request. */
 
-	ast_sip_create_request("OPTIONS", NULL, endpoint, &tdata);
+	ast_sip_create_request("OPTIONS", NULL, endpoint, NULL, &tdata);
 	ast_sip_send_request(tdata, NULL, endpoint);
 
 	ao2_cleanup(endpoint);
@@ -327,7 +327,7 @@
 		return CLI_FAILURE;
 	}
 
-	if (ast_sip_create_request("OPTIONS", NULL, endpoint, &tdata)) {
+	if (ast_sip_create_request("OPTIONS", NULL, endpoint, NULL, &tdata)) {
 		ast_log(LOG_ERROR, "Unable to create OPTIONS request to endpoint %s\n", endpoint_name);
 		return CLI_FAILURE;
 	}

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=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/sip_outbound_auth.c Thu Mar 21 14:59:19 2013
@@ -61,10 +61,10 @@
 		return PJ_FALSE;
 	}
 
-	if (ast_sip_create_auth_challenge_response(endpoint, rdata, tsx, &tdata)) {
+	if (ast_sip_create_request_with_auth(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);
@@ -75,7 +75,7 @@
 	return PJ_TRUE;
 }
 
-int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint,
+int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint,
 		ast_sip_dialog_outbound_auth_cb cb, void *user_data)
 {
 	struct outbound_auth_cb_data *cb_data = PJ_POOL_ZALLOC_T(dlg->pool, struct outbound_auth_cb_data);

Modified: team/mmichelson/outbound_auth/res/res_sip_outbound_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip_outbound_authenticator_digest.c?view=diff&rev=383539&r1=383538&r2=383539
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip_outbound_authenticator_digest.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip_outbound_authenticator_digest.c Thu Mar 21 14:59:19 2013
@@ -25,7 +25,7 @@
 #include "asterisk/module.h"
 #include "asterisk/strings.h"
 
-static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, struct ast_sip_endpoint *endpoint)
+static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, const struct ast_sip_endpoint *endpoint)
 {
 	struct ast_sip_auth **auths = ast_alloca(endpoint->num_outbound_auths * sizeof(*auths));
 	pjsip_cred_info *auth_creds = ast_alloca(endpoint->num_outbound_auths * sizeof(*auth_creds));
@@ -60,7 +60,7 @@
 	return res;
 }
 
-static int digest_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
+static int digest_create_request_with_auth(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request)
 {
 	pjsip_auth_clt_sess auth_sess;
@@ -86,7 +86,7 @@
 }
 
 static struct ast_sip_outbound_authenticator digest_authenticator = {
-	.challenge_response = digest_challenge_response,
+	.create_request_with_auth = digest_create_request_with_auth,
 };
 
 static int load_module(void)




More information about the asterisk-commits mailing list