Index: pjproject/trunk/pjnath/src/pjturn-srv/allocation.c
===================================================================
--- pjproject/trunk/pjnath/src/pjturn-srv/allocation.c	(revision 4360)
+++ pjproject/trunk/pjnath/src/pjturn-srv/allocation.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 "turn.h"
@@ -63,6 +63,6 @@
 				pj_turn_relay_res *relay);
 static void destroy_relay(pj_turn_relay_res *relay);
-static void on_rx_from_peer(pj_ioqueue_key_t *key, 
-                            pj_ioqueue_op_key_t *op_key, 
+static void on_rx_from_peer(pj_ioqueue_key_t *key,
+                            pj_ioqueue_op_key_t *op_key,
                             pj_ssize_t bytes_read);
 static pj_status_t stun_on_send_msg(pj_stun_session *sess,
@@ -125,5 +125,5 @@
     /* Check if we can satisfy the bandwidth */
     if (cfg->bandwidth > MAX_CLIENT_BANDWIDTH) {
-	pj_stun_session_respond(sess, rdata, 
+	pj_stun_session_respond(sess, rdata,
 				PJ_STUN_SC_ALLOCATION_QUOTA_REACHED,
 			        "Invalid bandwidth", NULL, PJ_TRUE,
@@ -137,5 +137,5 @@
     if (attr_req_tp == NULL) {
 	pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST,
-			        "Missing REQUESTED-TRANSPORT attribute", 
+			        "Missing REQUESTED-TRANSPORT attribute",
 				NULL, PJ_TRUE, src_addr, src_addr_len);
 	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST);
@@ -157,7 +157,7 @@
     if (attr_res_token) {
 	/* We don't support RESERVATION-TOKEN for now */
-	pj_stun_session_respond(sess, rdata, 
+	pj_stun_session_respond(sess, rdata,
 				PJ_STUN_SC_BAD_REQUEST,
-				"RESERVATION-TOKEN is not supported", NULL, 
+				"RESERVATION-TOKEN is not supported", NULL,
 				PJ_TRUE, src_addr, src_addr_len);
 	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST);
@@ -171,5 +171,5 @@
 	if (cfg->lifetime < MIN_LIFETIME) {
 	    pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST,
-				    "LIFETIME too short", NULL, 
+				    "LIFETIME too short", NULL,
 				    PJ_TRUE, src_addr, src_addr_len);
 	    return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST);
@@ -207,5 +207,5 @@
     /* Add LIFETIME. */
     pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg,
-			      PJ_STUN_ATTR_LIFETIME, 
+			      PJ_STUN_ATTR_LIFETIME,
 			      (unsigned)alloc->relay.lifetime);
 
@@ -223,8 +223,8 @@
 				  &alloc->hkey.clt_addr,
 				  pj_sockaddr_get_len(&alloc->hkey.clt_addr));
-    
+
     /* Send the response */
     return pj_stun_session_send_msg(srv_sess, transport, PJ_TRUE,
-				    PJ_FALSE, &alloc->hkey.clt_addr, 
+				    PJ_FALSE, &alloc->hkey.clt_addr,
 				    pj_sockaddr_get_len(&alloc->hkey.clt_addr),
 				    tdata);
@@ -256,7 +256,7 @@
 
     /* Lookup the password */
-    status = pj_turn_get_password(NULL, NULL, &realm->value, 
-				  &user->value, alloc->pool, 
-				  &alloc->cred.data.static_cred.data_type, 
+    status = pj_turn_get_password(NULL, NULL, &realm->value,
+				  &user->value, alloc->pool,
+				  &alloc->cred.data.static_cred.data_type,
 				  &alloc->cred.data.static_cred.data);
     if (status != PJ_SUCCESS)
@@ -315,5 +315,5 @@
     pj_memcpy(&alloc->hkey.clt_addr, src_addr, src_addr_len);
 
-    status = pj_lock_create_recursive_mutex(pool, alloc->obj_name, 
+    status = pj_lock_create_recursive_mutex(pool, alloc->obj_name,
 					    &alloc->lock);
     if (status != PJ_SUCCESS) {
@@ -328,5 +328,5 @@
 
     /* Print info */
-    pj_ansi_strcpy(alloc->info, 
+    pj_ansi_strcpy(alloc->info,
 		   pj_turn_tp_type_name(transport->listener->tp_type));
     alloc->info[3] = ':';
@@ -372,7 +372,7 @@
 
     /* Done */
-    pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp, 
+    pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp,
 		      sizeof(str_tmp), 3);
-    PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s", 
+    PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s",
 	      alloc->info, pj_turn_tp_type_name(req.tp_type), str_tmp));
 
@@ -384,5 +384,5 @@
     /* Send reply to the ALLOCATE request */
     pj_strerror(status, str_tmp, sizeof(str_tmp));
-    pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, 
+    pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp,
 			    transport, PJ_TRUE, src_addr, src_addr_len);
 
@@ -397,5 +397,5 @@
 {
     if (relay->timer.id) {
-	pj_timer_heap_cancel(relay->allocation->server->core.timer_heap, 
+	pj_timer_heap_cancel(relay->allocation->server->core.timer_heap,
 			     &relay->timer);
 	relay->timer.id = PJ_FALSE;
@@ -483,6 +483,6 @@
 
 /* Initiate shutdown sequence for this allocation and start destroy timer.
- * Once allocation is marked as shutting down, any packets will be 
- * rejected/discarded 
+ * Once allocation is marked as shutting down, any packets will be
+ * rejected/discarded
  */
 static void alloc_shutdown(pj_turn_allocation *alloc)
@@ -502,5 +502,5 @@
 	 */
 	return;
-    } 
+    }
 
     pj_assert(alloc->relay.timer.id == TIMER_ID_NONE);
@@ -531,5 +531,5 @@
     pj_assert(alloc->relay.timer.id != TIMER_ID_DESTROY);
     if (alloc->relay.timer.id != 0) {
-	pj_timer_heap_cancel(alloc->server->core.timer_heap, 
+	pj_timer_heap_cancel(alloc->server->core.timer_heap,
 			     &alloc->relay.timer);
 	alloc->relay.timer.id = TIMER_ID_NONE;
@@ -540,5 +540,5 @@
 
     alloc->relay.timer.id = TIMER_ID_TIMEOUT;
-    status = pj_timer_heap_schedule(alloc->server->core.timer_heap, 
+    status = pj_timer_heap_schedule(alloc->server->core.timer_heap,
 				    &alloc->relay.timer, &delay);
     if (status != PJ_SUCCESS) {
@@ -566,6 +566,6 @@
 	e->id = TIMER_ID_NONE;
 
-	PJ_LOG(4,(alloc->obj_name, 
-		  "Client %s refresh timed-out, shutting down..", 
+	PJ_LOG(4,(alloc->obj_name,
+		  "Client %s refresh timed-out, shutting down..",
 		  alloc->info));
 
@@ -575,5 +575,5 @@
 	e->id = TIMER_ID_NONE;
 
-	PJ_LOG(4,(alloc->obj_name, "Client %s destroying..", 
+	PJ_LOG(4,(alloc->obj_name, "Client %s destroying..",
 		  alloc->info));
 
@@ -601,8 +601,8 @@
 
     pj_bzero(relay, sizeof(*relay));
-    
+
     relay->allocation = alloc;
     relay->tp.sock = PJ_INVALID_SOCKET;
-    
+
     /* TODO: get the requested address family from somewhere */
     af = alloc->transport->listener->addr.addr.sa_family;
@@ -622,8 +622,8 @@
     /* Lifetime and timeout */
     relay->lifetime = req->lifetime;
-    pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay, 
+    pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay,
 			&relay_timeout_cb);
     resched_timeout(alloc);
-    
+
     /* Transport type */
     relay->hkey.tp_type = req->tp_type;
@@ -677,5 +677,5 @@
 	pj_sockaddr_init(af, &bound_addr, NULL, port);
 
-	status = pj_sock_bind(relay->tp.sock, &bound_addr, 
+	status = pj_sock_bind(relay->tp.sock, &bound_addr,
 			      pj_sockaddr_get_len(&bound_addr));
 	if (status == PJ_SUCCESS)
@@ -685,5 +685,5 @@
     if (status != PJ_SUCCESS) {
 	/* Unable to allocate port */
-	PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d", 
+	PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d",
 		  status));
 	pj_sock_close(relay->tp.sock);
@@ -696,5 +696,5 @@
     status = pj_sock_getsockname(relay->tp.sock, &relay->hkey.addr, &namelen);
     if (status != PJ_SUCCESS) {
-	PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d", 
+	PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d",
 		  status));
 	pj_sock_close(relay->tp.sock);
@@ -703,5 +703,5 @@
     }
     if (!pj_sockaddr_has_addr(&relay->hkey.addr)) {
-	pj_sockaddr_copy_addr(&relay->hkey.addr, 
+	pj_sockaddr_copy_addr(&relay->hkey.addr,
 			      &alloc->transport->listener->addr);
     }
@@ -719,5 +719,5 @@
 				      relay, &icb, &relay->tp.key);
     if (status != PJ_SUCCESS) {
-	PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d", 
+	PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d",
 		  status));
 	pj_sock_close(relay->tp.sock);
@@ -737,10 +737,10 @@
 static void send_reply_err(pj_turn_allocation *alloc,
 			   const pj_stun_rx_data *rdata,
-			   pj_bool_t cache, 
+			   pj_bool_t cache,
 			   int code, const char *errmsg)
 {
     pj_status_t status;
 
-    status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL, 
+    status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL,
 				     cache, &alloc->hkey.clt_addr,
 				     pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr));
@@ -787,7 +787,7 @@
     }
 
-    status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE, 
-				      PJ_FALSE, &alloc->hkey.clt_addr,  
-				      pj_sockaddr_get_len(&alloc->hkey.clt_addr), 
+    status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE,
+				      PJ_FALSE, &alloc->hkey.clt_addr,
+				      pj_sockaddr_get_len(&alloc->hkey.clt_addr),
 				      tdata);
     if (status != PJ_SUCCESS) {
@@ -807,5 +807,5 @@
     perm = PJ_POOL_ZALLOC_T(alloc->pool, pj_turn_permission);
     pj_memcpy(&perm->hkey.peer_addr, peer_addr, addr_len);
-    
+
     perm->allocation = alloc;
     perm->channel = PJ_TURN_INVALID_CHANNEL;
@@ -815,6 +815,6 @@
 
     /* Register to hash table (only the address part!) */
-    pj_hash_set(alloc->pool, alloc->peer_table, 
-		pj_sockaddr_get_addr(&perm->hkey.peer_addr), 
+    pj_hash_set(alloc->pool, alloc->peer_table,
+		pj_sockaddr_get_addr(&perm->hkey.peer_addr),
 	        pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, perm);
 
@@ -835,11 +835,11 @@
 
     /* Remove from permission hash table */
-    pj_hash_set(NULL, alloc->peer_table, 
-		pj_sockaddr_get_addr(&perm->hkey.peer_addr), 
+    pj_hash_set(NULL, alloc->peer_table,
+		pj_sockaddr_get_addr(&perm->hkey.peer_addr),
 	        pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, NULL);
 
     /* Remove from channel hash table, if assigned a channel number */
     if (perm->channel != PJ_TURN_INVALID_CHANNEL) {
-	pj_hash_set(NULL, alloc->ch_table, &perm->channel, 
+	pj_hash_set(NULL, alloc->ch_table, &perm->channel,
 		    sizeof(perm->channel), 0, NULL);
     }
@@ -859,8 +859,8 @@
 
     /* Lookup in peer hash table */
-    perm = (pj_turn_permission*) 
-	   pj_hash_get(alloc->peer_table, 
+    perm = (pj_turn_permission*)
+	   pj_hash_get(alloc->peer_table,
 		       pj_sockaddr_get_addr(peer_addr),
-		       pj_sockaddr_get_addr_len(peer_addr), 
+		       pj_sockaddr_get_addr_len(peer_addr),
 		       NULL);
     return perm ? check_permission_expiry(perm) : NULL;
@@ -881,5 +881,5 @@
 }
 
-/* Update permission because of data from client to peer. 
+/* Update permission because of data from client to peer.
  * Return PJ_TRUE is permission is found.
  */
@@ -917,5 +917,5 @@
 	 * callbacks.
 	 *
-	 * Note: currently it is necessary to specify the 
+	 * Note: currently it is necessary to specify the
 	 * PJ_STUN_NO_FINGERPRINT_CHECK otherwise the FINGERPRINT
 	 * attribute inside STUN Send Indication message will mess up
@@ -930,5 +930,5 @@
 	status = pj_stun_session_on_rx_pkt(alloc->sess, pkt->pkt, pkt->len,
 					   options, NULL, &parsed_len,
-					   &pkt->src.clt_addr, 
+					   &pkt->src.clt_addr,
 					   pkt->src_addr_len);
 
@@ -963,5 +963,5 @@
 	if (alloc->transport->listener->tp_type == PJ_TURN_TP_UDP) {
 	    if (pkt->len < pj_ntohs(cd->length)+sizeof(*cd)) {
-		PJ_LOG(4,(alloc->obj_name, 
+		PJ_LOG(4,(alloc->obj_name,
 			  "ChannelData from %s discarded: UDP size error",
 			  alloc->info));
@@ -976,5 +976,5 @@
 	if (!perm) {
 	    /* Discard */
-	    PJ_LOG(4,(alloc->obj_name, 
+	    PJ_LOG(4,(alloc->obj_name,
 		      "ChannelData from %s discarded: ch#0x%x not found",
 		      alloc->info, pj_ntohs(cd->ch_number)));
@@ -999,5 +999,5 @@
 
 /*
- * Handle incoming packet from peer. This function is called by 
+ * Handle incoming packet from peer. This function is called by
  * on_rx_from_peer().
  */
@@ -1010,5 +1010,5 @@
 
     /* Lookup permission */
-    perm = lookup_permission_by_addr(alloc, src_addr, 
+    perm = lookup_permission_by_addr(alloc, src_addr,
 				     pj_sockaddr_get_len(src_addr));
     if (perm == NULL) {
@@ -1050,5 +1050,5 @@
 	pj_status_t status;
 
-	status = pj_stun_session_create_ind(alloc->sess, 
+	status = pj_stun_session_create_ind(alloc->sess,
 					    PJ_STUN_DATA_INDICATION, &tdata);
 	if (status != PJ_SUCCESS) {
@@ -1057,14 +1057,14 @@
 	}
 
-	pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 
+	pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg,
 				      PJ_STUN_ATTR_XOR_PEER_ADDR, PJ_TRUE,
 				      src_addr, pj_sockaddr_get_len(src_addr));
 	pj_stun_msg_add_binary_attr(tdata->pool, tdata->msg,
-				    PJ_STUN_ATTR_DATA, 
+				    PJ_STUN_ATTR_DATA,
 				    (const pj_uint8_t*)pkt, len);
 
-	pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE, 
-				 PJ_FALSE, &alloc->hkey.clt_addr, 
-				 pj_sockaddr_get_len(&alloc->hkey.clt_addr), 
+	pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE,
+				 PJ_FALSE, &alloc->hkey.clt_addr,
+				 pj_sockaddr_get_len(&alloc->hkey.clt_addr),
 				 tdata);
     }
@@ -1074,6 +1074,6 @@
  * ioqueue notification on RX packets from the relay socket.
  */
-static void on_rx_from_peer(pj_ioqueue_key_t *key, 
-                            pj_ioqueue_op_key_t *op_key, 
+static void on_rx_from_peer(pj_ioqueue_key_t *key,
+                            pj_ioqueue_op_key_t *op_key,
                             pj_ssize_t bytes_read)
 {
@@ -1097,5 +1097,5 @@
 	status = pj_ioqueue_recvfrom(key, op_key,
 				     rel->tp.rx_pkt, &bytes_read, 0,
-				     &rel->tp.src_addr, 
+				     &rel->tp.src_addr,
 				     &rel->tp.src_addr_len);
 
@@ -1157,5 +1157,5 @@
     if (alloc->relay.lifetime == 0) {
 	/* Reject with 437 if we're shutting down */
-	send_reply_err(alloc, rdata, PJ_TRUE, 
+	send_reply_err(alloc, rdata, PJ_TRUE,
 		       PJ_STUN_SC_ALLOCATION_MISMATCH, NULL);
 	return PJ_SUCCESS;
@@ -1163,6 +1163,6 @@
 
     if (msg->hdr.type == PJ_STUN_REFRESH_REQUEST) {
-	/* 
-	 * Handle REFRESH request 
+	/*
+	 * Handle REFRESH request
 	 */
 	pj_stun_lifetime_attr *lifetime;
@@ -1176,4 +1176,7 @@
 	bandwidth = (pj_stun_bandwidth_attr*)
 	            pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_BANDWIDTH, 0);
+
+	/* TODO: process bandwidth */
+	PJ_UNUSED_ARG(bandwidth);
 
 	if (lifetime && lifetime->value==0) {
@@ -1187,5 +1190,5 @@
 
 	    /* Shutdown allocation */
-	    PJ_LOG(4,(alloc->obj_name, 
+	    PJ_LOG(4,(alloc->obj_name,
 		      "Client %s request to dealloc, shutting down",
 		      alloc->info));
@@ -1197,5 +1200,5 @@
 	     * This is a refresh request.
 	     */
-	    
+
 	    /* Update lifetime */
 	    if (lifetime) {
@@ -1227,5 +1230,5 @@
 
 	if (!ch_attr || !peer_attr) {
-	    send_reply_err(alloc, rdata, PJ_TRUE, 
+	    send_reply_err(alloc, rdata, PJ_TRUE,
 			   PJ_STUN_SC_BAD_REQUEST, NULL);
 	    return PJ_SUCCESS;
@@ -1235,5 +1238,5 @@
 	p1 = lookup_permission_by_chnum(alloc, PJ_STUN_GET_CH_NB(ch_attr->value));
 
-	/* If permission is found, this is supposed to be a channel bind 
+	/* If permission is found, this is supposed to be a channel bind
 	 * refresh. Make sure it's for the same peer.
 	 */
@@ -1241,6 +1244,6 @@
 	    if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) {
 		/* Address mismatch. Send 400 */
-		send_reply_err(alloc, rdata, PJ_TRUE, 
-			       PJ_STUN_SC_BAD_REQUEST, 
+		send_reply_err(alloc, rdata, PJ_TRUE,
+			       PJ_STUN_SC_BAD_REQUEST,
 			       "Peer address mismatch");
 		return PJ_SUCCESS;
@@ -1263,5 +1266,5 @@
 				       pj_sockaddr_get_len(&peer_attr->sockaddr));
 	if (p2 && p2->channel != PJ_TURN_INVALID_CHANNEL) {
-	    send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, 
+	    send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST,
 			   "Peer address already assigned a channel number");
 	    return PJ_SUCCESS;
@@ -1281,5 +1284,5 @@
 	/* Register to hash table */
 	pj_assert(sizeof(p2->channel==2));
-	pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel, 
+	pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel,
 		    sizeof(p2->channel), 0, p2);
 
@@ -1368,5 +1371,5 @@
     /* Relay the data to peer */
     len = data_attr->length;
-    pj_sock_sendto(alloc->relay.tp.sock, data_attr->data, 
+    pj_sock_sendto(alloc->relay.tp.sock, data_attr->data,
 		   &len, 0, &peer_attr->sockaddr,
 		   pj_sockaddr_get_len(&peer_attr->sockaddr));
