#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>
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;
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: