Index: pjproject/trunk/pjsip/build/pjsip_core.dsp
===================================================================
--- pjproject/trunk/pjsip/build/pjsip_core.dsp	(revision 118)
+++ pjproject/trunk/pjsip/build/pjsip_core.dsp	(revision 119)
@@ -125,11 +125,4 @@
 
 SOURCE=..\src\pjsip\sip_transaction.c
-
-!IF  "$(CFG)" == "pjsip_core - Win32 Release"
-
-!ELSEIF  "$(CFG)" == "pjsip_core - Win32 Debug"
-
-!ENDIF 
-
 # End Source File
 # Begin Source File
@@ -258,8 +251,4 @@
 
 # PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\include\pjsip\sip_msg_i.h
-# End Source File
 # End Group
 # Begin Source File
Index: pjproject/trunk/pjsip/include/pjsip/sip_msg.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_msg.h	(revision 118)
+++ pjproject/trunk/pjsip/include/pjsip/sip_msg.h	(revision 119)
@@ -717,5 +717,8 @@
  *      other list (or message). Otherwise Real Bad Thing will happen.
  */
-PJ_IDECL(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr );
+PJ_INLINE(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
+{
+    pj_list_insert_before(&msg->hdr, hdr);
+}
 
 /** 
@@ -728,5 +731,8 @@
  *      other list (or message). Otherwise Real Bad Thing will happen.
  */
-PJ_IDECL(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr );
+PJ_INLINE(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
+{
+    pj_list_insert_after(&msg->hdr, hdr);
+}
 
 /** 
@@ -1552,11 +1558,4 @@
  */
 
-/*
- * Include inline definitions.
- */
-#if PJ_FUNCTIONS_ARE_INLINED
-#  include <pjsip/sip_msg_i.h>
-#endif
-
 
 PJ_END_DECL
Index: pjproject/trunk/pjsip/include/pjsip/sip_msg_i.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_msg_i.h	(revision 118)
+++ 	(revision )
@@ -1,29 +1,0 @@
-/* $Id$ */
-/* 
- * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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 
- */
-
-PJ_IDEF(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
-{
-    pj_list_insert_before(&msg->hdr, hdr);
-}
-
-PJ_IDEF(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
-{
-    pj_list_insert_after(&msg->hdr, hdr);
-}
-
Index: pjproject/trunk/pjsip/include/pjsip/sip_uri.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_uri.h	(revision 118)
+++ pjproject/trunk/pjsip/include/pjsip/sip_uri.h	(revision 119)
@@ -106,5 +106,8 @@
  * @param pname_unres	Specification of allowed characters in pname.
  * @param pvalue_unres	Specification of allowed characters in pvalue.
- * @param sep		Separator character (either ';' or ',').
+ * @param sep		Separator character (either ';', ',', or '?').
+ *			When separator is set to '?', this function will
+ *			automatically adjust the separator character to
+ *			'&' after the first parameter is printed.
  *
  * @return		The number of bytes printed, or -1 on errr.
@@ -222,5 +225,5 @@
  * SIP and SIPS URL scheme.
  */
-typedef struct pjsip_url
+typedef struct pjsip_sip_uri
 {
     pjsip_uri_vptr *vptr;		/**< Pointer to virtual function table.*/
@@ -237,5 +240,5 @@
     pjsip_param	    other_param;	/**< Other parameters grouped together. */
     pjsip_param	    header_param;	/**< Optional header parameter. */
-} pjsip_url;
+} pjsip_sip_uri;
 
 
@@ -330,5 +333,5 @@
  * @return SIP URL.
  */
-PJ_DECL(pjsip_url*) pjsip_url_create( pj_pool_t *pool, int secure );
+PJ_DECL(pjsip_sip_uri*) pjsip_url_create( pj_pool_t *pool, int secure );
 
 /**
@@ -337,5 +340,5 @@
  * @return	    SIPS URL.
  */
-PJ_DECL(pjsip_url*) pjsips_url_create( pj_pool_t *pool );
+PJ_DECL(pjsip_sip_uri*) pjsips_url_create( pj_pool_t *pool );
 
 /**
@@ -343,5 +346,5 @@
  * @param url	    The URL.
  */
-PJ_DECL(void)  pjsip_url_init(pjsip_url *url, int secure);
+PJ_DECL(void)  pjsip_url_init(pjsip_sip_uri *url, int secure);
 
 /**
@@ -351,5 +354,6 @@
  * @param rhs	    The source URL.
  */
-PJ_DECL(void)  pjsip_url_assign(pj_pool_t *pool, pjsip_url *url, const pjsip_url *rhs);
+PJ_DECL(void)  pjsip_url_assign(pj_pool_t *pool, pjsip_sip_uri *url, 
+				const pjsip_sip_uri *rhs);
 
 /**
Index: pjproject/trunk/pjsip/src/pjsip-ua/sip_dialog.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip-ua/sip_dialog.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip-ua/sip_dialog.c	(revision 119)
@@ -413,5 +413,5 @@
     pjsip_contact_hdr *contact;
     pjsip_name_addr *name_addr;
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     unsigned flag;
     pjsip_event event;
@@ -446,5 +446,5 @@
     name_addr = (pjsip_name_addr *)dlg->local.info->uri;
     dlg->local.contact->uri = (pjsip_uri*) name_addr;
-    url = (pjsip_url*) name_addr->uri;
+    url = (pjsip_sip_uri*) name_addr->uri;
     //url->port = rdata->via->sent_by.port;
     //url->port = pj_sockaddr_get_port( pjsip_transport_get_local_addr(rdata->transport) );
Index: pjproject/trunk/pjsip/src/pjsip/sip_msg.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_msg.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_msg.c	(revision 119)
@@ -24,11 +24,4 @@
 #include <pj/pool.h>
 #include <pj/assert.h>
-
-/*
- * Include inline definitions here if functions are NOT inlined.
- */
-#if PJ_FUNCTIONS_ARE_INLINED==0
-#  include <pjsip/sip_msg_i.h>
-#endif
 
 const pjsip_method 
Index: pjproject/trunk/pjsip/src/pjsip/sip_parser.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 119)
@@ -155,7 +155,7 @@
 					        pj_pool_t *pool, 
                                                 unsigned option);
-static pjsip_url *  int_parse_sip_url( pj_scanner *scanner, 
-				       pj_pool_t *pool,
-				       pj_bool_t parse_params);
+static pjsip_sip_uri* int_parse_sip_url( pj_scanner *scanner, 
+				         pj_pool_t *pool,
+				         pj_bool_t parse_params);
 static pjsip_name_addr *
                     int_parse_name_addr( pj_scanner *scanner, 
@@ -954,21 +954,24 @@
     *pname = pj_str_unescape(pool, pname);
 
+    /* init pvalue */
+    pvalue->ptr = NULL;
+    pvalue->slen = 0;
+
     /* pvalue, if any */
     if (*scanner->curptr == '=') {
 	pj_scan_get_char(scanner);
-	/* pvalue can be a quoted string. */
-	if (*scanner->curptr == '"') {
-	    pj_scan_get_quote( scanner, '"', '"', pvalue);
-	    if (option & PJSIP_PARSE_REMOVE_QUOTE) {
-		pvalue->ptr++;
-		pvalue->slen -= 2;
+	if (!pj_scan_is_eof(scanner)) {
+	    /* pvalue can be a quoted string. */
+	    if (*scanner->curptr == '"') {
+		pj_scan_get_quote( scanner, '"', '"', pvalue);
+		if (option & PJSIP_PARSE_REMOVE_QUOTE) {
+		    pvalue->ptr++;
+		    pvalue->slen -= 2;
+		}
+	    } else if(pj_cis_match(&pjsip_PARAM_CHAR_SPEC, *scanner->curptr)) {
+		pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue);
+		*pvalue = pj_str_unescape(pool, pvalue);
 	    }
-	} else {
-	    pj_scan_get(scanner, &pjsip_PARAM_CHAR_SPEC, pvalue);
-	    *pvalue = pj_str_unescape(pool, pvalue);
-	}
-    } else {
-	pvalue->ptr = NULL;
-	pvalue->slen = 0;
+	}
     }
 }
@@ -997,12 +1000,17 @@
     *hname = pj_str_unescape(pool, hname);
 
+    /* Init hvalue */
+    hvalue->ptr = NULL;
+    hvalue->slen = 0;
+
     /* pvalue, if any */
     if (*scanner->curptr == '=') {
 	pj_scan_get_char(scanner);
-	pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hvalue);
-	*hvalue = pj_str_unescape(pool, hvalue);
-    } else {
-	hvalue->ptr = NULL;
-	hvalue->slen = 0;
+	if (!pj_scan_is_eof(scanner) && 
+	    pj_cis_match(&pjsip_HDR_CHAR_SPEC, *scanner->curptr))
+	{
+	    pj_scan_get(scanner, &pjsip_HDR_CHAR_SPEC, hvalue);
+	    *hvalue = pj_str_unescape(pool, hvalue);
+	}
     }
 }
@@ -1143,10 +1151,10 @@
 
 /* Parse "sip:" and "sips:" URI. */
-static pjsip_url *int_parse_sip_url( pj_scanner *scanner, 
-				     pj_pool_t *pool,
-				     pj_bool_t parse_params)
+static pjsip_sip_uri *int_parse_sip_url( pj_scanner *scanner, 
+					 pj_pool_t *pool,
+					 pj_bool_t parse_params)
 {
     pj_str_t scheme;
-    pjsip_url *url = NULL;
+    pjsip_sip_uri *url = NULL;
     int colon;
     int skip_ws = scanner->skip_ws;
Index: pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 119)
@@ -500,11 +500,18 @@
  * Register the transaction to the hash table.
  */
-static void mod_tsx_layer_register_tsx( pjsip_transaction *tsx)
+static pj_status_t mod_tsx_layer_register_tsx( pjsip_transaction *tsx)
 {
     pj_assert(tsx->transaction_key.slen != 0);
-    //pj_assert(tsx->state != PJSIP_TSX_STATE_NULL);
 
     /* Lock hash table mutex. */
     pj_mutex_lock(mod_tsx_layer.mutex);
+
+    /* Check if no transaction with the same key exists. */
+    if (pj_hash_get( mod_tsx_layer.htable, &tsx->transaction_key.ptr,
+		     tsx->transaction_key.slen) != NULL)
+    {
+	pj_mutex_unlock(mod_tsx_layer.mutex);
+	return PJ_EEXISTS;
+    }
 
     /* Register the transaction to the hash table. */
@@ -514,4 +521,6 @@
     /* Unlock mutex. */
     pj_mutex_unlock(mod_tsx_layer.mutex);
+
+    return PJ_SUCCESS;
 }
 
@@ -1051,5 +1060,10 @@
 
     /* Register transaction to hash table. */
-    mod_tsx_layer_register_tsx(tsx);
+    status = mod_tsx_layer_register_tsx(tsx);
+    if (status != PJ_SUCCESS) {
+	pj_assert(!"Bug in branch_param generator (i.e. not unique)");
+	tsx_destroy(tsx);
+	return status;
+    }
 
 
@@ -1160,6 +1174,9 @@
 
     /* Register the transaction. */
-    mod_tsx_layer_register_tsx(tsx);
-
+    status = mod_tsx_layer_register_tsx(tsx);
+    if (status != PJ_SUCCESS) {
+	tsx_destroy(tsx);
+	return status;
+    }
 
     /* Unlock transaction and return. */
@@ -1541,6 +1558,14 @@
     msec_time = (1 << (tsx->retransmit_count)) * PJSIP_T1_TIMEOUT;
 
-    if (msec_time>PJSIP_T2_TIMEOUT && tsx->method.id!=PJSIP_INVITE_METHOD)
-	msec_time = PJSIP_T2_TIMEOUT;
+    if (tsx->role == PJSIP_ROLE_UAC) {
+	/* Retransmission for non-INVITE transaction caps-off at T2 */
+	if (msec_time>PJSIP_T2_TIMEOUT && tsx->method.id!=PJSIP_INVITE_METHOD)
+	    msec_time = PJSIP_T2_TIMEOUT;
+    } else {
+	/* Retransmission of INVITE final response also caps-off at T2 */
+	pj_assert(tsx->status_code >= 200);
+	if (msec_time>PJSIP_T2_TIMEOUT)
+	    msec_time = PJSIP_T2_TIMEOUT;
+    }
 
     timeout.sec = msec_time / 1000;
Index: pjproject/trunk/pjsip/src/pjsip/sip_transport.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_transport.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_transport.c	(revision 119)
@@ -348,5 +348,6 @@
 {
 
-    PJ_ASSERT_RETURN(tdata && tdata->msg, "INVALID MSG");
+    if (tdata==NULL || tdata->msg==NULL)
+	return "INVALID MSG";
 
     if (tdata->info)
Index: pjproject/trunk/pjsip/src/pjsip/sip_uri.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_uri.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_uri.c	(revision 119)
@@ -112,4 +112,5 @@
 	}
 	p = p->next;
+	if (sep == '?') sep = '&';
     } while (p != param_list);
 
@@ -123,6 +124,6 @@
 #define IS_SIPS(url)	((url)->vptr==&sips_url_vptr)
 
-static const pj_str_t *pjsip_url_get_scheme( const pjsip_url* );
-static const pj_str_t *pjsips_url_get_scheme( const pjsip_url* );
+static const pj_str_t *pjsip_url_get_scheme( const pjsip_sip_uri* );
+static const pj_str_t *pjsips_url_get_scheme( const pjsip_sip_uri* );
 static const pj_str_t *pjsip_name_addr_get_scheme( const pjsip_name_addr * );
 static void *pjsip_get_uri( pjsip_uri *uri );
@@ -147,9 +148,11 @@
 				     const pjsip_name_addr *naddr2);
 static int pjsip_url_print(  pjsip_uri_context_e context,
-			     const pjsip_url *url, 
+			     const pjsip_sip_uri *url, 
 			     char *buf, pj_size_t size);
 static int pjsip_url_compare( pjsip_uri_context_e context,
-			      const pjsip_url *url1, const pjsip_url *url2);
-static pjsip_url* pjsip_url_clone(pj_pool_t *pool, const pjsip_url *rhs);
+			      const pjsip_sip_uri *url1, 
+			      const pjsip_sip_uri *url2);
+static pjsip_sip_uri* pjsip_url_clone(pj_pool_t *pool, 
+				      const pjsip_sip_uri *rhs);
 
 static pjsip_uri_vptr sip_url_vptr = 
@@ -180,5 +183,5 @@
 };
 
-static const pj_str_t *pjsip_url_get_scheme(const pjsip_url *url)
+static const pj_str_t *pjsip_url_get_scheme(const pjsip_sip_uri *url)
 {
     PJ_UNUSED_ARG(url);
@@ -186,5 +189,5 @@
 }
 
-static const pj_str_t *pjsips_url_get_scheme(const pjsip_url *url)
+static const pj_str_t *pjsips_url_get_scheme(const pjsip_sip_uri *url)
 {
     PJ_UNUSED_ARG(url);
@@ -202,5 +205,5 @@
 }
 
-PJ_DEF(void) pjsip_url_init(pjsip_url *url, int secure)
+PJ_DEF(void) pjsip_url_init(pjsip_sip_uri *url, int secure)
 {
     pj_memset(url, 0, sizeof(*url));
@@ -211,7 +214,7 @@
 }
 
-PJ_DEF(pjsip_url*) pjsip_url_create( pj_pool_t *pool, int secure )
-{
-    pjsip_url *url = pj_pool_alloc(pool, sizeof(pjsip_url));
+PJ_DEF(pjsip_sip_uri*) pjsip_url_create( pj_pool_t *pool, int secure )
+{
+    pjsip_sip_uri *url = pj_pool_alloc(pool, sizeof(pjsip_sip_uri));
     pjsip_url_init(url, secure);
     return url;
@@ -219,5 +222,5 @@
 
 static int pjsip_url_print(  pjsip_uri_context_e context,
-			     const pjsip_url *url, 
+			     const pjsip_sip_uri *url, 
 			     char *buf, pj_size_t size)
 {
@@ -226,6 +229,4 @@
     char *endbuf = buf+size;
     const pj_str_t *scheme;
-    pjsip_param *param;
-    char hparam_char = '?';
 
     *buf = '\0';
@@ -318,17 +319,16 @@
     buf += printed;
 
-    /* Header param. */
-    param = url->header_param.next;
-    while (param != &url->header_param) {
-	if (endbuf - buf < param->name.slen+2)
+    /* Header param. 
+     * Header param is only allowed in these contexts:
+     *	- PJSIP_URI_IN_CONTACT_HDR
+     *	- PJSIP_URI_IN_OTHER
+     */
+    if (context == PJSIP_URI_IN_CONTACT_HDR || context == PJSIP_URI_IN_OTHER) {
+	printed = pjsip_param_print_on(&url->header_param, buf, endbuf-buf,
+				       &pjsip_HDR_CHAR_SPEC, 
+				       &pjsip_HDR_CHAR_SPEC, '?');
+	if (printed < 0)
 	    return -1;
-	*buf++ = hparam_char;
-	copy_advance_escape(buf, param->name, pjsip_HDR_CHAR_SPEC);
-	if (param->value.slen) {
-	    *buf++ = '=';
-	    copy_advance_escape(buf, param->value, pjsip_HDR_CHAR_SPEC);
-	}
-	param = param->next;
-	hparam_char = '&';
+	buf += printed;
     }
 
@@ -338,6 +338,6 @@
 
 static pj_status_t pjsip_url_compare( pjsip_uri_context_e context,
-				      const pjsip_url *url1, 
-				      const pjsip_url *url2)
+				      const pjsip_sip_uri *url1, 
+				      const pjsip_sip_uri *url2)
 {
     const pjsip_param *p1;
@@ -466,6 +466,6 @@
 
 
-PJ_DEF(void) pjsip_url_assign(pj_pool_t *pool, pjsip_url *url, 
-			      const pjsip_url *rhs)
+PJ_DEF(void) pjsip_url_assign(pj_pool_t *pool, pjsip_sip_uri *url, 
+			      const pjsip_sip_uri *rhs)
 {
     pj_strdup( pool, &url->user, &rhs->user);
@@ -483,7 +483,7 @@
 }
 
-static pjsip_url* pjsip_url_clone(pj_pool_t *pool, const pjsip_url *rhs)
-{
-    pjsip_url *url = pj_pool_alloc(pool, sizeof(pjsip_url));
+static pjsip_sip_uri* pjsip_url_clone(pj_pool_t *pool, const pjsip_sip_uri *rhs)
+{
+    pjsip_sip_uri *url = pj_pool_alloc(pool, sizeof(pjsip_sip_uri));
     if (!url)
 	return NULL;
Index: pjproject/trunk/pjsip/src/pjsip/sip_util.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_util.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsip/sip_util.c	(revision 119)
@@ -113,8 +113,27 @@
     pjsip_msg_add_hdr(msg, (void*)param_cseq);
 
-    /* Add a blank Via header. */
+    /* Add a blank Via header in the front of the message. */
     via = pjsip_via_hdr_create(tdata->pool);
     via->rport_param = 0;
     pjsip_msg_insert_first_hdr(msg, (void*)via);
+
+    /* Add header params as request headers */
+    if (PJSIP_URI_SCHEME_IS_SIP(param_target) || 
+	PJSIP_URI_SCHEME_IS_SIPS(param_target)) 
+    {
+	pjsip_sip_uri *uri = (pjsip_sip_uri*) pjsip_uri_get_uri(param_target);
+	pjsip_param *hparam;
+
+	hparam = uri->header_param.next;
+	while (hparam != &uri->header_param) {
+	    pjsip_generic_string_hdr *hdr;
+
+	    hdr = pjsip_generic_string_hdr_create_with_text(tdata->pool, 
+							    &hparam->name,
+							    &hparam->value);
+	    pjsip_msg_add_hdr(msg, (pjsip_hdr*)hdr);
+	    hparam = hparam->next;
+	}
+    }
 
     /* Create message body. */
@@ -637,5 +656,6 @@
 	    PJSIP_URI_SCHEME_IS_SIPS(topmost_route_uri))
 	{
-	    const pjsip_url *url = pjsip_uri_get_uri((void*)topmost_route_uri);
+	    const pjsip_sip_uri *url = 
+		pjsip_uri_get_uri((void*)topmost_route_uri);
 	    has_lr_param = url->lr_param;
 	} else {
@@ -674,5 +694,5 @@
     if (PJSIP_URI_SCHEME_IS_SIPS(target_uri)) {
 	pjsip_uri *uri = (pjsip_uri*) target_uri;
-	const pjsip_url *url = (const pjsip_url*)pjsip_uri_get_uri(uri);
+	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
 	dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE);
 	pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
@@ -683,5 +703,5 @@
     } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) {
 	pjsip_uri *uri = (pjsip_uri*) target_uri;
-	const pjsip_url *url = (const pjsip_url*)pjsip_uri_get_uri(uri);
+	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
 	pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
 	dest_info->addr.port = url->port;
Index: pjproject/trunk/pjsip/src/pjsua/main.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua/main.c	(revision 118)
+++ pjproject/trunk/pjsip/src/pjsua/main.c	(revision 119)
@@ -1109,5 +1109,5 @@
 	if (uri) {
 	    if (pj_stricmp2(pjsip_uri_get_scheme(uri), "sip")==0) {
-		pjsip_url *url = (pjsip_url*)pjsip_uri_get_uri(uri);
+		pjsip_sip_uri *url = (pjsip_sip_uri*)pjsip_uri_get_uri(uri);
 		if (url->user.slen)
 		    strncpy(global.user_id, url->user.ptr, url->user.slen);
Index: pjproject/trunk/pjsip/src/test-pjsip/msg_test.c
===================================================================
--- pjproject/trunk/pjsip/src/test-pjsip/msg_test.c	(revision 118)
+++ pjproject/trunk/pjsip/src/test-pjsip/msg_test.c	(revision 119)
@@ -333,5 +333,5 @@
     pjsip_msg *msg;
     pjsip_name_addr *name_addr;
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     pjsip_fromto_hdr *fromto;
     pjsip_cid_hdr *cid;
@@ -538,5 +538,5 @@
     pjsip_route_hdr *route;
     pjsip_name_addr *name_addr;
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     pjsip_max_forwards_hdr *max_fwd;
     pjsip_to_hdr *to;
Index: pjproject/trunk/pjsip/src/test-pjsip/tsx_uas_test.c
===================================================================
--- pjproject/trunk/pjsip/src/test-pjsip/tsx_uas_test.c	(revision 118)
+++ pjproject/trunk/pjsip/src/test-pjsip/tsx_uas_test.c	(revision 119)
@@ -46,22 +46,29 @@
  ** TEST4_BRANCH_ID
  **	Transaction retransmits last response (if any) without notifying 
- **	transaction user upon receiving request  retransmissions on:
- **	    a. TRYING state.
- **	    a. PROCEEDING state.
- **	    b. COMPLETED state.
+ **	transaction user upon receiving request  retransmissions on TRYING
+ **	state
  **
  ** TEST5_BRANCH_ID
- **	INVITE transaction MUST retransmit final response. (Note: PJSIP also
- **	retransmit 2xx final response until it's terminated by user).
+ **	As above, in PROCEEDING state.
  **
  ** TEST6_BRANCH_ID
+ **	As above, in COMPLETED state, with first sending provisional response.
+ **
+ ** TEST7_BRANCH_ID
+ **	INVITE transaction MUST retransmit non-2xx final response.
+ **
+ ** TEST8_BRANCH_ID
+ **	As above, for INVITE's 2xx final response (this is PJSIP specific).
+ **
+ ** TEST9_BRANCH_ID
  **	INVITE transaction MUST cease retransmission of final response when
- *	ACK is received. (Note: PJSIP also retransmit 2xx final response 
- *	until it's terminated by user).
- **
- ** TEST7_BRANCH_ID
+ **	ACK is received. (Note: PJSIP also retransmit 2xx final response 
+ **	until it's terminated by user).
+ **     Transaction also MUST terminate in T4 seconds.
+ **
+ ** TEST10_BRANCH_ID
  **	Test where INVITE UAS transaction never receives ACK
  **
- ** TEST8_BRANCH_ID
+ ** TEST11_BRANCH_ID
  **	When UAS failed to deliver the response with the selected transport,
  **	it should try contacting the client with other transport or begin
@@ -73,5 +80,5 @@
  **	    c. COMPLETED state.
  **
- ** TEST9_BRANCH_ID
+ ** TEST12_BRANCH_ID
  **	Variant of previous test, where transaction fails to deliver the 
  **	response using any kind of transports. Transaction should report
@@ -87,4 +94,9 @@
 static char *TEST6_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test6";
 static char *TEST7_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test7";
+static char *TEST8_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test8";
+static char *TEST9_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test9";
+static char *TEST10_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test10";
+static char *TEST11_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test11";
+static char *TEST12_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test12";
 
 #define TEST1_STATUS_CODE	200
@@ -92,5 +104,25 @@
 #define TEST3_PROVISIONAL_CODE	PJSIP_SC_QUEUED
 #define TEST3_STATUS_CODE	202
-
+#define TEST4_STATUS_CODE	200
+#define TEST4_REQUEST_COUNT	2
+#define TEST5_PROVISIONAL_CODE	100
+#define TEST5_STATUS_CODE	200	
+#define TEST5_REQUEST_COUNT	2
+#define TEST5_RESPONSE_COUNT	2
+#define TEST6_PROVISIONAL_CODE	100
+#define TEST6_STATUS_CODE	200	/* Must be final */
+#define TEST6_REQUEST_COUNT	2
+#define TEST6_RESPONSE_COUNT	3
+#define TEST7_STATUS_CODE	301
+#define TEST8_STATUS_CODE	302
+
+
+#define TEST4_TITLE "test4: absorbing request retransmission"
+#define TEST5_TITLE "test5: retransmit last response in PROCEEDING state"
+#define TEST6_TITLE "test6: retransmit last response in COMPLETED state"
+
+
+#define TEST_TIMEOUT_ERROR	-30
+#define MAX_ALLOWED_DIFF	150
 
 static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e);
@@ -162,4 +194,5 @@
 };
 
+/* Timer callback to send response. */
 static void send_response_timer( pj_timer_heap_t *timer_heap,
 				 struct pj_timer_entry *entry)
@@ -180,4 +213,29 @@
 	PJ_LOG(3,(THIS_FILE,"    error: timer unable to send response"));
 	pjsip_tx_data_dec_ref(r->tdata);
+	return;
+    }
+}
+
+/* Utility to send response. */
+static void send_response( pjsip_rx_data *rdata,
+			   pjsip_transaction *tsx,
+			   int status_code )
+{
+    pj_status_t status;
+    pjsip_tx_data *tdata;
+
+    status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 
+					  &tdata);
+    if (status != PJ_SUCCESS) {
+	app_perror("    error: unable to create response", status);
+	test_complete = -196;
+	return;
+    }
+
+    status = pjsip_tsx_send_msg(tsx, tdata);
+    if (status != PJ_SUCCESS) {
+	app_perror("    error: unable to send response", status);
+	pjsip_tx_data_dec_ref(tdata);
+	test_complete = -197;
 	return;
     }
@@ -222,4 +280,47 @@
     }
 }
+
+
+/* Find and terminate tsx with the specified key. */
+static void terminate_our_tsx(int status_code)
+{
+    pjsip_transaction *tsx;
+
+    tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE);
+    if (!tsx) {
+	PJ_LOG(3,(THIS_FILE,"    error: timer unable to find transaction"));
+	return;
+    }
+
+    pjsip_tsx_terminate(tsx, status_code);
+    pj_mutex_unlock(tsx->mutex);
+}
+
+/* Timer callback to terminate transaction. */
+static void terminate_tsx_timer( pj_timer_heap_t *timer_heap,
+				 struct pj_timer_entry *entry)
+{
+    terminate_our_tsx(entry->id);
+}
+
+
+/* Schedule timer to terminate transaction. */
+static void schedule_terminate_tsx( pjsip_transaction *tsx,
+				    int status_code,
+				    int msec_delay )
+{
+    pj_time_val delay;
+
+    delay.sec = 0;
+    delay.msec = msec_delay;
+    pj_time_val_normalize(&delay);
+
+    pj_assert(pj_strcmp(&tsx->transaction_key, &tsx_key)==0);
+    timer.user_data = NULL;
+    timer.id = status_code;
+    timer.cb = &terminate_tsx_timer;
+    pjsip_endpt_schedule_timer(endpt, &timer, &delay);
+}
+
 
 /*
@@ -332,4 +433,146 @@
 	}
 
+    } else
+    if (pj_strcmp2(&tsx->branch, TEST4_BRANCH_ID)==0) {
+	/*
+	 * TEST4_BRANCH_ID tests receiving retransmissions in TRYING state.
+	 */
+	if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+
+	    /* Check that status code is status_code. */
+	    if (tsx->status_code != TEST4_STATUS_CODE) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -120;
+	    }
+	    
+	    /* Previous state. */
+	    if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect prev_state"));
+		test_complete = -121;
+	    }
+
+	} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) 
+	{
+	    PJ_LOG(3,(THIS_FILE, "    error: unexpected state"));
+	    test_complete = -122;
+
+	}
+
+
+    } else
+    if (pj_strcmp2(&tsx->branch, TEST5_BRANCH_ID)==0) {
+	/*
+	 * TEST5_BRANCH_ID tests receiving retransmissions in PROCEEDING state
+	 */
+	if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+
+	    /* Check that status code is status_code. */
+	    if (tsx->status_code != TEST5_STATUS_CODE) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -130;
+	    }
+	    
+	    /* Previous state. */
+	    if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect prev_state"));
+		test_complete = -131;
+	    }
+
+	} else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) {
+
+	    /* Check status code. */
+	    if (tsx->status_code != TEST5_PROVISIONAL_CODE) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -132;
+	    }
+
+	} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) {
+	    PJ_LOG(3,(THIS_FILE, "    error: unexpected state"));
+	    test_complete = -133;
+
+	}
+
+    } else
+    if (pj_strcmp2(&tsx->branch, TEST6_BRANCH_ID)==0) {
+	/*
+	 * TEST6_BRANCH_ID tests receiving retransmissions in COMPLETED state
+	 */
+	if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+
+	    /* Check that status code is status_code. */
+	    if (tsx->status_code != TEST6_STATUS_CODE) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -140;
+	    }
+	    
+	    /* Previous state. */
+	    if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect prev_state"));
+		test_complete = -141;
+	    }
+
+	} else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING &&
+		   tsx->state != PJSIP_TSX_STATE_COMPLETED &&
+		   tsx->state != PJSIP_TSX_STATE_DESTROYED) 
+	{
+	    PJ_LOG(3,(THIS_FILE, "    error: unexpected state"));
+	    test_complete = -142;
+
+	}
+
+
+    } else
+    if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID)==0 ||
+	pj_strcmp2(&tsx->branch, TEST8_BRANCH_ID)==0) 
+    {
+	/*
+	 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test retransmission of
+	 * INVITE final response
+	 */
+	int code;
+
+	if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID) == 0)
+	    code = TEST7_STATUS_CODE;
+	else
+	    code = TEST8_STATUS_CODE;
+
+	if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+
+	    if (test_complete == 0)
+		test_complete = 1;
+
+	    /* Check status code. */
+	    if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -150;
+	    }
+	    
+	    /* Previous state. */
+	    if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect prev_state"));
+		test_complete = -151;
+	    }
+
+	} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) {
+
+	    /* Check that status code is status_code. */
+	    if (tsx->status_code != code) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect status code"));
+		test_complete = -152;
+	    }
+	    
+	    /* Previous state. */
+	    if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) {
+		PJ_LOG(3,(THIS_FILE, "    error: incorrect prev_state"));
+		test_complete = -153;
+	    }
+
+	} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED)  {
+
+	    PJ_LOG(3,(THIS_FILE, "    error: unexpected state"));
+	    test_complete = -154;
+
+	}
+
     }
 
@@ -344,4 +587,6 @@
     pj_strcpy(&tsx_key, &key);
 }
+
+#define DIFF(a,b)   ((a<b) ? (b-a) : (a-b))
 
 /*
@@ -372,5 +617,4 @@
 	     */
 	    pjsip_transaction *tsx;
-	    pjsip_tx_data *tdata;
 
 	    status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx);
@@ -382,20 +626,5 @@
 
 	    save_key(tsx);
-
-	    status = pjsip_endpt_create_response(endpt, rdata, 
-						 status_code, NULL,
-						 &tdata);
-	    if (status != PJ_SUCCESS) {
-		app_perror("    error: unable to create response", status);
-		test_complete = -111;
-		return PJ_TRUE;
-	    }
-
-	    status = pjsip_tsx_send_msg(tsx, tdata);
-	    if (status != PJ_SUCCESS) {
-		app_perror("    error: unable to send response", status);
-		test_complete = -112;
-		return PJ_TRUE;
-	    }
+	    send_response(rdata, tsx, status_code);
 
 	} else {
@@ -428,5 +657,4 @@
 	     */
 	    pjsip_transaction *tsx;
-	    pjsip_tx_data *tdata;
 
 	    status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx);
@@ -439,20 +667,5 @@
 	    save_key(tsx);
 
-	    status = pjsip_endpt_create_response(endpt, rdata, 
-						 TEST3_PROVISIONAL_CODE, NULL,
-						 &tdata);
-	    if (status != PJ_SUCCESS) {
-		app_perror("    error: unable to create response", status);
-		test_complete = -121;
-		return PJ_TRUE;
-	    }
-
-	    status = pjsip_tsx_send_msg(tsx, tdata);
-	    if (status != PJ_SUCCESS) {
-		app_perror("    error: unable to send response", status);
-		test_complete = -122;
-		return PJ_TRUE;
-	    }
-
+	    send_response(rdata, tsx, TEST3_PROVISIONAL_CODE);
 	    schedule_send_response(rdata, &tsx->transaction_key, 
 				   TEST3_STATUS_CODE, 2000);
@@ -483,4 +696,253 @@
 	return PJ_TRUE;
 
+    } else if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0 ||
+	       pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0 ||
+	       pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) 
+    {
+
+	/* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state. */
+	/* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state. */
+	/* TEST6_BRANCH_ID: retransmit last response in COMPLETED state. */
+
+	if (msg->type == PJSIP_REQUEST_MSG) {
+	    /* On received response, create UAS. */
+	    pjsip_transaction *tsx;
+
+	    status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx);
+	    if (status != PJ_SUCCESS) {
+		app_perror("    error: unable to create transaction", status);
+		test_complete = -130;
+		return PJ_TRUE;
+	    }
+
+	    save_key(tsx);
+
+	    if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) {
+
+	    } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) {
+		send_response(rdata, tsx, TEST5_PROVISIONAL_CODE);
+
+	    } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) {
+		send_response(rdata, tsx, TEST6_PROVISIONAL_CODE);
+		send_response(rdata, tsx, TEST6_STATUS_CODE);
+	    }
+
+	} else {
+	    /* Verify the response received. */
+	    
+	    ++recv_count;
+
+	    if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) {
+		PJ_LOG(3,(THIS_FILE, "    error: not expecting response!"));
+		test_complete = -132;
+
+	    } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) {
+
+		if (rdata->msg_info.msg->line.status.code!=TEST5_PROVISIONAL_CODE) {
+		    PJ_LOG(3,(THIS_FILE, "    error: incorrect status code!"));
+		    test_complete = -133;
+
+		} 
+		if (recv_count > TEST5_RESPONSE_COUNT) {
+		    PJ_LOG(3,(THIS_FILE, "    error: not expecting response!"));
+		    test_complete = -134;
+		}
+
+	    } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) {
+
+		int code = rdata->msg_info.msg->line.status.code;
+
+		switch (recv_count) {
+		case 1:
+		    if (code != TEST6_PROVISIONAL_CODE) {
+			PJ_LOG(3,(THIS_FILE, "    error: invalid code!"));
+			test_complete = -135;
+		    }
+		    break;
+		case 2:
+		case 3:
+		    if (code != TEST6_STATUS_CODE) {
+			PJ_LOG(3,(THIS_FILE, "    error: invalid code!"));
+			test_complete = -136;
+		    }
+		    break;
+		default:
+		    PJ_LOG(3,(THIS_FILE, "    error: not expecting response"));
+		    test_complete = -137;
+		    break;
+		}
+	    }
+	}
+	return PJ_TRUE;
+
+
+    } else if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0 ||
+	       pj_strcmp2(&branch_param, TEST8_BRANCH_ID) == 0) 
+    {
+
+	/*
+	 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test the retransmission
+	 * of INVITE final response
+	 */
+	if (msg->type == PJSIP_REQUEST_MSG) {
+
+	    /* On received response, create UAS. */
+	    pjsip_transaction *tsx;
+
+	    status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx);
+	    if (status != PJ_SUCCESS) {
+		app_perror("    error: unable to create transaction", status);
+		test_complete = -140;
+		return PJ_TRUE;
+	    }
+
+	    save_key(tsx);
+
+	    if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) {
+
+		send_response(rdata, tsx, TEST7_STATUS_CODE);
+
+	    } else {
+
+		send_response(rdata, tsx, TEST8_STATUS_CODE);
+
+	    }
+
+	} else {
+	    int code;
+
+	    ++recv_count;
+
+	    if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0)
+		code = TEST7_STATUS_CODE;
+	    else
+		code = TEST8_STATUS_CODE;
+
+	    if (recv_count==1) {
+		
+		if (rdata->msg_info.msg->line.status.code != code) {
+		    PJ_LOG(3,(THIS_FILE,"    error: invalid status code"));
+		    test_complete = -141;
+		}
+
+		recv_last = rdata->pkt_info.timestamp;
+
+	    } else {
+
+		pj_time_val now;
+		unsigned msec, msec_expected;
+
+		now = rdata->pkt_info.timestamp;
+
+		PJ_TIME_VAL_SUB(now, recv_last);
+	    
+		msec = now.sec*1000 + now.msec;
+		msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT;
+		if (msec_expected > PJSIP_T2_TIMEOUT)
+		    msec_expected = PJSIP_T2_TIMEOUT;
+
+		if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) {
+		    PJ_LOG(3,(THIS_FILE,
+			      "    error: incorrect retransmission "
+			      "time (%d ms expected, %d ms received",
+			      msec_expected, msec));
+		    test_complete = -142;
+		}
+
+		if (recv_count > 11) {
+		    PJ_LOG(3,(THIS_FILE,"    error: too many responses (%d)",
+					recv_count));
+		    test_complete = -143;
+		}
+
+		recv_last = rdata->pkt_info.timestamp;
+	    }
+
+	}
+	return PJ_TRUE;
+
+    } else if (pj_strcmp2(&branch_param, TEST9_BRANCH_ID)) {
+
+	/*
+	 * TEST9_BRANCH_ID tests that the retransmission of INVITE final 
+	 * response should cease when ACK is received. Transaction also MUST
+	 * terminate in T4 seconds.
+	 */
+	if (msg->type == PJSIP_REQUEST_MSG) {
+
+	    /* On received response, create UAS. */
+	    pjsip_transaction *tsx;
+
+	    status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx);
+	    if (status != PJ_SUCCESS) {
+		app_perror("    error: unable to create transaction", status);
+		test_complete = -140;
+		return PJ_TRUE;
+	    }
+
+	    save_key(tsx);
+
+	    if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) {
+
+		send_response(rdata, tsx, TEST7_STATUS_CODE);
+
+	    } else {
+
+		send_response(rdata, tsx, TEST8_STATUS_CODE);
+
+	    }
+
+	} else {
+	    int code;
+
+	    ++recv_count;
+
+	    if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0)
+		code = TEST7_STATUS_CODE;
+	    else
+		code = TEST8_STATUS_CODE;
+
+	    if (recv_count==1) {
+		
+		if (rdata->msg_info.msg->line.status.code != code) {
+		    PJ_LOG(3,(THIS_FILE,"    error: invalid status code"));
+		    test_complete = -141;
+		}
+
+		recv_last = rdata->pkt_info.timestamp;
+
+	    } else {
+
+		pj_time_val now;
+		unsigned msec, msec_expected;
+
+		now = rdata->pkt_info.timestamp;
+
+		PJ_TIME_VAL_SUB(now, recv_last);
+	    
+		msec = now.sec*1000 + now.msec;
+		msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT;
+		if (msec_expected > PJSIP_T2_TIMEOUT)
+		    msec_expected = PJSIP_T2_TIMEOUT;
+
+		if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) {
+		    PJ_LOG(3,(THIS_FILE,
+			      "    error: incorrect retransmission "
+			      "time (%d ms expected, %d ms received",
+			      msec_expected, msec));
+		    test_complete = -142;
+		}
+
+		if (recv_count > 11) {
+		    PJ_LOG(3,(THIS_FILE,"    error: too many responses (%d)",
+					recv_count));
+		    test_complete = -143;
+		}
+
+		recv_last = rdata->pkt_info.timestamp;
+	    }
+
+	}
+	return PJ_TRUE;
     }
 
@@ -493,10 +955,13 @@
 static int perform_test( char *target_uri, char *from_uri, 
 			 char *branch_param, int test_time, 
-			 const pjsip_method *method )
+			 const pjsip_method *method,
+			 int request_cnt, int request_interval_msec,
+			 int expecting_timeout)
 {
     pjsip_tx_data *tdata;
     pj_str_t target, from;
     pjsip_via_hdr *via;
-    pj_time_val timeout;
+    pj_time_val timeout, next_send;
+    int sent_cnt;
     pj_status_t status;
 
@@ -527,15 +992,8 @@
     via->branch_param = pj_str(branch_param);
 
-    /* Add additional reference to tdata to prevent transaction from
-     * deleting it.
-     */
-    pjsip_tx_data_add_ref(tdata);
-
-    /* Send the first message. */
-    status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL);
-    if (status != PJ_SUCCESS) {
-	app_perror("   Error: unable to send request", status);
-	return -20;
-    }
+    /* Schedule first send. */
+    sent_cnt = 0;
+    pj_gettimeofday(&next_send);
+    pj_time_val_normalize(&next_send);
 
     /* Set test completion time. */
@@ -550,8 +1008,33 @@
 
 	pj_gettimeofday(&now);
+
+	if (sent_cnt < request_cnt && PJ_TIME_VAL_GTE(now, next_send)) {
+	    /* Add additional reference to tdata to prevent transaction from
+	     * deleting it.
+	     */
+	    pjsip_tx_data_add_ref(tdata);
+
+	    /* (Re)Send the request. */
+	    status = pjsip_endpt_send_request_stateless(endpt, tdata, 0, 0);
+	    if (status != PJ_SUCCESS) {
+		app_perror("   Error: unable to send request", status);
+		pjsip_tx_data_dec_ref(tdata);
+		return -20;
+	    }
+
+	    /* Schedule next send, if any. */
+	    sent_cnt++;
+	    if (sent_cnt < request_cnt) {
+		pj_gettimeofday(&next_send);
+		next_send.msec += request_interval_msec;
+		pj_time_val_normalize(&next_send);
+	    }
+	}
+
 	if (now.sec > timeout.sec) {
-	    PJ_LOG(3,(THIS_FILE, "   Error: test has timed out"));
+	    if (!expecting_timeout)
+		PJ_LOG(3,(THIS_FILE, "   Error: test has timed out"));
 	    pjsip_tx_data_dec_ref(tdata);
-	    return -30;
+	    return TEST_TIMEOUT_ERROR;
 	}
     }
@@ -613,5 +1096,5 @@
 			  TEST1_BRANCH_ID,
 			  33, /* Test duration must be greater than 32 secs */
-			  &pjsip_options_method);
+			  &pjsip_options_method, 1, 0, 0);
     if (status != 0)
 	return status;
@@ -623,5 +1106,5 @@
 			  TEST2_BRANCH_ID,
 			  33, /* Test duration must be greater than 32 secs */
-			  &pjsip_options_method);
+			  &pjsip_options_method, 1, 0, 0);
     if (status != 0)
 	return status;
@@ -647,7 +1130,86 @@
 			  TEST3_BRANCH_ID,
 			  35,
-			  &pjsip_options_method);
+			  &pjsip_options_method, 1, 0, 0);
+
     return status;
 }
+
+
+/*****************************************************************************
+ **
+ ** TEST4_BRANCH_ID: Absorbs retransmissions in TRYING state
+ ** TEST5_BRANCH_ID: Absorbs retransmissions in PROCEEDING state
+ ** TEST6_BRANCH_ID: Absorbs retransmissions in COMPLETED state
+ **
+ *****************************************************************************
+ */
+static int tsx_retransmit_last_response_test(const char *title,
+					     char *branch_id,
+					     int request_cnt,
+					     int status_code)
+{
+    int status;
+
+    PJ_LOG(3,(THIS_FILE,"  %s", title));
+
+    status = perform_test("sip:129.0.0.1;transport=loop-dgram",
+		          "sip:129.0.0.1;transport=loop-dgram",
+			  branch_id,
+			  5,
+			  &pjsip_options_method, 
+			  request_cnt, 1000, 1);
+    if (status && status != TEST_TIMEOUT_ERROR)
+	return status;
+    if (!status) {
+	PJ_LOG(3,(THIS_FILE, "   error: expecting timeout"));
+	return -31;
+    }
+
+    terminate_our_tsx(status_code);
+    flush_events(100);
+
+    if (test_complete != 1)
+	return test_complete;
+
+    flush_events(100);
+    return 0;
+}
+
+/*****************************************************************************
+ **
+ ** TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test
+ ** TEST8_BRANCH_ID: INVITE 2xx final response retransmission test
+ **
+ *****************************************************************************
+ */
+static int tsx_final_response_retransmission_test(void)
+{
+    int status;
+
+    PJ_LOG(3,(THIS_FILE,
+	      "  test7: INVITE non-2xx final response retransmission"));
+
+    status = perform_test("sip:129.0.0.1;transport=loop-dgram",
+		          "sip:129.0.0.1;transport=loop-dgram",
+			  TEST7_BRANCH_ID,
+			  33, /* Test duration must be greater than 32 secs */
+			  &pjsip_invite_method, 1, 0, 0);
+    if (status != 0)
+	return status;
+
+    PJ_LOG(3,(THIS_FILE,
+	      "  test8: INVITE 2xx final response retransmission"));
+
+    status = perform_test("sip:129.0.0.1;transport=loop-dgram",
+		          "sip:129.0.0.1;transport=loop-dgram",
+			  TEST8_BRANCH_ID,
+			  33, /* Test duration must be greater than 32 secs */
+			  &pjsip_invite_method, 1, 0, 0);
+    if (status != 0)
+	return status;
+
+    return 0;
+}
+
 
 
@@ -690,5 +1252,4 @@
     if (status != 0)
 	return status;
-#endif
 
     /* TEST3_BRANCH_ID: with provisional response
@@ -698,4 +1259,40 @@
 	return status;
 
+    /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state
+     */
+    status = tsx_retransmit_last_response_test(TEST4_TITLE,
+					       TEST4_BRANCH_ID, 
+					       TEST4_REQUEST_COUNT,
+					       TEST4_STATUS_CODE);
+    if (status != 0)
+	return status;
+
+    /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state
+     */
+    status = tsx_retransmit_last_response_test(TEST5_TITLE,
+					       TEST5_BRANCH_ID, 
+					       TEST5_REQUEST_COUNT,
+					       TEST5_STATUS_CODE);
+    if (status != 0)
+	return status;
+
+    /* TEST6_BRANCH_ID: retransmit last response in PROCEEDING state
+     */
+    status = tsx_retransmit_last_response_test(TEST6_TITLE,
+					       TEST6_BRANCH_ID, 
+					       TEST6_REQUEST_COUNT,
+					       TEST6_STATUS_CODE);
+    if (status != 0)
+	return status;
+
+    /* TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test
+     * TEST8_BRANCH_ID: INVITE 2xx final response retransmission test
+     */
+
+    status = tsx_final_response_retransmission_test();
+    if (status != 0)
+	return status;
+
+#endif
 
     pjsip_transport_dec_ref(loop);
Index: pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c
===================================================================
--- pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c	(revision 118)
+++ pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c	(revision 119)
@@ -30,5 +30,5 @@
  * This tests various core message creation functions. 
  */
-int txdata_test(void)
+static int core_txdata_test(void)
 {
     pj_status_t status;
@@ -36,4 +36,6 @@
     pjsip_rx_data dummy_rdata;
     pjsip_tx_data *invite, *invite2, *cancel, *response, *ack;
+
+    PJ_LOG(3,(THIS_FILE, "   core transmit data test"));
 
     /* Create INVITE request. */
@@ -322,2 +324,206 @@
 }
 
+/* This tests the request creating functions against the following
+ * requirements:
+ *  - header params in URI creates header in the request.
+ *  - method and headers params are correctly shown or hidden in
+ *    request URI, From, To, and Contact header.
+ */
+static int txdata_test_uri_params(void)
+{
+    char msgbuf[512];
+    pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201"
+			     "?X-Hdr-1=Header%201"
+			     "&X-Empty-Hdr=");
+    pj_str_t pname = pj_str("x-param");
+    pj_str_t hname = pj_str("X-Hdr-1");
+    pj_str_t hemptyname = pj_str("X-Empty-Hdr");
+    pjsip_from_hdr *from_hdr;
+    pjsip_to_hdr *to_hdr;
+    pjsip_contact_hdr *contact_hdr;
+    pjsip_generic_string_hdr *hdr;
+    pjsip_tx_data *tdata;
+    pjsip_sip_uri *uri;
+    pjsip_param *param;
+    pjsip_msg *msg;
+    int len;
+    pj_status_t status;
+
+    PJ_LOG(3,(THIS_FILE, "   header param in URI to create request"));
+
+    /* Create request with header param in target URI. */
+    status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
+					&target, &target, &target, NULL, -1,
+					NULL, &tdata);
+    if (status != 0) {
+	app_perror("   error: Unable to create request", status);
+	return -200;
+    }
+
+    /* Print and parse the request.
+     * We'll check that header params are not present in
+     */
+    len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf));
+    if (len < 1) {
+	PJ_LOG(3,(THIS_FILE, "   error: printing message"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -250;
+    }
+    msgbuf[len] = '\0';
+
+    PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n"
+			 "%s\n"
+			 "--end-msg--", len, msgbuf));
+
+    /* Now parse the message. */
+    msg = pjsip_parse_msg( tdata->pool, msgbuf, len, NULL);
+    if (msg == NULL) {
+	app_perror("   error: parsing message message", status);
+	pjsip_tx_data_dec_ref(tdata);
+	return -250;
+    }
+
+    /* Check the existence of port, other_param, and header param.
+     * Port is now allowed in To and From header.
+     */
+    /* Port in request URI. */
+    uri = (pjsip_sip_uri*) pjsip_uri_get_uri(msg->line.req.uri);
+    if (uri->port != 5061) {
+	PJ_LOG(3,(THIS_FILE, "   error: port not present in request URI"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -260;
+    }
+    /* other_param in request_uri */
+    param = pjsip_param_find(&uri->other_param, &pname);
+    if (param == NULL || pj_strcmp2(&param->value, "param 1") != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: x-param not present in request URI"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -261;
+    }
+    /* header param in request uri. */
+    if (!pj_list_empty(&uri->header_param)) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam in request URI"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -262;
+    }
+
+    /* Port in From header. */
+    from_hdr = (pjsip_from_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_FROM, NULL);
+    uri = (pjsip_sip_uri*) pjsip_uri_get_uri(from_hdr->uri);
+    if (uri->port != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: port most not exist in From header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -270;
+    }
+    /* other_param in From header */
+    param = pjsip_param_find(&uri->other_param, &pname);
+    if (param == NULL || pj_strcmp2(&param->value, "param 1") != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: x-param not present in From header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -271;
+    }
+    /* header param in From header. */
+    if (!pj_list_empty(&uri->header_param)) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam in From header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -272;
+    }
+
+
+    /* Port in To header. */
+    to_hdr = (pjsip_to_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_TO, NULL);
+    uri = (pjsip_sip_uri*) pjsip_uri_get_uri(to_hdr->uri);
+    if (uri->port != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: port most not exist in To header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -280;
+    }
+    /* other_param in To header */
+    param = pjsip_param_find(&uri->other_param, &pname);
+    if (param == NULL || pj_strcmp2(&param->value, "param 1") != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: x-param not present in To header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -281;
+    }
+    /* header param in From header. */
+    if (!pj_list_empty(&uri->header_param)) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam in To header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -282;
+    }
+
+
+
+    /* Port in Contact header. */
+    contact_hdr = (pjsip_contact_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
+    uri = (pjsip_sip_uri*) pjsip_uri_get_uri(contact_hdr->uri);
+    if (uri->port != 5061) {
+	PJ_LOG(3,(THIS_FILE, "   error: port not present in Contact header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -290;
+    }
+    /* other_param in Contact header */
+    param = pjsip_param_find(&uri->other_param, &pname);
+    if (param == NULL || pj_strcmp2(&param->value, "param 1") != 0) {
+	PJ_LOG(3,(THIS_FILE, "   error: x-param not present in Contact header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -291;
+    }
+    /* header param in Contact header. */
+    if (pj_list_empty(&uri->header_param)) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam is missing in Contact header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -292;
+    }
+    /* Check for X-Hdr-1 */
+    param = pjsip_param_find(&uri->header_param, &hname);
+    if (param == NULL || pj_strcmp2(&param->value, "Header 1")!=0) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam is missing in Contact header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -293;
+    }
+    /* Check for X-Empty-Hdr */
+    param = pjsip_param_find(&uri->header_param, &hemptyname);
+    if (param == NULL || pj_strcmp2(&param->value, "")!=0) {
+	PJ_LOG(3,(THIS_FILE, "   error: hparam is missing in Contact header"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -294;
+    }
+
+
+    /* Check that headers are present in the request. */
+    hdr = (pjsip_generic_string_hdr*) 
+	pjsip_msg_find_hdr_by_name(msg, &hname, NULL);
+    if (hdr == NULL || pj_strcmp2(&hdr->hvalue, "Header 1")!=0) {
+	PJ_LOG(3,(THIS_FILE, "   error: header X-Hdr-1 not created"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -300;
+    }
+
+    hdr = (pjsip_generic_string_hdr*) 
+	pjsip_msg_find_hdr_by_name(msg, &hemptyname, NULL);
+    if (hdr == NULL || pj_strcmp2(&param->value, "")!=0) {
+	PJ_LOG(3,(THIS_FILE, "   error: header X-Empty-Hdr not created"));
+	pjsip_tx_data_dec_ref(tdata);
+	return -330;
+    }
+
+    pjsip_tx_data_dec_ref(tdata);
+    return 0;
+}
+
+int txdata_test(void)
+{
+    int status;
+
+    status = core_txdata_test();
+    if (status  != 0)
+	return status;
+
+
+    status = txdata_test_uri_params();
+    if (status != 0)
+	return status;
+
+    return 0;
+}
Index: pjproject/trunk/pjsip/src/test-pjsip/uri_test.c
===================================================================
--- pjproject/trunk/pjsip/src/test-pjsip/uri_test.c	(revision 118)
+++ pjproject/trunk/pjsip/src/test-pjsip/uri_test.c	(revision 119)
@@ -318,5 +318,5 @@
 {
     /* "sip:localhost" */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2(pool, &url->host, "localhost");
@@ -327,5 +327,5 @@
 {
     /* "sip:user@localhost" */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2( pool, &url->user, "user");
@@ -338,5 +338,5 @@
 {
     /* "sip:user:password@localhost:5060" */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2( pool, &url->user, "user");
@@ -351,5 +351,5 @@
 {
     /* Like: "sip:localhost:5060", but without the port. */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2(pool, &url->host, "localhost");
@@ -360,5 +360,5 @@
 {
     /* "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK" */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2(pool, &url->host, "localhost");
@@ -387,5 +387,5 @@
        "?Subject=Hello%20There&Server=SIP%20Server" 
      */
-    pjsip_url *url = pjsip_url_create(pool, 0);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 0);
 
     pj_strdup2(pool, &url->host, "localhost");
@@ -406,5 +406,5 @@
 {
     /* "sips:localhost" */
-    pjsip_url *url = pjsip_url_create(pool, 1);
+    pjsip_sip_uri *url = pjsip_url_create(pool, 1);
 
     pj_strdup2(pool, &url->host, "localhost");
@@ -416,5 +416,5 @@
     /* "<sip:localhost>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -429,5 +429,5 @@
     /* "  Power Administrator <sips:localhost>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 1);
@@ -443,5 +443,5 @@
     /* " \"User\" <sip:user@localhost:5071>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -459,5 +459,5 @@
     /* " \"Strange User\\\"\\\\\\\"\" <sip:localhost>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -473,5 +473,5 @@
     /* " \"Rogue User\\\" <sip:localhost>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -487,5 +487,5 @@
     /* "Strange User\" <sip:localhost>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -500,5 +500,5 @@
 {
     /* "sip:localhost;pvalue=\"hello world\"" */
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     url = pjsip_url_create(pool, 0);
     pj_strdup2(pool, &url->host, "localhost");
@@ -512,5 +512,5 @@
     /* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@my_proxy09.my-domain.com:9801>" */
     pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
-    pjsip_url *url;
+    pjsip_sip_uri *url;
 
     url = pjsip_url_create(pool, 0);
@@ -528,5 +528,5 @@
 {
     /* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     url = pjsip_url_create(pool, 0);
     pj_strdup2(pool, &url->host, ALPHANUM "-_.com");
@@ -537,5 +537,5 @@
 {
     /* "sip:" USER_CHAR ":" PASS_CHAR "@host" */
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     url = pjsip_url_create(pool, 0);
     pj_strdup2(pool, &url->user, USER_CHAR);
@@ -548,5 +548,5 @@
 {
     /* "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21;lr;other=1;transport=sctp;other2" */
-    pjsip_url *url;
+    pjsip_sip_uri *url;
     url = pjsip_url_create(pool, 0);
     pj_strdup2(pool, &url->host, "host");
