[asterisk-commits] simon.perreault: branch group/v6-new r273881 - in /team/group/v6-new: apps/ c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 5 08:44:16 CDT 2010


Author: simon.perreault
Date: Mon Jul  5 08:44:09 2010
New Revision: 273881

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=273881
Log:
Refactored ast_sockaddr_from_sin()

Modified:
    team/group/v6-new/apps/app_externalivr.c
    team/group/v6-new/channels/chan_iax2.c
    team/group/v6-new/channels/chan_mgcp.c
    team/group/v6-new/channels/chan_skinny.c
    team/group/v6-new/channels/chan_unistim.c
    team/group/v6-new/include/asterisk/netsock2.h
    team/group/v6-new/main/http.c
    team/group/v6-new/main/manager.c
    team/group/v6-new/main/netsock2.c
    team/group/v6-new/res/res_rtp_asterisk.c

Modified: team/group/v6-new/apps/app_externalivr.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/apps/app_externalivr.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/apps/app_externalivr.c (original)
+++ team/group/v6-new/apps/app_externalivr.c Mon Jul  5 08:44:09 2010
@@ -510,7 +510,7 @@
 		remote_address_tmp.sin_family = AF_INET;
 		remote_address_tmp.sin_port = htons(port);
 		memcpy(&remote_address_tmp.sin_addr.s_addr, hp.hp.h_addr, sizeof(hp.hp.h_addr));
-		ivr_desc.remote_address = ast_sockaddr_from_sin(remote_address_tmp);
+		ast_sockaddr_from_sin(&ivr_desc.remote_address, &remote_address_tmp);
 		if (!(ser = ast_tcptls_client_create(&ivr_desc)) || !(ser = ast_tcptls_client_start(ser))) {
 			goto exit;
 		}

Modified: team/group/v6-new/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_iax2.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/channels/chan_iax2.c (original)
+++ team/group/v6-new/channels/chan_iax2.c Mon Jul  5 08:44:09 2010
@@ -4442,7 +4442,7 @@
 		struct ast_sockaddr sin_tmp;
 
 		cai->found = 0;
-		sin_tmp = ast_sockaddr_from_sin(*sin);
+		ast_sockaddr_from_sin(&sin_tmp, sin);
 		if (ast_get_ip_or_srv(&sin_tmp, peername, srvlookup ? "_iax._udp" : NULL)) {
 			ast_log(LOG_WARNING, "No such host: %s\n", peername);
 			return -1;
@@ -8320,7 +8320,7 @@
 		return -1;
 
 	reg->addr.sin_family = AF_INET;
-	reg_addr_tmp = ast_sockaddr_from_sin(reg->addr);
+	ast_sockaddr_from_sin(&reg_addr_tmp, &reg->addr);
 	if (ast_dnsmgr_lookup(hostname, &reg_addr_tmp, &reg->dnsmgr, srvlookup ? "_iax._udp" : NULL) < 0) {
 		ast_free(reg);
 		return -1;

Modified: team/group/v6-new/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_mgcp.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/channels/chan_mgcp.c (original)
+++ team/group/v6-new/channels/chan_mgcp.c Mon Jul  5 08:44:09 2010
@@ -1774,8 +1774,8 @@
 						struct sockaddr_in tmp3 = {0,};
 
 						tmp3.sin_addr = g->ourip;
-						tmp1 = ast_sockaddr_from_sin(g->addr);
-						tmp2 = ast_sockaddr_from_sin(tmp3);
+						ast_sockaddr_from_sin(&tmp1, &g->addr);
+						ast_sockaddr_from_sin(&tmp2, &tmp3);
 						if (ast_ouraddrfor(&tmp1, &tmp2)) {
 							memcpy(&g->ourip, &__ourip, sizeof(g->ourip));
 						}
@@ -1977,7 +1977,7 @@
 	sin.sin_family = AF_INET;
 	memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
 	sin.sin_port = htons(portno);
-	sin_tmp = ast_sockaddr_from_sin(sin);
+	ast_sockaddr_from_sin(&sin_tmp, &sin);
 	ast_rtp_instance_set_remote_address(sub->rtp, &sin_tmp);
 	ast_debug(3, "Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 	/* Scan through the RTP payload types specified in a "m=" line: */
@@ -2904,7 +2904,7 @@
 		sub->rtp = NULL;
 	}
 	/* Allocate the RTP now */
-	bindaddr_tmp = ast_sockaddr_from_sin(bindaddr);
+	ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
 	sub->rtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL);
 	if (sub->rtp && sub->owner)
 		ast_channel_set_fd(sub->owner, 0, ast_rtp_instance_fd(sub->rtp, 0));
@@ -3992,7 +3992,7 @@
 				{
 					struct ast_sockaddr tmp;
 
-					tmp = ast_sockaddr_from_sin(gw->addr);
+					ast_sockaddr_from_sin(&tmp, &gw->addr);
 					if (ast_get_ip(&tmp, v->value)) {
 						if (!gw_reload) {
 							ast_mutex_destroy(&gw->msgs_lock);
@@ -4006,7 +4006,7 @@
 		} else if (!strcasecmp(v->name, "defaultip")) {
 			struct ast_sockaddr tmp;
 
-			tmp = ast_sockaddr_from_sin(gw->defaddr);
+			ast_sockaddr_from_sin(&tmp, &gw->defaddr);
 			if (ast_get_ip(&tmp, v->value)) {
 				if (!gw_reload) {
 					ast_mutex_destroy(&gw->msgs_lock);
@@ -4362,8 +4362,8 @@
 			struct sockaddr_in tmp3 = {0,};
 
 			tmp3.sin_addr = gw->ourip;
-			tmp1 = ast_sockaddr_from_sin(gw->addr);
-			tmp2 = ast_sockaddr_from_sin(tmp3);
+			ast_sockaddr_from_sin(&tmp1, &gw->addr);
+			ast_sockaddr_from_sin(&tmp2, &tmp3);
 			if (gw->addr.sin_addr.s_addr && ast_ouraddrfor(&tmp1, &tmp2)) {
 				memcpy(&gw->ourip, &__ourip, sizeof(gw->ourip));
 			} else {

Modified: team/group/v6-new/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_skinny.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/channels/chan_skinny.c (original)
+++ team/group/v6-new/channels/chan_skinny.c Mon Jul  5 08:44:09 2010
@@ -3710,7 +3710,7 @@
 
 	ast_mutex_lock(&sub->lock);
 	/* Allocate the RTP */
-	bindaddr_tmp = ast_sockaddr_from_sin(bindaddr);
+	ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
 	sub->rtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL);
 	if (hasvideo)
 		sub->vrtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL);
@@ -5637,7 +5637,7 @@
 	l = sub->parent;
 
 	if (sub->rtp) {
-		sin_tmp = ast_sockaddr_from_sin(sin);
+		ast_sockaddr_from_sin(&sin_tmp, &sin);
 		ast_rtp_instance_set_remote_address(sub->rtp, &sin_tmp);
 		ast_rtp_instance_get_local_address(sub->rtp, &us_tmp);
 		ast_sockaddr_to_sin(&us_tmp, &us);

Modified: team/group/v6-new/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_unistim.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/channels/chan_unistim.c (original)
+++ team/group/v6-new/channels/chan_unistim.c Mon Jul  5 08:44:09 2010
@@ -2065,7 +2065,7 @@
 	/* Allocate the RTP */
 	if (unistimdebug)
 		ast_verb(0, "Starting RTP. Bind on %s\n", ast_inet_ntoa(sout.sin_addr));
-	sout_tmp = ast_sockaddr_from_sin(sout);
+	ast_sockaddr_from_sin(&sout_tmp, &sout);
 	sub->rtp = ast_rtp_instance_new("asterisk", sched, &sout_tmp, NULL);
 	if (!sub->rtp) {
 		ast_log(LOG_WARNING, "Unable to create RTP session: %s binaddr=%s\n",
@@ -2089,7 +2089,7 @@
 	memcpy(&sin.sin_addr, &sub->parent->parent->session->sin.sin_addr,
 		   sizeof(sin.sin_addr));
 	sin.sin_port = htons(sub->parent->parent->rtp_port);
-	sin_tmp = ast_sockaddr_from_sin(sin);
+	ast_sockaddr_from_sin(&sin_tmp, &sin);
 	ast_rtp_instance_set_remote_address(sub->rtp, &sin_tmp);
 	if (!(sub->owner->nativeformats & sub->owner->readformat)) {
 		format_t fmt;

Modified: team/group/v6-new/include/asterisk/netsock2.h
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/include/asterisk/netsock2.h?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/include/asterisk/netsock2.h (original)
+++ team/group/v6-new/include/asterisk/netsock2.h Mon Jul  5 08:44:09 2010
@@ -512,7 +512,7 @@
  * \param sin The sockaddr_in to convert
  * \return an ast_sockaddr structure
  */
-struct ast_sockaddr ast_sockaddr_from_sin(struct sockaddr_in sin);
+void ast_sockaddr_from_sin(struct ast_sockaddr *addr, const struct sockaddr_in *sin);
 
 /*@}*/
 

Modified: team/group/v6-new/main/http.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/main/http.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/main/http.c (original)
+++ team/group/v6-new/main/http.c Mon Jul  5 08:44:09 2010
@@ -999,10 +999,10 @@
 
 	/* default values */
 	tmp.sin_port = htons(8088);
-	http_desc.local_address = ast_sockaddr_from_sin(tmp);
+	ast_sockaddr_from_sin(&http_desc.local_address, &tmp);
 
 	tmp2.sin_port = htons(8089);
-	https_desc.local_address = ast_sockaddr_from_sin(tmp2);
+	ast_sockaddr_from_sin(&https_desc.local_address, &tmp2);
 
 	http_tls_cfg.enabled = 0;
 	if (http_tls_cfg.certfile) {
@@ -1043,15 +1043,14 @@
 				ast_sockaddr_to_sin(&http_desc.local_address,
 						    &tmp);
 				tmp.sin_port = htons(atoi(v->value));
-				http_desc.local_address =
-				    ast_sockaddr_from_sin(tmp);
+				ast_sockaddr_from_sin(&http_desc.local_address, &tmp);
 			} else if (!strcasecmp(v->name, "bindaddr")) {
 				if ((hp = ast_gethostbyname(v->value, &ahp))) {
 					ast_sockaddr_to_sin(&http_desc.local_address,
 							    &tmp);
 					memcpy(&tmp.sin_addr, hp->h_addr, sizeof(tmp.sin_addr));
-					http_desc.local_address =
-					    ast_sockaddr_from_sin(tmp);
+					ast_sockaddr_from_sin(&http_desc.local_address,
+							      &tmp);
 				} else {
 					ast_log(LOG_WARNING, "Invalid bind address '%s'\n", v->value);
 				}
@@ -1076,12 +1075,12 @@
 	ast_sockaddr_to_sin(&https_desc.local_address, &tmp2);
 	if (!tmp.sin_addr.s_addr) {
 		tmp2.sin_addr = tmp.sin_addr;
-		https_desc.local_address = ast_sockaddr_from_sin(tmp2);
+		ast_sockaddr_from_sin(&https_desc.local_address, &tmp2);
 	}
 	if (enabled) {
 		tmp.sin_family = tmp2.sin_family = AF_INET;
-		http_desc.local_address = ast_sockaddr_from_sin(tmp);
-		https_desc.local_address = ast_sockaddr_from_sin(tmp2);
+		ast_sockaddr_from_sin(&http_desc.local_address, &tmp);
+		ast_sockaddr_from_sin(&https_desc.local_address, &tmp2);
 	}
 	if (strcmp(prefix, newprefix)) {
 		ast_copy_string(prefix, newprefix, sizeof(prefix));

Modified: team/group/v6-new/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/main/manager.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/main/manager.c (original)
+++ team/group/v6-new/main/manager.c Mon Jul  5 08:44:09 2010
@@ -5922,7 +5922,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = generic_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -5933,7 +5933,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = generic_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -5944,7 +5944,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = generic_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -5981,7 +5981,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = auth_http_callback(ser, method, FORMAT_HTML, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -5992,7 +5992,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = auth_http_callback(ser, method, FORMAT_XML, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -6003,7 +6003,7 @@
 
 	ast_sockaddr_to_sin(&ser->remote_address, &ser_remote_address_tmp);
 	retval = auth_http_callback(ser, method, FORMAT_RAW, &ser_remote_address_tmp, uri, get_params, headers);
-	ser->remote_address = ast_sockaddr_from_sin(ser_remote_address_tmp);
+	ast_sockaddr_from_sin(&ser->remote_address, &ser_remote_address_tmp);
 	return retval;
 }
 
@@ -6280,10 +6280,8 @@
 	if (ami_tls_cfg.enabled) {
 		amis_desc_local_address_tmp.sin_family = AF_INET;
 	}
-	ami_desc.local_address =
-	    ast_sockaddr_from_sin(ami_desc_local_address_tmp);
-	amis_desc.local_address =
-	    ast_sockaddr_from_sin(amis_desc_local_address_tmp);
+	ast_sockaddr_from_sin(&ami_desc.local_address, &ami_desc_local_address_tmp);
+	ast_sockaddr_from_sin(&amis_desc.local_address, &amis_desc_local_address_tmp);
 
 	AST_RWLIST_WRLOCK(&users);
 

Modified: team/group/v6-new/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/main/netsock2.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/main/netsock2.c (original)
+++ team/group/v6-new/main/netsock2.c Mon Jul  5 08:44:09 2010
@@ -52,7 +52,7 @@
 	sin4.sin_port = sin6->sin6_port;
 	sin4.sin_addr.s_addr = ((uint32_t *)&sin6->sin6_addr)[3];
 
-	*ast_mapped = ast_sockaddr_from_sin(sin4);
+	ast_sockaddr_from_sin(ast_mapped, &sin4);
 
 	return 1;
 }
@@ -479,16 +479,13 @@
 	return 1;
 }
 
-struct ast_sockaddr ast_sockaddr_from_sin(struct sockaddr_in sin)
-{
-	struct ast_sockaddr addr;
-
-	memcpy(&addr.ss, &sin, sizeof(sin));
-
-	if (addr.ss.ss_family != AF_INET) {
+void ast_sockaddr_from_sin(struct ast_sockaddr *addr, const struct sockaddr_in *sin)
+{
+	memcpy(&addr->ss, &sin, sizeof(sin));
+
+	if (addr->ss.ss_family != AF_INET) {
 		ast_log(LOG_DEBUG, "Address family is not AF_INET\n");
 	}
 
-	addr.len = sizeof(sin);
-	return addr;
-}
+	addr->len = sizeof(sin);
+}

Modified: team/group/v6-new/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/res/res_rtp_asterisk.c?view=diff&rev=273881&r1=273880&r2=273881
==============================================================================
--- team/group/v6-new/res/res_rtp_asterisk.c (original)
+++ team/group/v6-new/res/res_rtp_asterisk.c Mon Jul  5 08:44:09 2010
@@ -2012,7 +2012,7 @@
 		ast_sockaddr_to_sin(&addr, &addr_tmp);
 		if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) &&
 		    ast_sockaddr_isnull(&remote_address)) {
-			addr = ast_sockaddr_from_sin(addr_tmp);
+			ast_sockaddr_from_sin(&addr, &addr_tmp);
 			ast_rtp_instance_set_remote_address(instance, &addr);
 		}
 		return &ast_null_frame;
@@ -2519,7 +2519,7 @@
 
 	ast_sockaddr_to_sin(suggestion, &suggestion_tmp);
 	ast_stun_request(rtp->s, &suggestion_tmp, username, NULL);
-	*suggestion = ast_sockaddr_from_sin(suggestion_tmp);
+	ast_sockaddr_from_sin(suggestion, &suggestion_tmp);
 }
 
 static void ast_rtp_stop(struct ast_rtp_instance *instance)




More information about the asterisk-commits mailing list