[asterisk-commits] file: branch group/dns r432448 - in /team/group/dns: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 4 11:35:35 CST 2015


Author: file
Date: Wed Mar  4 11:35:33 2015
New Revision: 432448

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432448
Log:
Implement resolver registration/unregistration.

Modified:
    team/group/dns/include/asterisk/dns_resolver.h
    team/group/dns/main/dns_core.c

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=432448&r1=432447&r2=432448
==============================================================================
--- team/group/dns/include/asterisk/dns_resolver.h (original)
+++ team/group/dns/include/asterisk/dns_resolver.h Wed Mar  4 11:35:33 2015
@@ -38,6 +38,8 @@
     int (*resolve)(struct ast_dns_query *query);
     /*! \brief Cancel resolution of a DNS query */
     int (*cancel)(struct ast_dns_query *query);
+    /*! \brief Linked list information */
+    AST_RWLIST_ENTRY(ast_dns_resolver) next;
 };
 
 /*!
@@ -103,17 +105,14 @@
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_dns_resolver_register(const struct ast_dns_resolver *resolver);
+int ast_dns_resolver_register(struct ast_dns_resolver *resolver);
 
 /*!
  * \brief Unregister a DNS resolver
  *
  * \param resolver A DNS resolver implementation
- *
- * \retval 0 success
- * \retval -1 failure
  */
-int ast_dns_resolver_unregister(const struct ast_dns_resolver *resolver);
+void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

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=432448&r1=432447&r2=432448
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Wed Mar  4 11:35:33 2015
@@ -31,12 +31,15 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include "asterisk/linkedlists.h"
 #include "asterisk/dns_core.h"
 #include "asterisk/dns_naptr.h"
 #include "asterisk/dns_srv.h"
 #include "asterisk/dns_tlsa.h"
 #include "asterisk/dns_resolver.h"
 
+AST_RWLIST_HEAD_STATIC(resolvers, ast_dns_resolver);
+
 const char *ast_dns_query_get_name(const struct ast_dns_query *query)
 {
 	return NULL;
@@ -234,12 +237,54 @@
 {
 }
 
-int ast_dns_resolver_register(const struct ast_dns_resolver *resolver)
-{
-	return -1;
-}
-
-int ast_dns_resolver_unregister(const struct ast_dns_resolver *resolver)
-{
-	return -1;
+int ast_dns_resolver_register(struct ast_dns_resolver *resolver)
+{
+	struct ast_dns_resolver *iter;
+	int inserted = 0;
+
+	AST_RWLIST_WRLOCK(&resolvers);
+
+	AST_LIST_TRAVERSE(&resolvers, iter, next) {
+		if (!strcmp(iter->name, resolver->name)) {
+			ast_log(LOG_ERROR, "A DNS resolver with the name '%s' is already registered\n", resolver->name);
+			AST_RWLIST_UNLOCK(&resolvers);
+			return -1;
+		}
+	}
+
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&resolvers, iter, next) {
+		if (iter->priority > resolver->priority) {
+			AST_RWLIST_INSERT_BEFORE_CURRENT(resolver, next);
+			inserted = 1;
+			break;
+		}
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END;
+
+	if (!inserted) {
+		AST_RWLIST_INSERT_TAIL(&resolvers, resolver, next);
+	}
+
+	AST_RWLIST_UNLOCK(&resolvers);
+
+	ast_verb(2, "Registered DNS resolver '%s' with priority '%d'\n", resolver->name, resolver->priority);
+
+	return 0;
+}
+
+void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver)
+{
+	struct ast_dns_resolver *iter;
+
+	AST_RWLIST_WRLOCK(&resolvers);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&resolvers, iter, next) {
+		if (resolver == iter) {
+			AST_RWLIST_REMOVE_CURRENT(next);
+			break;
+		}
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END;
+	AST_RWLIST_UNLOCK(&resolvers);
+
+	ast_verb(2, "Unregistered DNS resolver '%s'\n", resolver->name);
 }




More information about the asterisk-commits mailing list