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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 31 18:58:55 CDT 2008


Author: jpeeler
Date: Mon Mar 31 18:58:54 2008
New Revision: 112121

URL: http://svn.digium.com/view/asterisk?view=rev&rev=112121
Log:
shortened allocation required for ast_dnsmgr_entries, fixed port number assignment for peers without SRV records present

Modified:
    team/jpeeler/sip-dnsmgr/channels/chan_sip.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=112121&r1=112120&r2=112121
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Mon Mar 31 18:58:54 2008
@@ -4101,7 +4101,11 @@
 	/* This address should be updated using dnsmgr */
 	if (sin) {
 		memcpy(&dialog->sa.sin_addr, &sin->sin_addr, sizeof(dialog->sa.sin_addr));
-		portno = ntohs(sin->sin_port);
+		if (!sin->sin_port) {
+			portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+		} else {
+			portno = ntohs(sin->sin_port);
+		}
 		ast_log(LOG_DEBUG, "DNS manager address showing portno=%d\n", portno);
 	} else {
 
@@ -9227,7 +9231,7 @@
 		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(r->hostname, &r->us, &r->dnsmgr, global_srvlookup ? transport : NULL);
-		ast_log(LOG_DEBUG, "after dnsmgr lookup port=%d\n", htons(r->us.sin_port));
+		//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);
 	}
@@ -9257,6 +9261,10 @@
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 
 		p->outboundproxy = obproxy_get(p, NULL);
+
+		/* Use port number specified if no SRV record was found */
+		if (!r->us.sin_port && r->portno)
+			r->us.sin_port = htons(r->portno);
 
 		/* Find address to hostname */
 		if (create_addr(p, r->hostname, &r->us)) {

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=112121&r1=112120&r2=112121
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Mon Mar 31 18:58:54 2008
@@ -55,7 +55,7 @@
 	/*! the last result, used to check if address/port has changed */
 	struct sockaddr_in last;
 	/*! SRV record to lookup, if provided. Composed of service, protocol, and domain name: _Service._Proto.Name */
-	char service[MAXHOSTNAMELEN];
+	char *service;
 	/*! Set to 1 if the entry changes */
 	int changed:1;
 	ast_mutex_t lock;
@@ -88,15 +88,19 @@
 struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct sockaddr_in *result, const char *service)
 {
 	struct ast_dnsmgr_entry *entry;
-
-	if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
+	int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
+
+	if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size)))
 		return NULL;
 
 	entry->result = result;
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
-	strcpy(entry->service, service);
 	memcpy(&entry->last, result, sizeof(entry->last));
+	if (service) {
+		entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
+		strcpy(entry->service, service);
+	}
 
 	AST_RWLIST_WRLOCK(&entry_list);
 	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);




More information about the asterisk-commits mailing list