[svn-commits] jpeeler: branch jpeeler/sip-dnsmgr r111499 - in /team/jpeeler/sip-dnsmgr: inc...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 27 17:09:41 CDT 2008


Author: jpeeler
Date: Thu Mar 27 17:09:41 2008
New Revision: 111499

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111499
Log:
dnsmgr refreshes for hosts with dns srv records working, need to clean the code up a bit though

Modified:
    team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h
    team/jpeeler/sip-dnsmgr/main/dnsmgr.c

Modified: team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h?view=diff&rev=111499&r1=111498&r2=111499
==============================================================================
--- team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h (original)
+++ team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h Thu Mar 27 17:09:41 2008
@@ -53,7 +53,7 @@
  */
 struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result);
 
-struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno);
+struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno, const char *service);
 
 
 /*!

Modified: team/jpeeler/sip-dnsmgr/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/main/dnsmgr.c?view=diff&rev=111499&r1=111498&r2=111499
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Thu Mar 27 17:09:41 2008
@@ -50,6 +50,8 @@
 	struct in_addr last;
 	unsigned short result_portno;
 	unsigned short last_portno;
+	char service[MAXHOSTNAMELEN];
+	int dnssrv:1;
 	/*! Set to 1 if the entry changes */
 	int changed:1;
 	ast_mutex_t lock;
@@ -90,6 +92,7 @@
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
 	memcpy(&entry->last, result, sizeof(entry->last));
+	entry->dnssrv = 0;
 
 	AST_RWLIST_WRLOCK(&entry_list);
 	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
@@ -99,7 +102,7 @@
 }
 
 
-struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno)
+struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno, const char *service)
 {
 	struct ast_dnsmgr_entry *entry;
 
@@ -110,8 +113,10 @@
 	entry->result_portno = *portno;
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
+	strcpy(entry->service, service);
 	memcpy(&entry->last, result, sizeof(entry->last));
 	entry->last_portno = *portno;
+	entry->dnssrv = 1;
 
 	AST_RWLIST_WRLOCK(&entry_list);
 	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
@@ -201,7 +206,9 @@
 		ast_log(LOG_DEBUG, "name=%s realhostname=%s result_portno=%d hp->h_addr=%s\n", name, realhostname, *result_portno, hp->h_addr);
 	}
 
-	memcpy(result_addr, hp->h_addr, sizeof(result_addr));
+	if (hp) {
+		memcpy(result_addr, hp->h_addr, sizeof(result_addr));
+	}
 
 
 	/* if dnsmgr is not enabled don't bother adding an entry */
@@ -209,7 +216,7 @@
 		return 0;
 	
 	ast_verb(3, "adding dns manager for '%s'\n", name);
-	*dnsmgr = ast_dnsmgr_get_srv(name, result_addr, result_portno);
+	*dnsmgr = ast_dnsmgr_get_srv(name, result_addr, result_portno, service);
 	return !*dnsmgr;
 }
 
@@ -225,12 +232,35 @@
 	char iabuf2[INET_ADDRSTRLEN];
 	struct in_addr tmp;
 	int changed = 0;
+	char realhostname[MAXHOSTNAMELEN];
+	int real_portno;
         
 	ast_mutex_lock(&entry->lock);
 	if (verbose)
 		ast_verb(3, "refreshing '%s'\n", entry->name);
 
-	if ((hp = ast_gethostbyname(entry->name, &ahp))) {
+	if (entry->dnssrv) {
+		int srv_ret;
+		srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), &real_portno, entry->service);
+
+		if (srv_ret > 0) {
+			if ((hp = ast_gethostbyname(realhostname, &ahp))) {
+				memcpy(&tmp, hp->h_addr, sizeof(tmp));
+				if (tmp.s_addr != entry->last.s_addr) {
+					ast_copy_string(iabuf, ast_inet_ntoa(entry->last), sizeof(iabuf));
+					ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
+					ast_log(LOG_NOTICE, "host '%s' changed from %s to %s\n", 
+						entry->name, iabuf, iabuf2);
+
+					memcpy(entry->result, hp->h_addr, sizeof(entry->result));
+					memcpy(&entry->last, hp->h_addr, sizeof(entry->last));
+					entry->result_portno = htons((unsigned int)real_portno);
+					entry->last_portno = htons((unsigned int)real_portno);
+					changed = entry->changed = 1;
+				}
+			}
+		}
+	} else if ((hp = ast_gethostbyname(entry->name, &ahp))) {
 		/* check to see if it has changed, do callback if requested (where de callback is defined ????) */
 		memcpy(&tmp, hp->h_addr, sizeof(tmp));
 		if (tmp.s_addr != entry->last.s_addr) {




More information about the svn-commits mailing list