diff options
author | jacobkeeler <jacob.keeler@livioradio.com> | 2018-08-22 13:07:09 -0400 |
---|---|---|
committer | jacobkeeler <jacob.keeler@livioradio.com> | 2018-08-22 13:07:09 -0400 |
commit | 6ada4dc5bd0d9a2b6068745154e715fccd5dc943 (patch) | |
tree | 2890f67599792367ca6315867b66be682795dea7 /src/components/protocol_handler | |
parent | a086a8e23ed7c86f27460ddc61046ca595ab46a9 (diff) | |
parent | 6a436addb2811c3fbc6ff155a8a142aa14c8ec45 (diff) | |
download | sdl_core-6ada4dc5bd0d9a2b6068745154e715fccd5dc943.tar.gz |
Merge remote-tracking branch 'origin/develop' into feature/boost_datetime_implementation
Diffstat (limited to 'src/components/protocol_handler')
7 files changed, 34 insertions, 360 deletions
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..cb52c9d375 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; @@ -50,22 +52,9 @@ class ProtocolHandlerImpl; */ class HandshakeHandler : public security_manager::SecurityManagerListener { public: - DEPRECATED HandshakeHandler(ProtocolHandlerImpl& protocol_handler, - SessionObserver& session_observer, - uint32_t connection_key, - ConnectionID connection_id, - uint8_t session_id, - uint8_t protocol_version, - uint32_t hash_id, - ServiceType service_type, - const std::vector<int>& force_protected_service, - const bool is_new_service, - ProtocolPacket::ProtocolVersion& 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 +113,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..3e7d64e9d2 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 { @@ -417,27 +418,6 @@ class ProtocolHandlerImpl SessionObserver& get_session_observer() OVERRIDE; /** - * \brief Called by connection handler to notify the result of - * OnSessionStartedCallback(). - * \param connection_id Identifier of connection within which session exists - * \param session_id session ID passed to OnSessionStartedCallback() - * \param generated_session_id Generated session ID, will be 0 if session is - * not started - * \param hash_id Generated Hash ID - * \param protection whether the service will be protected - * \param rejected_params list of parameters' name that are rejected. - * Only valid when generated_session_id is 0. Note, even if - * generated_session_id is 0, the list may be empty. - */ - DEPRECATED void NotifySessionStartedResult( - int32_t connection_id, - uint8_t session_id, - uint8_t generated_session_id, - uint32_t hash_id, - bool protection, - std::vector<std::string>& rejected_params) OVERRIDE; - - /** * @brief Called by connection handler to notify the result of * OnSessionStartedCallback(). * @param context reference to structure with started session data @@ -648,9 +628,6 @@ class ProtocolHandlerImpl RESULT_CODE HandleControlMessageEndServiceACK(const ProtocolPacket& packet); - DEPRECATED RESULT_CODE - HandleControlMessageStartSession(const ProtocolPacket& packet); - RESULT_CODE HandleControlMessageStartSession(const ProtocolFramePtr packet); RESULT_CODE HandleControlMessageRegisterSecondaryTransport( 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..de4af84915 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_packet.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_packet.h @@ -64,58 +64,6 @@ class ProtocolPacket { }; /** - * \class ProtocolVersion - * \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); - if (diff == 0) { - diff = static_cast<int16_t>(version1.patchVersion - - version2.patchVersion); - } - } - 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(); - }; - - /** * \class ProtocolHeader * \brief Used for storing protocol header of a message. */ diff --git a/src/components/protocol_handler/src/handshake_handler.cc b/src/components/protocol_handler/src/handshake_handler.cc index 8db551cfd6..775d77db66 100644 --- a/src/components/protocol_handler/src/handshake_handler.cc +++ b/src/components/protocol_handler/src/handshake_handler.cc @@ -43,33 +43,12 @@ namespace protocol_handler { CREATE_LOGGERPTR_GLOBAL(logger_, "ProtocolHandler") -HandshakeHandler::HandshakeHandler( - ProtocolHandlerImpl& protocol_handler, - SessionObserver& session_observer, - uint32_t connection_key, - ConnectionID connection_id, - uint8_t session_id, - uint8_t protocol_version, - uint32_t hash_id, - ServiceType service_type, - const std::vector<int>& force_protected_service, - const bool is_new_service, - ProtocolPacket::ProtocolVersion& full_version, - std::shared_ptr<BsonObject> payload) - : protocol_handler_(protocol_handler) - , session_observer_(session_observer) - , context_() - , full_version_(full_version) - , 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 b4b66f47be..30435ccd61 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_); @@ -252,7 +252,7 @@ void ProtocolHandlerImpl::SendStartSessionAck( const bool proxy_supports_v5_protocol = input_protocol_version >= PROTOCOL_VERSION_5 || (ServiceTypeFromByte(service_type) == kRpc && - full_version.majorVersion >= PROTOCOL_VERSION_5); + full_version.major_version_ >= PROTOCOL_VERSION_5); if (kRpc != service_type) { // In case if input protocol version os bigger then supported, SDL should @@ -307,13 +307,13 @@ void ProtocolHandlerImpl::SendStartSessionAck( ¶ms, strings::hash_id))); // Minimum protocol version supported by both - ProtocolPacket::ProtocolVersion* minVersion = - (full_version.majorVersion < PROTOCOL_VERSION_5) + utils::SemanticVersion* minVersion = + (full_version.major_version_ < 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( ¶ms, strings::protocol_version, protocolVersionString); @@ -1546,166 +1546,6 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndServiceACK( return RESULT_OK; } -// Suppress warning for deprecated method used within another deprecated method -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession( - const ProtocolPacket& packet) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG( - logger_, - "Protocol version:" << static_cast<int>(packet.protocol_version())); - const ServiceType service_type = ServiceTypeFromByte(packet.service_type()); - -#ifdef ENABLE_SECURITY - const bool protection = - // Protocol version 1 is not support protection - (packet.protocol_version() > PROTOCOL_VERSION_1) - ? packet.protection_flag() - : false; -#else - const bool protection = false; -#endif // ENABLE_SECURITY - - uint32_t hash_id; - const ConnectionID connection_id = packet.connection_id(); - const uint32_t session_id = session_observer_.OnSessionStartedCallback( - connection_id, packet.session_id(), service_type, protection, &hash_id); - - if (0 == session_id) { - LOG4CXX_WARN(logger_, - "Refused by session_observer to create service " - << static_cast<int32_t>(service_type) << " type."); - SendStartSessionNAck(connection_id, - packet.session_id(), - packet.protocol_version(), - packet.service_type()); - return RESULT_OK; - } - -#ifdef ENABLE_SECURITY - // for packet is encrypted and security plugin is enable - if (protection && security_manager_) { - const uint32_t connection_key = - session_observer_.KeyFromPair(connection_id, session_id); - - security_manager::SSLContext* ssl_context = - security_manager_->CreateSSLContext( - connection_key, security_manager::SecurityManager::kUseExisting); - if (!ssl_context) { - const std::string error("CreateSSLContext failed"); - LOG4CXX_ERROR(logger_, error); - security_manager_->SendInternalError( - connection_key, - security_manager::SecurityManager::ERROR_INTERNAL, - error); - // Start service without protection - SendStartSessionAck(connection_id, - session_id, - packet.protocol_version(), - hash_id, - packet.service_type(), - PROTECTION_OFF); - return RESULT_OK; - } - ProtocolPacket::ProtocolVersion* 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( - std::string(bson_object_get_string(&obj, "protocolVersion"))); - bson_object_deinitialize(&obj); - // Constructed payloads added in Protocol v5 - if (fullVersion->majorVersion < PROTOCOL_VERSION_5) { - rejectedParams.push_back(std::string("protocolVersion")); - } - } else { - fullVersion = new ProtocolPacket::ProtocolVersion(); - } - if (!rejectedParams.empty()) { - SendStartSessionNAck(connection_id, - packet.session_id(), - packet.protocol_version(), - packet.service_type(), - rejectedParams); - } else if (ssl_context->IsInitCompleted()) { - // mark service as protected - session_observer_.SetProtectionFlag(connection_key, service_type); - // Start service as protected with current SSLContext - SendStartSessionAck(connection_id, - session_id, - packet.protocol_version(), - hash_id, - packet.service_type(), - PROTECTION_ON, - *fullVersion); - } else { - security_manager_->AddListener( - new HandshakeHandler(*this, - session_observer_, - connection_key, - connection_id, - session_id, - packet.protocol_version(), - hash_id, - service_type, - get_settings().force_protected_service(), - false, - *fullVersion, - NULL)); - if (!ssl_context->IsHandshakePending()) { - // Start handshake process - security_manager_->StartHandshake(connection_key); - } - } - delete fullVersion; - LOG4CXX_DEBUG(logger_, - "Protection establishing for connection " - << connection_key << " is in progress"); - return RESULT_OK; - } -#endif // ENABLE_SECURITY - if (packet.service_type() == kRpc && packet.data_size() != 0) { - BsonObject obj = bson_object_from_bytes(packet.data()); - ProtocolPacket::ProtocolVersion fullVersion( - bson_object_get_string(&obj, "protocolVersion")); - bson_object_deinitialize(&obj); - - if (fullVersion.majorVersion >= PROTOCOL_VERSION_5) { - // Start service without protection - SendStartSessionAck(connection_id, - session_id, - packet.protocol_version(), - hash_id, - packet.service_type(), - PROTECTION_OFF, - fullVersion); - } else { - std::vector<std::string> rejectedParams(1, - std::string("protocolVersion")); - SendStartSessionNAck(connection_id, - packet.session_id(), - packet.protocol_version(), - packet.service_type(), - rejectedParams); - } - - } else { - // Start service without protection - SendStartSessionAck(connection_id, - session_id, - packet.protocol_version(), - hash_id, - packet.service_type(), - PROTECTION_OFF); - } - return RESULT_OK; -} -#pragma GCC diagnostic pop - RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession( const ProtocolFramePtr packet) { LOG4CXX_AUTO_TRACE(logger_); @@ -1795,24 +1635,6 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageRegisterSecondaryTransport( return RESULT_OK; } -void ProtocolHandlerImpl::NotifySessionStartedResult( - int32_t connection_id, - uint8_t session_id, - uint8_t generated_session_id, - uint32_t hash_id, - bool protection, - std::vector<std::string>& rejected_params) { - LOG4CXX_AUTO_TRACE(logger_); - protocol_handler::SessionContext context(connection_id, - connection_id, - session_id, - generated_session_id, - ServiceType::kInvalidServiceType, - hash_id, - protection); - NotifySessionStarted(context, rejected_params); -} - void ProtocolHandlerImpl::NotifySessionStarted( const SessionContext& context, std::vector<std::string>& rejected_params) { LOG4CXX_AUTO_TRACE(logger_); @@ -1880,7 +1702,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 +1712,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) { + if (fullVersion->major_version_ < 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()) |