tcp_adapter: use CASecureEndpoint_t
authorHauke Mehrtens <hauke@hauke-m.de>
Fri, 15 Jan 2016 22:15:52 +0000 (23:15 +0100)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 20 Jan 2016 07:49:00 +0000 (07:49 +0000)
The callback function for g_networkPacketCallback gets
CASecureEndpoint_t as first parameter and not CAEndpoint_t. The TCP
adapter always provided it with the wrong type CAEndpoint_t. This patch
makes the tcp adapter use CASecureEndpoint_t instead and fix this
problem.

Change-Id: Ic3b1ca0aadf7a95c846a31424932a7e90a86a55b
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4821
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/inc/catcpadapter.h
resource/csdk/connectivity/inc/catcpinterface.h
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 1517289..b62df78 100644 (file)
@@ -39,7 +39,7 @@ extern "C"
  */
 typedef struct
 {
-    CAEndpoint_t endpoint;              /**< endpoint information */
+    CASecureEndpoint_t sep;             /**< secure endpoint information */
     int fd;                             /**< file descriptor info */
     void *recvData;                     /**< received data from remote device*/
     size_t recvDataLen;                 /**< received data length */
index db3bd56..d792e0c 100644 (file)
@@ -46,7 +46,7 @@ extern "C"
  * @param[in]  dataLength    Length of data in bytes.
  * @pre  Callback must be registered using CAIPSetPacketReceiveCallback().
  */
-typedef void (*CATCPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+typedef void (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint,
                                            const void *data,
                                            uint32_t dataLength);
 
index f75c5c5..3480fc0 100644 (file)
@@ -77,7 +77,7 @@ static CANetworkChangeCallback g_networkChangeCallback = NULL;
  */
 static CAErrorHandleCallback g_errorCallback = NULL;
 
-static void CATCPPacketReceivedCB(const CAEndpoint_t *endpoint,
+static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep,
                                   const void *data, uint32_t dataLength);
 
 static CAResult_t CATCPInitializeQueueHandles();
@@ -136,17 +136,17 @@ void CATCPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
     (void)status;
 }
 
-void CATCPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
+void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data,
                            uint32_t dataLength)
 {
-    VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL");
+    VERIFY_NON_NULL_VOID(sep, TAG, "sep is NULL");
     VERIFY_NON_NULL_VOID(data, TAG, "data is NULL");
 
-    OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port);
+    OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", sep->endpoint.addr, sep->endpoint.port);
 
     if (g_networkPacketCallback)
     {
-        g_networkPacketCallback(endpoint, data, dataLength);
+        g_networkPacketCallback(sep, data, dataLength);
     }
 }
 
index 067f5f2..e600b24 100644 (file)
@@ -260,7 +260,7 @@ static void CAAcceptConnection()
 
         svritem->fd = sockfd;
         CAConvertAddrToName((struct sockaddr_storage *)&clientaddr, clientlen,
-                            (char *) &svritem->endpoint.addr, &svritem->endpoint.port);
+                            (char *) &svritem->sep.endpoint.addr, &svritem->sep.endpoint.port);
 
         ca_mutex_lock(g_mutexObjectList);
         bool result = u_arraylist_add(caglobals.tcp.svrlist, svritem);
@@ -342,8 +342,8 @@ static void CAReceiveMessage(int fd)
     // #5. pass the received data information to upper layer.
     if ((svritem->totalDataLen == svritem->recvDataLen) && g_packetReceivedCallback)
     {
-        svritem->endpoint.adapter = CA_ADAPTER_TCP;
-        g_packetReceivedCallback(&svritem->endpoint, svritem->recvData, svritem->recvDataLen);
+        svritem->sep.endpoint.adapter = CA_ADAPTER_TCP;
+        g_packetReceivedCallback(&svritem->sep, svritem->recvData, svritem->recvDataLen);
         OIC_LOG_V(DEBUG, TAG, "total received data len:%d", svritem->recvDataLen);
 
         // initialize data info to receive next message.
@@ -367,7 +367,7 @@ static int CATCPCreateSocket(int family, CATCPSessionInfo_t *tcpServerInfo)
     }
 
     struct sockaddr_storage sa = { .ss_family = family };
-    CAConvertNameToAddr(tcpServerInfo->endpoint.addr, tcpServerInfo->endpoint.port, &sa);
+    CAConvertNameToAddr(tcpServerInfo->sep.endpoint.addr, tcpServerInfo->sep.endpoint.port, &sa);
     socklen_t socklen = sizeof (struct sockaddr_in);
 
     // connect to TCP server
@@ -713,8 +713,8 @@ CATCPSessionInfo_t *CAConnectTCPSession(const CAEndpoint_t *endpoint)
         OIC_LOG(ERROR, TAG, "Out of memory");
         return NULL;
     }
-    memcpy(svritem->endpoint.addr, endpoint->addr, sizeof(svritem->endpoint.addr));
-    svritem->endpoint.port = endpoint->port;
+    memcpy(svritem->sep.endpoint.addr, endpoint->addr, sizeof(svritem->sep.endpoint.addr));
+    svritem->sep.endpoint.port = endpoint->port;
 
     // #2. create the socket and connect to TCP server
     if (caglobals.tcp.ipv4tcpenabled)
@@ -805,8 +805,8 @@ CATCPSessionInfo_t *CAGetTCPSessionInfoFromEndpoint(const CAEndpoint_t *endpoint
             continue;
         }
 
-        if (!strncmp(svritem->endpoint.addr, endpoint->addr, sizeof(svritem->endpoint.addr))
-                && (svritem->endpoint.port == endpoint->port))
+        if (!strncmp(svritem->sep.endpoint.addr, endpoint->addr, sizeof(svritem->sep.endpoint.addr))
+                && (svritem->sep.endpoint.port == endpoint->port))
         {
             *index = i;
             return svritem;