From 91671cd8be6df253cdf9eee7b80f75c9c06cf92a Mon Sep 17 00:00:00 2001 From: Zbigniew Kostrzewa Date: Wed, 10 Apr 2013 08:56:34 +0200 Subject: [PATCH] Adjust verification of application configuration element to current spec. [Issue#] N/A [Problem] Currently configuration parser does not check for all attributes of tizen:application element and does not verify their format. [Cause] N/A [Solution] Update configuration parser. [SCMRequest] N/A [Verification] 1. Build repository. 2. Run tests `wrt-extra-tests-misc --output=text --regexp='installer'` Change-Id: Ia9cf2807d6e6e0cdd8eefa0dc5875fc318ee68a5 --- src/configuration_parser/widget_parser.cpp | 84 +++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index e22f4a6..da4e1b9 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -37,7 +37,9 @@ #include #include #include +#include #include +#include #include #include @@ -1263,34 +1265,84 @@ class ApplicationParser : public ElementParser virtual void Verify() { + VerifyIdAndPackage(); + VerifyVersion(); + } + + ApplicationParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_id(DPL::OptionalString::Null), + m_version(DPL::OptionalString::Null), + m_properNamespace(false) + {} + + private: + void VerifyIdAndPackage() + { + if (!m_package) + { + ThrowMsg(Exception::ParseError, + "application element must have package attribute"); + } + else + { + pcrecpp::RE re(REGEXP_PACKAGE); + if (!re.FullMatch(DPL::ToUTF8String(*m_package))) + { + ThrowMsg(Exception::ParseError, + "invalid format of package attribute"); + } + } + if (!m_id) { ThrowMsg(Exception::ParseError, "application element must have id attribute"); } - - if (!!m_package) { - m_data.tizenPkgId = m_package; + else + { + std::string package; + pcrecpp::RE re(REGEXP_ID); + if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package)) + { + ThrowMsg(Exception::ParseError, + "invalid format of id attribute"); + } + if (package != DPL::ToUTF8String(*m_package)) + { + ThrowMsg(Exception::ParseError, + "invalid package prefix in id attribute"); + } } - if (!m_version) { + m_data.tizenAppId = m_id; + m_data.tizenPkgId = m_package; + } + + void VerifyVersion() + { + if (!m_version) + { ThrowMsg(Exception::ParseError, "application element must have required_version attribute"); } + else + { + pcrecpp::RE re(REGEXP_VERSION); + if (!re.FullMatch(DPL::ToUTF8String(*m_version))) + { + ThrowMsg(Exception::ParseError, + "invalid format of version attribute"); + } + } - //TODO check if id and version format is right - m_data.tizenAppId = m_id; m_data.tizenMinVersionRequired = m_version; } - ApplicationParser(ConfigParserData& data) : - ElementParser(), - m_data(data), - m_id(DPL::OptionalString::Null), - m_version(DPL::OptionalString::Null), - m_properNamespace(false) - {} + static const char* const REGEXP_PACKAGE; + static const char* const REGEXP_ID; + static const char* const REGEXP_VERSION; - private: ConfigParserData& m_data; DPL::OptionalString m_id; DPL::OptionalString m_package; @@ -1298,6 +1350,10 @@ class ApplicationParser : public ElementParser bool m_properNamespace; }; +const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}"; +const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\..{2,52}"; +const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?"; + class SplashParser : public ElementParser { public: -- 2.7.4