[asterisk-commits] mmichelson: branch mmichelson/sip_endpoint_reorg r395526 - in /team/mmichelso...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 26 12:41:15 CDT 2013


Author: mmichelson
Date: Fri Jul 26 12:41:14 2013
New Revision: 395526

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395526
Log:
Re-group authentication configuration.

Scope crept a bit here, but I'm sticking by it. I was able
to remove some identical functions that existed in several
places and was able to make things less error-prone.


Modified:
    team/mmichelson/sip_endpoint_reorg/include/asterisk/res_sip.h
    team/mmichelson/sip_endpoint_reorg/res/res_sip.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_configuration.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_distributor.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_options.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_outbound_auth.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip_authenticator_digest.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_authenticator_digest.c
    team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_registration.c

Modified: team/mmichelson/sip_endpoint_reorg/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/include/asterisk/res_sip.h?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/include/asterisk/res_sip.h (original)
+++ team/mmichelson/sip_endpoint_reorg/include/asterisk/res_sip.h Fri Jul 26 12:41:14 2013
@@ -266,6 +266,13 @@
 	unsigned int nonce_lifetime;
 	/* Used to determine what to use when authenticating */
 	enum ast_sip_auth_type type;
+};
+
+struct ast_sip_auth_array {
+	/*! Array of Sorcery IDs of auth sections */
+	const char **names;
+	/*! Number of credentials in the array */
+	unsigned int num;
 };
 
 /*!
@@ -459,14 +466,10 @@
 	struct ast_sip_domain *domain;
 	/*! Address of record for incoming registrations */
 	struct ast_sip_aor *aor;
-	/*! Names of inbound authentication credentials */
-	const char **sip_inbound_auths;
-	/*! Number of configured auths */
-	size_t num_inbound_auths;
-	/*! Names of outbound authentication credentials */
-	const char **sip_outbound_auths;
-	/*! Number of configured outbound auths */
-	size_t num_outbound_auths;
+	/*! Inbound authentication credentials */
+	struct ast_sip_auth_array inbound_auths;
+	/*! Outbound authentication credentials */
+	struct ast_sip_auth_array outbound_auths;
 	/*! DTMF mode to use with this endpoint */
 	enum ast_sip_dtmf_mode dtmf;
 	/*! List of outbound registrations */
@@ -482,6 +485,23 @@
 	/*! Determines if transfers (using REFER) are allowed by this endpoint */
 	unsigned int allowtransfer;
 };
+
+/*!
+ * \brief Initialize an auth array with the configured values.
+ *
+ * \param array Array to initialize
+ * \param auth_names Comma-separated list of names to set in the array
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_sip_auth_array_init(struct ast_sip_auth_array *array, const char *auth_names);
+
+/*!
+ * \brief Free contents of an auth array.
+ *
+ * \param array Array whose contents are to be freed
+ */
+void ast_sip_auth_array_destroy(struct ast_sip_auth_array *array);
 
 /*!
  * \brief Possible returns from ast_sip_check_authentication
@@ -534,14 +554,13 @@
 	 * \brief Create a new request with authentication credentials
 	 *
 	 * \param auths An array of IDs of auth sorcery objects
-	 * \param num_auths The number of IDs in the array
 	 * \param challenge The SIP response with authentication challenge(s)
 	 * \param tsx The transaction in which the challenge was received
 	 * \param new_request The new SIP request with challenge response(s)
 	 * \retval 0 Successfully created new request
 	 * \retval -1 Failed to create a new request
 	 */
-	int (*create_request_with_auth)(const char **auths, size_t num_auths, struct pjsip_rx_data *challenge,
+	int (*create_request_with_auth)(const struct ast_sip_auth_array *auths, struct pjsip_rx_data *challenge,
 			struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
 };
 
@@ -1198,7 +1217,7 @@
  * callback in the \ref ast_sip_outbound_authenticator structure for details about
  * the parameters and return values.
  */
-int ast_sip_create_request_with_auth(const char **auths, size_t num_auths, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request);
 
 /*!
@@ -1309,11 +1328,10 @@
 /*!
  * \brief Retrieve relevant SIP auth structures from sorcery
  *
- * \param auth_names The sorcery IDs of auths to retrieve
- * \param num_auths The number of auths to retrieve
+ * \param auths Array of sorcery IDs of auth credentials to retrieve
  * \param[out] out The retrieved auths are stored here
  */
-int ast_sip_retrieve_auths(const char *auth_names[], size_t num_auths, struct ast_sip_auth **out);
+int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out);
 
 /*!
  * \brief Clean up retrieved auth structures from memory

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip.c Fri Jul 26 12:41:14 2013
@@ -1009,14 +1009,14 @@
 	ast_module_unref(ast_module_info->self);
 }
 
-int ast_sip_create_request_with_auth(const char **auths, size_t num_auths, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_auth_array *auths, 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->create_request_with_auth(auths, num_auths, challenge, tsx, new_request);
+	return registered_outbound_authenticator->create_request_with_auth(auths, challenge, tsx, new_request);
 }
 
 struct endpoint_identifier_list {
@@ -1416,7 +1416,7 @@
 		return;
 	}
 
-	if (!ast_sip_create_request_with_auth(endpoint->sip_outbound_auths, endpoint->num_outbound_auths, challenge, tsx, &tdata)) {
+	if (!ast_sip_create_request_with_auth(&endpoint->outbound_auths, challenge, tsx, &tdata)) {
 		pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL);
 	}
 }

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_configuration.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_configuration.c Fri Jul 26 12:41:14 2013
@@ -278,7 +278,7 @@
 	return 0;
 }
 
-static void destroy_auths(const char **auths, size_t num_auths)
+void ast_sip_auth_array_destroy(struct ast_sip_auth_array *auths)
 {
 	int i;
 
@@ -286,63 +286,57 @@
 		return;
 	}
 
-	for (i = 0; i < num_auths; ++i) {
-		ast_free((char *) auths[i]);
-	}
-	ast_free(auths);
+	for (i = 0; i < auths->num; ++i) {
+		ast_free((char *) auths->names[i]);
+	}
+	ast_free(auths->names);
+	auths->num = 0;
 }
 
 #define AUTH_INCREMENT 4
 
-static const char **auth_alloc(const char *value, size_t *num_auths)
-{
-	char *auths = ast_strdupa(value);
+int ast_sip_auth_array_init(struct ast_sip_auth_array *auths, const char *value)
+{
+	char *auth_names = ast_strdupa(value);
 	char *val;
 	int num_alloced = 0;
 	const char **alloced_auths = NULL;
 
-	while ((val = strsep(&auths, ","))) {
-		if (*num_auths >= num_alloced) {
+	while ((val = strsep(&auth_names, ","))) {
+		if (auths->num >= num_alloced) {
 			size_t size;
 			num_alloced += AUTH_INCREMENT;
 			size = num_alloced * sizeof(char *);
-			alloced_auths = ast_realloc(alloced_auths, size);
-			if (!alloced_auths) {
+			auths->names = ast_realloc(alloced_auths, size);
+			if (!auths->names) {
 				goto failure;
 			}
 		}
-		alloced_auths[*num_auths] = ast_strdup(val);
-		if (!alloced_auths[*num_auths]) {
+		auths->names[auths->num] = ast_strdup(val);
+		if (!auths->names[auths->num]) {
 			goto failure;
 		}
-		++(*num_auths);
-	}
-	return alloced_auths;
+		++auths->num;
+	}
+	return 0;
 
 failure:
-	destroy_auths(alloced_auths, *num_auths);
-	return NULL;
+	ast_sip_auth_array_destroy(auths);
+	return -1;
 }
 
 static int inbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct ast_sip_endpoint *endpoint = obj;
 
-	endpoint->sip_inbound_auths = auth_alloc(var->value, &endpoint->num_inbound_auths);
-	if (!endpoint->sip_inbound_auths) {
-		return -1;
-	}
-	return 0;
-}
+	return ast_sip_auth_array_init(&endpoint->inbound_auths, var->value);
+}
+
 static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct ast_sip_endpoint *endpoint = obj;
 
-	endpoint->sip_outbound_auths = auth_alloc(var->value, &endpoint->num_outbound_auths);
-	if (!endpoint->sip_outbound_auths) {
-		return -1;
-	}
-	return 0;
+	return ast_sip_auth_array_init(&endpoint->outbound_auths, var->value);
 }
 
 static int ident_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
@@ -767,8 +761,8 @@
 	if (endpoint->media.codecs) {
 		ast_format_cap_destroy(endpoint->media.codecs);
 	}
-	destroy_auths(endpoint->sip_inbound_auths, endpoint->num_inbound_auths);
-	destroy_auths(endpoint->sip_outbound_auths, endpoint->num_outbound_auths);
+	ast_sip_auth_array_destroy(&endpoint->inbound_auths);
+	ast_sip_auth_array_destroy(&endpoint->outbound_auths);
 	ast_party_id_free(&endpoint->id.self);
 	endpoint->pickup.named_callgroups = ast_unref_namedgroups(endpoint->pickup.named_callgroups);
 	endpoint->pickup.named_pickupgroups = ast_unref_namedgroups(endpoint->pickup.named_pickupgroups);
@@ -802,14 +796,14 @@
 	return endpoints;
 }
 
-int ast_sip_retrieve_auths(const char *auth_names[], size_t num_auths, struct ast_sip_auth **out)
+int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out)
 {
 	int i;
 
-	for (i = 0; i < num_auths; ++i) {
-		out[i] = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, auth_names[i]);
+	for (i = 0; i < auths->num; ++i) {
+		out[i] = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, auths->names[i]);
 		if (!out[i]) {
-			ast_log(LOG_NOTICE, "Couldn't find auth '%s'. Cannot authenticate\n", auth_names[i]);
+			ast_log(LOG_NOTICE, "Couldn't find auth '%s'. Cannot authenticate\n", auths->names[i]);
 			return -1;
 		}
 	}

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_distributor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_distributor.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_distributor.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_distributor.c Fri Jul 26 12:41:14 2013
@@ -170,7 +170,7 @@
 		return -1;
 	}
 
-	artificial_endpoint->num_inbound_auths = 1;
+	artificial_endpoint->inbound_auths.num = 1;
 	return 0;
 }
 

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_options.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_options.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_options.c Fri Jul 26 12:41:14 2013
@@ -234,8 +234,7 @@
 	   endpoint should do that matched on the contact */
 	endpoint = ao2_callback(endpoints, 0, NULL, NULL);
 
-	if (!ast_sip_create_request_with_auth(endpoint->sip_outbound_auths,
-					      endpoint->num_outbound_auths,
+	if (!ast_sip_create_request_with_auth(&endpoint->outbound_auths,
 					      challenge, tsx, &tdata)) {
 		pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata,
 					 -1, NULL, NULL);

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_outbound_auth.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_outbound_auth.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_outbound_auth.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip/sip_outbound_auth.c Fri Jul 26 12:41:14 2013
@@ -61,7 +61,7 @@
 		return PJ_FALSE;
 	}
 
-	if (ast_sip_create_request_with_auth(endpoint->sip_outbound_auths, endpoint->num_outbound_auths, rdata, tsx, &tdata)) {
+	if (ast_sip_create_request_with_auth(&endpoint->outbound_auths, rdata, tsx, &tdata)) {
 		return PJ_FALSE;
 	}
 

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip_authenticator_digest.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip_authenticator_digest.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip_authenticator_digest.c Fri Jul 26 12:41:14 2013
@@ -41,7 +41,7 @@
  */
 static int digest_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
 {
-	return endpoint->num_inbound_auths > 0;
+	return endpoint->inbound_auths.num > 0;
 }
 
 static void auth_store_cleanup(void *data)
@@ -380,8 +380,8 @@
 	RAII_VAR(struct ast_sip_endpoint *, artificial_endpoint,
 		 ast_sip_get_artificial_endpoint(), ao2_cleanup);
 
-	auths = ast_alloca(endpoint->num_inbound_auths * sizeof(*auths));
-	verify_res = ast_alloca(endpoint->num_inbound_auths * sizeof(*verify_res));
+	auths = ast_alloca(endpoint->inbound_auths.num * sizeof(*auths));
+	verify_res = ast_alloca(endpoint->inbound_auths.num * sizeof(*verify_res));
 
 	if (!auths) {
 		return AST_SIP_AUTHENTICATION_ERROR;
@@ -389,12 +389,12 @@
 
 	if (endpoint == artificial_endpoint) {
 		auths[0] = ast_sip_get_artificial_auth();
-	} else if (ast_sip_retrieve_auths(endpoint->sip_inbound_auths, endpoint->num_inbound_auths, auths)) {
+	} else if (ast_sip_retrieve_auths(&endpoint->inbound_auths, auths)) {
 		res = AST_SIP_AUTHENTICATION_ERROR;
 		goto cleanup;
 	}
 
-	for (i = 0; i < endpoint->num_inbound_auths; ++i) {
+	for (i = 0; i < endpoint->inbound_auths.num; ++i) {
 		verify_res[i] = verify(auths[i], rdata, tdata->pool);
 		if (verify_res[i] == AUTH_SUCCESS) {
 			res = AST_SIP_AUTHENTICATION_SUCCESS;
@@ -402,14 +402,14 @@
 		}
 	}
 
-	for (i = 0; i < endpoint->num_inbound_auths; ++i) {
+	for (i = 0; i < endpoint->inbound_auths.num; ++i) {
 		challenge(auths[i]->realm, tdata, rdata, verify_res[i] == AUTH_STALE);
 	}
 
 	res = AST_SIP_AUTHENTICATION_CHALLENGE;
 
 cleanup:
-	ast_sip_cleanup_auths(auths, endpoint->num_inbound_auths);
+	ast_sip_cleanup_auths(auths, endpoint->inbound_auths.num);
 	return res;
 }
 

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_authenticator_digest.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_authenticator_digest.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_authenticator_digest.c Fri Jul 26 12:41:14 2013
@@ -31,19 +31,19 @@
 #include "asterisk/module.h"
 #include "asterisk/strings.h"
 
-static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, const char **auth_strs, size_t num_auths)
+static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess, const struct ast_sip_auth_array *array)
 {
-	struct ast_sip_auth **auths = ast_alloca(num_auths * sizeof(*auths));
-	pjsip_cred_info *auth_creds = ast_alloca(num_auths * sizeof(*auth_creds));
+	struct ast_sip_auth **auths = ast_alloca(array->num * sizeof(*auths));
+	pjsip_cred_info *auth_creds = ast_alloca(array->num * sizeof(*auth_creds));
 	int res = 0;
 	int i;
 
-	if (ast_sip_retrieve_auths(auth_strs, num_auths, auths)) {
+	if (ast_sip_retrieve_auths(array, auths)) {
 		res = -1;
 		goto cleanup;
 	}
 
-	for (i = 0; i < num_auths; ++i) {
+	for (i = 0; i < array->num; ++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");
@@ -62,14 +62,14 @@
 		}
 	}
 
-	pjsip_auth_clt_set_credentials(auth_sess, num_auths, auth_creds);
+	pjsip_auth_clt_set_credentials(auth_sess, array->num, auth_creds);
 
 cleanup:
-	ast_sip_cleanup_auths(auths, num_auths);
+	ast_sip_cleanup_auths(auths, array->num);
 	return res;
 }
 
-static int digest_create_request_with_auth(const char **auths, size_t num_auths, pjsip_rx_data *challenge,
+static int digest_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request)
 {
 	pjsip_auth_clt_sess auth_sess;
@@ -80,7 +80,7 @@
 		return -1;
 	}
 
-	if (set_outbound_authentication_credentials(&auth_sess, auths, num_auths)) {
+	if (set_outbound_authentication_credentials(&auth_sess, auths)) {
 		ast_log(LOG_WARNING, "Failed to set authentication credentials\n");
 		return -1;
 	}

Modified: team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_registration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_registration.c?view=diff&rev=395526&r1=395525&r2=395526
==============================================================================
--- team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_registration.c (original)
+++ team/mmichelson/sip_endpoint_reorg/res/res_sip_outbound_registration.c Fri Jul 26 12:41:14 2013
@@ -128,7 +128,7 @@
 	/*! \brief Serializer for stuff and things */
 	struct ast_taskprocessor *serializer;
 	/*! \brief Configured authentication credentials */
-	const char **sip_outbound_auths;
+	struct ast_sip_auth_array outbound_auths;
 	/*! \brief Number of configured auths */
 	size_t num_outbound_auths;
 	/*! \brief Registration should be destroyed after completion of transaction */
@@ -169,19 +169,10 @@
 	/*! \brief Outbound registration state */
 	struct sip_outbound_registration_state *state;
 	/*! \brief Configured authentication credentials */
-	const char **sip_outbound_auths;
+	struct ast_sip_auth_array outbound_auths;
 	/*! \brief Number of configured auths */
 	size_t num_outbound_auths;
 };
-
-static void destroy_auths(const char **auths, size_t num_auths)
-{
-	int i;
-	for (i = 0; i < num_auths; ++i) {
-		ast_free((char *) auths[i]);
-	}
-	ast_free(auths);
-}
 
 /*! \brief Helper function which cancels the timer on a client */
 static void cancel_registration(struct sip_outbound_registration_client_state *client_state)
@@ -270,7 +261,7 @@
 	pjsip_regc_destroy(client_state->client);
 
 	client_state->status = SIP_REGISTRATION_STOPPED;
-	destroy_auths(client_state->sip_outbound_auths, client_state->num_outbound_auths);
+	ast_sip_auth_array_destroy(&client_state->outbound_auths);
 
 	return 0;
 }
@@ -340,7 +331,7 @@
 
 	if (response->code == 401 || response->code == 407) {
 		pjsip_tx_data *tdata;
-		if (!ast_sip_create_request_with_auth(response->client_state->sip_outbound_auths, response->client_state->num_outbound_auths,
+		if (!ast_sip_create_request_with_auth(&response->client_state->outbound_auths,
 				response->rdata, response->tsx, &tdata)) {
 			pjsip_regc_send(response->client_state->client, tdata);
 			return 0;
@@ -469,7 +460,7 @@
 	struct sip_outbound_registration *registration = obj;
 
 	ao2_cleanup(registration->state);
-	destroy_auths(registration->sip_outbound_auths, registration->num_outbound_auths);
+	ast_sip_auth_array_destroy(&registration->outbound_auths);
 
 	ast_string_field_free_memory(registration);
 }
@@ -568,7 +559,7 @@
 	}
 
 	for (i = 0; i < existing->num_outbound_auths; ++i) {
-		if (strcmp(existing->sip_outbound_auths[i], applied->sip_outbound_auths[i])) {
+		if (strcmp(existing->outbound_auths.names[i], applied->outbound_auths.names[i])) {
 			return 0;
 		}
 	}
@@ -667,15 +658,13 @@
 	size_t i;
 
 	/* Just in case the client state is being reused for this registration, free the auth information */
-	destroy_auths(registration->state->client_state->sip_outbound_auths,
-			registration->state->client_state->num_outbound_auths);
-	registration->state->client_state->num_outbound_auths = 0;
-
-	registration->state->client_state->sip_outbound_auths = ast_calloc(registration->num_outbound_auths, sizeof(char *));
-	for (i = 0; i < registration->num_outbound_auths; ++i) {
-		registration->state->client_state->sip_outbound_auths[i] = ast_strdup(registration->sip_outbound_auths[i]);
-	}
-	registration->state->client_state->num_outbound_auths = registration->num_outbound_auths;
+	ast_sip_auth_array_destroy(&registration->state->client_state->outbound_auths);
+
+	registration->state->client_state->outbound_auths.names = ast_calloc(registration->outbound_auths.num, sizeof(char *));
+	for (i = 0; i < registration->outbound_auths.num; ++i) {
+		registration->state->client_state->outbound_auths.names[i] = ast_strdup(registration->outbound_auths.names[i]);
+	}
+	registration->state->client_state->outbound_auths.num = registration->outbound_auths.num;
 	registration->state->client_state->retry_interval = registration->retry_interval;
 	registration->state->client_state->max_retries = registration->max_retries;
 	registration->state->client_state->retries = 0;
@@ -708,47 +697,11 @@
 	ao2_iterator_destroy(&i);
 }
 
-#define AUTH_INCREMENT 4
-
-static const char **auth_alloc(const char *value, size_t *num_auths)
-{
-	char *auths = ast_strdupa(value);
-	char *val;
-	int num_alloced = 0;
-	const char **alloced_auths = NULL;
-
-	while ((val = strsep(&auths, ","))) {
-		if (*num_auths >= num_alloced) {
-			size_t size;
-			num_alloced += AUTH_INCREMENT;
-			size = num_alloced * sizeof(char *);
-			alloced_auths = ast_realloc(alloced_auths, size);
-			if (!alloced_auths) {
-				goto failure;
-			}
-		}
-		alloced_auths[*num_auths] = ast_strdup(val);
-		if (!alloced_auths[*num_auths]) {
-			goto failure;
-		}
-		++(*num_auths);
-	}
-	return alloced_auths;
-
-failure:
-	destroy_auths(alloced_auths, *num_auths);
-	return NULL;
-}
-
 static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct sip_outbound_registration *registration = obj;
 
-	registration->sip_outbound_auths = auth_alloc(var->value, &registration->num_outbound_auths);
-	if (!registration->sip_outbound_auths) {
-		return -1;
-	}
-	return 0;
+	return ast_sip_auth_array_init(&registration->outbound_auths, var->value);
 }
 
 static int load_module(void)




More information about the asterisk-commits mailing list