From 6aee4f91ac63717ca49b2c355e0281e0baff59f8 Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Fri, 25 Jan 2013 12:35:56 +0100 Subject: [PATCH] CSP policy parsing support. [Issue#] LINUXWRT-34 [Problem] Support for scp policy in config xml [Cause] N/A [Solution] Implemented parsing and database storing for scp tag. [Verification] To verify run wrt-tests-mics --regexp='csp'. Tests should pass. Change-Id: Ibd009284d12dde4c06a95e3ee4acb85db8f53375 --- CMakeLists.txt | 8 +++- src/configuration_parser/widget_parser.cpp | 65 +++++++++++++++++++++++++++--- src/configuration_parser/widget_parser.h | 1 + 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f85fa56..ce03d83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,13 @@ ENDIF(NOT CMAKE_BUILD_TYPE) ############################# compilation defines ############################# -# EMPTY + +#csp from .xml parsing enabled +OPTION(CSP_SUPPORT "Support for csp policy" ON) + +IF(CSP_SUPPORT) + ADD_DEFINITIONS("-DCSP_ENABLED") +ENDIF(CSP_SUPPORT) ############################# compiler flags ################################## diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index c7da02b..10ed283 100755 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -1302,8 +1302,8 @@ class AppControlParser : public ElementParser if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end()) && (m_data.m_uriList.find(*m_value) == - m_data.m_uriList.end())) { - + m_data.m_uriList.end())) { + m_data.m_uriList.insert(*m_value); } else { LogDebug("Ignoring uri with name" << @@ -1361,7 +1361,7 @@ class AppControlParser : public ElementParser if ((m_data.m_mimeList.find(wildString) == m_data.m_mimeList.end()) && (m_data.m_mimeList.find(*m_value) == - m_data.m_mimeList.end())) { + m_data.m_mimeList.end())) { m_data.m_mimeList.insert(*m_value); } else { LogDebug("Ignoring mime with name" << @@ -1381,7 +1381,7 @@ class AppControlParser : public ElementParser DPL::OptionalString m_value; ConfigParserData::AppControlInfo& m_data; }; - + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, const DPL::String& name) { @@ -1460,7 +1460,7 @@ class AppControlParser : public ElementParser { return ElementParserPtr(new MimeParser(m_appControl)); } - + AppControlParser(ConfigParserData& data) : ElementParser(), m_data(data), @@ -2145,6 +2145,52 @@ class LiveboxParser : public ElementParser bool m_properNamespace; }; +class CspParser : public ElementParser +{ + public: + virtual ActionFunc GetElementParser(const DPL::String& ns, + const DPL::String& name) + { + return &IgnoringParser::Create; + } + + CspParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_properNamespace(false) + { + } + + virtual void Accept(const Element& element) + { + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) + { + m_properNamespace = true; + } + } + + virtual void Accept(const XmlAttribute& attribute) + { + } + + virtual void Accept(const Text& text) + { + if (m_properNamespace) + m_policy = text.value; + } + + virtual void Verify() + { + if (!m_policy.IsNull()) + m_data.cspPolicy = *m_policy; + } + + private: + ConfigParserData& m_data; + bool m_properNamespace; + DPL::OptionalString m_policy; +}; + ElementParser::ActionFunc WidgetParser::GetElementParser(const DPL::String& /*ns*/, const DPL::String& name) @@ -2189,7 +2235,9 @@ WidgetParser::WidgetParser(ConfigParserData& data) : m_map[L"category"] = DPL::MakeDelegate(this, &WidgetParser::OnCategoryElement); m_map[L"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement); - +#ifdef CSP_ENABLED + m_map[L"Content-Security-Policy"] = DPL::MakeDelegate(this, &WidgetParser::OnCspElement); +#endif } ElementParserPtr WidgetParser::OnNameElement() @@ -2287,6 +2335,11 @@ ElementParserPtr WidgetParser::OnLiveboxElement() return ElementParserPtr(new LiveboxParser(m_data)); } +ElementParserPtr WidgetParser::OnCspElement() +{ + return ElementParserPtr(new CspParser(m_data)); +} + void WidgetParser::Accept(const Element& element) { if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName && diff --git a/src/configuration_parser/widget_parser.h b/src/configuration_parser/widget_parser.h index 82b406c..4ee0c14 100755 --- a/src/configuration_parser/widget_parser.h +++ b/src/configuration_parser/widget_parser.h @@ -83,6 +83,7 @@ class WidgetParser : public ElementParser ElementParserPtr OnAppControlElement(); ElementParserPtr OnCategoryElement(); ElementParserPtr OnLiveboxElement(); + ElementParserPtr OnCspElement(); virtual ActionFunc GetElementParser(const DPL::String& ns, const DPL::String& name); -- 2.7.4