Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix V5 protocol message bson params #2235

Merged
merged 7 commits into from
Jun 18, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,6 @@ void ConnectionHandlerImpl::OnSessionStartedCallback(
const uint32_t session_key =
KeyFromPair(connection_handle, context.new_session_id_);

uint32_t app_id = 0;
GetDataOnSessionKey(
session_key, &app_id, NULL, static_cast<DeviceHandle*>(NULL));
if (app_id > 0) {
context.is_ptu_required_ =
!connection_handler_observer_->CheckAppIsNavi(app_id);
}

{
sync_primitives::AutoLock auto_lock(start_service_context_map_lock_);
start_service_context_map_[session_key] = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,6 @@ TEST_F(ConnectionHandlerTest, SessionStarted_WithRpc) {
true,
ByRef(empty)));

EXPECT_CALL(mock_connection_handler_observer, CheckAppIsNavi(_))
.WillOnce(Return(true));

connection_handler_->set_protocol_handler(&mock_protocol_handler_);
EXPECT_CALL(mock_protocol_handler_, NotifySessionStarted(_, _))
.WillOnce(SaveArg<0>(&out_context_));
Expand Down Expand Up @@ -1312,8 +1309,6 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_SUCCESS) {
session_key,
true,
ByRef(empty)));
EXPECT_CALL(mock_connection_handler_observer, CheckAppIsNavi(_))
.WillOnce(Return(true));

// confirm that NotifySessionStarted() is called
connection_handler_->set_protocol_handler(&mock_protocol_handler_);
Expand Down Expand Up @@ -1354,8 +1349,6 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_FAILURE) {
session_key,
false,
ByRef(empty)));
EXPECT_CALL(mock_connection_handler_observer, CheckAppIsNavi(_))
.WillOnce(Return(true));

// confirm that NotifySessionStarted() is called
connection_handler_->set_protocol_handler(&mock_protocol_handler_);
Expand Down Expand Up @@ -1446,9 +1439,6 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_Multiple) {
session_key1,
true,
ByRef(empty))));
EXPECT_CALL(mock_connection_handler_observer, CheckAppIsNavi(_))
.Times(2)
.WillOnce(Return(true));

// verify that connection handler will not mix up the two results
SessionContext new_context_first, new_context_second;
Expand Down
7 changes: 2 additions & 5 deletions src/components/include/protocol_handler/session_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct SessionContext {
uint32_t hash_id_;
bool is_protected_;
bool is_new_service_;
bool is_ptu_required_;

/**
* @brief Constructor
Expand All @@ -78,8 +77,7 @@ struct SessionContext {
, service_type_(protocol_handler::kInvalidServiceType)
, hash_id_(0)
, is_protected_(false)
, is_new_service_(false)
, is_ptu_required_(false) {}
, is_new_service_(false) {}

/**
* @brief Constructor
Expand All @@ -105,8 +103,7 @@ struct SessionContext {
, service_type_(service_type)
, hash_id_(hash_id)
, is_protected_(is_protected)
, is_new_service_(false)
, is_ptu_required_(false) {}
, is_new_service_(false) {}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,11 +1790,6 @@ StatusNotifier PolicyManagerImpl::AddApplication(
device_consent);
} else {
PromoteExistedApplication(application_id, device_consent);
if (helpers::in_range(hmi_types, policy_table::AHT_NAVIGATION) &&
!HasCertificate()) {
LOG4CXX_DEBUG(logger_, "Certificate does not exist, scheduling update.");
update_status_manager_.ScheduleUpdate();
}
return utils::MakeShared<utils::CallNothing>();
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/components/policy/policy_regular/src/policy_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1073,13 +1073,6 @@ StatusNotifier PolicyManagerImpl::AddApplication(
device_consent);
} else {
PromoteExistedApplication(application_id, device_consent);
const policy_table::AppHMIType type = policy_table::AHT_NAVIGATION;
if (helpers::in_range(hmi_types,
(rpc::Enum<policy_table::AppHMIType>)type) &&
!HasCertificate()) {
LOG4CXX_DEBUG(logger_, "Certificate does not exist, scheduling update.");
update_status_manager_.ScheduleUpdate();
}
return utils::MakeShared<utils::CallNothing>();
}
}
Expand Down Expand Up @@ -1157,6 +1150,10 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name,
if (ret) {
RefreshRetrySequence();
update_status_manager_.OnPolicyInit(cache_->UpdateRequired());
const std::string certificate_data = cache_->GetCertificate();
if (!certificate_data.empty()) {
listener_->OnCertificateUpdated(certificate_data);
}
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class HandshakeHandler : public security_manager::SecurityManagerListener {
const std::vector<int>& force_protected_service,
const bool is_new_service,
ProtocolPacket::ProtocolVersion& full_version,
std::shared_ptr<uint8_t> payload);
std::shared_ptr<BsonObject> payload);

HandshakeHandler(ProtocolHandlerImpl& protocol_handler,
SessionObserver& session_observer,
ProtocolPacket::ProtocolVersion& full_version,
const SessionContext& context,
const uint8_t protocol_version,
std::shared_ptr<uint8_t> payload);
std::shared_ptr<BsonObject> payload);

~HandshakeHandler();

Expand Down Expand Up @@ -126,7 +126,7 @@ class HandshakeHandler : public security_manager::SecurityManagerListener {
SessionContext context_;
ProtocolPacket::ProtocolVersion full_version_;
const uint8_t protocol_version_;
std::shared_ptr<uint8_t> payload_;
std::shared_ptr<BsonObject> payload_;
};

} // namespace protocol_handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,6 @@ class ProtocolHandlerImpl
void OnConnectionClosed(
const transport_manager::ConnectionUID connection_id) OVERRIDE;

/**
* @brief OnPTUFinished the callback which signals PTU has finished
*
* @param ptu_result the result from the PTU - true if successful,
* otherwise false.
*/
void OnPTUFinished(const bool ptu_result) OVERRIDE;

/**
* @brief Notifies subscribers about message
* received from mobile device.
Expand Down Expand Up @@ -685,12 +677,6 @@ class ProtocolHandlerImpl

#ifdef ENABLE_SECURITY
security_manager::SecurityManager* security_manager_;

bool is_ptu_triggered_;
std::list<std::shared_ptr<HandshakeHandler> > ptu_pending_handlers_;
std::list<std::shared_ptr<HandshakeHandler> > handshake_handlers_;
sync_primitives::Lock ptu_handlers_lock_;
sync_primitives::Lock handshake_handlers_lock_;
#endif // ENABLE_SECURITY

// Thread that pumps non-parsed messages coming from mobile side.
Expand Down
34 changes: 19 additions & 15 deletions src/components/protocol_handler/src/handshake_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HandshakeHandler::HandshakeHandler(
const std::vector<int>& force_protected_service,
const bool is_new_service,
ProtocolPacket::ProtocolVersion& full_version,
std::shared_ptr<uint8_t> payload)
std::shared_ptr<BsonObject> payload)
: protocol_handler_(protocol_handler)
, session_observer_(session_observer)
, context_()
Expand All @@ -69,7 +69,7 @@ HandshakeHandler::HandshakeHandler(
ProtocolPacket::ProtocolVersion& full_version,
const SessionContext& context,
const uint8_t protocol_version,
std::shared_ptr<uint8_t> payload)
std::shared_ptr<BsonObject> payload)
: protocol_handler_(protocol_handler)
, session_observer_(session_observer)
, context_(context)
Expand All @@ -93,14 +93,15 @@ bool HandshakeHandler::GetPolicyCertificateData(std::string& data) const {
void HandshakeHandler::OnCertificateUpdateRequired() {}

bool HandshakeHandler::OnHandshakeFailed() {
BsonObject params;
if (payload_) {
params = bson_object_from_bytes(payload_.get());
ProcessFailedHandshake(*payload_);
} else {
BsonObject params;
bson_object_initialize_default(&params);
ProcessFailedHandshake(params);
bson_object_deinitialize(&params);
}
ProcessFailedHandshake(params);
bson_object_deinitialize(&params);

return true;
}

Expand All @@ -122,20 +123,23 @@ bool HandshakeHandler::OnHandshakeDone(
const bool success =
result == security_manager::SSLContext::Handshake_Result_Success;

BsonObject params;
if (payload_) {
params = bson_object_from_bytes(payload_.get());
if (success) {
ProcessSuccessfulHandshake(connection_key, *payload_);
} else {
ProcessFailedHandshake(*payload_);
}
} else {
BsonObject params;
bson_object_initialize_default(&params);
if (success) {
ProcessSuccessfulHandshake(connection_key, params);
} else {
ProcessFailedHandshake(params);
}
bson_object_deinitialize(&params);
}

if (success) {
ProcessSuccessfulHandshake(connection_key, params);
} else {
ProcessFailedHandshake(params);
}

bson_object_deinitialize(&params);
return true;
}

Expand Down
Loading