*/
CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index);
+/**
+ * Get total payload length from CoAP over TCP header.
+ *
+ * @param[in] data Data to be send.
+ * @param[in] dlen Total data length.
+ * @return Payload length
+ */
+size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen);
+
#ifdef __cplusplus
}
#endif
}
else
{
+ // Check payload length from CoAP over TCP format header.
+ CAResult_t result = CA_STATUS_OK;
+ size_t payloadLen = CACheckPayloadLengthFromHeader(tcpData->data, tcpData->dataLen);
+ if (!payloadLen)
+ {
+ // if payload length is zero, disconnect from remote device.
+ OIC_LOG(DEBUG, TAG, "payload length is zero, disconnect from remote device");
+ size_t index = 0;
+ CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(tcpData->remoteEndpoint,
+ &index);
+ if (svritem)
+ {
+ result = CADisconnectTCPSession(svritem, index);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG_V(ERROR, TAG, "CADisconnectTCPSession failed, result[%d]", result);
+ }
+ }
+ return;
+ }
+
#ifdef __WITH_TLS__
if (tcpData->remoteEndpoint && tcpData->remoteEndpoint->flags & CA_SECURE)
{
- CAResult_t result = CA_STATUS_OK;
OIC_LOG(DEBUG, TAG, "CAencryptSsl called!");
result = CAencryptSsl(tcpData->remoteEndpoint, tcpData->data, tcpData->dataLen);
g_connectionCallback = connHandler;
}
-static size_t CACheckPayloadLength(const void *data, size_t dlen)
+size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen)
{
VERIFY_NON_NULL_RET(data, TAG, "data", -1);
}
}
- // #2. check payload length
-#ifdef __WITH_TLS__
- if (false == CAIsTlsMessage(data, dlen))
-#endif
- {
- size_t payloadLen = CACheckPayloadLength(data, dlen);
- // if payload length is zero, disconnect from TCP server
- if (!payloadLen)
- {
- OIC_LOG(DEBUG, TAG, "payload length is zero, disconnect from remote device");
- CADisconnectTCPSession(svritem, index);
- return;
- }
- }
-
- // #3. check connection state
+ // #2. check connection state
if (svritem->fd < 0)
{
// if file descriptor value is wrong, remove TCP Server info from list
return;
}
- // #4. send data to TCP Server
+ // #3. send data to TCP Server
ssize_t remainLen = dlen;
do
{