summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/commands/mobile/on_system_request_notification.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/commands/mobile/on_system_request_notification.cc')
-rw-r--r--src/components/application_manager/src/commands/mobile/on_system_request_notification.cc38
1 files changed, 36 insertions, 2 deletions
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 f94e37407f..03d9b47406 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
@@ -106,6 +106,7 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
LOG4CXX_AUTO_TRACE(logger_);
const int timeout = application_manager_.GetPolicyHandler().TimeoutExchange();
+ size_t content_length;
char size_str[24];
if (0 > sprintf(size_str, "%zu", static_cast<size_t>(message.size()))) {
@@ -117,6 +118,19 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
memset(timeout_str, 0, sizeof(timeout_str));
}
+ std::string policy_table_string = std::string(message.begin(), message.end());
+
+ /* The Content-Length to be sent in the HTTP Request header should be
+ calculated before additional escape characters are added to the
+ policy table string. The mobile proxy will remove the escape
+ characters after receiving this request. */
+
+ content_length = ParsePTString(policy_table_string);
+
+ if (0 > sprintf(size_str, "%zu", content_length)) {
+ memset(size_str, 0, sizeof(size_str));
+ }
+
const std::string header =
"{"
@@ -135,11 +149,11 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
","
"\"InstanceFollowRedirects\": false,"
"\"charset\": \"utf-8\","
- "\"Content_Length\": " +
+ "\"Content-Length\": " +
std::string(size_str) +
"},"
"\"body\": \"" +
- std::string(message.begin(), message.end()) +
+ policy_table_string +
"\""
"}"
"}";
@@ -150,6 +164,26 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
LOG4CXX_DEBUG(
logger_, "Header added: " << std::string(message.begin(), message.end()));
}
+
+size_t OnSystemRequestNotification::ParsePTString(
+ std::string& pt_string) const {
+ std::string result;
+ size_t length = pt_string.length();
+ size_t result_length = length;
+ result.reserve(length * 2);
+ for (size_t i = 0; i < length; ++i) {
+ if (pt_string[i] == '\"' || pt_string[i] == '\\') {
+ result += '\\';
+ } else if (pt_string[i] == '\n') {
+ result_length--; // contentLength is adjusted when this character is not
+ // copied to result.
+ continue;
+ }
+ result += pt_string[i];
+ }
+ pt_string = result;
+ return result_length;
+}
#endif
} // namespace mobile