[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r111855 - in /team/jpeeler/sip-dnsmgr: cha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 16:27:00 CDT 2008


Author: jpeeler
Date: Fri Mar 28 16:26:59 2008
New Revision: 111855

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111855
Log:
utilized ast_get_ip_or_srv for dnsmgr

Modified:
    team/jpeeler/sip-dnsmgr/channels/chan_sip.c
    team/jpeeler/sip-dnsmgr/main/acl.c
    team/jpeeler/sip-dnsmgr/main/dnsmgr.c

Modified: team/jpeeler/sip-dnsmgr/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/channels/chan_sip.c?view=diff&rev=111855&r1=111854&r2=111855
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Fri Mar 28 16:26:59 2008
@@ -9227,12 +9227,12 @@
 	}
 
 	if (r->dnsmgr == NULL) {
-		char service[MAXHOSTNAMELEN];
+		char transport[MAXHOSTNAMELEN];
 		//ast_dnsmgr_lookup(r->hostname, &r->us.sin_addr, &r->dnsmgr);
  
-		snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(r->transport), r->hostname); /* have to use static get_transport function */
+		snprintf(transport, sizeof(transport), "_sip._%s", get_transport(r->transport)); /* have to use static get_transport function */
 		ast_log(LOG_DEBUG, "hostname: %s portno:%d sin_family:%d\n", r->hostname, r->portno, r->us.sin_family);
-		ast_dnsmgr_lookup_srv(r->hostname, &r->us, &r->dnsmgr, service);
+		ast_dnsmgr_lookup_srv(r->hostname, &r->us, &r->dnsmgr, transport);
 		ast_log(LOG_DEBUG, "after dnsmgr lookup port=%d\n", htons(r->us.sin_port));
 	} else {
 		ast_log(LOG_DEBUG, "DNS manager detected, r->us.sin_addr=%s r->us.sin_port=%d r->us.sin_family=%d\n", ast_inet_ntoa(r->us.sin_addr), ntohs(r->us.sin_port), r->us.sin_family);

Modified: team/jpeeler/sip-dnsmgr/main/acl.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/main/acl.c?view=diff&rev=111855&r1=111854&r2=111855
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/acl.c (original)
+++ team/jpeeler/sip-dnsmgr/main/acl.c Fri Mar 28 16:26:59 2008
@@ -364,6 +364,7 @@
 	int tportno = ntohs(sin->sin_port);
 	if (service) {
 		snprintf(srv, sizeof(srv), "%s.%s", service, value);
+		ast_log(LOG_DEBUG, "srv=%s\n", srv);
 		if (ast_get_srv(NULL, host, sizeof(host), &tportno, srv) > 0) {
 			sin->sin_port = htons(tportno);
 			value = host;

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=111855&r1=111854&r2=111855
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Fri Mar 28 16:26:59 2008
@@ -38,6 +38,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/cli.h"
 #include "asterisk/manager.h"
+#include "asterisk/acl.h"
 
 static struct sched_context *sched;
 static int refresh_sched = -1;
@@ -49,7 +50,6 @@
 	/*! the last result, used to check if address has changed */
 	struct sockaddr_in last;
 	char service[MAXHOSTNAMELEN];
-	int dnssrv:1;
 	/*! Set to 1 if the entry changes */
 	int changed:1;
 	ast_mutex_t lock;
@@ -90,7 +90,6 @@
 	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);
@@ -112,7 +111,6 @@
 	strcpy(entry->name, name);
 	strcpy(entry->service, service);
 	memcpy(&entry->last, &result, sizeof(entry->last));
-	entry->dnssrv = 1;
 
 	AST_RWLIST_WRLOCK(&entry_list);
 	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
@@ -169,11 +167,13 @@
 
 int ast_dnsmgr_lookup_srv(const char *name, struct sockaddr_in *sin, struct ast_dnsmgr_entry **dnsmgr, const char *service)
 {
+	/*
 	char realhostname[MAXHOSTNAMELEN];
 	int real_portno;
 	int srv_ret;
 	struct hostent *hp;
 	struct ast_hostent ahp;
+	*/
 
 	if (ast_strlen_zero(name) || !sin || !dnsmgr || !service) {
 		return -1;
@@ -189,7 +189,9 @@
 		return 0;
 
 	ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
-
+	ast_get_ip_or_srv(sin, name, service);
+
+	/*
 	srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), &real_portno, service);
 	if (srv_ret > 0) {
 		char buf[INET_ADDRSTRLEN];
@@ -203,7 +205,7 @@
 	if (hp) {
 		memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
 	}
-
+	*/
 
 	/* if dnsmgr is not enabled don't bother adding an entry */
 	if (!enabled)
@@ -220,19 +222,30 @@
  */
 static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
 {
-	struct ast_hostent ahp;
-	struct hostent *hp;
+	//struct ast_hostent ahp;
+	//struct hostent *hp;
 	char iabuf[INET_ADDRSTRLEN];
 	char iabuf2[INET_ADDRSTRLEN];
-	struct in_addr tmp;
+	//struct in_addr tmp;
 	int changed = 0;
-	char realhostname[MAXHOSTNAMELEN];
-	int real_portno;
+	//char realhostname[MAXHOSTNAMELEN];
+	//int real_portno;
         
 	ast_mutex_lock(&entry->lock);
 	if (verbose)
 		ast_verb(3, "refreshing '%s'\n", entry->name);
 
+	ast_get_ip_or_srv(entry->result, entry->name, entry->service);
+	if (entry->result->sin_addr.s_addr != entry->last.sin_addr.s_addr || entry->result->sin_port != entry->last.sin_port) {
+		ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
+		ast_copy_string(iabuf2, ast_inet_ntoa(entry->result->sin_addr), sizeof(iabuf2));
+		ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s:%d to %s:%d\n", 
+			entry->name, iabuf, ntohs(entry->last.sin_port), iabuf2, ntohs(entry->result->sin_port));
+		entry->last = *entry->result;
+		changed = entry->changed = 1;
+	}
+
+/*
 	if (entry->dnssrv) {
 		int srv_ret;
 		srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), &real_portno, entry->service);
@@ -255,7 +268,7 @@
 			}
 		}
 	} else if ((hp = ast_gethostbyname(entry->name, &ahp))) {
-		/* check to see if it has changed, do callback if requested (where de callback is defined ????) */
+		// 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.sin_addr.s_addr) {
 			ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
@@ -266,8 +279,8 @@
 			memcpy(&entry->last, hp->h_addr, sizeof(entry->last));
 			changed = entry->changed = 1;
 		} 
-		
-	}
+	}
+*/
 	ast_mutex_unlock(&entry->lock);
 	return changed;
 }




More information about the asterisk-commits mailing list