[asterisk-commits] mmichelson: trunk r403499 - in /trunk: include/asterisk/ res/ res/res_pjsip/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 9 10:10:12 CST 2013


Author: mmichelson
Date: Mon Dec  9 10:10:05 2013
New Revision: 403499

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403499
Log:
Switch PJSIP auth to use a vector.

Since Asterisk has a vector API now, places where arrays are manually
resized don't really make sense any more. Since the auth work in PJSIP
was freshly-written, it was easy to reform it to use a vector.

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


Modified:
    trunk/include/asterisk/res_pjsip.h
    trunk/res/res_pjsip.c
    trunk/res/res_pjsip/config_auth.c
    trunk/res/res_pjsip/pjsip_configuration.c
    trunk/res/res_pjsip/pjsip_distributor.c
    trunk/res/res_pjsip_authenticator_digest.c
    trunk/res/res_pjsip_outbound_authenticator_digest.c
    trunk/res/res_pjsip_outbound_registration.c

Modified: trunk/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip.h?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/include/asterisk/res_pjsip.h (original)
+++ trunk/include/asterisk/res_pjsip.h Mon Dec  9 10:10:05 2013
@@ -38,6 +38,8 @@
 #include <pjlib.h>
 /* Needed for ast_rtp_dtls_cfg struct */
 #include "asterisk/rtp_engine.h"
+/* Needed for AST_VECTOR macro */
+#include "asterisk/vector.h"
 
 /* Forward declarations of PJSIP stuff */
 struct pjsip_rx_data;
@@ -259,12 +261,7 @@
 	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;
-};
+AST_VECTOR(ast_sip_auth_vector, const char *);
 
 /*!
  * \brief Different methods by which incoming requests can be matched to endpoints
@@ -555,9 +552,9 @@
 	/*! Call pickup configuration */
 	struct ast_sip_endpoint_pickup_configuration pickup;
 	/*! Inbound authentication credentials */
-	struct ast_sip_auth_array inbound_auths;
+	struct ast_sip_auth_vector inbound_auths;
 	/*! Outbound authentication credentials */
-	struct ast_sip_auth_array outbound_auths;
+	struct ast_sip_auth_vector outbound_auths;
 	/*! DTMF mode to use with this endpoint */
 	enum ast_sip_dtmf_mode dtmf;
 	/*! Method(s) by which the endpoint should be identified. */
@@ -577,21 +574,21 @@
 };
 
 /*!
- * \brief Initialize an auth array with the configured values.
- *
- * \param array Array to initialize
+ * \brief Initialize an auth vector with the configured values.
+ *
+ * \param vector Vector 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);
+int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names);
+
+/*!
+ * \brief Free contents of an auth vector.
+ *
+ * \param array Vector whose contents are to be freed
+ */
+void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector);
 
 /*!
  * \brief Possible returns from ast_sip_check_authentication
@@ -643,14 +640,14 @@
 	/*!
 	 * \brief Create a new request with authentication credentials
 	 *
-	 * \param auths An array of IDs of auth sorcery objects
+	 * \param auths A vector of IDs of auth sorcery objects
 	 * \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 struct ast_sip_auth_array *auths, struct pjsip_rx_data *challenge,
+	int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
 			struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
 };
 
@@ -1263,7 +1260,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 struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request);
 
 /*!
@@ -1307,7 +1304,7 @@
 /*!
  * \brief Add a multipart body to an outbound SIP message
  *
- * This will treat each part of the input array as part of a multipart body and
+ * This will treat each part of the input vector as part of a multipart body and
  * add each part to the SIP message.
  *
  * \param tdata The message to add the body to
@@ -1374,10 +1371,10 @@
 /*!
  * \brief Retrieve relevant SIP auth structures from sorcery
  *
- * \param auths Array of sorcery IDs of auth credentials to retrieve
+ * \param auths Vector of sorcery IDs of auth credentials to retrieve
  * \param[out] out The retrieved auths are stored here
  */
-int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out);
+int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out);
 
 /*!
  * \brief Clean up retrieved auth structures from memory
@@ -1385,8 +1382,8 @@
  * Call this function once you have completed operating on auths
  * retrieved from \ref ast_sip_retrieve_auths
  *
- * \param auths An array of auth structures to clean up
- * \param num_auths The number of auths in the array
+ * \param auths An vector of auth structures to clean up
+ * \param num_auths The number of auths in the vector
  */
 void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths);
 
@@ -1578,7 +1575,7 @@
  * \param arg user data passed to handler
  * \retval 0 Success, non-zero on failure
  */
-int ast_sip_for_each_auth(const struct ast_sip_auth_array *array,
+int ast_sip_for_each_auth(const struct ast_sip_auth_vector *array,
 			  ao2_callback_fn on_auth, void *arg);
 
 /*!
@@ -1596,7 +1593,7 @@
  * \param buf the string buffer to write the object data
  * \retval 0 Success, non-zero on failure
  */
-int ast_sip_auths_to_str(const struct ast_sip_auth_array *auths, char **buf);
+int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf);
 
 /*
  * \brief AMI variable container
@@ -1675,7 +1672,7 @@
  * \param ami ami variable container
  * \retval 0 Success, non-zero on failure
  */
-int ast_sip_format_auths_ami(const struct ast_sip_auth_array *auths,
+int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths,
 			     struct ast_sip_ami *ami);
 
 #endif /* _RES_PJSIP_H */

Modified: trunk/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip.c (original)
+++ trunk/res/res_pjsip.c Mon Dec  9 10:10:05 2013
@@ -1194,7 +1194,7 @@
 	ast_module_unref(ast_module_info->self);
 }
 
-int ast_sip_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
+int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request)
 {
 	if (!registered_outbound_authenticator) {

Modified: trunk/res/res_pjsip/config_auth.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_auth.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip/config_auth.c (original)
+++ trunk/res/res_pjsip/config_auth.c Mon Dec  9 10:10:05 2013
@@ -118,19 +118,20 @@
 	return res;
 }
 
-int ast_sip_for_each_auth(const struct ast_sip_auth_array *array,
+int ast_sip_for_each_auth(const struct ast_sip_auth_vector *vector,
 			  ao2_callback_fn on_auth, void *arg)
 {
 	int i;
 
-	if (!array || !array->num) {
+	if (!vector || !AST_VECTOR_SIZE(vector)) {
 		return 0;
 	}
 
-	for (i = 0; i < array->num; ++i) {
+	for (i = 0; i < AST_VECTOR_SIZE(vector); ++i) {
+		/* AST_VECTOR_GET is safe to use since the vector is immutable */
 		RAII_VAR(struct ast_sip_auth *, auth, ast_sorcery_retrieve_by_id(
 				 ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE,
-				 array->names[i]), ao2_cleanup);
+				 AST_VECTOR_GET(vector,i)), ao2_cleanup);
 
 		if (!auth) {
 			continue;
@@ -175,7 +176,7 @@
 	return 0;
 }
 
-int ast_sip_format_auths_ami(const struct ast_sip_auth_array *auths,
+int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths,
 			     struct ast_sip_ami *ami)
 {
 	return ast_sip_for_each_auth(auths, format_ami_auth_handler, ami);

Modified: trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ trunk/res/res_pjsip/pjsip_configuration.c Mon Dec  9 10:10:05 2013
@@ -331,55 +331,47 @@
 	return 0;
 }
 
-void ast_sip_auth_array_destroy(struct ast_sip_auth_array *auths)
+void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *auths)
 {
 	int i;
+	size_t size;
 
 	if (!auths) {
 		return;
 	}
 
-	for (i = 0; i < auths->num; ++i) {
-		ast_free((char *) auths->names[i]);
-	}
-	ast_free(auths->names);
-	auths->names = NULL;
-	auths->num = 0;
-}
-
-#define AUTH_INCREMENT 4
-
-int ast_sip_auth_array_init(struct ast_sip_auth_array *auths, const char *value)
+	size = AST_VECTOR_SIZE(auths);
+
+	for (i = 0; i < size; ++i) {
+		const char *name = AST_VECTOR_REMOVE_UNORDERED(auths, 0);
+		ast_free((char *) name);
+	}
+	AST_VECTOR_FREE(auths);
+}
+
+int ast_sip_auth_vector_init(struct ast_sip_auth_vector *auths, const char *value)
 {
 	char *auth_names = ast_strdupa(value);
 	char *val;
-	int num_alloced = 0;
-	const char **alloced_auths;
 
 	ast_assert(auths != NULL);
-	ast_assert(auths->names == NULL);
-	ast_assert(!auths->num);
+	ast_assert(AST_VECTOR_SIZE(auths) == 0);
+
+	AST_VECTOR_INIT(auths, 1);
 
 	while ((val = strsep(&auth_names, ","))) {
-		if (auths->num >= num_alloced) {
-			num_alloced += AUTH_INCREMENT;
-			alloced_auths = ast_realloc(auths->names, num_alloced * sizeof(char *));
-			if (!alloced_auths) {
-				goto failure;
-			}
-			auths->names = alloced_auths;
-		}
 		val = ast_strdup(val);
 		if (!val) {
 			goto failure;
 		}
-		auths->names[auths->num] = val;
-		++auths->num;
+		if (AST_VECTOR_APPEND(auths, val)) {
+			goto failure;
+		}
 	}
 	return 0;
 
 failure:
-	ast_sip_auth_array_destroy(auths);
+	ast_sip_auth_vector_destroy(auths);
 	return -1;
 }
 
@@ -387,19 +379,19 @@
 {
 	struct ast_sip_endpoint *endpoint = obj;
 
-	return ast_sip_auth_array_init(&endpoint->inbound_auths, var->value);
+	return ast_sip_auth_vector_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;
 
-	return ast_sip_auth_array_init(&endpoint->outbound_auths, var->value);
-}
-
-int ast_sip_auths_to_str(const struct ast_sip_auth_array *auths, char **buf)
-{
-	if (!auths || !auths->num) {
+	return ast_sip_auth_vector_init(&endpoint->outbound_auths, var->value);
+}
+
+int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf)
+{
+	if (!auths || !AST_VECTOR_SIZE(auths)) {
 		return 0;
 	}
 
@@ -407,7 +399,8 @@
 		return -1;
 	}
 
-	ast_join_delim(*buf, MAX_OBJECT_FIELD, auths->names, auths->num, ',');
+	/* I feel like accessing the vector's elem array directly is cheating...*/
+	ast_join_delim(*buf, MAX_OBJECT_FIELD, auths->elems, AST_VECTOR_SIZE(auths), ',');
 	return 0;
 }
 
@@ -1171,7 +1164,7 @@
 	return 0;
 }
 
-static int format_str_append_auth(const struct ast_sip_auth_array *auths,
+static int format_str_append_auth(const struct ast_sip_auth_vector *auths,
 				  struct ast_str **buf)
 {
 	char *str = NULL;
@@ -1473,8 +1466,8 @@
 	subscription_configuration_destroy(&endpoint->subscription);
 	info_configuration_destroy(&endpoint->info);
 	media_configuration_destroy(&endpoint->media);
-	ast_sip_auth_array_destroy(&endpoint->inbound_auths);
-	ast_sip_auth_array_destroy(&endpoint->outbound_auths);
+	ast_sip_auth_vector_destroy(&endpoint->inbound_auths);
+	ast_sip_auth_vector_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);
@@ -1535,14 +1528,16 @@
 	return endpoints;
 }
 
-int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out)
+int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out)
 {
 	int 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]);
+	for (i = 0; i < AST_VECTOR_SIZE(auths); ++i) {
+		/* Using AST_VECTOR_GET is safe since the vector is immutable */
+		const char *name = AST_VECTOR_GET(auths, i);
+		out[i] = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, name);
 		if (!out[i]) {
-			ast_log(LOG_NOTICE, "Couldn't find auth '%s'. Cannot authenticate\n", auths->names[i]);
+			ast_log(LOG_NOTICE, "Couldn't find auth '%s'. Cannot authenticate\n", name);
 			return -1;
 		}
 	}

Modified: trunk/res/res_pjsip/pjsip_distributor.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_distributor.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip/pjsip_distributor.c (original)
+++ trunk/res/res_pjsip/pjsip_distributor.c Mon Dec  9 10:10:05 2013
@@ -227,7 +227,7 @@
 		return -1;
 	}
 
-	artificial_endpoint->inbound_auths.num = 1;
+	AST_VECTOR_INIT(&artificial_endpoint->inbound_auths, 1);
 	return 0;
 }
 

Modified: trunk/res/res_pjsip_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_authenticator_digest.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip_authenticator_digest.c (original)
+++ trunk/res/res_pjsip_authenticator_digest.c Mon Dec  9 10:10:05 2013
@@ -41,7 +41,7 @@
  */
 static int digest_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
 {
-	return endpoint->inbound_auths.num > 0;
+	return AST_VECTOR_SIZE(&endpoint->inbound_auths) > 0;
 }
 
 static void auth_store_cleanup(void *data)
@@ -384,12 +384,15 @@
 	enum ast_sip_check_auth_result res;
 	int i;
 	int failures = 0;
+	size_t auth_size;
 
 	RAII_VAR(struct ast_sip_endpoint *, artificial_endpoint,
 		 ast_sip_get_artificial_endpoint(), ao2_cleanup);
 
-	auths = ast_alloca(endpoint->inbound_auths.num * sizeof(*auths));
-	verify_res = ast_alloca(endpoint->inbound_auths.num * sizeof(*verify_res));
+	auth_size = AST_VECTOR_SIZE(&endpoint->inbound_auths);
+
+	auths = ast_alloca(auth_size * sizeof(*auths));
+	verify_res = ast_alloca(auth_size * sizeof(*verify_res));
 
 	if (!auths) {
 		return AST_SIP_AUTHENTICATION_ERROR;
@@ -402,7 +405,7 @@
 		goto cleanup;
 	}
 
-	for (i = 0; i < endpoint->inbound_auths.num; ++i) {
+	for (i = 0; i < auth_size; ++i) {
 		if (ast_strlen_zero(auths[i]->realm)) {
 			ast_string_field_set(auths[i], realm, "asterisk");
 		}
@@ -416,18 +419,18 @@
 		}
 	}
 
-	for (i = 0; i < endpoint->inbound_auths.num; ++i) {
+	for (i = 0; i < auth_size; ++i) {
 		challenge(auths[i]->realm, tdata, rdata, verify_res[i] == AUTH_STALE);
 	}
 
-	if (failures == endpoint->inbound_auths.num) {
+	if (failures == auth_size) {
 		res = AST_SIP_AUTHENTICATION_FAILED;
 	} else {
 		res = AST_SIP_AUTHENTICATION_CHALLENGE;
 	}
 
 cleanup:
-	ast_sip_cleanup_auths(auths, endpoint->inbound_auths.num);
+	ast_sip_cleanup_auths(auths, auth_size);
 	return res;
 }
 

Modified: trunk/res/res_pjsip_outbound_authenticator_digest.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_outbound_authenticator_digest.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip_outbound_authenticator_digest.c (original)
+++ trunk/res/res_pjsip_outbound_authenticator_digest.c Mon Dec  9 10:10:05 2013
@@ -50,15 +50,16 @@
 }
 
 static int set_outbound_authentication_credentials(pjsip_auth_clt_sess *auth_sess,
-		const struct ast_sip_auth_array *array, pjsip_rx_data *challenge)
+		const struct ast_sip_auth_vector *auth_vector, pjsip_rx_data *challenge)
 {
-	struct ast_sip_auth **auths = ast_alloca(array->num * sizeof(*auths));
-	pjsip_cred_info *auth_creds = ast_alloca(array->num * sizeof(*auth_creds));
+	size_t auth_size = AST_VECTOR_SIZE(auth_vector);
+	struct ast_sip_auth **auths = ast_alloca(auth_size * sizeof(*auths));
+	pjsip_cred_info *auth_creds = ast_alloca(auth_size * sizeof(*auth_creds));
 	pjsip_www_authenticate_hdr *auth_hdr = NULL;
 	int res = 0;
 	int i;
 
-	if (ast_sip_retrieve_auths(array, auths)) {
+	if (ast_sip_retrieve_auths(auth_vector, auths)) {
 		res = -1;
 		goto cleanup;
 	}
@@ -70,7 +71,7 @@
 		goto cleanup;
 	}
 
-	for (i = 0; i < array->num; ++i) {
+	for (i = 0; i < auth_size; ++i) {
 		if (ast_strlen_zero(auths[i]->realm)) {
 			auth_creds[i].realm = auth_hdr->challenge.common.realm;
 		} else {
@@ -93,14 +94,14 @@
 		}
 	}
 
-	pjsip_auth_clt_set_credentials(auth_sess, array->num, auth_creds);
+	pjsip_auth_clt_set_credentials(auth_sess, auth_size, auth_creds);
 
 cleanup:
-	ast_sip_cleanup_auths(auths, array->num);
+	ast_sip_cleanup_auths(auths, auth_size);
 	return res;
 }
 
-static int digest_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge,
+static int digest_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
 		pjsip_transaction *tsx, pjsip_tx_data **new_request)
 {
 	pjsip_auth_clt_sess auth_sess;

Modified: trunk/res/res_pjsip_outbound_registration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_outbound_registration.c?view=diff&rev=403499&r1=403498&r2=403499
==============================================================================
--- trunk/res/res_pjsip_outbound_registration.c (original)
+++ trunk/res/res_pjsip_outbound_registration.c Mon Dec  9 10:10:05 2013
@@ -192,9 +192,7 @@
 	/*! \brief Serializer for stuff and things */
 	struct ast_taskprocessor *serializer;
 	/*! \brief Configured authentication credentials */
-	struct ast_sip_auth_array outbound_auths;
-	/*! \brief Number of configured auths */
-	size_t num_outbound_auths;
+	struct ast_sip_auth_vector outbound_auths;
 	/*! \brief Registration should be destroyed after completion of transaction */
 	unsigned int destroy:1;
 };
@@ -235,9 +233,7 @@
 	/*! \brief Outbound registration state */
 	struct sip_outbound_registration_state *state;
 	/*! \brief Configured authentication credentials */
-	struct ast_sip_auth_array outbound_auths;
-	/*! \brief Number of configured auths */
-	size_t num_outbound_auths;
+	struct ast_sip_auth_vector outbound_auths;
 };
 
 /*! \brief Helper function which cancels the timer on a client */
@@ -334,7 +330,7 @@
 	pjsip_regc_destroy(client_state->client);
 
 	client_state->status = SIP_REGISTRATION_STOPPED;
-	ast_sip_auth_array_destroy(&client_state->outbound_auths);
+	ast_sip_auth_vector_destroy(&client_state->outbound_auths);
 
 	return 0;
 }
@@ -564,7 +560,7 @@
 	struct sip_outbound_registration *registration = obj;
 
 	ao2_cleanup(registration->state);
-	ast_sip_auth_array_destroy(&registration->outbound_auths);
+	ast_sip_auth_vector_destroy(&registration->outbound_auths);
 
 	ast_string_field_free_memory(registration);
 }
@@ -657,13 +653,14 @@
 
 	if (strcmp(existing->server_uri, applied->server_uri) || strcmp(existing->client_uri, applied->client_uri) ||
 		strcmp(existing->transport, applied->transport) || strcmp(existing->contact_user, applied->contact_user) ||
-		strcmp(existing->outbound_proxy, applied->outbound_proxy) || existing->num_outbound_auths != applied->num_outbound_auths ||
+		strcmp(existing->outbound_proxy, applied->outbound_proxy) ||
+		AST_VECTOR_SIZE(&existing->outbound_auths) != AST_VECTOR_SIZE(&applied->outbound_auths) ||
 		existing->auth_rejection_permanent != applied->auth_rejection_permanent) {
 		return 0;
 	}
 
-	for (i = 0; i < existing->num_outbound_auths; ++i) {
-		if (strcmp(existing->outbound_auths.names[i], applied->outbound_auths.names[i])) {
+	for (i = 0; i < AST_VECTOR_SIZE(&existing->outbound_auths); ++i) {
+		if (strcmp(AST_VECTOR_GET(&existing->outbound_auths, i), AST_VECTOR_GET(&applied->outbound_auths, i))) {
 			return 0;
 		}
 	}
@@ -764,13 +761,13 @@
 	size_t i;
 
 	/* Just in case the client state is being reused for this registration, free the auth information */
-	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;
+	ast_sip_auth_vector_destroy(&registration->state->client_state->outbound_auths);
+
+	AST_VECTOR_INIT(&registration->state->client_state->outbound_auths, AST_VECTOR_SIZE(&registration->outbound_auths));
+	for (i = 0; i < AST_VECTOR_SIZE(&registration->outbound_auths); ++i) {
+		const char *name = ast_strdup(AST_VECTOR_GET(&registration->outbound_auths, i));
+		AST_VECTOR_APPEND(&registration->state->client_state->outbound_auths, name);
+	}
 	registration->state->client_state->retry_interval = registration->retry_interval;
 	registration->state->client_state->forbidden_retry_interval = registration->forbidden_retry_interval;
 	registration->state->client_state->max_retries = registration->max_retries;
@@ -808,7 +805,7 @@
 {
 	struct sip_outbound_registration *registration = obj;
 
-	return ast_sip_auth_array_init(&registration->outbound_auths, var->value);
+	return ast_sip_auth_vector_init(&registration->outbound_auths, var->value);
 }
 
 static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **buf)




More information about the asterisk-commits mailing list