summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2016-06-08 15:20:25 -0400
committerJackLivio <jack@livio.io>2016-06-08 15:20:25 -0400
commitac1bce0ae273ad189b0e48efcf62a46b17369a6e (patch)
tree7e3b0d81ca2b71d3fb56f97a6082932f79ea4e12
parentbcf8405bbcb80823ac8bda564115695826ca99c4 (diff)
downloadsdl_core-ac1bce0ae273ad189b0e48efcf62a46b17369a6e.tar.gz
Parse PT String for HTTP Request Body
The "body" portion of the httprequest needs to be a valid string. Before this fix, the policy table content of the request did not have properly escaped double quotes and was causing the JSON received by the mobile side to be considered invalid. The new method "ParsePtString()" adds an escaped backslash during every occurance of a double quote or other escaped backslash. This method also removes any newlines located in the policy table string.
-rw-r--r--src/components/application_manager/include/application_manager/commands/mobile/on_system_request_notification.h1
-rw-r--r--src/components/application_manager/src/commands/mobile/on_system_request_notification.cc20
2 files changed, 19 insertions, 2 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 78b41159ff..9d4584adf9 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
@@ -72,6 +72,7 @@ class OnSystemRequestNotification : public CommandNotificationImpl {
* @param message Message
*/
void AddHeader(BinaryMessage& message) const;
+ std::string ParsePTString(std::string& pt_string) 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 90ec18d3b1..7de1700fe8 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
@@ -116,7 +116,8 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
if (0 > sprintf(timeout_str, "%d", timeout)) {
memset(timeout_str, 0, sizeof(timeout_str));
}
-
+ std::string temp_string = std::string(message.begin(), message.end());
+ std::string policy_table_string = ParsePTString(temp_string);
const std::string header =
"{"
@@ -133,7 +134,7 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
"\"charset\": \"utf-8\","
"\"Content_Length\": " + std::string(size_str) +
"},"
- "\"body\": \"" + std::string(message.begin(), message.end()) + "\""
+ "\"body\": \"" + policy_table_string + "\""
"}"
"}";
@@ -143,6 +144,21 @@ void OnSystemRequestNotification::AddHeader(BinaryMessage& message) const {
LOG4CXX_DEBUG(
logger_, "Header added: " << std::string(message.begin(), message.end()));
}
+
+std::string OnSystemRequestNotification::ParsePTString(std::string& pt_string) const{
+ std::string result;
+ int length = pt_string.length();
+ result.reserve(length*2);
+ for(int i=0;i<length;++i){
+ if(pt_string[i]=='\"' || pt_string[i]=='\\'){
+ result += '\\';
+ } else if(pt_string[i] == '\n') {
+ continue;
+ }
+ result += pt_string[i];
+ }
+ return result;
+}
#endif
} //namespace mobile