Index: pjproject/trunk/pjnath/src/pjnath/stun_session.c
===================================================================
--- pjproject/trunk/pjnath/src/pjnath/stun_session.c	(revision 1062)
+++ pjproject/trunk/pjnath/src/pjnath/stun_session.c	(revision 1080)
@@ -17,10 +17,10 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
-#include <pjlib-util/stun_session.h>
+#include <pjnath/stun_session.h>
 #include <pjlib.h>
 
 struct pj_stun_session
 {
-    pj_stun_endpoint	*endpt;
+    pj_stun_config	*cfg;
     pj_pool_t		*pool;
     pj_mutex_t		*mutex;
@@ -120,5 +120,5 @@
 
     /* Create pool and initialize basic tdata attributes */
-    pool = pj_pool_create(sess->endpt->pf, "tdata%p", 
+    pool = pj_pool_create(sess->cfg->pf, "tdata%p", 
 			  TDATA_POOL_SIZE, TDATA_POOL_INC, NULL);
     PJ_ASSERT_RETURN(pool, PJ_ENOMEM);
@@ -171,5 +171,5 @@
     }
     if (tdata->res_timer.id != PJ_FALSE) {
-	pj_timer_heap_cancel(tdata->sess->endpt->timer_heap, 
+	pj_timer_heap_cancel(tdata->sess->cfg->timer_heap, 
 			     &tdata->res_timer);
 	tdata->res_timer.id = PJ_FALSE;
@@ -224,6 +224,6 @@
 
     /* The server SHOULD include a SERVER attribute in all responses */
-    if (PJ_STUN_IS_RESPONSE(msg->hdr.type) ||
-	PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type)) 
+    if (sess->srv_name.slen && (PJ_STUN_IS_RESPONSE(msg->hdr.type) ||
+			        PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type))) 
     {
 	pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SERVER,
@@ -301,5 +301,5 @@
 /* **************************************************************************/
 
-PJ_DEF(pj_status_t) pj_stun_session_create( pj_stun_endpoint *endpt,
+PJ_DEF(pj_status_t) pj_stun_session_create( pj_stun_config *cfg,
 					    const char *name,
 					    const pj_stun_session_cb *cb,
@@ -311,14 +311,14 @@
     pj_status_t status;
 
-    PJ_ASSERT_RETURN(endpt && cb && p_sess, PJ_EINVAL);
+    PJ_ASSERT_RETURN(cfg && cb && p_sess, PJ_EINVAL);
 
     if (name==NULL)
 	name = "sess%p";
 
-    pool = pj_pool_create(endpt->pf, name, 4000, 4000, NULL);
+    pool = pj_pool_create(cfg->pf, name, 4000, 4000, NULL);
     PJ_ASSERT_RETURN(pool, PJ_ENOMEM);
 
     sess = PJ_POOL_ZALLOC_T(pool, pj_stun_session);
-    sess->endpt = endpt;
+    sess->cfg = cfg;
     sess->pool = pool;
     pj_memcpy(&sess->cb, cb, sizeof(*cb));
@@ -384,6 +384,9 @@
 						    const pj_str_t *srv_name)
 {
-    PJ_ASSERT_RETURN(sess && srv_name, PJ_EINVAL);
-    pj_strdup(sess->pool, &sess->srv_name, srv_name);
+    PJ_ASSERT_RETURN(sess, PJ_EINVAL);
+    if (srv_name)
+	pj_strdup(sess->pool, &sess->srv_name, srv_name);
+    else
+	sess->srv_name.slen = 0;
     return PJ_SUCCESS;
 }
@@ -490,12 +493,10 @@
     char buf[512];
     
-    if (dst->sa_family == PJ_AF_INET) {
-	const pj_sockaddr_in *dst4 = (const pj_sockaddr_in*)dst;
-	dst_name = pj_inet_ntoa(dst4->sin_addr);
-	dst_port = pj_ntohs(dst4->sin_port);
-    } else if (dst->sa_family == PJ_AF_INET6) {
-	const pj_sockaddr_in6 *dst6 = (const pj_sockaddr_in6*)dst;
+    if (dst->addr.sa_family == PJ_AF_INET) {
+	dst_name = pj_inet_ntoa(dst->ipv4.sin_addr);
+	dst_port = pj_ntohs(dst->ipv4.sin_port);
+    } else if (dst->addr.sa_family == PJ_AF_INET6) {
 	dst_name = "IPv6";
-	dst_port = pj_ntohs(dst6->sin6_port);
+	dst_port = pj_ntohs(dst->ipv6.sin6_port);
     } else {
 	LOG_ERR_(sess, "Invalid address family", PJ_EINVAL);
@@ -559,5 +560,5 @@
 
 	/* Create STUN client transaction */
-	status = pj_stun_client_tsx_create(sess->endpt, tdata->pool, 
+	status = pj_stun_client_tsx_create(sess->cfg, tdata->pool, 
 					   &tsx_cb, &tdata->client_tsx);
 	PJ_ASSERT_RETURN(status==PJ_SUCCESS, status);
@@ -593,8 +594,8 @@
 				&on_cache_timeout);
 
-	    timeout.sec = sess->endpt->res_cache_msec / 1000;
-	    timeout.msec = sess->endpt->res_cache_msec % 1000;
-
-	    status = pj_timer_heap_schedule(sess->endpt->timer_heap, 
+	    timeout.sec = sess->cfg->res_cache_msec / 1000;
+	    timeout.msec = sess->cfg->res_cache_msec % 1000;
+
+	    status = pj_timer_heap_schedule(sess->cfg->timer_heap, 
 					    &tdata->res_timer,
 					    &timeout);
@@ -830,5 +831,5 @@
     PJ_ASSERT_RETURN(sess && packet && pkt_size, PJ_EINVAL);
 
-    tmp_pool = pj_pool_create(sess->endpt->pf, "tmpstun", 1024, 1024, NULL);
+    tmp_pool = pj_pool_create(sess->cfg->pf, "tmpstun", 1024, 1024, NULL);
     if (!tmp_pool)
 	return PJ_ENOMEM;
