[asterisk-commits] mmichelson: branch group/dns r432518 - in /team/group/dns: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 6 09:30:43 CST 2015


Author: mmichelson
Date: Fri Mar  6 09:30:40 2015
New Revision: 432518

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432518
Log:
Get rid of nxdomain parameter for ast_dns_resolver_set_result().

Since an rcode parameter is present, NXDOMAIN can be represented
through that instead of a redundant parameter.

The unit tests have been updated to pass based on this information.


Modified:
    team/group/dns/include/asterisk/dns_core.h
    team/group/dns/include/asterisk/dns_internal.h
    team/group/dns/include/asterisk/dns_resolver.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=432518&r1=432517&r2=432518
==============================================================================
--- team/group/dns/include/asterisk/dns_core.h (original)
+++ team/group/dns/include/asterisk/dns_core.h Fri Mar  6 09:30:40 2015
@@ -80,15 +80,6 @@
 struct ast_dns_result *ast_dns_query_get_result(const struct ast_dns_query *query);
 
 /*!
- * \brief Get whether the domain exists or not
- *
- * \param query The DNS result
- *
- * \return whether the domain exists or not
- */
-unsigned int ast_dns_result_get_nxdomain(const struct ast_dns_result *result);
-
-/*!
  * \brief Get whether the result is secure or not
  *
  * \param result The DNS result

Modified: team/group/dns/include/asterisk/dns_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_internal.h?view=diff&rev=432518&r1=432517&r2=432518
==============================================================================
--- team/group/dns/include/asterisk/dns_internal.h (original)
+++ team/group/dns/include/asterisk/dns_internal.h Fri Mar  6 09:30:40 2015
@@ -73,8 +73,6 @@
 
 /*! \brief The result of a DNS query */
 struct ast_dns_result {
-	/*! \brief Whether the domain was not found */
-	unsigned int nxdomain;
 	/*! \brief Whether the result is secure */
 	unsigned int secure;
 	/*! \brief Whether the result is bogus */

Modified: team/group/dns/include/asterisk/dns_resolver.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_resolver.h?view=diff&rev=432518&r1=432517&r2=432518
==============================================================================
--- team/group/dns/include/asterisk/dns_resolver.h (original)
+++ team/group/dns/include/asterisk/dns_resolver.h Fri Mar  6 09:30:40 2015
@@ -72,7 +72,6 @@
  * \brief Set result information for a DNS query
  *
  * \param query The DNS query
- * \param nxdomain Whether the domain was not found
  * \param result Whether the result is secured or not
  * \param bogus Whether the result is bogus or not
  * \param rcode Optional response code
@@ -81,7 +80,7 @@
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int nxdomain, unsigned int secure, unsigned int bogus,
+int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus,
 	unsigned int rcode, const char *canonical);
 
 /*!

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=432518&r1=432517&r2=432518
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Fri Mar  6 09:30:40 2015
@@ -75,11 +75,6 @@
 	return query->result;
 }
 
-unsigned int ast_dns_result_get_nxdomain(const struct ast_dns_result *result)
-{
-	return result->nxdomain;
-}
-
 unsigned int ast_dns_result_get_secure(const struct ast_dns_result *result)
 {
 	return result->secure;
@@ -353,7 +348,7 @@
 	}
 }
 
-int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int nxdomain, unsigned int secure, unsigned int bogus,
+int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus,
 	unsigned int rcode, const char *canonical)
 {
 	if (secure && bogus) {
@@ -377,7 +372,6 @@
 		return -1;
 	}
 
-	query->result->nxdomain = nxdomain;
 	query->result->secure = secure;
 	query->result->bogus = bogus;
 	query->result->rcode = rcode;

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=432518&r1=432517&r2=432518
==============================================================================
--- team/group/dns/tests/test_dns.c (original)
+++ team/group/dns/tests/test_dns.c Fri Mar  6 09:30:40 2015
@@ -265,8 +265,8 @@
 }
 
 static int test_results(struct ast_test *test, const struct ast_dns_query *query,
-		int expected_nxdomain, int expected_secure, int expected_bogus,
-		const char *expected_canonical)
+		unsigned int expected_secure, unsigned int expected_bogus,
+		unsigned int expected_rcode, const char *expected_canonical)
 {
 	struct ast_dns_result *result;
 
@@ -276,9 +276,9 @@
 		return -1;
 	}
 
-	if (ast_dns_result_get_nxdomain(result) != expected_nxdomain ||
-			ast_dns_result_get_secure(result) != expected_secure ||
+	if (ast_dns_result_get_secure(result) != expected_secure ||
 			ast_dns_result_get_bogus(result) != expected_bogus ||
+			ast_dns_result_get_rcode(result) != expected_rcode ||
 			strcmp(ast_dns_result_get_canonical(result), expected_canonical)) {
 		ast_test_status_update(test, "Unexpected values in result from query\n");
 		return -1;
@@ -291,6 +291,19 @@
 {
 	struct ast_dns_query some_query;
 	struct ast_dns_result *result;
+	
+	struct dns_result {
+		unsigned int secure;
+		unsigned int bogus;
+		unsigned int rcode;
+	} results[] = {
+		{ 0, 0, ns_r_noerror },
+		{ 0, 1, ns_r_noerror },
+		{ 1, 0, ns_r_noerror },
+		{ 0, 0, ns_r_nxdomain },
+	};
+	int i;
+	enum ast_test_result_state res = AST_TEST_PASS;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -299,10 +312,10 @@
 		info->summary = "Test setting and getting results on DNS queries";
 		info->description =
 			"This test performs the following:\n"
-			"\t* Sets a result that is not secure, bogus, or nxdomain\n"
-			"\t* Sets a result that is not secure or nxdomain, but is secure\n"
-			"\t* Sets a result that is not bogus or nxdomain, but is secure\n"
-			"\t* Sets a result that is not secure or bogus, but is nxdomain\n"
+			"\t* Sets a result that is not secure, bogus, and has rcode 0\n"
+			"\t* Sets a result that is not secure, has rcode 0, but is secure\n"
+			"\t* Sets a result that is not bogus, has rcode 0, but is secure\n"
+			"\t* Sets a result that is not secure or bogus, but has rcode NXDOMAIN\n"
 			"After each result is set, we ensure that parameters retrieved from\n"
 			"the result have the expected values.";
 		return AST_TEST_NOT_RUN;
@@ -312,47 +325,24 @@
 
 	memset(&some_query, 0, sizeof(some_query));
 
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, 0, 0, "asterisk.org")) {
-		ast_test_status_update(test, "Unable to add legitimate DNS result to query\n");
-		return AST_TEST_FAIL;
-	}
-
-	if (test_results(test, &some_query, 0, 0, 0, "asterisk.org")) {
-		return AST_TEST_FAIL;
-	}
-
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, 1, 0, "asterisk.org")) {
-		ast_test_status_update(test, "Unable to add bogus DNS result to query\n");
-		return AST_TEST_FAIL;
-	}
-
-	if (test_results(test, &some_query, 0, 0, 1, "asterisk.org")) {
-		return AST_TEST_FAIL;
-	}
-
-	if (ast_dns_resolver_set_result(&some_query, 0, 1, 0, 0, "asterisk.org")) {
-		ast_test_status_update(test, "Unable to add secure DNS result to query\n");
-		return AST_TEST_FAIL;
-	}
-
-	if (test_results(test, &some_query, 0, 1, 0, "asterisk.org")) {
-		return AST_TEST_FAIL;
-	}
-
-	if (ast_dns_resolver_set_result(&some_query, 1, 0, 0, 0, "asterisk.org")) {
-		ast_test_status_update(test, "Unable to add nxdomain DNS result to query\n");
-		return AST_TEST_FAIL;
-	}
-
-	if (test_results(test, &some_query, 1, 0, 0, "asterisk.org")) {
-		return AST_TEST_FAIL;
+	for (i = 0; i < ARRAY_LEN(results); ++i) {
+		if (ast_dns_resolver_set_result(&some_query, results[i].secure, results[i].bogus,
+				results[i].rcode, "asterisk.org")) {
+			ast_test_status_update(test, "Unable to add DNS result to query\n");
+			res = AST_TEST_FAIL;
+		}
+
+		if (test_results(test, &some_query, results[i].secure, results[i].bogus,
+				results[i].rcode, "asterisk.org")) {
+			res = AST_TEST_FAIL;
+		}
 	}
 
 	/* The final result we set needs to be freed */
 	result = ast_dns_query_get_result(&some_query);
 	ast_dns_result_free(result);
 
-	return AST_TEST_PASS;
+	return res;
 }
 
 AST_TEST_DEFINE(resolver_set_result_off_nominal)
@@ -376,14 +366,14 @@
 
 	memset(&some_query, 0, sizeof(some_query));
 
-	if (!ast_dns_resolver_set_result(&some_query, 0, 1, 1, 0, "asterisk.org")) {
+	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);
 		return AST_TEST_FAIL;
 	}
 
-	if (!ast_dns_resolver_set_result(&some_query, 0, 0, 0, 0, NULL)) {
+	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);
@@ -465,7 +455,7 @@
 
 	memset(&some_query, 0, sizeof(some_query));
 
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, 0, 0, "asterisk.org")) {
+	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org")) {
 		ast_test_status_update(test, "Unable to set result for DNS query\n");
 		return AST_TEST_FAIL;
 	}
@@ -582,7 +572,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, 0, 0, "asterisk.org")) {
+	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org")) {
 		ast_test_status_update(test, "Unable to set result for DNS query\n");
 		return AST_TEST_FAIL;
 	}
@@ -664,7 +654,7 @@
 		return NULL;
 	}
 
-	ast_dns_resolver_set_result(query, 0, 0, 0, 0, "asterisk.org");
+	ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org");
 
 	inet_pton(AF_INET, V4, v4_buf);
 	ast_dns_resolver_add_record(query, ns_t_a, ns_c_in, 12345, v4_buf, V4_BUFSIZE);




More information about the asterisk-commits mailing list