[asterisk-commits] mmichelson: branch group/dns r434086 - in /team/group/dns: include/asterisk/ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 6 12:29:01 CDT 2015
Author: mmichelson
Date: Mon Apr 6 12:28:59 2015
New Revision: 434086
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434086
Log:
Streamline the allocation and sorting functions for SRV and NAPTR.
This places allocation and sorting into a table, thus allowing simpler
lookups of allocation and sorting by record type. Additional record types
can be added by adding an appropriate row in the allocation and sorting
tables.
This may get taken a step further by having record types register themselves
with the DNS core, but for the time being this seems like overkill since
all DNS types exist in the core, and not in loadable modules.
Modified:
team/group/dns/include/asterisk/dns_internal.h
team/group/dns/main/dns_core.c
team/group/dns/main/dns_srv.c
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=434086&r1=434085&r2=434086
==============================================================================
--- team/group/dns/include/asterisk/dns_internal.h (original)
+++ team/group/dns/include/asterisk/dns_internal.h Mon Apr 6 12:28:59 2015
@@ -195,12 +195,12 @@
* \retval non-NULL success
* \retval NULL failure
*/
-struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
+struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
/*!
* \brief Sort the SRV records on a result
*
* \param result The DNS result
*/
-void ast_dns_srv_sort(struct ast_dns_result *result);
-
+void dns_srv_sort(struct ast_dns_result *result);
+
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=434086&r1=434085&r2=434086
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Mon Apr 6 12:28:59 2015
@@ -426,6 +426,20 @@
return record;
}
+typedef struct ast_dns_record *(*dns_alloc_fn)(struct ast_dns_query *query, const char *data, const size_t size);
+
+static dns_alloc_fn dns_alloc_table [] = {
+ [ns_t_naptr] = dns_naptr_alloc,
+ [ns_t_srv] = dns_srv_alloc,
+};
+
+static struct ast_dns_record *allocate_dns_record(int rr_type, struct ast_dns_query *query, const char *data, const size_t size)
+{
+ dns_alloc_fn allocator = dns_alloc_table[rr_type] ?: generic_record_alloc;
+
+ return allocator(query, data, size);
+}
+
int ast_dns_resolver_add_record(struct ast_dns_query *query, int rr_type, int rr_class, int ttl, const char *data, const size_t size)
{
struct ast_dns_record *record;
@@ -460,14 +474,7 @@
return -1;
}
- if (rr_type == ns_t_naptr) {
- record = dns_naptr_alloc(query, data, size);
- } else if (rr_type == ns_t_srv) {
- record = ast_dns_srv_alloc(query, data, size);
- } else {
- record = generic_record_alloc(query, data, size);
- }
-
+ record = allocate_dns_record(rr_type, query, data, size);
if (!record) {
return -1;
}
@@ -483,13 +490,23 @@
return 0;
}
+typedef void (*dns_sort_fn)(struct ast_dns_result *result);
+
+static dns_sort_fn dns_sort_table [] = {
+ [ns_t_naptr] = dns_naptr_sort,
+ [ns_t_srv] = dns_srv_sort,
+};
+
+static void sort_result(int rr_type, struct ast_dns_result *result)
+{
+ if (dns_sort_table[rr_type]) {
+ dns_sort_table[rr_type](result);
+ }
+}
+
void ast_dns_resolver_completed(struct ast_dns_query *query)
{
- if (ast_dns_query_get_rr_type(query) == ns_t_naptr) {
- dns_naptr_sort(query->result);
- } else if (ast_dns_query_get_rr_type(query) == ns_t_srv) {
- ast_dns_srv_sort(query->result);
- }
+ sort_result(ast_dns_query_get_rr_type(query), query->result);
query->callback(query);
}
Modified: team/group/dns/main/dns_srv.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_srv.c?view=diff&rev=434086&r1=434085&r2=434086
==============================================================================
--- team/group/dns/main/dns_srv.c (original)
+++ team/group/dns/main/dns_srv.c Mon Apr 6 12:28:59 2015
@@ -41,7 +41,7 @@
#include "asterisk/dns_internal.h"
#include "asterisk/utils.h"
-struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size)
+struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size)
{
uint16_t priority;
uint16_t weight;
@@ -129,7 +129,7 @@
/* This implementation was taken from the existing srv.c which, after reading the RFC, implements it
* as it should.
*/
-void ast_dns_srv_sort(struct ast_dns_result *result)
+void dns_srv_sort(struct ast_dns_result *result)
{
struct ast_dns_record *current;
struct dns_records newlist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
More information about the asterisk-commits
mailing list