Index: pjproject/trunk/pjnath/src/pjturn-srv/allocation.c
===================================================================
--- pjproject/trunk/pjnath/src/pjturn-srv/allocation.c	(revision 1854)
+++ pjproject/trunk/pjnath/src/pjturn-srv/allocation.c	(revision 1877)
@@ -73,5 +73,5 @@
 				      const pj_uint8_t *pkt,
 				      unsigned pkt_len,
-				      const pj_stun_msg *msg,
+				      const pj_stun_rx_data *rdata,
 				      const pj_sockaddr_t *src_addr,
 				      unsigned src_addr_len);
@@ -98,8 +98,9 @@
 static pj_status_t parse_allocate_req(alloc_request *cfg,
 				      pj_stun_session *sess,
-				      const pj_stun_msg *req,
+				      const pj_stun_rx_data *rdata,
 				      const pj_sockaddr_t *src_addr,
 				      unsigned src_addr_len)
 {
+    const pj_stun_msg *req = rdata->msg;
     pj_stun_bandwidth_attr *attr_bw;
     pj_stun_req_transport_attr *attr_req_tp;
@@ -121,5 +122,6 @@
     /* Check if we can satisfy the bandwidth */
     if (cfg->bandwidth > MAX_CLIENT_BANDWIDTH) {
-	pj_stun_session_respond(sess, req, PJ_STUN_SC_ALLOCATION_QUOTA_REACHED,
+	pj_stun_session_respond(sess, rdata, 
+				PJ_STUN_SC_ALLOCATION_QUOTA_REACHED,
 			        "Invalid bandwidth", PJ_TRUE,
 				src_addr, src_addr_len);
@@ -131,5 +133,5 @@
 	          pj_stun_msg_find_attr(req, PJ_STUN_ATTR_REQ_TRANSPORT, 0);
     if (attr_req_tp == NULL) {
-	pj_stun_session_respond(sess, req, PJ_STUN_SC_BAD_REQUEST,
+	pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST,
 			        "Missing REQUESTED-TRANSPORT attribute", 
 				PJ_TRUE, src_addr, src_addr_len);
@@ -141,5 +143,5 @@
     /* Can only support UDP for now */
     if (cfg->tp_type != PJ_TURN_TP_UDP) {
-	pj_stun_session_respond(sess, req, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO,
+	pj_stun_session_respond(sess, rdata, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO,
 				NULL, PJ_TRUE, src_addr, src_addr_len);
 	return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO);
@@ -152,5 +154,5 @@
     if (attr_res_token) {
 	/* We don't support RESERVATION-TOKEN for now */
-	pj_stun_session_respond(sess, req, 
+	pj_stun_session_respond(sess, rdata, 
 				PJ_STUN_SC_BAD_REQUEST,
 				"RESERVATION-TOKEN is not supported", PJ_TRUE, 
@@ -164,5 +166,5 @@
     if (attr_rpp) {
 	/* We don't support REQUESTED-PROPS for now */
-	pj_stun_session_respond(sess, req, 
+	pj_stun_session_respond(sess, rdata, 
 				PJ_STUN_SC_BAD_REQUEST,
 				"REQUESTED-PROPS is not supported", PJ_TRUE, 
@@ -177,5 +179,5 @@
 	cfg->lifetime = attr_lifetime->value;
 	if (cfg->lifetime < MIN_LIFETIME) {
-	    pj_stun_session_respond(sess, req, PJ_STUN_SC_BAD_REQUEST,
+	    pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST,
 				    "LIFETIME too short", PJ_TRUE, 
 				    src_addr, src_addr_len);
@@ -195,5 +197,5 @@
 static pj_status_t send_allocate_response(pj_turn_allocation *alloc,
 					  pj_stun_session *srv_sess,
-					  const pj_stun_msg *msg)
+					  const pj_stun_rx_data *rdata)
 {
     pj_stun_tx_data *tdata;
@@ -201,5 +203,5 @@
 
     /* Respond the original ALLOCATE request */
-    status = pj_stun_session_create_res(srv_sess, msg, 0, NULL, &tdata);
+    status = pj_stun_session_create_res(srv_sess, rdata, 0, NULL, &tdata);
     if (status != PJ_SUCCESS)
 	return status;
@@ -285,9 +287,10 @@
 					      const pj_sockaddr_t *src_addr,
 					      unsigned src_addr_len,
-					      const pj_stun_msg *msg,
+					      const pj_stun_rx_data *rdata,
 					      pj_stun_session *srv_sess,
 					      pj_turn_allocation **p_alloc)
 {
     pj_turn_srv *srv = listener->server;
+    const pj_stun_msg *msg = rdata->msg;
     pj_pool_t *pool;
     alloc_request req;
@@ -298,5 +301,5 @@
 
     /* Parse ALLOCATE request */
-    status = parse_allocate_req(&req, srv_sess, msg, src_addr, src_addr_len);
+    status = parse_allocate_req(&req, srv_sess, rdata, src_addr, src_addr_len);
     if (status != PJ_SUCCESS)
 	return status;
@@ -355,5 +358,6 @@
 
     /* Attach authentication credential to STUN session */
-    pj_stun_session_set_credential(alloc->sess, &alloc->cred);
+    pj_stun_session_set_credential(alloc->sess, PJ_STUN_AUTH_LONG_TERM,
+				   &alloc->cred);
 
     /* Create the relay resource */
@@ -367,5 +371,5 @@
 
     /* Respond to ALLOCATE request */
-    status = send_allocate_response(alloc, srv_sess, msg);
+    status = send_allocate_response(alloc, srv_sess, rdata);
     if (status != PJ_SUCCESS)
 	goto on_error;
@@ -384,5 +388,5 @@
     /* Send reply to the ALLOCATE request */
     pj_strerror(status, str_tmp, sizeof(str_tmp));
-    pj_stun_session_respond(srv_sess, msg, PJ_STUN_SC_BAD_REQUEST, str_tmp, 
+    pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, 
 			    PJ_TRUE, src_addr, src_addr_len);
 
@@ -710,5 +714,5 @@
 /* Create and send error response */
 static void send_reply_err(pj_turn_allocation *alloc,
-			   const pj_stun_msg *req,
+			   const pj_stun_rx_data *rdata,
 			   pj_bool_t cache, 
 			   int code, const char *errmsg)
@@ -716,5 +720,5 @@
     pj_status_t status;
 
-    status = pj_stun_session_respond(alloc->sess, req, code, errmsg, cache,
+    status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, cache,
 				     &alloc->hkey.clt_addr,
 				     pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr));
@@ -727,5 +731,5 @@
 /* Create and send successful response */
 static void send_reply_ok(pj_turn_allocation *alloc,
-		          const pj_stun_msg *req)
+		          const pj_stun_rx_data *rdata)
 {
     pj_status_t status;
@@ -733,5 +737,5 @@
     pj_stun_tx_data *tdata;
 
-    status = pj_stun_session_create_res(alloc->sess, req, 0, NULL, &tdata);
+    status = pj_stun_session_create_res(alloc->sess, rdata, 0, NULL, &tdata);
     if (status != PJ_SUCCESS) {
 	alloc_err(alloc, "Error creating STUN success response", status);
@@ -1073,8 +1077,9 @@
 				      const pj_uint8_t *pkt,
 				      unsigned pkt_len,
-				      const pj_stun_msg *msg,
+				      const pj_stun_rx_data *rdata,
 				      const pj_sockaddr_t *src_addr,
 				      unsigned src_addr_len)
 {
+    const pj_stun_msg *msg = rdata->msg;
     pj_turn_allocation *alloc;
 
@@ -1089,5 +1094,5 @@
     if (alloc->relay.lifetime == 0) {
 	/* Reject with 437 if we're shutting down */
-	send_reply_err(alloc, msg, PJ_TRUE, 
+	send_reply_err(alloc, rdata, PJ_TRUE, 
 		       PJ_STUN_SC_ALLOCATION_MISMATCH, NULL);
 	return PJ_SUCCESS;
@@ -1116,5 +1121,5 @@
 
 	    /* Respond first */
-	    send_reply_ok(alloc, msg);
+	    send_reply_ok(alloc, rdata);
 
 	    /* Shutdown allocation */
@@ -1142,5 +1147,5 @@
 
 	    /* Send reply */
-	    send_reply_ok(alloc, msg);
+	    send_reply_ok(alloc, rdata);
 	}
 
@@ -1159,5 +1164,6 @@
 
 	if (!ch_attr || !peer_attr) {
-	    send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL);
+	    send_reply_err(alloc, rdata, PJ_TRUE, 
+			   PJ_STUN_SC_BAD_REQUEST, NULL);
 	    return PJ_SUCCESS;
 	}
@@ -1172,5 +1178,5 @@
 	    if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) {
 		/* Address mismatch. Send 400 */
-		send_reply_err(alloc, msg, PJ_TRUE, 
+		send_reply_err(alloc, rdata, PJ_TRUE, 
 			       PJ_STUN_SC_BAD_REQUEST, 
 			       "Peer address mismatch");
@@ -1191,5 +1197,5 @@
 				       pj_sockaddr_get_len(&peer_attr->sockaddr));
 	if (p2 && p2->channel != PJ_TURN_INVALID_CHANNEL) {
-	    send_reply_err(alloc, msg, 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;
@@ -1211,5 +1217,5 @@
 
 	/* Reply */
-	send_reply_ok(alloc, msg);
+	send_reply_ok(alloc, rdata);
 
 	return PJ_SUCCESS;
@@ -1218,10 +1224,11 @@
 
 	/* Respond with 437 (section 6.3 turn-07) */
-	send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_ALLOCATION_MISMATCH, NULL);
+	send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_ALLOCATION_MISMATCH,
+		       NULL);
 
     } else {
 
 	/* Respond with Bad Request? */
-	send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL);
+	send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL);
 
     }
