Skip to content

Commit

Permalink
refactor(pubsub): Include the error handling checks
Browse files Browse the repository at this point in the history
Signed-off-by: Keerthivasan Alagarsamy Senthilkumaran <keerthivasan.as@kalycito.com>
Change-Id: Ifbb0e9e1da48176862d291df70bb97e827a4a7a7
  • Loading branch information
opcua-tsn-team-kalycito authored and jpfr committed Nov 16, 2021
1 parent e593781 commit c3b252f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion plugins/ua_pubsub_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ UA_PubSubChannelEthernet_receive(UA_PubSubChannel *channel,
receiveFlags = MSG_DONTWAIT;

#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
break; //ToDO: Multiple Receive handling for PubsubEncryption need to be done
break;//ToDO: Multiple Receive handling for PubsubEncryption need to be done
#endif
} while(true); /* 1518 bytes is the maximum size of ethernet packet
* where 18 bytes used for header size, 4 bytes of LLC
Expand Down
3 changes: 3 additions & 0 deletions plugins/ua_pubsub_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ UA_PubSubChannelUDPMC_receive(UA_PubSubChannel *channel,
UA_DateTime newTimeoutValue = remainingTimeoutValue - receiveDuration;
timeoutValue.tv_sec = (long int)(newTimeoutValue / UA_DATETIME_SEC);
timeoutValue.tv_usec = (long int)((newTimeoutValue % UA_DATETIME_SEC) * 100);
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
break;//ToDO: Multiple Receive handling for PubsubEncryption need to be done
#endif
} while(true); /* TODO:Need to handle for jumbo frames*/
/* 1518 bytes is the maximum size of ethernet packet
* where 18 bytes used for header size, 28 bytes of header
Expand Down
35 changes: 19 additions & 16 deletions src/pubsub/ua_pubsub_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,22 +1384,25 @@ decodeAndProcessNetworkMessageRT(UA_Server *server, UA_ReaderGroup *readerGroup,
UA_NetworkMessage *nm = dataSetReader->bufferedMessage.nm;

#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
UA_NetworkMessage currentNetworkMessage;
memset(&currentNetworkMessage, 0, sizeof(UA_NetworkMessage));
UA_StatusCode rv;
size_t payLoadPosition = 0;
rv = UA_NetworkMessage_decodeHeaders(
buffer, &payLoadPosition, &currentNetworkMessage);

UA_CHECK_STATUS_ERROR(rv, return rv, &server->config.logger, UA_LOGCATEGORY_SERVER,
"PubSub receive. decoding headers failed");
rv = verifyAndDecryptNetworkMessage(&server->config.logger,
buffer,
&payLoadPosition,
&currentNetworkMessage,
readerGroup);
UA_CHECK_STATUS_WARN(rv, return rv, &server->config.logger, UA_LOGCATEGORY_SERVER,
"Subscribe failed. verify and decrypt network message failed.");
if(readerGroup->config.securityMode > UA_MESSAGESECURITYMODE_NONE) {
UA_NetworkMessage currentNetworkMessage;
memset(&currentNetworkMessage, 0, sizeof(UA_NetworkMessage));
UA_StatusCode rv;
size_t payLoadPosition = 0;
rv = UA_NetworkMessage_decodeHeaders(
buffer, &payLoadPosition, &currentNetworkMessage);

UA_CHECK_STATUS_ERROR(rv, return rv, &server->config.logger, UA_LOGCATEGORY_SERVER,
"PubSub receive. decoding headers failed");
rv = verifyAndDecryptNetworkMessage(&server->config.logger,
buffer,
&payLoadPosition,
&currentNetworkMessage,
readerGroup);
UA_CHECK_STATUS_WARN(rv, return rv, &server->config.logger, UA_LOGCATEGORY_SERVER,
"Subscribe failed. verify and decrypt network message failed.");
UA_NetworkMessage_clear(&currentNetworkMessage);
}
#endif
/* Decode only the necessary offset and update the networkMessage */
UA_StatusCode res =
Expand Down

0 comments on commit c3b252f

Please sign in to comment.