[asterisk-commits] file: branch group/dns r432992 - in /team/group/dns: include/asterisk/ main/ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 16 09:32:07 CDT 2015
Author: file
Date: Mon Mar 16 09:31:52 2015
New Revision: 432992
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432992
Log:
Incorporate review feedback.
Modified:
team/group/dns/include/asterisk/dns_core.h
team/group/dns/main/dns_core.c
team/group/dns/tests/test_dns.c
Modified: team/group/dns/include/asterisk/dns_core.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_core.h?view=diff&rev=432992&r1=432991&r2=432992
==============================================================================
--- team/group/dns/include/asterisk/dns_core.h (original)
+++ team/group/dns/include/asterisk/dns_core.h Mon Mar 16 09:31:52 2015
@@ -69,7 +69,7 @@
*/
void *ast_dns_query_get_data(const struct ast_dns_query *query);
-/*! \brief Opaque structure for a DNS query result */
+/*! \brief Opaque structure for a DNS query result, guaranteed to be immutable */
struct ast_dns_result;
/*!
@@ -78,6 +78,8 @@
* \param query The DNS query
*
* \return the DNS result information
+ *
+ * \note The result is NOT ao2 allocated
*/
struct ast_dns_result *ast_dns_query_get_result(const struct ast_dns_query *query);
Modified: team/group/dns/main/dns_core.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_core.c?view=diff&rev=432992&r1=432991&r2=432992
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Mon Mar 16 09:31:52 2015
@@ -124,7 +124,17 @@
void ast_dns_result_free(struct ast_dns_result *result)
{
- ao2_cleanup(result);
+ struct ast_dns_record *record;
+
+ if (!result) {
+ return;
+ }
+
+ while ((record = AST_LIST_REMOVE_HEAD(&result->records, list))) {
+ ast_free(record);
+ }
+
+ ast_free(result);
}
int ast_dns_record_get_rr_type(const struct ast_dns_record *record)
@@ -167,26 +177,26 @@
struct ast_dns_query *query;
if (ast_strlen_zero(name)) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution, no name provided\n");
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution, no name provided\n");
return NULL;
} else if (rr_type > ns_t_max) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
name, rr_type);
return NULL;
} else if (rr_type < 0) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution of '%s', invalid resource record type '%d'\n",
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', invalid resource record type '%d'\n",
name, rr_type);
return NULL;
} else if (rr_class > ns_c_max) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
name, rr_class);
return NULL;
} else if (rr_class < 0) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution of '%s', invalid resource class '%d'\n",
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', invalid resource class '%d'\n",
name, rr_class);
return NULL;
} else if (!callback) {
- ast_log(LOG_ERROR, "Could not perform asynchronous resolution of '%s', no callback provided\n",
+ ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', no callback provided\n",
name);
return NULL;
}
@@ -256,7 +266,8 @@
{
struct dns_synchronous_resolve *synchronous = ast_dns_query_get_data(query);
- synchronous->result = ao2_bump(ast_dns_query_get_result(query));
+ synchronous->result = query->result;
+ ((struct ast_dns_query *)query)->result = NULL;
ast_mutex_lock(&synchronous->lock);
synchronous->completed = 1;
@@ -270,26 +281,26 @@
struct ast_dns_query *query;
if (ast_strlen_zero(name)) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution, no name provided\n");
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution, no name provided\n");
return -1;
} else if (rr_type > ns_t_max) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
name, rr_type);
return -1;
} else if (rr_type < 0) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution of '%s', invalid resource record type '%d'\n",
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', invalid resource record type '%d'\n",
name, rr_type);
return -1;
} else if (rr_class > ns_c_max) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
name, rr_class);
return -1;
} else if (rr_class < 0) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution of '%s', invalid resource class '%d'\n",
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', invalid resource class '%d'\n",
name, rr_class);
return -1;
} else if (!result) {
- ast_log(LOG_ERROR, "Could not perform synchronous resolution of '%s', no result pointer provided for storing results\n",
+ ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', no result pointer provided for storing results\n",
name);
return -1;
}
@@ -335,17 +346,6 @@
return query->resolver_data;
}
-/*! \brief Destructor for DNS result */
-static void dns_result_destroy(void *obj)
-{
- struct ast_dns_result *result = obj;
- struct ast_dns_record *record;
-
- while ((record = AST_LIST_REMOVE_HEAD(&result->records, list))) {
- ast_free(record);
- }
-}
-
int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus,
unsigned int rcode, const char *canonical)
{
@@ -361,11 +361,9 @@
return -1;
}
- if (query->result) {
- ast_dns_result_free(query->result);
- }
-
- query->result = ao2_alloc_options(sizeof(*query->result) + strlen(canonical) + 1, dns_result_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ ast_dns_result_free(query->result);
+
+ query->result = ast_calloc(1, sizeof(*query->result) + strlen(canonical) + 1);
if (!query->result) {
return -1;
}
Modified: team/group/dns/tests/test_dns.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/tests/test_dns.c?view=diff&rev=432992&r1=432991&r2=432992
==============================================================================
--- team/group/dns/tests/test_dns.c (original)
+++ team/group/dns/tests/test_dns.c Mon Mar 16 09:31:52 2015
@@ -367,14 +367,14 @@
if (!ast_dns_resolver_set_result(&some_query, 1, 1, ns_r_noerror, "asterisk.org")) {
ast_test_status_update(test, "Successfully added a result that was both secure and bogus\n");
result = ast_dns_query_get_result(&some_query);
- ao2_cleanup(result);
+ ast_dns_result_free(result);
return AST_TEST_FAIL;
}
if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL)) {
ast_test_status_update(test, "Successfully added result with no canonical name\n");
result = ast_dns_query_get_result(&some_query);
- ao2_cleanup(result);
+ ast_dns_result_free(result);
return AST_TEST_FAIL;
}
More information about the asterisk-commits
mailing list