[asterisk-scf-commits] asterisk-scf/release/pjproject.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Mar 22 07:08:44 CDT 2011


branch "master" has been updated
       via  58f0370234f9909ce64a2ccd2119898619814067 (commit)
       via  c280c62340844ede191fd8dbaf96fe36a0ada46a (commit)
       via  aac76109af0f8740b9b32f6459a02c0fc4bc8c29 (commit)
       via  8b80c1fc3380c940ba808a682e954671850c9df2 (commit)
       via  43d76d7843c50d7cb07cd34aa088569b9a753894 (commit)
       via  6b0facfda2b5a7968fe371af353a22f8af946066 (commit)
       via  6e75f807e8590a2bc1240b42b2a8239abdb7126b (commit)
       via  3b1bbd8b7e396ce050bef182a734f0ac2750e20f (commit)
      from  875f29e7faf0a0824da018a0eae18cad3226dffc (commit)

Summary of changes:
 pjsip/build/Makefile                               |    1 +
 pjsip/include/pjsip/sip_transport_tls.h            |    2 +-
 pjsip/include/pjsip/sip_types.h                    |    5 +-
 pjsip/misc/tlstestcert.pem                         |   32 +++
 pjsip/src/pjsip/sip_transport.c                    |    7 +
 pjsip/src/pjsip/sip_transport_tls.c                |  199 +++++++++++++-------
 pjsip/src/pjsua-lib/pjsua_core.c                   |   10 +-
 pjsip/src/test/test.c                              |    5 +
 pjsip/src/test/test.h                              |    5 +-
 pjsip/src/test/transport_tcp_test.c                |    2 +-
 pjsip/src/test/transport_tcp_test_v6.c             |    2 +-
 pjsip/src/test/transport_test.c                    |   14 +-
 .../{transport_tcp_test.c => transport_tls_test.c} |   68 ++++---
 ...sport_tcp_test_v6.c => transport_tls_test_v6.c} |   66 ++++---
 14 files changed, 275 insertions(+), 143 deletions(-)
 create mode 100644 pjsip/misc/tlstestcert.pem
 copy pjsip/src/test/{transport_tcp_test.c => transport_tls_test.c} (65%)
 copy pjsip/src/test/{transport_tcp_test_v6.c => transport_tls_test_v6.c} (65%)


- Log -----------------------------------------------------------------
commit 58f0370234f9909ce64a2ccd2119898619814067
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Mar 22 09:07:06 2011 -0300

    Remove unused variable.

diff --git a/pjsip/src/test/transport_tls_test.c b/pjsip/src/test/transport_tls_test.c
index d6e193b..6353405 100644
--- a/pjsip/src/test/transport_tls_test.c
+++ b/pjsip/src/test/transport_tls_test.c
@@ -32,7 +32,6 @@
 int transport_tls_test(void)
 {
     enum { SEND_RECV_LOOP = 8 };
-    const char ciphers[] = "eNULL";
     pjsip_tpfactory *tpfactory;
     pjsip_transport *tls;
     pj_sockaddr rem_addr;

commit c280c62340844ede191fd8dbaf96fe36a0ada46a
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Mar 22 09:03:48 2011 -0300

    Incorporate code review feedback.

diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c
index 67c73a7..7043dc1 100644
--- a/pjsip/src/pjsip/sip_transport_tls.c
+++ b/pjsip/src/pjsip/sip_transport_tls.c
@@ -458,9 +458,7 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 	    if (status != PJ_SUCCESS)
 		goto on_error;
 
-            pj_memcpy(pj_sockaddr_get_addr(listener_addr),
-		pj_sockaddr_get_addr(&hostip),
-		pj_sockaddr_get_addr_len(&hostip));
+	    pj_sockaddr_copy_addr(listener_addr, &hostip);
 	}
 
 	/* Save the address name */

commit aac76109af0f8740b9b32f6459a02c0fc4bc8c29
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Mar 16 17:57:30 2011 -0300

    Add a self signed certificate for the TLS tests and use it.

diff --git a/pjsip/misc/tlstestcert.pem b/pjsip/misc/tlstestcert.pem
new file mode 100644
index 0000000..32ba54c
--- /dev/null
+++ b/pjsip/misc/tlstestcert.pem
@@ -0,0 +1,32 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQDUc++AwwYFyF26wwY+X8U+PB6OKEBaNAxB4lNSQHCxIVxrEPYz
+UxU5IRa0zFMBUN2l/+wVkCwaPw8y+2kyYqhdXtA9/MdtwYW+iGj1q0RCtucqjQes
+PuGxMJiiot8656iFE9SMvu+KMpxDJnTDHej7USrcSgsNFwNYdYn9BZMqMQIDAQAB
+AoGAIKdlI3xWO6NNTLxXBFVCAsvIwn7LTVH8pE++EMFY0NDY3Jfxz3ewpmRAki9p
+fqVIPBB23+WV8b7JfkOIKrdhOxjt+G3OtFmIFpKiwaROK4Nv4iCv4dyI8yHHewyS
+IWhnBlJnTxOvnQyo6nvlW8b6XPODLeJJFiajNvDZ1P5DFnECQQDyeJG3aQEgNc9Q
+BwE7+5AuzC6A/IrxvAhN7E/0mYzX9gZ2JlDY6233xMHMK3r+vo+1OUiTjRy3qdZm
++BZg45QdAkEA4E6XQkPPtxTRVv+rhN2a+4Cgy2oKCViZSbAWs4dGdVgaMUWXIvfD
++92Z4ebim5dmP/ch+KWGC5mDLGmL9koqJQJAHNI0D+cNWTTMNaj/fo/Cba2bgX2D
+ToSZQBnszxhJY4o87mJTjdU+NwtONeSdNBaWomXyuIc3eKVZdNfcYRvsCQJAHC9j
+7EyvDhdMkrz/pWtfLRklm0nQxwneARdiUt69qMMQT36qFhfCBaT70Bn+AYUNsR3x
+o9fQtyZsCCmfD6yUDQJBAO4uXcIsNoUkgQrpdCuBGW4O4z1t7qKvVSuG7pOrstSu
+WlWqyHKihu2vdn/h+2WTZxBGas7LeN+J4YYgNfTZYu8=
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICwTCCAiqgAwIBAgIJAPrYGlpdQ19lMA0GCSqGSIb3DQEBBQUAMEoxCzAJBgNV
+BAYTAkNBMRYwFAYDVQQIEw1OZXcgQnJ1bnN3aWNrMRAwDgYDVQQHEwdNb25jdG9u
+MREwDwYDVQQDEwhUTFMgVGVzdDAgFw0xMTAzMTYyMDQ0MDRaGA8yMjg0MTIyOTIw
+NDQwNFowSjELMAkGA1UEBhMCQ0ExFjAUBgNVBAgTDU5ldyBCcnVuc3dpY2sxEDAO
+BgNVBAcTB01vbmN0b24xETAPBgNVBAMTCFRMUyBUZXN0MIGfMA0GCSqGSIb3DQEB
+AQUAA4GNADCBiQKBgQDUc++AwwYFyF26wwY+X8U+PB6OKEBaNAxB4lNSQHCxIVxr
+EPYzUxU5IRa0zFMBUN2l/+wVkCwaPw8y+2kyYqhdXtA9/MdtwYW+iGj1q0RCtucq
+jQesPuGxMJiiot8656iFE9SMvu+KMpxDJnTDHej7USrcSgsNFwNYdYn9BZMqMQID
+AQABo4GsMIGpMB0GA1UdDgQWBBQdhOx52xY5kpmKc/C/HDkfjcB06DB6BgNVHSME
+czBxgBQdhOx52xY5kpmKc/C/HDkfjcB06KFOpEwwSjELMAkGA1UEBhMCQ0ExFjAU
+BgNVBAgTDU5ldyBCcnVuc3dpY2sxEDAOBgNVBAcTB01vbmN0b24xETAPBgNVBAMT
+CFRMUyBUZXN0ggkA+tgaWl1DX2UwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUF
+AAOBgQBk23CJcNeZmwy1yiqnEKKvX0btySaKrWHBdPI+DW2mCFHK1RdrBfpyaWUb
+HZ0L6kYDdX96a2Z8NeezuxWkWGImDDvV0BZTD8xIlTusRCr0Q899Rk7NUVuc97tp
+DwofHQDkWiZeIHCsNjKdUgFaBH6P6jMA5OSNpUdF6Q7imxCjLA==
+-----END CERTIFICATE-----
diff --git a/pjsip/src/test/transport_tls_test.c b/pjsip/src/test/transport_tls_test.c
index 842070a..d6e193b 100644
--- a/pjsip/src/test/transport_tls_test.c
+++ b/pjsip/src/test/transport_tls_test.c
@@ -50,8 +50,8 @@ int transport_tls_test(void)
 
     /* Start TLS listener on arbitrary port. */
     pjsip_tls_setting_default(&tls_setting);
-    tls_setting.cert_file = pj_str("/home/jcolp/mycert.pem");
-    tls_setting.privkey_file = pj_str("/home/jcolp/mycert.pem");
+    tls_setting.cert_file = pj_str("../misc/tlstestcert.pem");
+    tls_setting.privkey_file = pj_str("../misc/tlstestcert.pem");
     status = pjsip_tls_transport_start(endpt, &tls_setting, (pj_sockaddr*)&local_addr, NULL, 1, &tpfactory);
     if (status != PJ_SUCCESS) {
 	app_perror("   Error: unable to start TLS transport", status);
diff --git a/pjsip/src/test/transport_tls_test_v6.c b/pjsip/src/test/transport_tls_test_v6.c
index c694db8..e2e16c9 100644
--- a/pjsip/src/test/transport_tls_test_v6.c
+++ b/pjsip/src/test/transport_tls_test_v6.c
@@ -44,8 +44,8 @@ int transport_tls_test_v6(void)
 
     /* Start TLS listener on arbitrary port. */
     pjsip_tls_setting_default(&tls_setting);
-    tls_setting.cert_file = pj_str("/home/jcolp/mycert.pem");
-    tls_setting.privkey_file = pj_str("/home/jcolp/mycert.pem");
+    tls_setting.cert_file = pj_str("../misc/tlstestcert.pem");
+    tls_setting.privkey_file = pj_str("../misc/tlstestcert.pem");
     status = pjsip_tls_transport_start(endpt, &tls_setting, NULL, NULL, 1, &tpfactory);
     if (status != PJ_SUCCESS) {
 	app_perror("   Error: unable to start TLS transport", status);

commit 8b80c1fc3380c940ba808a682e954671850c9df2
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Mar 16 12:38:07 2011 -0300

    Move TLS tests to their own section.

diff --git a/pjsip/src/test/test.c b/pjsip/src/test/test.c
index 757ef45..754e1d2 100644
--- a/pjsip/src/test/test.c
+++ b/pjsip/src/test/test.c
@@ -325,6 +325,9 @@ int test_main(void)
 #if INCLUDE_TCP_TEST
     DO_TEST(transport_tcp_test());
     DO_TEST(transport_tcp_test_v6());
+#endif
+
+#if INCLUDE_TLS_TEST
     DO_TEST(transport_tls_test());
     DO_TEST(transport_tls_test_v6());
 #endif
diff --git a/pjsip/src/test/test.h b/pjsip/src/test/test.h
index 4caffc8..b27a511 100644
--- a/pjsip/src/test/test.h
+++ b/pjsip/src/test/test.h
@@ -62,6 +62,7 @@ extern pjsip_endpoint *endpt;
 #define INCLUDE_UDP_TEST	INCLUDE_TRANSPORT_GROUP
 #define INCLUDE_LOOP_TEST	INCLUDE_TRANSPORT_GROUP
 #define INCLUDE_TCP_TEST	INCLUDE_TRANSPORT_GROUP
+#define INCLUDE_TLS_TEST        INCLUDE_TRANSPORT_GROUP
 #define INCLUDE_RESOLVE_TEST	INCLUDE_TRANSPORT_GROUP
 #define INCLUDE_TSX_TEST	INCLUDE_TSX_GROUP
 #define INCLUDE_INV_OA_TEST	INCLUDE_INV_GROUP

commit 43d76d7843c50d7cb07cd34aa088569b9a753894
Author: Joshua Colp <jcolp at digium.com>
Date:   Wed Mar 16 12:31:17 2011 -0300

    Add IPv6 support to the TLS transport. The test now passes.

diff --git a/pjsip/include/pjsip/sip_transport_tls.h b/pjsip/include/pjsip/sip_transport_tls.h
index c6692da..918c682 100644
--- a/pjsip/include/pjsip/sip_transport_tls.h
+++ b/pjsip/include/pjsip/sip_transport_tls.h
@@ -283,7 +283,7 @@ PJ_INLINE(void) pjsip_tls_setting_copy(pj_pool_t *pool,
  */
 PJ_DECL(pj_status_t) pjsip_tls_transport_start(pjsip_endpoint *endpt,
 					       const pjsip_tls_setting *opt,
-					       const pj_sockaddr_in *local,
+					       const pj_sockaddr *local,
 					       const pjsip_host_port *a_name,
 					       unsigned async_cnt,
 					       pjsip_tpfactory **p_factory);
diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c
index e501cf4..67c73a7 100644
--- a/pjsip/src/pjsip/sip_transport_tls.c
+++ b/pjsip/src/pjsip/sip_transport_tls.c
@@ -146,8 +146,8 @@ static pj_status_t tls_create(struct tls_listener *listener,
 			      pj_pool_t *pool,
 			      pj_ssl_sock_t *ssock, 
 			      pj_bool_t is_server,
-			      const pj_sockaddr_in *local,
-			      const pj_sockaddr_in *remote,
+			      const pj_sockaddr *local,
+			      const pj_sockaddr *remote,
 			      const pj_str_t *remote_name,
 			      struct tls_transport **p_tls);
 
@@ -164,11 +164,11 @@ static void tls_perror(const char *sender, const char *title,
 
 
 static void sockaddr_to_host_port( pj_pool_t *pool,
-				   pjsip_host_port *host_port,
-				   const pj_sockaddr_in *addr )
+    pjsip_host_port *host_port,
+    const pj_sockaddr *addr )
 {
     host_port->host.ptr = (char*) pj_pool_alloc(pool, PJ_INET6_ADDRSTRLEN+4);
-    pj_sockaddr_print(addr, host_port->host.ptr, PJ_INET6_ADDRSTRLEN+4, 2);
+    pj_sockaddr_print(addr, host_port->host.ptr, PJ_INET6_ADDRSTRLEN+4, 0);
     host_port->host.slen = pj_ansi_strlen(host_port->host.ptr);
     host_port->port = pj_sockaddr_get_port(addr);
 }
@@ -211,6 +211,60 @@ static void tls_init_shutdown(struct tls_transport *tls, pj_status_t status)
     pjsip_transport_dec_ref(&tls->base);
 }
 
+enum tls_v6_test_result {
+    TLS_V6_TEST_SUCCESS,
+    TLS_V6_TEST_FAIL_FALLBACK,
+    TLS_V6_TEST_FAIL_NO_FALLBACK
+};
+
+static enum tls_v6_test_result tls_v6_test(void)
+{
+    /* We made the assumption of pj_AF_INET6(), so let's
+     * do a quick check to be sure we actually can successfully
+     * bind to ::.
+     */
+    pj_sockaddr addr;
+    pj_sock_t sock;
+    pj_status_t status;
+    status = pj_sockaddr_init(pj_AF_INET6(), &addr, NULL, 0);
+    if (status != PJ_SUCCESS) {
+#if defined(PJ_WIN32) || defined(PJ_WINCE)
+	if (pj_get_native_netos_error() == WSAEAFNOSUPPORT) {
+#else
+	if (pj_get_native_netos_error() == EAFNOSUPPORT) {
+#endif
+	    return TLS_V6_TEST_FAIL_FALLBACK;
+	}
+	return TLS_V6_TEST_FAIL_NO_FALLBACK;
+     }
+     status = pj_sock_socket(pj_AF_INET6(), pj_SOCK_STREAM(), 0, &sock);
+     if (status != PJ_SUCCESS) {
+#if defined(PJ_WIN32) || defined( PJ_WINCE)
+	 if (pj_get_native_netos_error() == WSAEAFNOSUPPORT) {
+#else
+	 if (pj_get_native_netos_error() == EAFNOSUPPORT) {
+#endif
+	     return TLS_V6_TEST_FAIL_FALLBACK;
+	 }
+	 return TLS_V6_TEST_FAIL_NO_FALLBACK;
+     }
+     status = pj_sock_bind(sock, &addr, sizeof(pj_sockaddr_in6));
+     if (status != PJ_SUCCESS) {
+#if defined(PJ_WIN32) || (PJ_WINCE)
+	 if (pj_get_native_netos_error() == WSAEAFNOSUPPORT || pj_get_native_netos_error() == WSAEADDRNOTAVAIL) {
+#else
+	 if (pj_get_native_netos_error() == EAFNOSUPPORT || pj_get_native_netos_error() == EADDRNOTAVAIL) {
+#endif
+	     pj_sock_close(sock);
+	     return TLS_V6_TEST_FAIL_FALLBACK;
+	 }
+	 pj_sock_close(sock);
+	 return TLS_V6_TEST_FAIL_NO_FALLBACK;
+     }
+     pj_sock_close(sock);
+     return TLS_V6_TEST_SUCCESS;
+}
+	
 
 /****************************************************************************
  * The TLS listener/transport factory.
@@ -222,7 +276,7 @@ static void tls_init_shutdown(struct tls_transport *tls, pj_status_t status)
  */
 PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 					       const pjsip_tls_setting *opt,
-					       const pj_sockaddr_in *local,
+					       const pj_sockaddr *local,
 					       const pjsip_host_port *a_name,
 					       unsigned async_cnt,
 					       pjsip_tpfactory **p_factory)
@@ -230,21 +284,33 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
     pj_pool_t *pool;
     struct tls_listener *listener;
     pj_ssl_sock_param ssock_param;
-    pj_sockaddr_in *listener_addr;
+    pj_sockaddr *listener_addr;
     pj_bool_t has_listener;
     pj_status_t status;
+    pj_uint16_t af = local ? local->addr.sa_family : pj_AF_INET6();
 
     /* Sanity check */
     PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL);
 
+    if (!local)
+    {
+        enum tls_v6_test_result v6_works = tls_v6_test();
+        if (v6_works == TLS_V6_TEST_FAIL_FALLBACK) {
+            af = pj_AF_INET();
+        } else if (v6_works == TLS_V6_TEST_FAIL_NO_FALLBACK) {
+            return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
+        }
+    }
+
     /* Verify that address given in a_name (if any) is valid */
     if (a_name && a_name->host.slen) {
-	pj_sockaddr_in tmp;
+	pj_sockaddr tmp;
 
-	status = pj_sockaddr_in_init(&tmp, &a_name->host, 
+	status = pj_sockaddr_init(af, &tmp, &a_name->host, 
 				     (pj_uint16_t)a_name->port);
-	if (status != PJ_SUCCESS || tmp.sin_addr.s_addr == PJ_INADDR_ANY ||
-	    tmp.sin_addr.s_addr == PJ_INADDR_NONE)
+	if (status != PJ_SUCCESS || !pj_sockaddr_has_addr(&tmp) ||
+	    (af == pj_AF_INET() &&
+		tmp.ipv4.sin_addr.s_addr == PJ_INADDR_NONE))
 	{
 	    /* Invalid address */
 	    return PJ_EINVAL;
@@ -257,10 +323,10 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 
     listener = PJ_POOL_ZALLOC_T(pool, struct tls_listener);
     listener->factory.pool = pool;
-    listener->factory.type = PJSIP_TRANSPORT_TLS;
+    listener->factory.type = af == pj_AF_INET6() ? PJSIP_TRANSPORT_TLS6 : PJSIP_TRANSPORT_TLS;
     listener->factory.type_name = "tls";
     listener->factory.flag = 
-	pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_TLS);
+	pjsip_transport_get_flag_from_type(listener->factory.type);
 
     pj_ansi_strcpy(listener->factory.obj_name, "tlslis");
 
@@ -318,17 +384,18 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 	break;
     }
 
+    ssock_param.sock_af = af;
+
     /* Create SSL socket */
     status = pj_ssl_sock_create(pool, &ssock_param, &listener->ssock);
     if (status != PJ_SUCCESS)
 	goto on_error;
 
-    listener_addr = (pj_sockaddr_in*)&listener->factory.local_addr;
+    listener_addr = &listener->factory.local_addr;
     if (local) {
-	pj_sockaddr_cp((pj_sockaddr_t*)listener_addr, 
-		       (const pj_sockaddr_t*)local);
+	pj_sockaddr_cp(listener_addr, local);
     } else {
-	pj_sockaddr_in_init(listener_addr, NULL, 0);
+	pj_sockaddr_init(af, listener_addr, NULL, 0);
     }
 
     /* Check if certificate/CA list for SSL socket is set */
@@ -355,9 +422,7 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
      */
     has_listener = PJ_FALSE;
 
-    status = pj_ssl_sock_start_accept(listener->ssock, pool, 
-			  (pj_sockaddr_t*)listener_addr, 
-			  pj_sockaddr_get_len((pj_sockaddr_t*)listener_addr));
+    status = pj_ssl_sock_start_accept(listener->ssock, pool, listener_addr, pj_sockaddr_get_len(listener_addr));
     if (status == PJ_SUCCESS || status == PJ_EPENDING) {
 	pj_ssl_sock_info info;
 	has_listener = PJ_TRUE;
@@ -365,7 +430,7 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 	/* Retrieve the bound address */
 	status = pj_ssl_sock_get_info(listener->ssock, &info);
 	if (status == PJ_SUCCESS)
-	    pj_sockaddr_cp(listener_addr, (pj_sockaddr_t*)&info.local_addr);
+	    pj_sockaddr_cp(listener_addr, &info.local_addr);
     } else if (status != PJ_ENOTSUP) {
 	goto on_error;
     }
@@ -386,14 +451,16 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 	/* If the address returns 0.0.0.0, use the default
 	 * interface address as the transport's address.
 	 */
-	if (listener_addr->sin_addr.s_addr == 0) {
+	if (!pj_sockaddr_has_addr(listener_addr)) {
 	    pj_sockaddr hostip;
 
-	    status = pj_gethostip(pj_AF_INET(), &hostip);
+	    status = pj_gethostip(af, &hostip);
 	    if (status != PJ_SUCCESS)
 		goto on_error;
 
-	    listener_addr->sin_addr.s_addr = hostip.ipv4.sin_addr.s_addr;
+            pj_memcpy(pj_sockaddr_get_addr(listener_addr),
+		pj_sockaddr_get_addr(&hostip),
+		pj_sockaddr_get_addr_len(&hostip));
 	}
 
 	/* Save the address name */
@@ -403,7 +470,7 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start (pjsip_endpoint *endpt,
 
     /* If port is zero, get the bound port */
     if (listener->factory.addr_name.port == 0) {
-	listener->factory.addr_name.port = pj_ntohs(listener_addr->sin_port);
+	listener->factory.addr_name.port = pj_sockaddr_get_port(listener_addr);
     }
 
     pj_ansi_snprintf(listener->factory.obj_name, 
@@ -520,15 +587,15 @@ static pj_status_t tls_create( struct tls_listener *listener,
 			       pj_pool_t *pool,
 			       pj_ssl_sock_t *ssock,
 			       pj_bool_t is_server,
-			       const pj_sockaddr_in *local,
-			       const pj_sockaddr_in *remote,
+			       const pj_sockaddr *local,
+			       const pj_sockaddr *remote,
 			       const pj_str_t *remote_name,
 			       struct tls_transport **p_tls)
 {
     struct tls_transport *tls;
     const pj_str_t ka_pkt = PJSIP_TLS_KEEP_ALIVE_DATA;
     pj_status_t status;
-    
+    char remote_addr_str[PJ_INET6_ADDRSTRLEN];    
 
     PJ_ASSERT_RETURN(listener && ssock && local && remote && p_tls, PJ_EINVAL);
 
@@ -564,32 +631,31 @@ static pj_status_t tls_create( struct tls_listener *listener,
     if (remote_name)
 	pj_strdup(pool, &tls->remote_name, remote_name);
 
-    tls->base.key.type = PJSIP_TRANSPORT_TLS;
-    pj_memcpy(&tls->base.key.rem_addr, remote, sizeof(pj_sockaddr_in));
+    tls->base.key.type = local->addr.sa_family == pj_AF_INET6() ? PJSIP_TRANSPORT_TLS6 : PJSIP_TRANSPORT_TLS;
+    pj_memcpy(&tls->base.key.rem_addr, remote, pj_sockaddr_get_len(remote));
     tls->base.type_name = "tls";
-    tls->base.flag = pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_TLS);
+    tls->base.flag = pjsip_transport_get_flag_from_type(tls->base.key.type);
 
     tls->base.info = (char*) pj_pool_alloc(pool, 64);
-    pj_ansi_snprintf(tls->base.info, 64, "TLS to %s:%d",
-		     pj_inet_ntoa(remote->sin_addr), 
-		     (int)pj_ntohs(remote->sin_port));
+    pj_ansi_snprintf(tls->base.info, 64, "TLS to %s",
+	pj_sockaddr_print(remote, remote_addr_str, sizeof(remote_addr_str), 1 | 2));
 
-    tls->base.addr_len = sizeof(pj_sockaddr_in);
     tls->base.dir = is_server? PJSIP_TP_DIR_INCOMING : PJSIP_TP_DIR_OUTGOING;
     
     /* Set initial local address */
     if (!pj_sockaddr_has_addr(local)) {
         pj_sockaddr_cp(&tls->base.local_addr,
                        &listener->factory.local_addr);
+	tls->base.addr_len = pj_sockaddr_get_len(&listener->factory.local_addr);
     } else {
 	pj_sockaddr_cp(&tls->base.local_addr, local);
+	tls->base.addr_len = pj_sockaddr_get_len(local);
     }
     
-    sockaddr_to_host_port(pool, &tls->base.local_name, 
-			  (pj_sockaddr_in*)&tls->base.local_addr);
+    sockaddr_to_host_port(pool, &tls->base.local_name, &tls->base.local_addr);
     if (tls->remote_name.slen) {
 	tls->base.remote_name.host = tls->remote_name;
-	tls->base.remote_name.port = pj_sockaddr_in_get_port(remote);
+	tls->base.remote_name.port = pj_sockaddr_get_port(remote);
     } else {
 	sockaddr_to_host_port(pool, &tls->base.remote_name, remote);
     }
@@ -770,9 +836,10 @@ static pj_status_t tls_start_read(struct tls_transport *tls)
 {
     pj_pool_t *pool;
     pj_ssize_t size;
-    pj_sockaddr_in *rem_addr;
+    pj_sockaddr *rem_addr;
     void *readbuf[1];
     pj_status_t status;
+    char remote_addr_str[PJ_INET6_ADDRSTRLEN];
 
     /* Init rdata */
     pool = pjsip_endpt_create_pool(tls->base.endpt,
@@ -793,11 +860,11 @@ static pj_status_t tls_start_read(struct tls_transport *tls)
 			   sizeof(pj_ioqueue_op_key_t));
 
     tls->rdata.pkt_info.src_addr = tls->base.key.rem_addr;
-    tls->rdata.pkt_info.src_addr_len = sizeof(pj_sockaddr_in);
-    rem_addr = (pj_sockaddr_in*) &tls->base.key.rem_addr;
+    tls->rdata.pkt_info.src_addr_len = pj_sockaddr_get_len(&tls->base.key.rem_addr);
+    rem_addr = &tls->base.key.rem_addr;
     pj_ansi_strcpy(tls->rdata.pkt_info.src_name,
-		   pj_inet_ntoa(rem_addr->sin_addr));
-    tls->rdata.pkt_info.src_port = pj_ntohs(rem_addr->sin_port);
+	pj_sockaddr_print(rem_addr, remote_addr_str, sizeof(remote_addr_str), 2));
+    tls->rdata.pkt_info.src_port = pj_sockaddr_get_port(rem_addr);
 
     size = sizeof(tls->rdata.pkt_info.packet);
     readbuf[0] = tls->rdata.pkt_info.packet;
@@ -830,18 +897,22 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,
     pj_pool_t *pool;
     pj_ssl_sock_t *ssock;
     pj_ssl_sock_param ssock_param;
-    pj_sockaddr_in local_addr;
+    pj_sockaddr local_addr;
     pj_str_t remote_name;
     pj_status_t status;
+    pj_uint16_t rem_family = rem_addr->addr.sa_family;
 
     /* Sanity checks */
     PJ_ASSERT_RETURN(factory && mgr && endpt && rem_addr &&
 		     addr_len && p_transport, PJ_EINVAL);
 
     /* Check that address is a sockaddr_in */
-    PJ_ASSERT_RETURN(rem_addr->addr.sa_family == pj_AF_INET() &&
-		     addr_len == sizeof(pj_sockaddr_in), PJ_EINVAL);
+    PJ_ASSERT_RETURN((rem_family == pj_AF_INET() &&
+	    addr_len == sizeof(pj_sockaddr_in)) ||
+	(rem_family == pj_AF_INET6() &&
+	    addr_len == sizeof(pj_sockaddr_in6)), PJ_EINVAL);
 
+    pj_sockaddr_init(rem_family, &local_addr, NULL, 0);
 
     listener = (struct tls_listener*)factory;
 
@@ -895,6 +966,8 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,
 	break;
     }
 
+    ssock_param.sock_af = rem_family;
+
     status = pj_ssl_sock_create(pool, &ssock_param, &ssock);
     if (status != PJ_SUCCESS)
 	return status;
@@ -906,12 +979,9 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,
 	    return status;
     }
 
-    /* Initially set bind address to PJ_INADDR_ANY port 0 */
-    pj_sockaddr_in_init(&local_addr, NULL, 0);
-
     /* Create the transport descriptor */
     status = tls_create(listener, pool, ssock, PJ_FALSE, &local_addr, 
-			(pj_sockaddr_in*)rem_addr, &remote_name, &tls);
+			rem_addr, &remote_name, &tls);
     if (status != PJ_SUCCESS)
 	return status;
 
@@ -921,9 +991,9 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,
     /* Start asynchronous connect() operation */
     tls->has_pending_connect = PJ_TRUE;
     status = pj_ssl_sock_start_connect(tls->ssock, tls->base.pool, 
-				       (pj_sockaddr_t*)&local_addr,
-				       (pj_sockaddr_t*)rem_addr,
-				       addr_len);
+	(pj_sockaddr_t*)&local_addr,
+	(pj_sockaddr_t*)rem_addr,
+	addr_len);
     if (status == PJ_SUCCESS) {
 	on_connect_complete(tls->ssock, PJ_SUCCESS);
     } else if (status != PJ_EPENDING) {
@@ -958,7 +1028,7 @@ static pj_status_t lis_create_transport(pjsip_tpfactory *factory,
 	    }
 
 	    sockaddr_to_host_port(tls->base.pool, &tls->base.local_name,
-				  (pj_sockaddr_in*)&tls->base.local_addr);
+				  &tls->base.local_addr);
 	}
 
 	PJ_LOG(4,(tls->base.obj_name, 
@@ -1024,8 +1094,8 @@ static pj_bool_t on_accept_complete(pj_ssl_sock_t *ssock,
      * Create TLS transport for the new socket.
      */
     status = tls_create( listener, NULL, new_ssock, PJ_TRUE,
-			 (const pj_sockaddr_in*)&listener->factory.local_addr,
-			 (const pj_sockaddr_in*)src_addr, NULL, &tls);
+			 &listener->factory.local_addr,
+			 src_addr, NULL, &tls);
     
     if (status != PJ_SUCCESS)
 	return PJ_TRUE;
@@ -1175,7 +1245,7 @@ static pj_status_t tls_send_msg(pjsip_transport *transport,
     PJ_ASSERT_RETURN(tdata->op_key.tdata == NULL, PJSIP_EPENDINGTX);
     
     /* Check the address is supported */
-    PJ_ASSERT_RETURN(rem_addr && addr_len==sizeof(pj_sockaddr_in), PJ_EINVAL);
+    PJ_ASSERT_RETURN(rem_addr && addr_len==pj_sockaddr_get_len(rem_addr), PJ_EINVAL);
 
 
 
@@ -1350,7 +1420,7 @@ static pj_bool_t on_connect_complete(pj_ssl_sock_t *ssock,
 {
     struct tls_transport *tls;
     pj_ssl_sock_info ssl_info;
-    pj_sockaddr_in addr, *tp_addr;
+    pj_sockaddr addr, *tp_addr;
     pjsip_tp_state_callback state_cb;
     pj_bool_t is_shutdown;
 
@@ -1388,14 +1458,15 @@ static pj_bool_t on_connect_complete(pj_ssl_sock_t *ssock,
      * set is different now that the socket is connected (could happen
      * on some systems, like old Win32 probably?).
      */
-    tp_addr = (pj_sockaddr_in*)&tls->base.local_addr;
-    pj_sockaddr_cp((pj_sockaddr_t*)&addr, 
-		   (pj_sockaddr_t*)&ssl_info.local_addr);
-    if (tp_addr->sin_addr.s_addr != addr.sin_addr.s_addr) {
-	tp_addr->sin_addr.s_addr = addr.sin_addr.s_addr;
-	tp_addr->sin_port = addr.sin_port;
+    tp_addr = &tls->base.local_addr;
+    pj_sockaddr_cp(&addr, &ssl_info.local_addr);
+    if (pj_sockaddr_has_addr(&addr) && 
+	memcmp(pj_sockaddr_get_addr(tp_addr), pj_sockaddr_get_addr(&addr), pj_sockaddr_get_len(&addr)))
+    {
+	pj_sockaddr_copy_addr(tp_addr, &addr);
+	pj_sockaddr_set_port(tp_addr, pj_sockaddr_get_port(&addr));
 	sockaddr_to_host_port(tls->base.pool, &tls->base.local_name,
-			      tp_addr);
+	    tp_addr);
     }
 
     /* Server identity verification based on server certificate. */
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 88bdfbf..7ddfd59 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1876,7 +1876,7 @@ PJ_DEF(pj_status_t) pjsua_transport_create( pjsip_transport_type_e type,
 	pjsua_transport_config config;
 	pjsip_host_port a_name;
 	pjsip_tpfactory *tls;
-	pj_sockaddr_in local_addr;
+	pj_sockaddr local_addr;
 
 	/* Supply default config if it's not specified */
 	if (cfg == NULL) {
@@ -1886,13 +1886,13 @@ PJ_DEF(pj_status_t) pjsua_transport_create( pjsip_transport_type_e type,
 	}
 
 	/* Init local address */
-	pj_sockaddr_in_init(&local_addr, 0, 0);
+	pj_sockaddr_init(pj_AF_INET(), &local_addr, 0, 0);
 
 	if (cfg->port)
-	    local_addr.sin_port = pj_htons((pj_uint16_t)cfg->port);
+	    pj_sockaddr_set_port(&local_addr, cfg->port);
 
 	if (cfg->bound_addr.slen) {
-	    status = pj_sockaddr_in_set_str_addr(&local_addr,&cfg->bound_addr);
+	    status = pj_sockaddr_set_str_addr(pj_AF_INET(), &local_addr,&cfg->bound_addr);
 	    if (status != PJ_SUCCESS) {
 		pjsua_perror(THIS_FILE, 
 			     "Unable to resolve transport bound address", 

commit 6b0facfda2b5a7968fe371af353a22f8af946066
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Mar 15 19:44:05 2011 -0300

    Add test for IPv6 TLS.

diff --git a/pjsip/build/Makefile b/pjsip/build/Makefile
index 865c7b4..8589097 100644
--- a/pjsip/build/Makefile
+++ b/pjsip/build/Makefile
@@ -89,7 +89,7 @@ export TEST_OBJS += dlg_core_test.o dns_test.o msg_err_test.o \
 		    msg_logger.o msg_test.o multipart_test.o regc_test.o \
 		    test.o transport_loop_test.o transport_tcp_test.o transport_tcp_test_v6.o \
 		    transport_test.o transport_udp_test.o transport_udp_test_v6.o\
-		    transport_tls_test.o \
+		    transport_tls_test.o transport_tls_test_v6.o \
 		    tsx_basic_test.o tsx_bench.o tsx_uac_test.o \
 		    tsx_uas_test.o txdata_test.o uri_test.o \
 		    inv_offer_answer_test.o
diff --git a/pjsip/src/test/test.c b/pjsip/src/test/test.c
index dc8c1dc..757ef45 100644
--- a/pjsip/src/test/test.c
+++ b/pjsip/src/test/test.c
@@ -326,6 +326,7 @@ int test_main(void)
     DO_TEST(transport_tcp_test());
     DO_TEST(transport_tcp_test_v6());
     DO_TEST(transport_tls_test());
+    DO_TEST(transport_tls_test_v6());
 #endif
 
 #if INCLUDE_RESOLVE_TEST
diff --git a/pjsip/src/test/transport_tls_test_v6.c b/pjsip/src/test/transport_tls_test_v6.c
new file mode 100644
index 0000000..c694db8
--- /dev/null
+++ b/pjsip/src/test/transport_tls_test_v6.c
@@ -0,0 +1,157 @@
+/* $Id: transport_tls_test_v6.c 2638 2009-04-22 14:27:55Z nanang $ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny at 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 
+ */
+
+#include "test.h"
+#include <pjsip.h>
+#include <pjlib.h>
+
+#define THIS_FILE   "transport_tls_test_v6.c"
+
+
+/*
+ * TLS transport test.
+ */
+#if PJ_HAS_TCP
+int transport_tls_test_v6(void)
+{
+    enum { SEND_RECV_LOOP = 8 };
+    pjsip_tpfactory *tpfactory;
+    pjsip_transport *tls;
+    pj_sockaddr rem_addr;
+    pj_status_t status;
+    char url[PJSIP_MAX_URL_SIZE];
+    int rtt[SEND_RECV_LOOP], min_rtt;
+    int i, pkt_lost;
+    char rem_addr_str[PJ_INET6_ADDRSTRLEN];
+    pjsip_tls_setting tls_setting;
+
+    /* Start TLS listener on arbitrary port. */
+    pjsip_tls_setting_default(&tls_setting);
+    tls_setting.cert_file = pj_str("/home/jcolp/mycert.pem");
+    tls_setting.privkey_file = pj_str("/home/jcolp/mycert.pem");
+    status = pjsip_tls_transport_start(endpt, &tls_setting, NULL, NULL, 1, &tpfactory);
+    if (status != PJ_SUCCESS) {
+	app_perror("   Error: unable to start TLS transport", status);
+	return -10;
+    }
+
+    /* Get the listener address */
+    status = pj_sockaddr_init(pj_AF_INET6(), &rem_addr, &tpfactory->addr_name.host,
+				 (pj_uint16_t)tpfactory->addr_name.port);
+    if (status != PJ_SUCCESS) {
+	app_perror("   Error: possibly invalid TLS address name", status);
+	return -14;
+    }
+
+    pj_ansi_sprintf(url, "sip:alice@%s;transport=tls",
+            pj_sockaddr_print(&rem_addr, rem_addr_str, sizeof(rem_addr_str), 1 | 2));
+
+    /* Acquire one TLS transport. */
+    status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_TLS6, 
+					   &rem_addr, pj_sockaddr_get_len(&rem_addr),
+					   NULL, &tls);
+    if (status != PJ_SUCCESS || tls == NULL) {
+	app_perror("   Error: unable to acquire TLS transport", status);
+	return -17;
+    }
+
+    /* After pjsip_endpt_acquire_transport, TLS transport must have
+     * reference counter 1. 
+     */
+    if (pj_atomic_get(tls->ref_cnt) != 1)
+	return -20;
+
+    /* Test basic transport attributes */
+    status = generic_transport_test(tls);
+    if (status != PJ_SUCCESS)
+	return status;
+
+
+    /* Check again that reference counter is 1. */
+    if (pj_atomic_get(tls->ref_cnt) != 1)
+	return -40;
+
+    /* Load test */
+    if (transport_load_test(url, 500) != 0)
+	return -60;
+
+    /* Basic transport's send/receive loopback test. */
+    for (i=0; i<SEND_RECV_LOOP; ++i) {
+	status = transport_send_recv_test(PJSIP_TRANSPORT_TLS, tls, url, &rtt[i]);
+
+	if (status != 0) {
+	    pjsip_transport_dec_ref(tls);
+	    flush_events(500);
+	    return -72;
+	}
+    }
+
+    min_rtt = 0xFFFFFFF;
+    for (i=0; i<SEND_RECV_LOOP; ++i)
+	if (rtt[i] < min_rtt) min_rtt = rtt[i];
+
+    report_ival("tls-rtt-usec", min_rtt, "usec",
+		"Best TLS transport round trip time, in microseconds "
+		"(time from sending request until response is received. "
+		"Tests were performed on local machine only, and after "
+		"TLS socket has been established by previous test)");
+
+
+    /* Multi-threaded round-trip test. */
+    status = transport_rt_test(PJSIP_TRANSPORT_TLS, tls, url, &pkt_lost);
+    if (status != 0) {
+	pjsip_transport_dec_ref(tls);
+	return status;
+    }
+
+    if (pkt_lost != 0)
+	PJ_LOG(3,(THIS_FILE, "   note: %d packet(s) was lost", pkt_lost));
+
+    /* Check again that reference counter is still 1. */
+    if (pj_atomic_get(tls->ref_cnt) != 1)
+	return -80;
+
+    /* Destroy this transport. */
+    pjsip_transport_dec_ref(tls);
+
+    /* Force destroy this transport. */
+    status = pjsip_transport_destroy(tls);
+    if (status != PJ_SUCCESS)
+	return -90;
+
+    /* Unregister factory */
+    status = pjsip_tpmgr_unregister_tpfactory(pjsip_endpt_get_tpmgr(endpt), 
+					      tpfactory);
+    if (status != PJ_SUCCESS)
+	return -95;
+
+    /* Flush events. */
+    PJ_LOG(3,(THIS_FILE, "   Flushing events, 1 second..."));
+    flush_events(1000);
+
+    /* Done */
+    return 0;
+}
+#else	/* PJ_HAS_TCP */
+int transport_tls_test_v6(void)
+{
+    return 0;
+}
+#endif	/* PJ_HAS_TCP */

commit 6e75f807e8590a2bc1240b42b2a8239abdb7126b
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Mar 15 19:05:46 2011 -0300

    Add IPv6 TLS transport type to places where it is needed.

diff --git a/pjsip/include/pjsip/sip_types.h b/pjsip/include/pjsip/sip_types.h
index 717605d..83dd61d 100644
--- a/pjsip/include/pjsip/sip_types.h
+++ b/pjsip/include/pjsip/sip_types.h
@@ -92,7 +92,10 @@ typedef enum pjsip_transport_type_e
     PJSIP_TRANSPORT_UDP6 = PJSIP_TRANSPORT_UDP + PJSIP_TRANSPORT_IPV6,
 
     /** TCP over IPv6 */
-    PJSIP_TRANSPORT_TCP6 = PJSIP_TRANSPORT_TCP + PJSIP_TRANSPORT_IPV6
+    PJSIP_TRANSPORT_TCP6 = PJSIP_TRANSPORT_TCP + PJSIP_TRANSPORT_IPV6,
+
+    /** TLS over IPv6 */
+    PJSIP_TRANSPORT_TLS6 = PJSIP_TRANSPORT_TLS + PJSIP_TRANSPORT_IPV6
 
 } pjsip_transport_type_e;
 
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index 246abcd..b5b8e98 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -197,6 +197,13 @@ struct transport_names_t
 	"TCP IPv6 transport", 
 	PJSIP_TRANSPORT_RELIABLE
     },
+    {
+        PJSIP_TRANSPORT_TLS6,
+        5061,
+        {"TLS", 3},
+        "TLS IPv6 transport",
+        PJSIP_TRANSPORT_RELIABLE | PJSIP_TRANSPORT_SECURE
+    },
 };
 
 static void tp_state_callback(pjsip_transport *tp,
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index cfaa519..88bdfbf 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1869,7 +1869,7 @@ PJ_DEF(pj_status_t) pjsua_transport_create( pjsip_transport_type_e type,
 #endif	/* PJ_HAS_TCP */
 
 #if defined(PJSIP_HAS_TLS_TRANSPORT) && PJSIP_HAS_TLS_TRANSPORT!=0
-    } else if (type == PJSIP_TRANSPORT_TLS) {
+    } else if (type == PJSIP_TRANSPORT_TLS || type == PJSIP_TRANSPORT_TLS6) {
 	/*
 	 * Create TLS transport.
 	 */

commit 3b1bbd8b7e396ce050bef182a734f0ac2750e20f
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Mar 15 18:18:21 2011 -0300

    Add IPv4 TLS transport test and tweak it so the test only does a network load test with 500 messages instead of 2000.

diff --git a/pjsip/build/Makefile b/pjsip/build/Makefile
index 1922a09..865c7b4 100644
--- a/pjsip/build/Makefile
+++ b/pjsip/build/Makefile
@@ -89,6 +89,7 @@ export TEST_OBJS += dlg_core_test.o dns_test.o msg_err_test.o \
 		    msg_logger.o msg_test.o multipart_test.o regc_test.o \
 		    test.o transport_loop_test.o transport_tcp_test.o transport_tcp_test_v6.o \
 		    transport_test.o transport_udp_test.o transport_udp_test_v6.o\
+		    transport_tls_test.o \
 		    tsx_basic_test.o tsx_bench.o tsx_uac_test.o \
 		    tsx_uas_test.o txdata_test.o uri_test.o \
 		    inv_offer_answer_test.o
diff --git a/pjsip/src/test/test.c b/pjsip/src/test/test.c
index a32c1b2..dc8c1dc 100644
--- a/pjsip/src/test/test.c
+++ b/pjsip/src/test/test.c
@@ -325,6 +325,7 @@ int test_main(void)
 #if INCLUDE_TCP_TEST
     DO_TEST(transport_tcp_test());
     DO_TEST(transport_tcp_test_v6());
+    DO_TEST(transport_tls_test());
 #endif
 
 #if INCLUDE_RESOLVE_TEST
diff --git a/pjsip/src/test/test.h b/pjsip/src/test/test.h
index 894db99..4caffc8 100644
--- a/pjsip/src/test/test.h
+++ b/pjsip/src/test/test.h
@@ -80,6 +80,8 @@ int transport_udp_test_v6(void);
 int transport_loop_test(void);
 int transport_tcp_test(void);
 int transport_tcp_test_v6(void);
+int transport_tls_test(void);
+int transport_tls_test_v6(void);
 int resolve_test(void);
 int regc_test(void);
 
@@ -104,7 +106,7 @@ int transport_rt_test( pjsip_transport_type_e tp_type,
 		       pjsip_transport *ref_tp,
 		       char *target_url,
 		       int *pkt_lost);
-int transport_load_test(char *target_url);
+int transport_load_test(char *target_url, int count);
 
 /* Invite session */
 int inv_offer_answer_test(void);
diff --git a/pjsip/src/test/transport_tcp_test.c b/pjsip/src/test/transport_tcp_test.c
index 1472221..9141054 100644
--- a/pjsip/src/test/transport_tcp_test.c
+++ b/pjsip/src/test/transport_tcp_test.c
@@ -90,7 +90,7 @@ int transport_tcp_test(void)
 	return -40;
 
     /* Load test */
-    if (transport_load_test(url) != 0)
+    if (transport_load_test(url, 0) != 0)
 	return -60;
 
     /* Basic transport's send/receive loopback test. */
diff --git a/pjsip/src/test/transport_tcp_test_v6.c b/pjsip/src/test/transport_tcp_test_v6.c
index 232fcc8..0890427 100644
--- a/pjsip/src/test/transport_tcp_test_v6.c
+++ b/pjsip/src/test/transport_tcp_test_v6.c
@@ -85,7 +85,7 @@ int transport_tcp_test_v6(void)
 	return -40;
 
     /* Load test */
-    if (transport_load_test(url) != 0)
+    if (transport_load_test(url, 0) != 0)
 	return -60;
 
     /* Basic transport's send/receive loopback test. */
diff --git a/pjsip/src/test/transport_test.c b/pjsip/src/test/transport_test.c
index 4e1f6d9..c2efbe5 100644
--- a/pjsip/src/test/transport_test.c
+++ b/pjsip/src/test/transport_test.c
@@ -710,12 +710,16 @@ static pj_bool_t load_on_rx_request(pjsip_rx_data *rdata)
     return PJ_TRUE;
 }
 
-int transport_load_test(char *target_url)
+int transport_load_test(char *target_url, int count)
 {
-    enum { COUNT = 2000 };
     unsigned i;
     pj_status_t status = PJ_SUCCESS;
 
+    if (count < 1)
+    {
+	count = 2000;
+    }
+
     /* exhaust packets */
     do {
 	pj_time_val delay = {1, 0};
@@ -735,7 +739,7 @@ int transport_load_test(char *target_url)
     mod_load.err = PJ_FALSE;
     mod_load.next_seq = 0;
 
-    for (i=0; i<COUNT && !mod_load.err; ++i) {
+    for (i=0; i<count && !mod_load.err; ++i) {
 	pj_str_t target, from, call_id;
 	pjsip_tx_data *tdata;
 
@@ -764,9 +768,9 @@ int transport_load_test(char *target_url)
 	pjsip_endpt_handle_events2(endpt, &delay, &i);
     } while (i != 0);
 
-    if (mod_load.next_seq != COUNT) {
+    if (mod_load.next_seq != count) {
 	PJ_LOG(1,("THIS_FILE", "    err: expecting %u msg, got only %u", 
-		  COUNT, mod_load.next_seq));
+		  count, mod_load.next_seq));
 	status = -2;
 	goto on_return;
     }
diff --git a/pjsip/src/test/transport_tcp_test.c b/pjsip/src/test/transport_tls_test.c
similarity index 65%
copy from pjsip/src/test/transport_tcp_test.c
copy to pjsip/src/test/transport_tls_test.c
index 1472221..842070a 100644
--- a/pjsip/src/test/transport_tcp_test.c
+++ b/pjsip/src/test/transport_tls_test.c
@@ -1,4 +1,4 @@
-/* $Id: transport_tcp_test.c 2638 2009-04-22 14:27:55Z nanang $ */
+/* $Id: transport_tls_test.c 2638 2009-04-22 14:27:55Z nanang $ */
 /* 
  * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny at prijono.org>
@@ -22,18 +22,19 @@
 #include <pjsip.h>
 #include <pjlib.h>
 
-#define THIS_FILE   "transport_tcp_test.c"
+#define THIS_FILE   "transport_tls_test.c"
 
 
 /*
- * TCP transport test.
+ * TLS transport test.
  */
 #if PJ_HAS_TCP
-int transport_tcp_test(void)
+int transport_tls_test(void)
 {
     enum { SEND_RECV_LOOP = 8 };
+    const char ciphers[] = "eNULL";
     pjsip_tpfactory *tpfactory;
-    pjsip_transport *tcp;
+    pjsip_transport *tls;
     pj_sockaddr rem_addr;
     pj_sockaddr_in local_addr;
     pj_status_t status;
@@ -41,15 +42,19 @@ int transport_tcp_test(void)
     int rtt[SEND_RECV_LOOP], min_rtt;
     int i, pkt_lost;
     char rem_addr_str[PJ_INET6_ADDRSTRLEN];
+    struct pjsip_tls_setting tls_setting;
 
     pj_bzero(&local_addr, sizeof(local_addr));
     local_addr.sin_family = pj_AF_INET();
-    local_addr.sin_port = 5060;
+    local_addr.sin_port = 5061;
 
-    /* Start TCP listener on arbitrary port. */
-    status = pjsip_tcp_transport_start(endpt, (pj_sockaddr *)&local_addr, 1, &tpfactory);
+    /* Start TLS listener on arbitrary port. */
+    pjsip_tls_setting_default(&tls_setting);
+    tls_setting.cert_file = pj_str("/home/jcolp/mycert.pem");
+    tls_setting.privkey_file = pj_str("/home/jcolp/mycert.pem");
+    status = pjsip_tls_transport_start(endpt, &tls_setting, (pj_sockaddr*)&local_addr, NULL, 1, &tpfactory);
     if (status != PJ_SUCCESS) {
-	app_perror("   Error: unable to start TCP transport", status);
+	app_perror("   Error: unable to start TLS transport", status);
 	return -10;
     }
 
@@ -57,48 +62,48 @@ int transport_tcp_test(void)
     status = pj_sockaddr_init(pj_AF_INET(), &rem_addr, &tpfactory->addr_name.host,
 				 (pj_uint16_t)tpfactory->addr_name.port);
     if (status != PJ_SUCCESS) {
-	app_perror("   Error: possibly invalid TCP address name", status);
+	app_perror("   Error: possibly invalid TLS address name", status);
 	return -14;
     }
 
-    pj_ansi_sprintf(url, "sip:alice@%s;transport=tcp",
+    pj_ansi_sprintf(url, "sip:alice@%s;transport=tls",
             pj_sockaddr_print(&rem_addr, rem_addr_str, sizeof(rem_addr_str), 1 | 2));
 
-    /* Acquire one TCP transport. */
-    status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_TCP, 
+    /* Acquire one TLS transport. */
+    status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_TLS, 
 					   &rem_addr, pj_sockaddr_get_len(&rem_addr),
-					   NULL, &tcp);
-    if (status != PJ_SUCCESS || tcp == NULL) {
-	app_perror("   Error: unable to acquire TCP transport", status);
+					   NULL, &tls);
+    if (status != PJ_SUCCESS || tls == NULL) {
+	app_perror("   Error: unable to acquire TLS transport", status);
 	return -17;
     }
 
-    /* After pjsip_endpt_acquire_transport, TCP transport must have
+    /* After pjsip_endpt_acquire_transport, TLS transport must have
      * reference counter 1. 
      */
-    if (pj_atomic_get(tcp->ref_cnt) != 1)
+    if (pj_atomic_get(tls->ref_cnt) != 1)
 	return -20;
 
     /* Test basic transport attributes */
-    status = generic_transport_test(tcp);
+    status = generic_transport_test(tls);
     if (status != PJ_SUCCESS)
 	return status;
 
 
     /* Check again that reference counter is 1. */
-    if (pj_atomic_get(tcp->ref_cnt) != 1)
+    if (pj_atomic_get(tls->ref_cnt) != 1)
 	return -40;
 
     /* Load test */
-    if (transport_load_test(url) != 0)
+    if (transport_load_test(url, 500) != 0)
 	return -60;
 
     /* Basic transport's send/receive loopback test. */
     for (i=0; i<SEND_RECV_LOOP; ++i) {
-	status = transport_send_recv_test(PJSIP_TRANSPORT_TCP, tcp, url, &rtt[i]);
+	status = transport_send_recv_test(PJSIP_TRANSPORT_TLS, tls, url, &rtt[i]);
 
 	if (status != 0) {
-	    pjsip_transport_dec_ref(tcp);
+	    pjsip_transport_dec_ref(tls);
 	    flush_events(500);
 	    return -72;
 	}
@@ -108,17 +113,17 @@ int transport_tcp_test(void)
     for (i=0; i<SEND_RECV_LOOP; ++i)
 	if (rtt[i] < min_rtt) min_rtt = rtt[i];
 
-    report_ival("tcp-rtt-usec", min_rtt, "usec",
-		"Best TCP transport round trip time, in microseconds "
+    report_ival("tls-rtt-usec", min_rtt, "usec",
+		"Best TLS transport round trip time, in microseconds "
 		"(time from sending request until response is received. "
 		"Tests were performed on local machine only, and after "
-		"TCP socket has been established by previous test)");
+		"TLS socket has been established by previous test)");
 
 
     /* Multi-threaded round-trip test. */
-    status = transport_rt_test(PJSIP_TRANSPORT_TCP, tcp, url, &pkt_lost);
+    status = transport_rt_test(PJSIP_TRANSPORT_TLS, tls, url, &pkt_lost);
     if (status != 0) {
-	pjsip_transport_dec_ref(tcp);
+	pjsip_transport_dec_ref(tls);
 	return status;
     }
 
@@ -126,14 +131,14 @@ int transport_tcp_test(void)
 	PJ_LOG(3,(THIS_FILE, "   note: %d packet(s) was lost", pkt_lost));
 
     /* Check again that reference counter is still 1. */
-    if (pj_atomic_get(tcp->ref_cnt) != 1)
+    if (pj_atomic_get(tls->ref_cnt) != 1)
 	return -80;
 
     /* Destroy this transport. */
-    pjsip_transport_dec_ref(tcp);
+    pjsip_transport_dec_ref(tls);
 
     /* Force destroy this transport. */
-    status = pjsip_transport_destroy(tcp);
+    status = pjsip_transport_destroy(tls);
     if (status != PJ_SUCCESS)
 	return -90;
 
@@ -151,7 +156,7 @@ int transport_tcp_test(void)
     return 0;
 }
 #else	/* PJ_HAS_TCP */
-int transport_tcp_test(void)
+int transport_tls_test(void)
 {
     return 0;
 }

-----------------------------------------------------------------------


-- 
asterisk-scf/release/pjproject.git



More information about the asterisk-scf-commits mailing list