summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2018-08-10 14:18:20 -0400
committerJackLivio <jack@livio.io>2018-08-10 14:18:20 -0400
commitf48c90c90d86b2da5f3337c0599efad9da4e0289 (patch)
tree25d305540c5dfbd57d4febef679db75145341744
parent5f651c9e75441633c4e489d81b09900d1457bfb1 (diff)
downloadsdl_core-f48c90c90d86b2da5f3337c0599efad9da4e0289.tar.gz
Address comments and logic refactor
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc6
-rw-r--r--src/components/application_manager/src/rpc_handler_impl.cc2
-rw-r--r--src/components/include/utils/semantic_version.h115
-rw-r--r--src/components/protocol_handler/include/protocol_handler/handshake_handler.h8
-rw-r--r--src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h5
-rw-r--r--src/components/protocol_handler/include/protocol_handler/protocol_packet.h87
-rw-r--r--src/components/protocol_handler/src/handshake_handler.cc15
-rw-r--r--src/components/protocol_handler/src/protocol_handler_impl.cc33
-rw-r--r--src/components/protocol_handler/src/protocol_packet.cc43
-rw-r--r--src/components/protocol_handler/test/protocol_handler_tm_test.cc9
-rw-r--r--src/components/smart_objects/include/smart_objects/enum_schema_item.h112
-rw-r--r--src/components/smart_objects/include/smart_objects/object_schema_item.h10
-rw-r--r--src/components/smart_objects/src/object_schema_item.cc92
13 files changed, 226 insertions, 311 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc
index 4284b97786..69e602c278 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc
@@ -621,11 +621,11 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile(
utils::SemanticVersion negotiated_version = application->msg_version();
response_params[strings::sync_msg_version][strings::major_version] =
- negotiated_version.major_version;
+ negotiated_version.majorVersion;
response_params[strings::sync_msg_version][strings::minor_version] =
- negotiated_version.minor_version;
+ negotiated_version.minorVersion;
response_params[strings::sync_msg_version][strings::patch_version] =
- negotiated_version.patch_version;
+ negotiated_version.patchVersion;
const smart_objects::SmartObject& msg_params =
(*message_)[strings::msg_params];
diff --git a/src/components/application_manager/src/rpc_handler_impl.cc b/src/components/application_manager/src/rpc_handler_impl.cc
index 37319738f9..0bf62cf64d 100644
--- a/src/components/application_manager/src/rpc_handler_impl.cc
+++ b/src/components/application_manager/src/rpc_handler_impl.cc
@@ -232,7 +232,7 @@ bool RPCHandlerImpl::ConvertMessageToSO(
} else if (mobile_apis::FunctionID::RegisterAppInterfaceID ==
static_cast<mobile_apis::FunctionID::eType>(
output[strings::params][strings::function_id].asInt())) {
- // Assume default version 1.0.0 until properly set in RAI
+ // Assume default version 2.0.0 until properly set in RAI
output[NsSmartDeviceLink::NsJSONHandler::strings::S_PARAMS]
[NsSmartDeviceLink::NsJSONHandler::strings::S_RPC_MSG_VERSION] =
msg_version.toString();
diff --git a/src/components/include/utils/semantic_version.h b/src/components/include/utils/semantic_version.h
index a67cf6d2d1..6c54a11984 100644
--- a/src/components/include/utils/semantic_version.h
+++ b/src/components/include/utils/semantic_version.h
@@ -33,93 +33,88 @@
#ifndef SRC_COMPONENTS_INCLUDE_UTILS_SEMANTIC_VERSION_H_
#define SRC_COMPONENTS_INCLUDE_UTILS_SEMANTIC_VERSION_H_
-#include <boost/algorithm/string.hpp>
-
namespace utils {
struct SemanticVersion {
SemanticVersion(uint16_t major = 0, uint16_t minor = 0, uint16_t patch = 0) {
- major_version = major;
- minor_version = minor;
- patch_version = patch;
+ majorVersion = major;
+ minorVersion = minor;
+ patchVersion = patch;
+ }
+
+ SemanticVersion(const SemanticVersion& other) {
+ majorVersion = other.majorVersion;
+ minorVersion = other.minorVersion;
+ patchVersion = other.patchVersion;
}
- SemanticVersion(const std::string& str_version) {
- std::vector<std::string> str_array;
- boost::split(str_array, str_version, boost::is_any_of("."));
- if (str_array.size() == 3) {
- major_version = atoi(str_array[0].c_str());
- minor_version = atoi(str_array[1].c_str());
- patch_version = atoi(str_array[2].c_str());
+ SemanticVersion(const std::string& versionString)
+ : majorVersion(0), minorVersion(0), patchVersion(0) {
+ unsigned int majorInt, minorInt, patchInt;
+ int readElements = sscanf(
+ versionString.c_str(), "%u.%u.%u", &majorInt, &minorInt, &patchInt);
+ if (readElements != 3) {
+ // LOG4CXX_WARN(logger_,
+ // "Error while parsing version string: " << versionString);
} else {
- // Invalid case
- major_version = 0;
- minor_version = 0;
- patch_version = 0;
+ majorVersion = static_cast<uint8_t>(majorInt);
+ minorVersion = static_cast<uint8_t>(minorInt);
+ patchVersion = static_cast<uint8_t>(patchInt);
}
}
- bool operator==(const SemanticVersion& version) const {
- return (major_version == version.major_version &&
- minor_version == version.minor_version &&
- patch_version == version.patch_version);
+ static inline int16_t cmp(const SemanticVersion& version1,
+ const SemanticVersion& version2) {
+ int16_t diff =
+ static_cast<int16_t>(version1.majorVersion - version2.majorVersion);
+ if (diff == 0) {
+ diff =
+ static_cast<int16_t>(version1.minorVersion - version2.minorVersion);
+ if (diff == 0) {
+ diff =
+ static_cast<int16_t>(version1.patchVersion - version2.patchVersion);
+ }
+ }
+ return diff;
}
- bool operator<(const SemanticVersion& version) const {
- return (major_version < version.major_version) ||
- ((major_version == version.major_version) &&
- (minor_version < version.minor_version)) ||
- ((major_version == version.major_version) &&
- (minor_version == version.minor_version) &&
- (patch_version < version.patch_version));
+ bool operator==(const SemanticVersion& other) const {
+ return SemanticVersion::cmp(*this, other) == 0;
}
-
- bool operator<=(const SemanticVersion& version) const {
- if (this->operator==(version)) {
- return true;
- } else if (this->operator<(version)) {
- return true;
- } else {
- return false;
- }
+ bool operator<(const SemanticVersion& other) const {
+ return SemanticVersion::cmp(*this, other) < 0;
}
-
- bool operator>(const SemanticVersion& version) const {
- return (major_version > version.major_version) ||
- ((major_version == version.major_version) &&
- (minor_version > version.minor_version)) ||
- ((major_version == version.major_version) &&
- (minor_version == version.minor_version) &&
- (patch_version > version.patch_version));
+ bool operator>(const SemanticVersion& other) const {
+ return SemanticVersion::cmp(*this, other) > 0;
}
-
- bool operator>=(const SemanticVersion& version) const {
- if (this->operator==(version)) {
- return true;
- } else if (this->operator>(version)) {
- return true;
- } else {
- return false;
- }
+ bool operator<=(const SemanticVersion& other) const {
+ return SemanticVersion::cmp(*this, other) <= 0;
+ }
+ bool operator>=(const SemanticVersion& other) const {
+ return SemanticVersion::cmp(*this, other) >= 0;
+ }
+ static inline SemanticVersion* min(SemanticVersion& version1,
+ SemanticVersion& version2) {
+ return (version1 < version2) ? &version1 : &version2;
}
const std::string toString() const {
std::string result = "";
- result += std::to_string(major_version);
+ result += std::to_string(majorVersion);
result += ".";
- result += std::to_string(minor_version);
+ result += std::to_string(minorVersion);
result += ".";
- result += std::to_string(patch_version);
+ result += std::to_string(patchVersion);
return result;
}
bool isValid() const {
- return major_version > 0 || minor_version > 0 || patch_version > 0;
+ return majorVersion > 0 || minorVersion > 0 || patchVersion > 0;
}
- uint16_t major_version = 0;
- uint16_t minor_version = 0;
- uint16_t patch_version = 0;
+ uint16_t majorVersion = 0;
+ uint16_t minorVersion = 0;
+ uint16_t patchVersion = 0;
};
}
diff --git a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
index 8b7f28d50e..be81493e7a 100644
--- a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
+++ b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h
@@ -40,6 +40,8 @@
#include "protocol_handler/session_observer.h"
#include "security_manager/security_manager_listener.h"
+#include "utils/semantic_version.h"
+
namespace protocol_handler {
class ProtocolHandlerImpl;
@@ -60,12 +62,12 @@ class HandshakeHandler : public security_manager::SecurityManagerListener {
ServiceType service_type,
const std::vector<int>& force_protected_service,
const bool is_new_service,
- ProtocolPacket::ProtocolVersion& full_version,
+ utils::SemanticVersion& full_version,
std::shared_ptr<BsonObject> payload);
HandshakeHandler(ProtocolHandlerImpl& protocol_handler,
SessionObserver& session_observer,
- ProtocolPacket::ProtocolVersion& full_version,
+ utils::SemanticVersion& full_version,
const SessionContext& context,
const uint8_t protocol_version,
std::shared_ptr<BsonObject> payload);
@@ -124,7 +126,7 @@ class HandshakeHandler : public security_manager::SecurityManagerListener {
ProtocolHandlerImpl& protocol_handler_;
SessionObserver& session_observer_;
SessionContext context_;
- ProtocolPacket::ProtocolVersion full_version_;
+ utils::SemanticVersion full_version_;
const uint8_t protocol_version_;
std::shared_ptr<BsonObject> payload_;
};
diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h
index 58877ac611..e763be8c1b 100644
--- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h
+++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h
@@ -45,6 +45,7 @@
#include "utils/messagemeter.h"
#include "utils/custom_string.h"
+#include "utils/semantic_version.h"
#include "protocol_handler/protocol_handler.h"
#include "protocol_handler/protocol_packet.h"
@@ -313,7 +314,7 @@ class ProtocolHandlerImpl
uint32_t hash_code,
uint8_t service_type,
bool protection,
- ProtocolPacket::ProtocolVersion& full_version);
+ utils::SemanticVersion& full_version);
/**
* \brief Sends acknowledgement of starting session to mobile application
@@ -337,7 +338,7 @@ class ProtocolHandlerImpl
uint32_t hash_code,
uint8_t service_type,
bool protection,
- ProtocolPacket::ProtocolVersion& full_version,
+ utils::SemanticVersion& full_version,
BsonObject& params);
const ProtocolHandlerSettings& get_settings() const OVERRIDE {
diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
index ff084beff8..4ca22261b6 100644
--- a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
+++ b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h
@@ -68,52 +68,53 @@ class ProtocolPacket {
* \brief Used for storing the full protocol version of a service
* (major.minor.patch).
*/
- class ProtocolVersion {
- public:
- ProtocolVersion();
- ProtocolVersion(uint8_t majorVersion,
- uint8_t minorVersion,
- uint8_t patchVersion);
- ProtocolVersion(ProtocolVersion& other);
- ProtocolVersion(std::string versionString);
- uint8_t majorVersion;
- uint8_t minorVersion;
- uint8_t patchVersion;
- static inline int16_t cmp(const ProtocolVersion& version1,
- const ProtocolVersion& version2) {
- int16_t diff =
- static_cast<int16_t>(version1.majorVersion - version2.majorVersion);
- if (diff == 0) {
- diff =
- static_cast<int16_t>(version1.minorVersion - version2.minorVersion);
+ /* class ProtocolVersion {
+ public:
+ ProtocolVersion();
+ ProtocolVersion(uint8_t majorVersion,
+ uint8_t minorVersion,
+ uint8_t patchVersion);
+ ProtocolVersion(ProtocolVersion& other);
+ ProtocolVersion(std::string versionString);
+ uint8_t majorVersion;
+ uint8_t minorVersion;
+ uint8_t patchVersion;
+ static inline int16_t cmp(const ProtocolVersion& version1,
+ const ProtocolVersion& version2) {
+ int16_t diff =
+ static_cast<int16_t>(version1.majorVersion - version2.majorVersion);
if (diff == 0) {
- diff = static_cast<int16_t>(version1.patchVersion -
- version2.patchVersion);
+ diff =
+ static_cast<int16_t>(version1.minorVersion -
+ version2.minorVersion);
+ if (diff == 0) {
+ diff = static_cast<int16_t>(version1.patchVersion -
+ version2.patchVersion);
+ }
}
+ return diff;
}
- return diff;
- }
- inline bool operator==(const ProtocolVersion& other) {
- return ProtocolVersion::cmp(*this, other) == 0;
- }
- inline bool operator<(const ProtocolVersion& other) {
- return ProtocolVersion::cmp(*this, other) < 0;
- }
- bool operator>(const ProtocolVersion& other) {
- return ProtocolVersion::cmp(*this, other) > 0;
- }
- inline bool operator<=(const ProtocolVersion& other) {
- return ProtocolVersion::cmp(*this, other) <= 0;
- }
- bool operator>=(const ProtocolVersion& other) {
- return ProtocolVersion::cmp(*this, other) >= 0;
- }
- static inline ProtocolVersion* min(ProtocolVersion& version1,
- ProtocolVersion& version2) {
- return (version1 < version2) ? &version1 : &version2;
- }
- std::string to_string();
- };
+ inline bool operator==(const ProtocolVersion& other) {
+ return ProtocolVersion::cmp(*this, other) == 0;
+ }
+ inline bool operator<(const ProtocolVersion& other) {
+ return ProtocolVersion::cmp(*this, other) < 0;
+ }
+ bool operator>(const ProtocolVersion& other) {
+ return ProtocolVersion::cmp(*this, other) > 0;
+ }
+ inline bool operator<=(const ProtocolVersion& other) {
+ return ProtocolVersion::cmp(*this, other) <= 0;
+ }
+ bool operator>=(const ProtocolVersion& other) {
+ return ProtocolVersion::cmp(*this, other) >= 0;
+ }
+ static inline ProtocolVersion* min(ProtocolVersion& version1,
+ ProtocolVersion& version2) {
+ return (version1 < version2) ? &version1 : &version2;
+ }
+ std::string to_string();
+ };*/
/**
* \class ProtocolHeader
diff --git a/src/components/protocol_handler/src/handshake_handler.cc b/src/components/protocol_handler/src/handshake_handler.cc
index 8db551cfd6..f6ab08319e 100644
--- a/src/components/protocol_handler/src/handshake_handler.cc
+++ b/src/components/protocol_handler/src/handshake_handler.cc
@@ -54,7 +54,7 @@ HandshakeHandler::HandshakeHandler(
ServiceType service_type,
const std::vector<int>& force_protected_service,
const bool is_new_service,
- ProtocolPacket::ProtocolVersion& full_version,
+ utils::SemanticVersion& full_version,
std::shared_ptr<BsonObject> payload)
: protocol_handler_(protocol_handler)
, session_observer_(session_observer)
@@ -63,13 +63,12 @@ HandshakeHandler::HandshakeHandler(
, protocol_version_(protocol_version)
, payload_(payload) {}
-HandshakeHandler::HandshakeHandler(
- ProtocolHandlerImpl& protocol_handler,
- SessionObserver& session_observer,
- ProtocolPacket::ProtocolVersion& full_version,
- const SessionContext& context,
- const uint8_t protocol_version,
- std::shared_ptr<BsonObject> payload)
+HandshakeHandler::HandshakeHandler(ProtocolHandlerImpl& protocol_handler,
+ SessionObserver& session_observer,
+ utils::SemanticVersion& full_version,
+ const SessionContext& context,
+ const uint8_t protocol_version,
+ std::shared_ptr<BsonObject> payload)
: protocol_handler_(protocol_handler)
, session_observer_(session_observer)
, context_(context)
diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc
index 872a8dc755..4ff24f9e64 100644
--- a/src/components/protocol_handler/src/protocol_handler_impl.cc
+++ b/src/components/protocol_handler/src/protocol_handler_impl.cc
@@ -61,8 +61,8 @@ std::string ConvertPacketDataToString(const uint8_t* data,
const size_t kStackSize = 65536;
-ProtocolPacket::ProtocolVersion defaultProtocolVersion(5, 1, 0);
-ProtocolPacket::ProtocolVersion minMultipleTransportsVersion(5, 1, 0);
+utils::SemanticVersion defaultProtocolVersion(5, 1, 0);
+utils::SemanticVersion minMultipleTransportsVersion(5, 1, 0);
ProtocolHandlerImpl::ProtocolHandlerImpl(
const ProtocolHandlerSettings& settings,
@@ -199,7 +199,7 @@ void ProtocolHandlerImpl::SendStartSessionAck(ConnectionID connection_id,
uint8_t service_type,
bool protection) {
LOG4CXX_AUTO_TRACE(logger_);
- ProtocolPacket::ProtocolVersion fullVersion;
+ utils::SemanticVersion fullVersion;
SendStartSessionAck(connection_id,
session_id,
input_protocol_version,
@@ -216,7 +216,7 @@ void ProtocolHandlerImpl::SendStartSessionAck(
uint32_t hash_id,
uint8_t service_type,
bool protection,
- ProtocolPacket::ProtocolVersion& full_version) {
+ utils::SemanticVersion& full_version) {
LOG4CXX_AUTO_TRACE(logger_);
BsonObject empty_param;
@@ -241,7 +241,7 @@ void ProtocolHandlerImpl::SendStartSessionAck(
uint32_t hash_id,
uint8_t service_type,
bool protection,
- ProtocolPacket::ProtocolVersion& full_version,
+ utils::SemanticVersion& full_version,
BsonObject& params) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -307,13 +307,13 @@ void ProtocolHandlerImpl::SendStartSessionAck(
&params, strings::hash_id)));
// Minimum protocol version supported by both
- ProtocolPacket::ProtocolVersion* minVersion =
+ utils::SemanticVersion* minVersion =
(full_version.majorVersion < PROTOCOL_VERSION_5)
? &defaultProtocolVersion
- : ProtocolPacket::ProtocolVersion::min(full_version,
- defaultProtocolVersion);
+ : utils::SemanticVersion::min(full_version,
+ defaultProtocolVersion);
char protocolVersionString[256];
- strncpy(protocolVersionString, (*minVersion).to_string().c_str(), 255);
+ strncpy(protocolVersionString, (*minVersion).toString().c_str(), 255);
const bool protocol_ver_written = bson_object_put_string(
&params, strings::protocol_version, protocolVersionString);
@@ -1608,14 +1608,14 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
PROTECTION_OFF);
return RESULT_OK;
}
- ProtocolPacket::ProtocolVersion* fullVersion;
+ utils::SemanticVersion* fullVersion;
std::vector<std::string> rejectedParams(0, std::string(""));
// Can't check protocol_version because the first packet is v1, but there
// could still be a payload, in which case we can get the real protocol
// version
if (packet.service_type() == kRpc && packet.data_size() != 0) {
BsonObject obj = bson_object_from_bytes(packet.data());
- fullVersion = new ProtocolPacket::ProtocolVersion(
+ fullVersion = new utils::SemanticVersion(
std::string(bson_object_get_string(&obj, "protocolVersion")));
bson_object_deinitialize(&obj);
// Constructed payloads added in Protocol v5
@@ -1623,7 +1623,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
rejectedParams.push_back(std::string("protocolVersion"));
}
} else {
- fullVersion = new ProtocolPacket::ProtocolVersion();
+ fullVersion = new utils::SemanticVersion();
}
if (!rejectedParams.empty()) {
SendStartSessionNAck(connection_id,
@@ -1670,7 +1670,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
#endif // ENABLE_SECURITY
if (packet.service_type() == kRpc && packet.data_size() != 0) {
BsonObject obj = bson_object_from_bytes(packet.data());
- ProtocolPacket::ProtocolVersion fullVersion(
+ utils::SemanticVersion fullVersion(
bson_object_get_string(&obj, "protocolVersion"));
bson_object_deinitialize(&obj);
@@ -1880,7 +1880,7 @@ void ProtocolHandlerImpl::NotifySessionStarted(
bson_object_deinitialize(&req_param);
}
- std::shared_ptr<ProtocolPacket::ProtocolVersion> fullVersion;
+ std::shared_ptr<utils::SemanticVersion> fullVersion;
// Can't check protocol_version because the first packet is v1, but there
// could still be a payload, in which case we can get the real protocol
@@ -1890,15 +1890,14 @@ void ProtocolHandlerImpl::NotifySessionStarted(
char* version_param =
bson_object_get_string(&request_params, strings::protocol_version);
std::string version_string(version_param == NULL ? "" : version_param);
- fullVersion =
- std::make_shared<ProtocolPacket::ProtocolVersion>(version_string);
+ fullVersion = std::make_shared<utils::SemanticVersion>(version_string);
// Constructed payloads added in Protocol v5
if (fullVersion->majorVersion < PROTOCOL_VERSION_5) {
rejected_params.push_back(std::string(strings::protocol_version));
}
bson_object_deinitialize(&request_params);
} else {
- fullVersion = std::make_shared<ProtocolPacket::ProtocolVersion>();
+ fullVersion = std::make_shared<utils::SemanticVersion>();
}
#ifdef ENABLE_SECURITY
diff --git a/src/components/protocol_handler/src/protocol_packet.cc b/src/components/protocol_handler/src/protocol_packet.cc
index 3cd9e7f781..d5422e11bc 100644
--- a/src/components/protocol_handler/src/protocol_packet.cc
+++ b/src/components/protocol_handler/src/protocol_packet.cc
@@ -41,6 +41,7 @@
#include "protocol_handler/protocol_packet.h"
#include "utils/macro.h"
#include "utils/byte_order.h"
+#include "utils/semantic_version.h"
namespace protocol_handler {
@@ -52,48 +53,6 @@ ProtocolPacket::ProtocolData::~ProtocolData() {
delete[] data;
}
-ProtocolPacket::ProtocolVersion::ProtocolVersion()
- : majorVersion(0), minorVersion(0), patchVersion(0) {}
-
-ProtocolPacket::ProtocolVersion::ProtocolVersion(uint8_t majorVersion,
- uint8_t minorVersion,
- uint8_t patchVersion)
- : majorVersion(majorVersion)
- , minorVersion(minorVersion)
- , patchVersion(patchVersion) {}
-
-ProtocolPacket::ProtocolVersion::ProtocolVersion(ProtocolVersion& other) {
- this->majorVersion = other.majorVersion;
- this->minorVersion = other.minorVersion;
- this->patchVersion = other.patchVersion;
-}
-
-ProtocolPacket::ProtocolVersion::ProtocolVersion(std::string versionString)
- : majorVersion(0), minorVersion(0), patchVersion(0) {
- unsigned int majorInt, minorInt, patchInt;
- int readElements = sscanf(
- versionString.c_str(), "%u.%u.%u", &majorInt, &minorInt, &patchInt);
- if (readElements != 3) {
- LOG4CXX_WARN(logger_,
- "Error while parsing version string: " << versionString);
- } else {
- majorVersion = static_cast<uint8_t>(majorInt);
- minorVersion = static_cast<uint8_t>(minorInt);
- patchVersion = static_cast<uint8_t>(patchInt);
- }
-}
-
-std::string ProtocolPacket::ProtocolVersion::to_string() {
- char versionString[256];
- snprintf(versionString,
- 255,
- "%u.%u.%u",
- static_cast<unsigned int>(majorVersion),
- static_cast<unsigned int>(minorVersion),
- static_cast<unsigned int>(patchVersion));
- return std::string(versionString);
-}
-
ProtocolPacket::ProtocolHeader::ProtocolHeader()
: version(0x00)
, protection_flag(PROTECTION_OFF)
diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
index cfda0a550a..615900c7fa 100644
--- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc
+++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
@@ -48,6 +48,7 @@
#endif // ENABLE_SECURITY
#include "transport_manager/mock_transport_manager.h"
#include "utils/mock_system_time_handler.h"
+#include "utils/semantic_version.h"
#include "utils/test_async_waiter.h"
#include <bson_object.h>
@@ -1539,7 +1540,7 @@ void ProtocolHandlerImplTest::VerifySecondaryTransportParamsInStartSessionAck(
const uint8_t input_protocol_version = 5;
const uint32_t hash_id = 123456;
- ProtocolPacket::ProtocolVersion full_version(5, 1, 0);
+ utils::SemanticVersion full_version(5, 1, 0);
char full_version_string[] = "5.1.0";
// configuration setup
@@ -2030,7 +2031,7 @@ TEST_F(ProtocolHandlerImplTest,
const uint8_t input_protocol_version = 5;
const uint32_t hash_id = 123456;
- ProtocolPacket::ProtocolVersion full_version(5, 0, 0);
+ utils::SemanticVersion full_version(5, 0, 0);
char full_version_string[] = "5.0.0";
const size_t maximum_rpc_payload_size = 1500;
@@ -2190,7 +2191,7 @@ TEST_F(ProtocolHandlerImplTest,
const uint8_t input_protocol_version = 5;
const uint32_t hash_id = 123456;
- ProtocolPacket::ProtocolVersion full_version(5, 1, 0);
+ utils::SemanticVersion full_version(5, 1, 0);
const size_t maximum_rpc_payload_size = 1500;
EXPECT_CALL(protocol_handler_settings_mock, maximum_rpc_payload_size())
@@ -2313,7 +2314,7 @@ TEST_F(ProtocolHandlerImplTest,
const uint8_t input_protocol_version = 5;
const uint32_t hash_id = 123456;
- ProtocolPacket::ProtocolVersion full_version(5, 1, 0);
+ utils::SemanticVersion full_version(5, 1, 0);
const size_t maximum_rpc_payload_size = 1500;
EXPECT_CALL(protocol_handler_settings_mock, maximum_rpc_payload_size())
diff --git a/src/components/smart_objects/include/smart_objects/enum_schema_item.h b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
index 54de61d4e5..b9f8547922 100644
--- a/src/components/smart_objects/include/smart_objects/enum_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
@@ -138,6 +138,15 @@ class TEnumSchemaItem : public CDefaultSchemaItem<EnumType> {
rpc::ValidationReport* report__,
const utils::SemanticVersion& MessageVersion) OVERRIDE;
/**
+ * @brief Return the correct history signature based on message version.
+ * @param signatures Vector reference of enums history items.
+ * @param MessageVersion RPC Version of mobile app.
+ **/
+ const ElementSignature getSignature(
+ const std::vector<ElementSignature>& signatures,
+ const utils::SemanticVersion& MessageVersion);
+
+ /**
* @brief Apply schema.
* This implementation checks if enumeration is represented as string
* and tries to convert it to integer according to element-to-string
@@ -287,9 +296,8 @@ TEnumSchemaItem<EnumType>::createWithSignatures(
const std::set<EnumType>& AllowedElements,
const std::map<EnumType, std::vector<ElementSignature> >& ElementSignatures,
const TSchemaItemParameter<EnumType>& DefaultValue) {
- return std::shared_ptr<TEnumSchemaItem<EnumType> >(
- new TEnumSchemaItem<EnumType>(
- AllowedElements, DefaultValue, ElementSignatures));
+ std::make_shared<TEnumSchemaItem<EnumType> >(
+ AllowedElements, DefaultValue, ElementSignatures);
}
template <typename EnumType>
@@ -326,6 +334,40 @@ Errors::eType TEnumSchemaItem<EnumType>::validate(
}
template <typename EnumType>
+const ElementSignature TEnumSchemaItem<EnumType>::getSignature(
+ const std::vector<ElementSignature>& signatures,
+ const utils::SemanticVersion& MessageVersion) {
+ for (uint i = 0; i < signatures.size(); i++) {
+ ElementSignature signature = signatures[i];
+ // Check if signature matches message version
+ if (signature.mSince != boost::none) {
+ if (MessageVersion < signature.mSince.get()) {
+ // Msg version predates 'since' field, check next entry
+ continue;
+ }
+
+ if (signature.mUntil != boost::none &&
+ (MessageVersion >= signature.mUntil.get())) {
+ continue; // Msg version newer than `until` field
+ }
+
+ return signature;
+ }
+
+ if (signature.mUntil != boost::none &&
+ (MessageVersion >= signature.mUntil.get())) {
+ continue; // Msg version newer than `until` field, check next entry
+ }
+
+ return signature;
+ }
+
+ // Could not match msg version to element siganture
+ ElementSignature ret("", "", true);
+ return ret;
+}
+
+template <typename EnumType>
Errors::eType TEnumSchemaItem<EnumType>::validate(
const SmartObject& Object,
rpc::ValidationReport* report__,
@@ -361,60 +403,17 @@ Errors::eType TEnumSchemaItem<EnumType>::validate(
auto signatures_it = mElementSignatures.find(value);
if (signatures_it != mElementSignatures.end()) {
if (!signatures_it->second.empty()) {
- for (uint i = 0; i < signatures_it->second.size(); i++) {
- ElementSignature signature = signatures_it->second[i];
- // Check if signature matches message version
- if (signature.mSince.is_initialized()) {
- if (MessageVersion < signature.mSince.get()) {
- // Msg version predates 'since' field, check next entry
- continue;
- } else {
- if (signature.mUntil.is_initialized() &&
- (MessageVersion >= signature.mUntil.get())) {
- continue; // Msg version newer than `until` field
- } else {
- // Found correct version
- if (signature.mRemoved) {
- // Element was removed for this version
- std::string validation_info = "Invalid enum value: " +
- Object.asString() +
- " removed for SyncMsgVersion " +
- MessageVersion.toString();
- report__->set_validation_info(validation_info);
- return Errors::INVALID_VALUE;
- }
- return Errors::OK; // Mobile msg version falls within specified
- // version range and is not removed
- }
- }
- } // end if signature.mSince.is_initialized()
-
- if (signature.mUntil.is_initialized() &&
- (MessageVersion >= signature.mUntil.get())) {
- continue; // Msg version newer than `until` field, check next entry
- } else {
- // Found correct version
- if (signature.mRemoved) {
- // Element was removed for this version
- std::string validation_info =
- "Enum value : " + Object.asString() +
- " removed for SyncMsgVersion " + MessageVersion.toString();
- report__->set_validation_info(validation_info);
- return Errors::INVALID_VALUE;
- }
- return Errors::OK; // Mobile msg version falls within specified
- // version range and is not removed
- }
- } // End For Loop Version not found.
- std::string validation_info =
- "Invalid enum value: " + Object.asString() +
- " for SyncMsgVersion " + MessageVersion.toString();
- report__->set_validation_info(validation_info);
- return Errors::INVALID_VALUE;
+ if (getSignature(signatures_it->second, MessageVersion).mRemoved) {
+ // Element was removed for this version
+ std::string validation_info = "Enum value : " + Object.asString() +
+ " removed for SyncMsgVersion " +
+ MessageVersion.toString();
+ report__->set_validation_info(validation_info);
+ return Errors::INVALID_VALUE;
+ }
}
}
}
-
return Errors::OK;
}
@@ -464,9 +463,8 @@ TEnumSchemaItem<EnumType>::TEnumSchemaItem(
const TSchemaItemParameter<EnumType>& DefaultValue,
const std::map<EnumType, std::vector<ElementSignature> >& ElementSignatures)
: CDefaultSchemaItem<EnumType>(DefaultValue)
- , mAllowedElements(AllowedElements) {
- mElementSignatures = ElementSignatures;
-}
+ , mAllowedElements(AllowedElements)
+ , mElementSignatures(ElementSignatures) {}
} // namespace NsSmartObjects
} // namespace NsSmartDeviceLink
diff --git a/src/components/smart_objects/include/smart_objects/object_schema_item.h b/src/components/smart_objects/include/smart_objects/object_schema_item.h
index 4a36f06f3c..aa807e98ab 100644
--- a/src/components/smart_objects/include/smart_objects/object_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/object_schema_item.h
@@ -64,7 +64,6 @@ class CObjectSchemaItem : public ISchemaItem {
* @param IsMandatory true if member is mandatory, false
* otherwise. Defaults to true.
**/
- // SMember(const ISchemaItemPtr SchemaItem, const bool IsMandatory = true);
SMember(const ISchemaItemPtr SchemaItem,
const bool IsMandatory = true,
@@ -174,11 +173,12 @@ class CObjectSchemaItem : public ISchemaItem {
const utils::SemanticVersion& MessageVersion);
/**
- * @brief Checks mandatory and version fields to see
- * if a member is required.
- * @param Object Object to remove fake parameters.
+ * @brief Returns the correct schema item based on messge version.
+ * @param member Schema member
+ * @param MmessageVersion Semantic Version of mobile message.
**/
- bool IsMandatory(const SMember& member);
+ const CObjectSchemaItem::SMember& GetCorrectMember(
+ const SMember& member, const utils::SemanticVersion& messageVersion);
/**
* @brief Map of member name to SMember structure describing the object
diff --git a/src/components/smart_objects/src/object_schema_item.cc b/src/components/smart_objects/src/object_schema_item.cc
index d046e49bcd..533f3b5e2c 100644
--- a/src/components/smart_objects/src/object_schema_item.cc
+++ b/src/components/smart_objects/src/object_schema_item.cc
@@ -166,45 +166,12 @@ Errors::eType CObjectSchemaItem::validate(
++it) {
const std::string& key = it->first;
const SMember& member = it->second;
+ const SMember& correct_member = GetCorrectMember(member, MessageVersion);
+
std::set<std::string>::const_iterator key_it = object_keys.find(key);
if (object_keys.end() == key_it) {
- if (member.mSince != boost::none &&
- MessageVersion < member.mSince.get() &&
- member.mHistoryVector.size() > 0) {
- // Message version predates parameter and a history vector exists.
- for (uint i = 0; i < member.mHistoryVector.size(); i++) {
- if (member.mHistoryVector[i].mSince != boost::none &&
- MessageVersion >= member.mHistoryVector[i].mSince.get()) {
- if (member.mHistoryVector[i].mUntil != boost::none &&
- MessageVersion >= member.mHistoryVector[i].mUntil.get()) {
- // MessageVersion is newer than the specified "Until" version
- continue;
- } else {
- if (member.mHistoryVector[i].mIsMandatory == true &&
- (member.mHistoryVector[i].mIsRemoved == false)) {
- std::string validation_info =
- "Missing mandatory parameter since and until: " + key;
- report__->set_validation_info(validation_info);
- return Errors::MISSING_MANDATORY_PARAMETER;
- }
- break;
- }
- } else if (member.mHistoryVector[i].mSince == boost::none &&
- member.mHistoryVector[i].mUntil != boost::none &&
- MessageVersion < member.mHistoryVector[i].mUntil.get()) {
- if (member.mHistoryVector[i].mIsMandatory == true &&
- (member.mHistoryVector[i].mIsRemoved == false)) {
- std::string validation_info =
- "Missing mandatory parameter until: " + key;
- report__->set_validation_info(validation_info);
- return Errors::MISSING_MANDATORY_PARAMETER;
- }
- break;
- }
- }
- } else if (member.mIsMandatory &&
- member.CheckHistoryFieldVersion(MessageVersion) &&
- (member.mIsMandatory == false)) {
+ if (correct_member.mIsMandatory == true &&
+ correct_member.mIsRemoved == false) {
std::string validation_info = "Missing mandatory parameter: " + key;
report__->set_validation_info(validation_info);
return Errors::MISSING_MANDATORY_PARAMETER;
@@ -215,19 +182,8 @@ Errors::eType CObjectSchemaItem::validate(
Errors::eType result = Errors::OK;
// Check if MessageVersion matches schema version
- if (member.CheckHistoryFieldVersion(MessageVersion) ||
- member.mHistoryVector.empty()) {
- result = member.mSchemaItem->validate(
- field, &report__->ReportSubobject(key), MessageVersion);
- } else if (member.mHistoryVector.size() > 0) { // Check for history
- for (uint i = 0; i < member.mHistoryVector.size(); i++) {
- if (member.mHistoryVector[i].CheckHistoryFieldVersion(MessageVersion)) {
- // Found the correct history schema. Call validate
- result = member.mHistoryVector[i].mSchemaItem->validate(
- field, &report__->ReportSubobject(key), MessageVersion);
- }
- }
- }
+ result = correct_member.mSchemaItem->validate(
+ field, &report__->ReportSubobject(key), MessageVersion);
if (Errors::OK != result) {
return result;
}
@@ -328,30 +284,34 @@ void CObjectSchemaItem::RemoveFakeParams(
key.compare(app_id) != 0) {
++it;
Object.erase(key);
- } else if (mMembers.end() != members_it && members_it->second.mIsRemoved &&
- members_it->second.CheckHistoryFieldVersion(MessageVersion)) {
- ++it;
- Object.erase(key);
+
} else if (mMembers.end() != members_it &&
- members_it->second.mHistoryVector.size() > 0) {
- for (uint i = 0; i < members_it->second.mHistoryVector.size(); i++) {
- if (members_it->second.mHistoryVector[i].CheckHistoryFieldVersion(
- MessageVersion) &&
- members_it->second.mHistoryVector[i].mIsRemoved) {
- ++it;
- Object.erase(key);
- break;
- }
- }
+ GetCorrectMember(members_it->second, MessageVersion)
+ .mIsRemoved) {
++it;
+ Object.erase(key);
} else {
++it;
}
}
}
-bool CObjectSchemaItem::IsMandatory(const SMember& member) {
- return true;
+const CObjectSchemaItem::SMember& CObjectSchemaItem::GetCorrectMember(
+ const SMember& member, const utils::SemanticVersion& messageVersion) {
+ // Check if member is the correct version
+ if (member.CheckHistoryFieldVersion(messageVersion)) {
+ return member;
+ }
+ // Check for history tag items
+ if (!member.mHistoryVector.empty()) {
+ for (uint i = 0; i < member.mHistoryVector.size(); i++) {
+ if (member.mHistoryVector[i].CheckHistoryFieldVersion(messageVersion)) {
+ return member.mHistoryVector[i];
+ }
+ }
+ }
+ // Return member as default
+ return member;
}
} // namespace NsSmartObjects