summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Oleynik <aoleynik@luxoft.com>2016-04-06 12:52:22 +0300
committerAndrey Oleynik <aoleynik@luxoft.com>2016-04-11 10:01:42 +0300
commit220535a04280dd5c112a3913db84a295e5705204 (patch)
tree421426a2d38c21af8f1731e326188d4c6f46ee82 /src
parenta352aacb150678b0c011f15dceac6384bd25590b (diff)
downloadsdl_core-220535a04280dd5c112a3913db84a295e5705204.tar.gz
Adds HTTP header to message being sent with OnSystemRequest
SDL must to add HTTP header which provides policy snapshot data within that header along with timeouts and message size. Implements: APPLINK-22313 Conflicts: src/components/application_manager/src/commands/mobile/on_system_request_notification.cc
Diffstat (limited to 'src')
-rw-r--r--src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h21
-rw-r--r--src/components/application_manager/src/commands/mobile/on_system_request_notification.cc95
2 files changed, 90 insertions, 26 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h b/src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h
index 7eee611700..78b41159ff 100644
--- a/src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h
+++ b/src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h
@@ -1,6 +1,5 @@
/*
-
- Copyright (c) 2013, Ford Motor Company
+ Copyright (c) 2016, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,8 +33,8 @@
#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_ON_SYSTEM_REQUEST_NOTIFICATION_H_
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_ON_SYSTEM_REQUEST_NOTIFICATION_H_
-
#include "application_manager/commands/command_notification_impl.h"
+#include <vector>
namespace application_manager {
@@ -48,6 +47,7 @@ namespace mobile {
**/
class OnSystemRequestNotification : public CommandNotificationImpl {
public:
+ typedef std::vector<uint8_t> BinaryMessage;
/**
* @brief OnSystemRequestNotification class constructor
*
@@ -58,13 +58,22 @@ class OnSystemRequestNotification : public CommandNotificationImpl {
/**
* @brief OnSystemRequestNotification class destructor
**/
- virtual ~OnSystemRequestNotification();
+ ~OnSystemRequestNotification() OVERRIDE;
/**
* @brief Execute command
**/
- virtual void Run();
- private:
+ void Run() OVERRIDE;
+
+ private:
+#ifdef EXTENDED_POLICY
+ /**
+ * @brief Adds HTTP header to message
+ * @param message Message
+ */
+ void AddHeader(BinaryMessage& message) const;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(OnSystemRequestNotification);
};
diff --git a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc
index 4e7354776f..2ac96e61b0 100644
--- a/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc
+++ b/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc
@@ -1,6 +1,5 @@
/*
-
- Copyright (c) 2013, Ford Motor Company
+ Copyright (c) 2016, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -31,6 +30,9 @@
POSSIBILITY OF SUCH DAMAGE.
*/
+#include <cstring>
+#include <cstdio>
+#include <string>
#include "application_manager/commands/mobile/on_system_request_notification.h"
#include "interfaces/MOBILE_API.h"
#include "utils/file_system.h"
@@ -45,43 +47,52 @@ namespace mobile {
OnSystemRequestNotification::OnSystemRequestNotification(
const MessageSharedPtr& message)
- : CommandNotificationImpl(message) {
-}
+ : CommandNotificationImpl(message) {}
-OnSystemRequestNotification::~OnSystemRequestNotification() {
-}
+OnSystemRequestNotification::~OnSystemRequestNotification() {}
void OnSystemRequestNotification::Run() {
LOG4CXX_AUTO_TRACE(logger_);
using namespace application_manager;
using namespace mobile_apis;
- ApplicationSharedPtr app = ApplicationManagerImpl::instance()->
- application(connection_key());
+ ApplicationSharedPtr app =
+ ApplicationManagerImpl::instance()->application(connection_key());
if (!app.valid()) {
- LOG4CXX_ERROR(logger_, "Application with connection key "
- << connection_key() << " is not registered.");
+ LOG4CXX_ERROR(logger_,
+ "Application with connection key " << connection_key()
+ << " is not registered.");
return;
}
- RequestType::eType request_type = static_cast<RequestType::eType>
- ((*message_)[strings::msg_params][strings::request_type].asInt());
+ RequestType::eType request_type = static_cast<RequestType::eType>(
+ (*message_)[strings::msg_params][strings::request_type].asInt());
if (!policy::PolicyHandler::instance()->IsRequestTypeAllowed(
- app->mobile_app_id(), request_type)) {
- LOG4CXX_WARN(logger_, "Request type " << request_type
- <<" is not allowed by policies");
+ app->mobile_app_id(), request_type)) {
+ LOG4CXX_WARN(logger_,
+ "Request type " << request_type
+ << " is not allowed by policies");
return;
}
if (RequestType::PROPRIETARY == request_type) {
- std::string filename =
- (*message_)[strings::msg_params][strings::file_name].asString();
-
- std::vector<uint8_t> binary_data;
- file_system::ReadBinaryFile(filename, binary_data);
+/* According to requirements:
+ "If the requestType = PROPRIETARY, add to mobile API fileType = JSON
+ If the requestType = HTTP, add to mobile API fileType = BINARY"
+ Also in Genivi SDL we don't save the PT to file - we put it directly in
+ binary_data */
+
+#ifdef EXTENDED_POLICY
+ const std::string filename =
+ (*message_)[strings::msg_params][strings::file_name].asString();
+
+ BinaryMessage binary_data;
+ file_system::ReadBinaryFile(filename, binary_data);
+ AddHeader(binary_data);
(*message_)[strings::params][strings::binary_data] = binary_data;
+#endif
(*message_)[strings::msg_params][strings::file_type] = FileType::JSON;
} else if (RequestType::HTTP == request_type) {
(*message_)[strings::msg_params][strings::file_type] = FileType::BINARY;
@@ -90,6 +101,50 @@ void OnSystemRequestNotification::Run() {
SendNotification();
}
+#ifdef EXTENDED_POLICY
+void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ const int timeout = policy::PolicyHandler::instance()->TimeoutExchange();
+
+ char size_str[24];
+
+ if (0 > sprintf(size_str, "%lu", message.size())) {
+ memset(size_str, 0, sizeof(size_str));
+ }
+
+ char timeout_str[24];
+ if (0 > sprintf(timeout_str, "%d", timeout)) {
+ memset(timeout_str, 0, sizeof(timeout_str));
+ }
+
+ const std::string header =
+
+ "{"
+ " \"HTTPRequest\": {"
+ "\"headers\": {"
+ "\"ContentType\": \"application/json\","
+ "\"ConnectTimeout\": " + std::string(timeout_str) + ","
+ "\"DoOutput\": true,"
+ "\"DoInput\": true,"
+ "\"UseCaches\": false,"
+ "\"RequestMethod\": \"POST\","
+ "\"ReadTimeout\":" + std::string(timeout_str) + ","
+ "\"InstanceFollowRedirects\": false,"
+ "\"charset\": \"utf-8\","
+ "\"Content_Length\": " + std::string(size_str) +
+ "},"
+ "\"body\": \"" + std::string(message.begin(), message.end()) + "\""
+ "}"
+ "}";
+
+ message.clear();
+ message.assign(header.begin(), header.end());
+
+ LOG4CXX_DEBUG(
+ logger_, "Header added: " << std::string(message.begin(), message.end()));
+}
+#endif
+
} //namespace mobile
} // namespace commands