Adjust verification of application configuration element to current spec.
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Wed, 10 Apr 2013 06:56:34 +0000 (08:56 +0200)
committerGerrit Code Review <gerrit2@kim11>
Mon, 22 Apr 2013 05:28:14 +0000 (14:28 +0900)
[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

index e22f4a6..da4e1b9 100644 (file)
@@ -37,7 +37,9 @@
 #include <dpl/log/log.h>
 #include <dpl/fast_delegate.h>
 #include <dpl/foreach.h>
+#include <pcrecpp.h>
 #include <algorithm>
+#include <string>
 #include <cstdio>
 #include <cerrno>
 
@@ -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: