Index: /pjproject/trunk/pjnath/build/Makefile
===================================================================
--- /pjproject/trunk/pjnath/build/Makefile	(revision 1881)
+++ /pjproject/trunk/pjnath/build/Makefile	(revision 1882)
@@ -32,5 +32,6 @@
 export PJNATH_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
 		errno.o ice_session.o ice_strans.o nat_detect.o stun_auth.o \
-		stun_msg.o stun_msg_dump.o stun_session.o stun_transaction.o
+		stun_msg.o stun_msg_dump.o stun_session.o stun_transaction.o \
+		turn_session.o turn_udp.o
 export PJNATH_CFLAGS += $(_CFLAGS)
 
@@ -46,21 +47,21 @@
 	
 ###############################################################################
-# Defines for building test client application
+# Defines for building TURN client application
 #
-export PJSTUN_CLIENT_SRCDIR = ../src/pjstun-client
-export PJSTUN_CLIENT_OBJS += client_main.o
-export PJSTUN_CLIENT_CFLAGS += $(_CFLAGS)
-export PJSTUN_CLIENT_LDFLAGS += $(_LDFLAGS)
-export PJSTUN_CLIENT_EXE:=../bin/pjstun-client-$(TARGET_NAME)$(HOST_EXE)
+export PJTURN_CLIENT_SRCDIR = ../src/pjturn-client
+export PJTURN_CLIENT_OBJS += client_main.o
+export PJTURN_CLIENT_CFLAGS += $(_CFLAGS)
+export PJTURN_CLIENT_LDFLAGS += $(_LDFLAGS)
+export PJTURN_CLIENT_EXE:=../bin/pjturn-client-$(TARGET_NAME)$(HOST_EXE)
 
 ###############################################################################
-# Defines for building test server application
+# Defines for building TURN server application
 #
-export PJSTUN_SRV_TEST_SRCDIR = ../src/pjstun-srv-test
-export PJSTUN_SRV_TEST_OBJS += 	bind_usage.o server.o turn_usage.o usage.o \
+export PJTURN_SRV_SRCDIR = ../src/pjturn-srv
+export PJTURN_SRV_OBJS += 	allocation.o auth.o listener_udp.o server.o \
 				main.o
-export PJSTUN_SRV_TEST_CFLAGS += $(_CFLAGS)
-export PJSTUN_SRV_TEST_LDFLAGS += $(_LDFLAGS)
-export PJSTUN_SRV_TEST_EXE:=../bin/pjstun-srv-test-$(TARGET_NAME)$(HOST_EXE)
+export PJTURN_SRV_CFLAGS += $(_CFLAGS)
+export PJTURN_SRV_LDFLAGS += $(_LDFLAGS)
+export PJTURN_SRV_EXE:=../bin/pjturn-srv-$(TARGET_NAME)$(HOST_EXE)
 
 	
@@ -72,6 +73,5 @@
 # $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
 #
-TARGETS := pjnath pjnath-test 
-#pjstun-client pjstun-srv-test
+TARGETS := pjnath pjnath-test pjturn-client pjturn-srv
 
 all: $(TARGETS)
@@ -91,9 +91,9 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH_TEST app=pjnath-test $(PJNATH_TEST_EXE)
 
-pjstun-client: $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJNATH_LIB)
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_CLIENT app=pjstun-client $(PJSTUN_CLIENT_EXE)
+pjturn-client: $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJNATH_LIB)
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_CLIENT app=pjturn-client $(PJTURN_CLIENT_EXE)
 
-pjstun-srv-test: $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJNATH_LIB)
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_SRV_TEST app=pjstun-srv-test $(PJSTUN_SRV_TEST_EXE)
+pjturn-srv: $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJNATH_LIB)
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_SRV app=pjturn-srv $(PJTURN_SRV_EXE)
 
 .PHONY: ../lib/pjnath.ko
@@ -109,22 +109,22 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH app=pjnath $@
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH_TEST app=pjnath-test $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_CLIENT app=pjstun-client $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_SRV_TEST app=pjstun-srv-test $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_CLIENT app=pjturn-client $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_SRV app=pjturn-srv $@
 
 realclean:
 	$(subst @@,$(subst /,$(HOST_PSEP),.pjnath-$(TARGET_NAME).depend),$(HOST_RMR))
 	$(subst @@,$(subst /,$(HOST_PSEP),.pjnath-test-$(TARGET_NAME).depend),$(HOST_RMR))
-	$(subst @@,$(subst /,$(HOST_PSEP),.pjstun-client-$(TARGET_NAME).depend),$(HOST_RMR))
-	$(subst @@,$(subst /,$(HOST_PSEP),.pjstun-srv-test-$(TARGET_NAME).depend),$(HOST_RMR))
+	$(subst @@,$(subst /,$(HOST_PSEP),.pjturn-client-$(TARGET_NAME).depend),$(HOST_RMR))
+	$(subst @@,$(subst /,$(HOST_PSEP),.pjturn-srv-$(TARGET_NAME).depend),$(HOST_RMR))
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH app=pjnath $@
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH_TEST app=pjnath-test $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_CLIENT app=pjstun-client $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_SRV_TEST app=pjstun-srv-test $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_CLIENT app=pjturn-client $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_SRV app=pjturn-srv $@
 
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH app=pjnath $@
 	$(MAKE) -f $(RULES_MAK) APP=PJNATH_TEST app=pjnath-test $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_CLIENT app=pjstun-client $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSTUN_SRV_TEST app=pjstun-srv-test $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_CLIENT app=pjturn-client $@
+	$(MAKE) -f $(RULES_MAK) APP=PJTURN_SRV app=pjturn-srv $@
 	echo '$(TEST_EXE): $(PJNATH_LIB)' >> .pjnath-test-$(TARGET_NAME).depend; \
 
Index: /pjproject/trunk/pjnath/src/pjnath/turn_session.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/turn_session.c	(revision 1881)
+++ /pjproject/trunk/pjnath/src/pjnath/turn_session.c	(revision 1882)
@@ -337,4 +337,5 @@
 	break;
     case PJ_TURN_STATE_DEALLOCATED:
+    case PJ_TURN_STATE_DESTROYING:
 	break;
     }
Index: /pjproject/trunk/pjnath/src/pjturn-client/client_main.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjturn-client/client_main.c	(revision 1881)
+++ /pjproject/trunk/pjnath/src/pjturn-client/client_main.c	(revision 1882)
@@ -67,5 +67,4 @@
 
 static int worker_thread(void *unused);
-static pj_status_t parse_addr(const char *input, pj_sockaddr_in *addr);
 static void turn_on_rx_data(pj_turn_udp *udp_rel,
 			    const pj_uint8_t *pkt,
@@ -319,37 +318,4 @@
 	g.udp_rel = NULL;
     }
-}
-
-static pj_status_t parse_addr(const char *input,
-			      pj_sockaddr_in *addr)
-{
-    const char *pos;
-    pj_str_t ip;
-    pj_uint16_t port;
-    pj_sockaddr tmp_addr;
-
-    pos = pj_ansi_strchr(input, ':');
-    if (pos==NULL) {
-	puts("Invalid format");
-	return -1;
-    }
-
-    ip.ptr = (char*)input;
-    ip.slen = pos - input;
-    port = (pj_uint16_t)atoi(pos+1);
-
-    if (port==0) {
-	puts("Invalid port");
-	return -1;
-    }
-
-    if (pj_sockaddr_in_init(&tmp_addr.ipv4, &ip, port)!=PJ_SUCCESS) {
-	puts("Invalid address");
-	return -1;
-    }
-
-    pj_memcpy(addr, &tmp_addr, sizeof(pj_sockaddr_in));
-
-    return PJ_SUCCESS;
 }
 
@@ -424,5 +390,6 @@
 
 	    strcpy(input, "Hello from client");
-	    status = pj_turn_udp_sendto(g.udp_rel, input, strlen(input)+1, 
+	    status = pj_turn_udp_sendto(g.udp_rel, (const pj_uint8_t*)input, 
+					strlen(input)+1, 
 					&peer->addr, 
 					pj_sockaddr_get_len(&peer->addr));
@@ -454,4 +421,8 @@
 	case '0':
 	case '1':
+	    if (g.udp_rel == NULL) {
+		puts("No relay");
+		break;
+	    }
 	    peer = &g.peer[input[0]-'0'];
 	    sprintf(input, "Hello from peer%d", input[0]-'0');
@@ -523,4 +494,5 @@
     if (pj_optind == argc) {
 	puts("Error: TARGET is needed");
+	usage();
 	return 1;
     }
Index: /pjproject/trunk/pjnath/src/pjturn-srv/auth.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjturn-srv/auth.c	(revision 1881)
+++ /pjproject/trunk/pjnath/src/pjturn-srv/auth.c	(revision 1882)
@@ -86,5 +86,5 @@
 					 const pj_str_t *username,
 					 pj_pool_t *pool,
-					 int *data_type,
+					 pj_stun_passwd_type *data_type,
 					 pj_str_t *data)
 {
@@ -96,5 +96,5 @@
 
     if (pj_stricmp2(realm, g_realm))
-	PJ_EINVAL;
+	return PJ_EINVAL;
 
     for (i=0; i<PJ_ARRAY_SIZE(g_cred); ++i) {
Index: /pjproject/trunk/pjnath/src/pjturn-srv/auth.h
===================================================================
--- /pjproject/trunk/pjnath/src/pjturn-srv/auth.h	(revision 1881)
+++ /pjproject/trunk/pjnath/src/pjturn-srv/auth.h	(revision 1882)
@@ -89,5 +89,5 @@
 					  const pj_str_t *username,
 					  pj_pool_t *pool,
-					  int *data_type,
+					  pj_stun_passwd_type *data_type,
 					  pj_str_t *data);
 
Index: /pjproject/trunk/pjnath/src/pjturn-srv/main.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjturn-srv/main.c	(revision 1881)
+++ /pjproject/trunk/pjnath/src/pjturn-srv/main.c	(revision 1882)
@@ -70,14 +70,15 @@
 	pj_turn_allocation *alloc = (pj_turn_allocation*) 
 				    pj_hash_this(srv->tables.alloc, it);
-	printf("%-3d %-22s %-22s %-8.*s %-4d %-4d %-4d %-4d\n",
+	printf("%-3d %-22s %-22s %-8.*s %-4d %-4ld %-4d %-4d\n",
 	       i,
 	       alloc->info,
 	       pj_sockaddr_print(&alloc->relay.hkey.addr, addr, sizeof(addr), 3),
 	       (int)alloc->cred.data.static_cred.username.slen,
-	       (int)alloc->cred.data.static_cred.username.ptr,
+	       alloc->cred.data.static_cred.username.ptr,
 	       alloc->relay.lifetime,
 	       alloc->relay.expiry.sec - now.sec,
 	       pj_hash_count(alloc->peer_table), 
 	       pj_hash_count(alloc->ch_table));
+
 	it = pj_hash_next(srv->tables.alloc, it);
 	++i;
