Add adapter type parameter to CAcloseSslConnectionAll
authorJoonghwan Lee <jh05.lee@samsung.com>
Thu, 9 Feb 2017 07:14:16 +0000 (16:14 +0900)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 16 Feb 2017 17:03:15 +0000 (17:03 +0000)
Adapter(Transport) type parameter is added to CAcloseSslConnectionAll function
in order to enable sessions related to the only specified transport type to be closed.

Patch 1: Initial upload
Patch 2: Fixed print format

Change-Id: I3bb658cf4c90e0e283a0b052f69f1fa8b593e748
Signed-off-by: Joonghwan Lee <jh05.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17139
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/connectivity/api/casecurityinterface.h
resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 3aa7685..32b09dc 100644 (file)
@@ -246,7 +246,7 @@ CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
 /**
  * Close All of DTLS sessions.
  */
-void CAcloseSslConnectionAll();
+void CAcloseSslConnectionAll(CATransportAdapter_t transportType);
 
 #ifdef __cplusplus
 } /* extern "C" */
index 4eae1d5..594135d 100644 (file)
@@ -1080,7 +1080,7 @@ CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint)
     return CA_STATUS_OK;
 }
 
-void CAcloseSslConnectionAll()
+void CAcloseSslConnectionAll(CATransportAdapter_t transportType)
 {
     OIC_LOG_V(DEBUG, NET_SSL_TAG, "In %s", __func__);
     oc_mutex_lock(g_sslContextMutex);
@@ -1092,15 +1092,24 @@ void CAcloseSslConnectionAll()
     }
 
     uint32_t listLength = u_arraylist_length(g_caSslContext->peerList);
+    OIC_LOG_V(DEBUG, NET_SSL_TAG,
+            "Required transport [%d], peer count [%u]", transportType, listLength);
     for (uint32_t i = listLength; i > 0; i--)
     {
-        SslEndPoint_t *tep = (SslEndPoint_t *)u_arraylist_remove(g_caSslContext->peerList, i - 1);
+        SslEndPoint_t *tep = (SslEndPoint_t *)u_arraylist_get(g_caSslContext->peerList, i - 1);
         if (NULL == tep)
         {
             continue;
         }
-        OIC_LOG_V(DEBUG, NET_SSL_TAG, "SSL Connection [%s:%d]",
-                  tep->sep.endpoint.addr, tep->sep.endpoint.port);
+        OIC_LOG_V(DEBUG, NET_SSL_TAG, "SSL Connection [%s:%d], Transport [%d]",
+                  tep->sep.endpoint.addr, tep->sep.endpoint.port, tep->sep.endpoint.adapter);
+
+        // check transport matching
+        if (0 == (tep->sep.endpoint.adapter & transportType))
+        {
+            OIC_LOG(DEBUG, NET_SSL_TAG, "Skip the un-matched transport session");
+            continue;
+        }
 
         // TODO: need to check below code after socket close is ensured.
         /*int ret = 0;
@@ -1110,6 +1119,8 @@ void CAcloseSslConnectionAll()
         }
         while (MBEDTLS_ERR_SSL_WANT_WRITE == ret);*/
 
+        // delete from list
+        u_arraylist_remove(g_caSslContext->peerList, i - 1);
         DeleteSslEndPoint(tep);
     }
     oc_mutex_unlock(g_sslContextMutex);
index 153b8c7..876ba23 100644 (file)
@@ -176,7 +176,7 @@ void CAIPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status)
         OIC_LOG(DEBUG, TAG, "Network status for IP is down");
 #ifdef __WITH_DTLS__
         OIC_LOG(DEBUG, TAG, "close all ssl session");
-        CAcloseSslConnectionAll();
+        CAcloseSslConnectionAll(CA_ADAPTER_IP);
 #endif
     }
 }
index 4042592..9b92cac 100644 (file)
@@ -1444,7 +1444,7 @@ void CATCPDisconnectAll()
     oc_mutex_unlock(g_mutexObjectList);
 
 #ifdef __WITH_TLS__
-    CAcloseSslConnectionAll();
+    CAcloseSslConnectionAll(CA_ADAPTER_TCP);
 #endif
 
 }