diff options
author | AKalinich-Luxoft <AKalinich@luxoft.com> | 2017-12-22 15:13:21 +0200 |
---|---|---|
committer | AKalinich-Luxoft <AKalinich@luxoft.com> | 2018-01-29 09:04:14 +0200 |
commit | 7898292b5de8d80354ab3b9fecacbadcf9d41c61 (patch) | |
tree | cf588c13a8f522d5672c90316b31f87e42ee03f9 /src/components/protocol_handler | |
parent | 96a14a8de28ea2ad877745494f2e53211ffb34b9 (diff) | |
download | sdl_core-7898292b5de8d80354ab3b9fecacbadcf9d41c61.tar.gz |
Refactoring in connection/protocol handlers
NotifySessionStartedResult function were updated to use
StartingSessionContext class for accessing to needed data
instead of tones of separate parameters.
Also in protocol handler some raw pointer data were replaced
with smart objects.
Diffstat (limited to 'src/components/protocol_handler')
-rw-r--r-- | src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h | 13 | ||||
-rw-r--r-- | src/components/protocol_handler/src/protocol_handler_impl.cc | 91 |
2 files changed, 54 insertions, 50 deletions
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 dc1a119223..65f03900db 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 @@ -391,7 +391,7 @@ class ProtocolHandlerImpl * Only valid when generated_session_id is 0. Note, even if * generated_session_id is 0, the list may be empty. */ - void NotifySessionStartedResult( + DEPRECATED void NotifySessionStartedResult( int32_t connection_id, uint8_t session_id, uint8_t generated_session_id, @@ -399,6 +399,17 @@ class ProtocolHandlerImpl 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 + * @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. + */ + void NotifySessionStarted(const SessionContext& context, + std::vector<std::string>& rejected_params) OVERRIDE; + #ifdef BUILD_TESTS const impl::FromMobileQueue& get_from_mobile_queue() const { return raw_ford_messages_from_mobile_; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 1ffbff3b08..3d97201ab4 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1285,12 +1285,14 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession( 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()) { @@ -1390,11 +1392,25 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( uint32_t hash_id, bool protection, std::vector<std::string>& rejected_params) { + LOG4CXX_AUTO_TRACE(logger_); + protocol_handler::SessionContext context(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_); + ProtocolFramePtr packet; { sync_primitives::AutoLock auto_lock(start_session_frame_map_lock_); StartSessionFrameMap::iterator it = start_session_frame_map_.find( - std::make_pair(connection_id, session_id)); + std::make_pair(context.connection_id_, context.initial_session_id_)); if (it == start_session_frame_map_.end()) { LOG4CXX_ERROR(logger_, "Cannot find Session Started packet"); return; @@ -1406,11 +1422,11 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( const ServiceType service_type = ServiceTypeFromByte(packet->service_type()); const uint8_t protocol_version = packet->protocol_version(); - if (0 == generated_session_id) { + if (0 == context.new_session_id_) { LOG4CXX_WARN(logger_, "Refused by session_observer to create service " << static_cast<int32_t>(service_type) << " type."); - SendStartSessionNAck(connection_id, + SendStartSessionNAck(context.connection_id_, packet->session_id(), protocol_version, packet->service_type(), @@ -1418,8 +1434,9 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( return; } - BsonObject start_session_ack_params; - bson_object_initialize_default(&start_session_ack_params); + std::shared_ptr<BsonObject> start_session_ack_params( + new BsonObject(), [](BsonObject* obj) { bson_object_deinitialize(obj); }); + bson_object_initialize_default(start_session_ack_params.get()); // when video service is successfully started, copy input parameters // ("width", "height", "videoProtocol", "videoCodec") to the ACK packet if (packet->service_type() == kMobileNav && packet->data() != NULL) { @@ -1428,13 +1445,13 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( if ((element = bson_object_get(&req_param, strings::height)) != NULL && element->type == TYPE_INT32) { - bson_object_put_int32(&start_session_ack_params, + bson_object_put_int32(start_session_ack_params.get(), strings::height, bson_object_get_int32(&req_param, strings::height)); } if ((element = bson_object_get(&req_param, strings::width)) != NULL && element->type == TYPE_INT32) { - bson_object_put_int32(&start_session_ack_params, + bson_object_put_int32(start_session_ack_params.get(), strings::width, bson_object_get_int32(&req_param, strings::width)); } @@ -1442,17 +1459,17 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( bson_object_get_string(&req_param, strings::video_protocol); if (protocol != NULL) { bson_object_put_string( - &start_session_ack_params, strings::video_protocol, protocol); + start_session_ack_params.get(), strings::video_protocol, protocol); } char* codec = bson_object_get_string(&req_param, strings::video_codec); if (codec != NULL) { bson_object_put_string( - &start_session_ack_params, strings::video_codec, codec); + start_session_ack_params.get(), strings::video_codec, codec); } bson_object_deinitialize(&req_param); } - ProtocolPacket::ProtocolVersion* fullVersion; + std::shared_ptr<ProtocolPacket::ProtocolVersion> 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 @@ -1487,22 +1504,15 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( connection_key, security_manager::SecurityManager::ERROR_INTERNAL, error); - // Start service without protection - SendStartSessionAck(connection_id, - generated_session_id, - packet->protocol_version(), - hash_id, - packet->service_type(), - PROTECTION_OFF, - *fullVersion, - start_session_ack_params); - delete fullVersion; - bson_object_deinitialize(&start_session_ack_params); + + handler->OnHandshakeDone( + connection_key, security_manager::SSLContext::Handshake_Result_Fail); + return; } if (!rejected_params.empty()) { - SendStartSessionNAck(connection_id, + SendStartSessionNAck(context.connection_id_, packet->session_id(), protocol_version, packet->service_type(), @@ -1511,36 +1521,21 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( // mark service as protected session_observer_.SetProtectionFlag(connection_key, service_type); // Start service as protected with current SSLContext - SendStartSessionAck(connection_id, - generated_session_id, + SendStartSessionAck(context.connection_id_, + context.new_session_id_, packet->protocol_version(), - hash_id, + context.hash_id_, packet->service_type(), PROTECTION_ON, *fullVersion, - start_session_ack_params); + *start_session_ack_params); } else { - // Need a copy because fullVersion will be deleted - ProtocolPacket::ProtocolVersion fullVersionCopy(*fullVersion); - security_manager_->AddListener(new StartSessionHandler( - connection_key, - this, - session_observer_, - connection_id, - generated_session_id, - packet->protocol_version(), - hash_id, - service_type, - get_settings().force_protected_service(), - fullVersionCopy, - bson_object_to_bytes(&start_session_ack_params))); + security_manager_->AddListener(new HandshakeHandler(*handler)); if (!ssl_context->IsHandshakePending()) { // Start handshake process security_manager_->StartHandshake(connection_key); } } - delete fullVersion; - bson_object_deinitialize(&start_session_ack_params); LOG4CXX_DEBUG(logger_, "Protection establishing for connection " << connection_key << " is in progress"); @@ -1548,23 +1543,21 @@ void ProtocolHandlerImpl::NotifySessionStartedResult( } #endif // ENABLE_SECURITY if (rejected_params.empty()) { - SendStartSessionAck(connection_id, - generated_session_id, + SendStartSessionAck(context.connection_id_, + context.new_session_id_, packet->protocol_version(), - hash_id, + context.hash_id_, packet->service_type(), PROTECTION_OFF, *fullVersion, - start_session_ack_params); + *start_session_ack_params); } else { - SendStartSessionNAck(connection_id, + SendStartSessionNAck(context.connection_id_, packet->session_id(), protocol_version, packet->service_type(), rejected_params); } - delete fullVersion; - bson_object_deinitialize(&start_session_ack_params); } RESULT_CODE ProtocolHandlerImpl::HandleControlMessageHeartBeat( |