Index: pjproject/trunk/pjnath/src/pjnath/ice_strans.c
===================================================================
--- pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 4606)
+++ pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 4728)
@@ -1,4 +1,4 @@
 /* $Id$ */
-/* 
+/*
  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@@ -16,5 +16,5 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include <pjnath/ice_strans.h>
@@ -66,5 +66,5 @@
 
 /* The candidate type preference when STUN candidate is used */
-static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] = 
+static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] =
 {
 #if PJNATH_ICE_PRIO_STD
@@ -85,5 +85,5 @@
 /* ICE callbacks */
 static void	   on_ice_complete(pj_ice_sess *ice, pj_status_t status);
-static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 
+static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
 			      unsigned comp_id,
 			      unsigned transport_id,
@@ -91,6 +91,6 @@
 			      const pj_sockaddr_t *dst_addr,
 			      unsigned dst_addr_len);
-static void	   ice_rx_data(pj_ice_sess *ice, 
-			       unsigned comp_id, 
+static void	   ice_rx_data(pj_ice_sess *ice,
+			       unsigned comp_id,
 			       unsigned transport_id,
 			       void *pkt, pj_size_t size,
@@ -111,5 +111,5 @@
 				   pj_ssize_t sent);
 /* Notification when the status of the STUN transport has changed. */
-static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, 
+static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
 				pj_stun_sock_op op,
 				pj_status_t status);
@@ -137,5 +137,5 @@
  * in ICE stream transport typically corresponds to a single socket created
  * for this component, and bound to a specific transport address. This
- * component may have multiple alias addresses, for example one alias 
+ * component may have multiple alias addresses, for example one alias
  * address for each interfaces in multi-homed host, another for server
  * reflexive alias, and another for relayed alias. For each transport
@@ -299,9 +299,9 @@
     /* Override with component specific socket buffer size settings, if any */
     if (ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size > 0) {
-	ice_st->cfg.turn.cfg.so_rcvbuf_size = 
+	ice_st->cfg.turn.cfg.so_rcvbuf_size =
 	    ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size;
     }
     if (ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size > 0) {
-	ice_st->cfg.turn.cfg.so_sndbuf_size = 
+	ice_st->cfg.turn.cfg.so_sndbuf_size =
 	    ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size;
     }
@@ -382,8 +382,8 @@
 	stun_sock_cb.on_status = &stun_on_status;
 	stun_sock_cb.on_data_sent = &stun_on_data_sent;
-	
+
 	/* Override component specific QoS settings, if any */
 	if (ice_st->cfg.comp[comp_id-1].qos_type) {
-	    ice_st->cfg.stun.cfg.qos_type = 
+	    ice_st->cfg.stun.cfg.qos_type =
 		ice_st->cfg.comp[comp_id-1].qos_type;
 	}
@@ -396,9 +396,9 @@
 	/* Override component specific socket buffer size settings, if any */
 	if (ice_st->cfg.comp[comp_id-1].so_rcvbuf_size > 0) {
-	    ice_st->cfg.stun.cfg.so_rcvbuf_size = 
+	    ice_st->cfg.stun.cfg.so_rcvbuf_size =
 		ice_st->cfg.comp[comp_id-1].so_rcvbuf_size;
 	}
 	if (ice_st->cfg.comp[comp_id-1].so_sndbuf_size > 0) {
-	    ice_st->cfg.stun.cfg.so_sndbuf_size = 
+	    ice_st->cfg.stun.cfg.so_sndbuf_size =
 		ice_st->cfg.comp[comp_id-1].so_sndbuf_size;
 	}
@@ -412,6 +412,6 @@
 	    return status;
 
-	/* Start STUN Binding resolution and add srflx candidate 
-	 * only if server is set 
+	/* Start STUN Binding resolution and add srflx candidate
+	 * only if server is set
 	 */
 	if (ice_st->cfg.stun.server.slen) {
@@ -421,5 +421,5 @@
 	    ///sess_add_ref(ice_st);
 
-	    PJ_LOG(4,(ice_st->obj_name, 
+	    PJ_LOG(4,(ice_st->obj_name,
 		      "Comp %d: srflx candidate starts Binding discovery",
 		      comp_id));
@@ -428,7 +428,7 @@
 
 	    /* Start Binding resolution */
-	    status = pj_stun_sock_start(comp->stun_sock, 
+	    status = pj_stun_sock_start(comp->stun_sock,
 					&ice_st->cfg.stun.server,
-					ice_st->cfg.stun.port, 
+					ice_st->cfg.stun.port,
 					ice_st->cfg.resolver);
 	    if (status != PJ_SUCCESS) {
@@ -476,6 +476,6 @@
 		return status;
 
-	    for (i=0; i<stun_sock_info.alias_cnt && 
-		      i<ice_st->cfg.stun.max_host_cands; ++i) 
+	    for (i=0; i<stun_sock_info.alias_cnt &&
+		      i<ice_st->cfg.stun.max_host_cands; ++i)
 	    {
 		char addrinfo[PJ_INET6_ADDRSTRLEN+10];
@@ -488,6 +488,6 @@
 		}
 
-		/* Ignore loopback addresses unless cfg->stun.loop_addr 
-		 * is set 
+		/* Ignore loopback addresses unless cfg->stun.loop_addr
+		 * is set
 		 */
 		if ((pj_ntohl(addr->ipv4.sin_addr.s_addr)>>24)==127) {
@@ -509,5 +509,5 @@
 				       cand->type, &cand->base_addr);
 
-		PJ_LOG(4,(ice_st->obj_name, 
+		PJ_LOG(4,(ice_st->obj_name,
 			  "Comp %d: host candidate %s added",
 			  comp_id, pj_sockaddr_print(&cand->addr, addrinfo,
@@ -533,6 +533,6 @@
 
 
-/* 
- * Create ICE stream transport 
+/*
+ * Create ICE stream transport
  */
 PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name,
@@ -565,5 +565,5 @@
     ice_st->user_data = user_data;
 
-    PJ_LOG(4,(ice_st->obj_name, 
+    PJ_LOG(4,(ice_st->obj_name,
 	      "Creating ICE stream transport with %d component(s)",
 	      comp_cnt));
@@ -587,5 +587,5 @@
 
     ice_st->comp_cnt = comp_cnt;
-    ice_st->comp = (pj_ice_strans_comp**) 
+    ice_st->comp = (pj_ice_strans_comp**)
 		   pj_pool_calloc(pool, comp_cnt, sizeof(pj_ice_strans_comp*));
 
@@ -593,5 +593,5 @@
     ice_st->state = PJ_ICE_STRANS_STATE_INIT;
 
-    /* Acquire initialization mutex to prevent callback to be 
+    /* Acquire initialization mutex to prevent callback to be
      * called before we finish initialization.
      */
@@ -750,5 +750,5 @@
     ice_st->state = PJ_ICE_STRANS_STATE_READY;
     if (ice_st->cb.on_ice_complete)
-	(*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT, 
+	(*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT,
 				      PJ_SUCCESS);
 }
@@ -786,5 +786,5 @@
 
 /*
- * Specify various options for this ICE stream transport. 
+ * Specify various options for this ICE stream transport.
  */
 PJ_DEF(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st,
@@ -835,5 +835,5 @@
     /* Create! */
     status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role,
-			        ice_st->comp_cnt, &ice_cb, 
+			        ice_st->comp_cnt, &ice_cb,
 			        local_ufrag, local_passwd,
 			        ice_st->grp_lock,
@@ -853,5 +853,5 @@
      */
     if (ice_st->comp[0]->default_cand >= 0 &&
-	ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type 
+	ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type
 	    == PJ_ICE_CAND_TYPE_SRFLX)
     {
@@ -866,5 +866,5 @@
 	/* Re-enable logging for Send/Data indications */
 	if (comp->turn_sock) {
-	    PJ_LOG(5,(ice_st->obj_name, 
+	    PJ_LOG(5,(ice_st->obj_name,
 		      "Disabling STUN Indication logging for "
 		      "component %d", i+1));
@@ -879,5 +879,5 @@
 	    /* Skip if candidate is not ready */
 	    if (cand->status != PJ_SUCCESS) {
-		PJ_LOG(5,(ice_st->obj_name, 
+		PJ_LOG(5,(ice_st->obj_name,
 			  "Candidate %d of comp %d is not added (pending)",
 			  j, i));
@@ -889,8 +889,8 @@
 
 	    /* Add the candidate */
-	    status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id, 
-					  cand->transport_id, cand->type, 
-					  cand->local_pref, 
-					  &cand->foundation, &cand->addr, 
+	    status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id,
+					  cand->transport_id, cand->type,
+					  cand->local_pref,
+					  &cand->foundation, &cand->addr,
 					  &cand->base_addr,  &cand->rel_addr,
 					  pj_sockaddr_get_len(&cand->addr),
@@ -912,5 +912,5 @@
 
 /*
- * Check if the ICE stream transport has the ICE session created. 
+ * Check if the ICE stream transport has the ICE session created.
  */
 PJ_DEF(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st)
@@ -985,5 +985,5 @@
     unsigned i, cnt;
 
-    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && 
+    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id &&
 		     comp_id <= ice_st->comp_cnt, 0);
 
@@ -1008,5 +1008,5 @@
     unsigned i, cnt;
 
-    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && 
+    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id &&
 		     comp_id <= ice_st->comp_cnt && count && cand, PJ_EINVAL);
 
@@ -1042,5 +1042,5 @@
 	pj_ice_strans_comp *comp = ice_st->comp[comp_id - 1];
 	pj_assert(comp->default_cand>=0 && comp->default_cand<comp->cand_cnt);
-	pj_memcpy(cand, &comp->cand_list[comp->default_cand], 
+	pj_memcpy(cand, &comp->cand_list[comp->default_cand],
 		  sizeof(pj_ice_sess_cand));
     }
@@ -1108,5 +1108,5 @@
 
 	    if (count) {
-		status = pj_turn_sock_set_perm(comp->turn_sock, count, 
+		status = pj_turn_sock_set_perm(comp->turn_sock, count,
 					       addrs, 0);
 		if (status != PJ_SUCCESS) {
@@ -1132,5 +1132,5 @@
  * Get valid pair.
  */
-PJ_DEF(const pj_ice_sess_check*) 
+PJ_DEF(const pj_ice_sess_check*)
 pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st,
 			     unsigned comp_id)
@@ -1138,8 +1138,8 @@
     PJ_ASSERT_RETURN(ice_st && comp_id && comp_id <= ice_st->comp_cnt,
 		     NULL);
-    
+
     if (ice_st->ice == NULL)
 	return NULL;
-    
+
     return ice_st->ice->comp[comp_id-1].valid_check;
 }
@@ -1171,5 +1171,4 @@
 					  int dst_addr_len)
 {
-    pj_ssize_t pkt_size;
     pj_ice_strans_comp *comp;
     unsigned def_cand;
@@ -1220,5 +1219,5 @@
 	    if (!comp->turn_log_off) {
 		/* Disable logging for Send/Data indications */
-		PJ_LOG(5,(ice_st->obj_name, 
+		PJ_LOG(5,(ice_st->obj_name,
 			  "Disabling STUN Indication logging for "
 			  "component %d", comp->comp_id));
@@ -1227,16 +1226,15 @@
 	    }
 
-	    status = pj_turn_sock_sendto(comp->turn_sock, 
-					 (const pj_uint8_t*)data, 
+	    status = pj_turn_sock_sendto(comp->turn_sock,
+					 (const pj_uint8_t*)data,
 					 (unsigned)data_len,
 					 dst_addr, dst_addr_len);
-	    return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 
+	    return (status==PJ_SUCCESS||status==PJ_EPENDING) ?
 		    PJ_SUCCESS : status;
 	} else {
-	    pkt_size = data_len;
-	    status = pj_stun_sock_sendto(comp->stun_sock, NULL, data, 
-					 (unsigned)data_len, 0, dst_addr, 
+	    status = pj_stun_sock_sendto(comp->stun_sock, NULL, data,
+					 (unsigned)data_len, 0, dst_addr,
 					 dst_addr_len);
-	    return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 
+	    return (status==PJ_SUCCESS||status==PJ_EPENDING) ?
 		    PJ_SUCCESS : status;
 	}
@@ -1266,6 +1264,6 @@
 	    char errmsg[PJ_ERR_MSG_SIZE];
 	    pj_strerror(status, errmsg, sizeof(errmsg));
-	    PJ_LOG(4,(ice_st->obj_name, 
-		      "ICE negotiation failed after %ds:%03d: %s", 
+	    PJ_LOG(4,(ice_st->obj_name,
+		      "ICE negotiation failed after %ds:%03d: %s",
 		      msec/1000, msec%1000, errmsg));
 	} else {
@@ -1277,5 +1275,5 @@
 	    };
 
-	    PJ_LOG(4,(ice_st->obj_name, 
+	    PJ_LOG(4,(ice_st->obj_name,
 		      "ICE negotiation success after %ds:%03d",
 		      msec/1000, msec%1000));
@@ -1289,7 +1287,7 @@
 		    char rip[PJ_INET6_ADDRSTRLEN+10];
 
-		    pj_sockaddr_print(&check->lcand->addr, lip, 
+		    pj_sockaddr_print(&check->lcand->addr, lip,
 				      sizeof(lip), 3);
-		    pj_sockaddr_print(&check->rcand->addr, rip, 
+		    pj_sockaddr_print(&check->rcand->addr, rip,
 				      sizeof(rip), 3);
 
@@ -1304,5 +1302,5 @@
 
 			/* Disable logging for Send/Data indications */
-			PJ_LOG(5,(ice_st->obj_name, 
+			PJ_LOG(5,(ice_st->obj_name,
 				  "Disabling STUN Indication logging for "
 				  "component %d", i+1));
@@ -1315,12 +1313,12 @@
 			      "sending from %s candidate %s to "
 			      "%s candidate %s",
-			      i+1, 
+			      i+1,
 			      pj_ice_get_cand_type_name(check->lcand->type),
 			      lip,
 			      pj_ice_get_cand_type_name(check->rcand->type),
 			      rip));
-			      
+
 		} else {
-		    PJ_LOG(4,(ice_st->obj_name, 
+		    PJ_LOG(4,(ice_st->obj_name,
 			      "Comp %d: disabled", i+1));
 		}
@@ -1332,8 +1330,8 @@
 
 	pj_log_push_indent();
-	(*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION, 
+	(*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION,
 				      status);
 	pj_log_pop_indent();
-	
+
     }
 
@@ -1344,6 +1342,6 @@
  * Callback called by ICE session when it wants to send outgoing packet.
  */
-static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 
-			      unsigned comp_id, 
+static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
+			      unsigned comp_id,
 			      unsigned transport_id,
 			      const void *pkt, pj_size_t size,
@@ -1362,7 +1360,7 @@
     comp = ice_st->comp[comp_id-1];
 
-    TRACE_PKT((comp->ice_st->obj_name, 
+    TRACE_PKT((comp->ice_st->obj_name,
 	       "Component %d TX packet to %s:%d with transport %d",
-	       comp_id, 
+	       comp_id,
 	       pj_sockaddr_print(dst_addr, daddr, sizeof(addr), 0),
 	       pj_sockaddr_get_port(dst_addr),
@@ -1371,6 +1369,6 @@
     if (transport_id == TP_TURN) {
 	if (comp->turn_sock) {
-	    status = pj_turn_sock_sendto(comp->turn_sock, 
-					 (const pj_uint8_t*)pkt, 
+	    status = pj_turn_sock_sendto(comp->turn_sock,
+					 (const pj_uint8_t*)pkt,
 					 (unsigned)size,
 					 dst_addr, dst_addr_len);
@@ -1379,5 +1377,5 @@
 	}
     } else if (transport_id == TP_STUN) {
-	status = pj_stun_sock_sendto(comp->stun_sock, NULL, 
+	status = pj_stun_sock_sendto(comp->stun_sock, NULL,
 				     pkt, (unsigned)size, 0,
 				     dst_addr, dst_addr_len);
@@ -1386,5 +1384,5 @@
 	status = PJ_EINVALIDOP;
     }
-    
+
     return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status;
 }
@@ -1393,6 +1391,6 @@
  * Callback called by ICE session when it receives application data.
  */
-static void ice_rx_data(pj_ice_sess *ice, 
-		        unsigned comp_id, 
+static void ice_rx_data(pj_ice_sess *ice,
+		        unsigned comp_id,
 			unsigned transport_id,
 		        void *pkt, pj_size_t size,
@@ -1405,5 +1403,5 @@
 
     if (ice_st->cb.on_rx_data) {
-	(*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size, 
+	(*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size,
 				 src_addr, src_addr_len);
     }
@@ -1411,5 +1409,5 @@
 
 /* Notification when incoming packet has been received from
- * the STUN socket. 
+ * the STUN socket.
  */
 static pj_bool_t stun_on_rx_data(pj_stun_sock *stun_sock,
@@ -1439,5 +1437,5 @@
 	 */
 	if (ice_st->cb.on_rx_data) {
-	    (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len, 
+	    (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len,
 				     src_addr, addr_len);
 	}
@@ -1446,10 +1444,10 @@
 
 	/* Hand over the packet to ICE session */
-	status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id, 
+	status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id,
 				       TP_STUN, pkt, pkt_len,
 				       src_addr, addr_len);
 
 	if (status != PJ_SUCCESS) {
-	    ice_st_perror(comp->ice_st, "Error processing packet", 
+	    ice_st_perror(comp->ice_st, "Error processing packet",
 			  status);
 	}
@@ -1460,5 +1458,5 @@
 
 /* Notifification when asynchronous send operation to the STUN socket
- * has completed. 
+ * has completed.
  */
 static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock,
@@ -1473,5 +1471,5 @@
 
 /* Notification when the status of the STUN transport has changed. */
-static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, 
+static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
 				pj_stun_sock_op op,
 				pj_status_t status)
@@ -1573,9 +1571,9 @@
 		}
 
-		PJ_LOG(4,(comp->ice_st->obj_name, 
+		PJ_LOG(4,(comp->ice_st->obj_name,
 			  "Comp %d: %s, "
 			  "srflx address is %s",
-			  comp->comp_id, op_name, 
-			  pj_sockaddr_print(&info.mapped_addr, ipaddr, 
+			  comp->comp_id, op_name,
+			  pj_sockaddr_print(&info.mapped_addr, ipaddr,
 					     sizeof(ipaddr), 3)));
 
@@ -1663,6 +1661,6 @@
 
 	if (status != PJ_SUCCESS) {
-	    ice_st_perror(comp->ice_st, 
-			  "Error processing packet from TURN relay", 
+	    ice_st_perror(comp->ice_st,
+			  "Error processing packet from TURN relay",
 			  status);
 	}
@@ -1722,6 +1720,6 @@
 	pj_sockaddr_cp(&cand->base_addr, &rel_info.relay_addr);
 	pj_sockaddr_cp(&cand->rel_addr, &rel_info.mapped_addr);
-	pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation, 
-			       PJ_ICE_CAND_TYPE_RELAYED, 
+	pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation,
+			       PJ_ICE_CAND_TYPE_RELAYED,
 			       &rel_info.relay_addr);
 	cand->status = PJ_SUCCESS;
@@ -1730,8 +1728,8 @@
 	comp->default_cand = (unsigned)(cand - comp->cand_list);
 
-	PJ_LOG(4,(comp->ice_st->obj_name, 
+	PJ_LOG(4,(comp->ice_st->obj_name,
 		  "Comp %d: TURN allocation complete, relay address is %s",
-		  comp->comp_id, 
-		  pj_sockaddr_print(&rel_info.relay_addr, ipaddr, 
+		  comp->comp_id,
+		  pj_sockaddr_print(&rel_info.relay_addr, ipaddr,
 				     sizeof(ipaddr), 3)));
 
