summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Keeler <jacobkeeler@ymail.com>2018-06-01 14:11:15 -0700
committerJacob Keeler <jacobkeeler@ymail.com>2018-06-01 14:29:56 -0700
commit47b7b86071d92b9074c504075cd25f563bc9d46b (patch)
treec6bb3db1e1e3d1a75d3f77cca805df1e8db08151
parente2dccaa5d115a4e5de899909c253a5add400c11a (diff)
downloadsdl_core-47b7b86071d92b9074c504075cd25f563bc9d46b.tar.gz
Validate existence of files used in TtsChunks
-rw-r--r--src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h2
-rw-r--r--src/components/application_manager/include/application_manager/message_helper.h10
-rw-r--r--src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc15
-rw-r--r--src/components/application_manager/src/commands/mobile/alert_request.cc17
-rw-r--r--src/components/application_manager/src/commands/mobile/change_registration_request.cc17
-rw-r--r--src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc20
-rw-r--r--src/components/application_manager/src/commands/mobile/perform_interaction_request.cc57
-rw-r--r--src/components/application_manager/src/commands/mobile/register_app_interface_request.cc23
-rw-r--r--src/components/application_manager/src/commands/mobile/set_global_properties_request.cc49
-rw-r--r--src/components/application_manager/src/commands/mobile/speak_request.cc15
-rw-r--r--src/components/application_manager/src/message_helper/message_helper.cc42
11 files changed, 247 insertions, 20 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h
index 5713e2e814..a88789bc73 100644
--- a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h
+++ b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h
@@ -210,7 +210,7 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl {
private:
std::string response_info_;
- mobile_apis::Result::eType result_checking_app_hmi_type_;
+ mobile_apis::Result::eType result_code_;
policy::PolicyHandlerInterface& GetPolicyHandler();
DISALLOW_COPY_AND_ASSIGN(RegisterAppInterfaceRequest);
diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h
index b94609c01b..71e79e8338 100644
--- a/src/components/application_manager/include/application_manager/message_helper.h
+++ b/src/components/application_manager/include/application_manager/message_helper.h
@@ -548,6 +548,16 @@ class MessageHelper {
const uint32_t correlation_id,
int32_t result_code);
+ static utils::SharedPtr<std::string> CheckAppFileExists(
+ std::string file_name,
+ ApplicationConstSharedPtr app,
+ ApplicationManager& app_mngr);
+
+ static mobile_apis::Result::eType VerifyTtsFiles(
+ smart_objects::SmartObject& tts_chunks,
+ ApplicationConstSharedPtr app,
+ ApplicationManager& app_mngr);
+
/**
* @brief Verify image and add image file full path
* and add path, although the image doesn't exist
diff --git a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc
index d5767690d7..dee364cb99 100644
--- a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc
+++ b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc
@@ -92,6 +92,21 @@ void AlertManeuverRequest::Run() {
// check TTSChunk parameter
if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) {
+ smart_objects::SmartObject& tts_chunks =
+ (*message_)[strings::msg_params][strings::tts_chunks];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ SendResponse(false,
+ mobile_apis::Result::FILE_NOT_FOUND,
+ "One or more files needed for tts_chunks are not present");
+ return;
+ }
+
if (0 < (*message_)[strings::msg_params][strings::tts_chunks].length()) {
pending_requests_.Add(hmi_apis::FunctionID::TTS_Speak);
tts_is_ok = true;
diff --git a/src/components/application_manager/src/commands/mobile/alert_request.cc b/src/components/application_manager/src/commands/mobile/alert_request.cc
index 3c42e43767..e0cbe9e600 100644
--- a/src/components/application_manager/src/commands/mobile/alert_request.cc
+++ b/src/components/application_manager/src/commands/mobile/alert_request.cc
@@ -281,6 +281,23 @@ bool AlertRequest::Validate(uint32_t app_id) {
return false;
}
+ if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) {
+ smart_objects::SmartObject& tts_chunks =
+ (*message_)[strings::msg_params][strings::tts_chunks];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ SendResponse(false,
+ mobile_apis::Result::FILE_NOT_FOUND,
+ "One or more files needed for tts_chunks are not present");
+ return false;
+ }
+ }
+
return true;
}
diff --git a/src/components/application_manager/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/src/commands/mobile/change_registration_request.cc
index f55767c723..06027a42db 100644
--- a/src/components/application_manager/src/commands/mobile/change_registration_request.cc
+++ b/src/components/application_manager/src/commands/mobile/change_registration_request.cc
@@ -178,6 +178,23 @@ void ChangeRegistrationRequest::Run() {
return;
}
+ if ((*message_)[strings::msg_params].keyExists(strings::tts_name)) {
+ smart_objects::SmartObject& tts_name =
+ (*message_)[strings::msg_params][strings::tts_name];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(tts_name, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ SendResponse(false,
+ mobile_apis::Result::FILE_NOT_FOUND,
+ "One or more files needed for tts_name are not present");
+ return;
+ }
+ }
+
const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces();
const HmiInterfaces::InterfaceState vr_state =
diff --git a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc
index 20076ac50c..a758f04aac 100644
--- a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc
+++ b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc
@@ -96,8 +96,24 @@ void PerformAudioPassThruRequest::Run() {
// need set flag before sending to hmi
StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI);
- if ((*message_)[str::msg_params].keyExists(str::initial_prompt) &&
- (0 < (*message_)[str::msg_params][str::initial_prompt].length())) {
+ if ((*message_)[str::msg_params].keyExists(str::initial_prompt)) {
+ smart_objects::SmartObject& initial_prompt =
+ (*message_)[strings::msg_params][strings::initial_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(
+ initial_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ SendResponse(
+ false,
+ mobile_apis::Result::FILE_NOT_FOUND,
+ "One or more files needed for initial_prompt are not present");
+ return;
+ }
+
// In case TTS Speak, subscribe on notification
SendSpeakRequest();
SendPerformAudioPassThruRequest();
diff --git a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc
index 68940158b9..86ab0a97c0 100644
--- a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc
+++ b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc
@@ -31,6 +31,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/
+#include <numeric>
#include <string.h>
#include <string>
#include "application_manager/commands/mobile/perform_interaction_request.h"
@@ -536,9 +537,21 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest(
}
}
+ std::vector<std::string> invalid_params;
if ((*message_)[strings::msg_params].keyExists(strings::help_prompt)) {
- msg_params[strings::help_prompt] =
+ smart_objects::SmartObject& help_prompt =
(*message_)[strings::msg_params][strings::help_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(help_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_WARN(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ invalid_params.push_back("help_prompt");
+ } else {
+ msg_params[strings::help_prompt] = help_prompt;
+ }
} else {
if (choice_list.length() != 0) {
msg_params[strings::help_prompt] =
@@ -573,8 +586,20 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest(
}
if ((*message_)[strings::msg_params].keyExists(strings::timeout_prompt)) {
- msg_params[strings::timeout_prompt] =
+ smart_objects::SmartObject& timeout_prompt =
(*message_)[strings::msg_params][strings::timeout_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(
+ timeout_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_WARN(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ invalid_params.push_back("timeout_prompt");
+ } else {
+ msg_params[strings::timeout_prompt] = timeout_prompt;
+ }
} else {
if (msg_params.keyExists(strings::help_prompt)) {
msg_params[strings::timeout_prompt] = msg_params[strings::help_prompt];
@@ -582,8 +607,34 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest(
}
if ((*message_)[strings::msg_params].keyExists(strings::initial_prompt)) {
- msg_params[strings::initial_prompt] =
+ smart_objects::SmartObject& initial_prompt =
(*message_)[strings::msg_params][strings::initial_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(
+ initial_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_WARN(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ invalid_params.push_back("initial_prompt");
+ } else {
+ msg_params[strings::initial_prompt] = initial_prompt;
+ }
+ }
+
+ if (!invalid_params.empty()) {
+ const std::string params_list =
+ std::accumulate(std::begin(invalid_params),
+ std::end(invalid_params),
+ std::string(""),
+ [](std::string& first, std::string& second) {
+ return first.empty() ? second : first + ", " + second;
+ });
+ const std::string info =
+ "One or more files needed for " + params_list + " are not present";
+ SendResponse(false, mobile_apis::Result::FILE_NOT_FOUND, info.c_str());
+ return;
}
mobile_apis::InteractionMode::eType mode =
diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc
index d32afad00b..b5573c0680 100644
--- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc
+++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc
@@ -179,7 +179,7 @@ namespace commands {
RegisterAppInterfaceRequest::RegisterAppInterfaceRequest(
const MessageSharedPtr& message, ApplicationManager& application_manager)
: CommandRequestImpl(message, application_manager)
- , result_checking_app_hmi_type_(mobile_apis::Result::INVALID_ENUM) {}
+ , result_code_(mobile_apis::Result::INVALID_ENUM) {}
RegisterAppInterfaceRequest::~RegisterAppInterfaceRequest() {}
@@ -320,7 +320,20 @@ void RegisterAppInterfaceRequest::Run() {
}
if (msg_params.keyExists(strings::tts_name)) {
- application->set_tts_name(msg_params[strings::tts_name]);
+ smart_objects::SmartObject& tts_name =
+ (*message_)[strings::msg_params][strings::tts_name];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(
+ tts_name, application, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_WARN(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ response_info_ = "One or more files needed for tts_name are not present";
+ result_code_ = mobile_apis::Result::WARNINGS;
+ }
+ application->set_tts_name(tts_name);
}
if (msg_params.keyExists(strings::app_hmi_type)) {
@@ -694,9 +707,9 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile(
}
}
if ((mobile_apis::Result::SUCCESS == result_code) &&
- (mobile_apis::Result::INVALID_ENUM != result_checking_app_hmi_type_)) {
+ (mobile_apis::Result::INVALID_ENUM != result_code_)) {
add_info += response_info_;
- result_code = result_checking_app_hmi_type_;
+ result_code = result_code_;
}
// in case application exist in resumption we need to send resumeVrgrammars
@@ -1023,7 +1036,7 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckWithPolicyData() {
"Following AppHmiTypes are not present in policy "
"table:" +
log;
- result_checking_app_hmi_type_ = mobile_apis::Result::WARNINGS;
+ result_code_ = mobile_apis::Result::WARNINGS;
}
}
// Replace AppHmiTypes in request with values allowed by policy table
diff --git a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc
index e811f5d154..621aa90447 100644
--- a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc
+++ b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc
@@ -31,6 +31,7 @@
*/
#include <string.h>
+#include <numeric>
#include <algorithm>
#include "application_manager/commands/mobile/set_global_properties_request.h"
@@ -185,14 +186,54 @@ void SetGlobalPropertiesRequest::Run() {
smart_objects::SmartObject params =
smart_objects::SmartObject(smart_objects::SmartType_Map);
+ std::vector<std::string> invalid_params;
if (is_help_prompt_present) {
- app->set_help_prompt(msg_params.getElement(strings::help_prompt));
- params[strings::help_prompt] = (*app->help_prompt());
+ smart_objects::SmartObject& help_prompt =
+ (*message_)[strings::msg_params][strings::help_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(help_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ invalid_params.push_back("help_prompt");
+ } else {
+ app->set_help_prompt(help_prompt);
+ params[strings::help_prompt] = (*app->help_prompt());
+ }
}
if (is_timeout_prompt_present) {
- app->set_timeout_prompt(msg_params.getElement(strings::timeout_prompt));
- params[strings::timeout_prompt] = (*app->timeout_prompt());
+ smart_objects::SmartObject& timeout_prompt =
+ (*message_)[strings::msg_params][strings::timeout_prompt];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(
+ timeout_prompt, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ invalid_params.push_back("timeout_prompt");
+ } else {
+ app->set_timeout_prompt(timeout_prompt);
+ params[strings::timeout_prompt] = (*app->timeout_prompt());
+ }
+ }
+
+ if (!invalid_params.empty()) {
+ std::string params_list = std::accumulate(
+ std::begin(invalid_params),
+ std::end(invalid_params),
+ std::string(""),
+ [](std::string& first, std::string& second) {
+ return first.empty() ? second : first + ", " + second;
+ });
+ const std::string info =
+ "One or more files needed for " + params_list + " are not present";
+ SendResponse(false, mobile_apis::Result::FILE_NOT_FOUND, info.c_str());
+ return;
}
params[strings::app_id] = app->app_id();
diff --git a/src/components/application_manager/src/commands/mobile/speak_request.cc b/src/components/application_manager/src/commands/mobile/speak_request.cc
index 1954cde181..6da6b482b3 100644
--- a/src/components/application_manager/src/commands/mobile/speak_request.cc
+++ b/src/components/application_manager/src/commands/mobile/speak_request.cc
@@ -69,6 +69,21 @@ void SpeakRequest::Run() {
return;
}
+ smart_objects::SmartObject& tts_chunks =
+ (*message_)[strings::msg_params][strings::tts_chunks];
+ mobile_apis::Result::eType verification_result =
+ MessageHelper::VerifyTtsFiles(tts_chunks, app, application_manager_);
+
+ if (mobile_apis::Result::FILE_NOT_FOUND == verification_result) {
+ LOG4CXX_ERROR(logger_,
+ "MessageHelper::VerifyTtsFiles return "
+ << verification_result);
+ SendResponse(false,
+ mobile_apis::Result::FILE_NOT_FOUND,
+ "One or more files needed for tts_chunks are not present");
+ return;
+ }
+
(*message_)[strings::msg_params][strings::app_id] = app->app_id();
(*message_)[strings::msg_params][hmi_request::speak_type] =
hmi_apis::Common_MethodName::SPEAK;
diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc
index a848cf9ad9..d10ede4637 100644
--- a/src/components/application_manager/src/message_helper/message_helper.cc
+++ b/src/components/application_manager/src/message_helper/message_helper.cc
@@ -2745,11 +2745,24 @@ mobile_apis::Result::eType MessageHelper::VerifyImageApplyPath(
}
const std::string& file_name = image[strings::value].asString();
+ const utils::SharedPtr<std::string> full_file_path =
+ CheckAppFileExists(file_name, app, app_mngr);
+ if (full_file_path) {
+ image[strings::value] = *full_file_path;
+ return mobile_apis::Result::SUCCESS;
+ }
+ return mobile_apis::Result::INVALID_DATA;
+}
+utils::SharedPtr<std::string> MessageHelper::CheckAppFileExists(
+ std::string file_name,
+ ApplicationConstSharedPtr app,
+ ApplicationManager& app_mngr) {
std::string str = file_name;
+ // Verify that file name is not only space characters
str.erase(remove(str.begin(), str.end(), ' '), str.end());
if (0 == str.size()) {
- return mobile_apis::Result::INVALID_DATA;
+ return utils::SharedPtr<std::string>();
}
std::string full_file_path;
@@ -2775,12 +2788,31 @@ mobile_apis::Result::eType MessageHelper::VerifyImageApplyPath(
full_file_path += file_name;
}
- image[strings::value] = full_file_path;
if (!file_system::FileExists(full_file_path)) {
- return mobile_apis::Result::INVALID_DATA;
+ return utils::SharedPtr<std::string>();
}
- return mobile_apis::Result::SUCCESS;
+ utils::SharedPtr<std::string> path_ptr(new std::string(full_file_path));
+ return path_ptr;
+}
+
+mobile_apis::Result::eType MessageHelper::VerifyTtsFiles(
+ smart_objects::SmartObject& tts_chunks,
+ ApplicationConstSharedPtr app,
+ ApplicationManager& app_mngr) {
+ mobile_apis::Result::eType result = mobile_apis::Result::SUCCESS;
+ for (auto& tts_chunk : *(tts_chunks.asArray())) {
+ if (tts_chunk[strings::type] == mobile_apis::SpeechCapabilities::FILE) {
+ utils::SharedPtr<std::string> full_file_path = CheckAppFileExists(
+ tts_chunk[strings::text].asString(), app, app_mngr);
+ if (!full_file_path) {
+ result = mobile_apis::Result::FILE_NOT_FOUND;
+ } else {
+ tts_chunk[strings::text] = *full_file_path;
+ }
+ }
+ }
+ return result;
}
mobile_apis::Result::eType MessageHelper::VerifyImage(
@@ -3024,4 +3056,4 @@ bool MessageHelper::PrintSmartObject(const smart_objects::SmartObject& object) {
return true;
}
-} // namespace application_manager
+} // namespace application_manager \ No newline at end of file