#include <dpl/log/log.h>
#include <dpl/fast_delegate.h>
#include <dpl/foreach.h>
+#include <dpl/scoped_ptr.h>
+#include <pcrecpp.h>
#include <algorithm>
+#include <string>
#include <cstdio>
#include <cerrno>
m_type = value;
MimeTypeUtils::MimeAttributes mimeAttributes =
MimeTypeUtils::getMimeAttributes(value);
- if (mimeAttributes.count(L"charset") > 0) {
+ if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull())
+ {
m_encoding = mimeAttributes[L"charset"];
}
} else if (attribute.name == L"encoding") {
ConfigParserData::Setting m_setting;
};
-class AppServiceParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create;
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"src") {
- m_src = attribute.value;
- } else if (attribute.name == L"operation") {
- m_operation = attribute.value;
- } else if (attribute.name == L"scheme") {
- m_scheme = attribute.value;
- } else if (attribute.name == L"mime") {
- m_mime = attribute.value;
- } else if (attribute.name == L"disposition") {
- if (attribute.value == L"inline")
- m_disposition =
- ConfigParserData::ServiceInfo::Disposition::INLINE;
- }
- }
-
- virtual void Accept(const Element& element)
- {
- LogWarning("namespace for app service = " << element.ns);
- if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
- ThrowMsg(Exception::ParseError,
- "Wrong xml namespace for widget element");
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {
- ThrowMsg(Exception::ParseError, "param element must be empty");
- }
-
- virtual void Verify()
- {
- if (m_src.IsNull()) {
- LogWarning("service element must have target attribute");
- return;
- } else if (m_operation.IsNull()) {
- LogWarning("service element must have operation attribute");
- return;
- }
- NormalizeString(m_src);
- NormalizeString(m_operation);
- NormalizeString(m_scheme);
- NormalizeString(m_mime);
-
- // exception
- DPL::String ignoreUri(L"file");
-
- if (!m_scheme.IsNull() && *m_scheme == ignoreUri)
- {
- LogInfo("exception : '" << *m_scheme << "' scheme will be ignored.");
- m_scheme = DPL::OptionalString::Null;
- }
-
- // verify duplicate element
- DPL::String wildString(L"*/*");
- DPL::String nullString(L"");
- ConfigParserData::ServiceInfo serviceInfo(
- m_src.IsNull() ? nullString : *m_src,
- m_operation.IsNull() ? nullString : *m_operation,
- m_scheme.IsNull() ? nullString : *m_scheme,
- m_mime.IsNull() ? nullString : *m_mime,
- m_disposition);
-
- FOREACH(iterator, m_data.appServiceList) {
- if (iterator->m_operation == serviceInfo.m_operation &&
- // check scheme
- (iterator->m_scheme == serviceInfo.m_scheme ||
- // check input scheme is "*/*" case
- (iterator->m_scheme == wildString &&
- serviceInfo.m_scheme != nullString) ||
- // check iterator scheme is "*/*" case
- (serviceInfo.m_scheme == wildString &&
- iterator->m_scheme != nullString)) &&
-
- (iterator->m_mime == serviceInfo.m_mime ||
- // check input mime is "*/*" case
- (iterator->m_mime == wildString &&
- serviceInfo.m_mime != nullString) ||
- // check iterator mime is "*/*" case
- (serviceInfo.m_mime == wildString &&
- iterator->m_mime != nullString)))
- {
- ThrowMsg(Exception::ParseError,
- "service operation is duplicated " +
- DPL::ToUTF8String(*m_operation));
- }
- }
- m_data.appServiceList.push_back(serviceInfo);
- }
-
- AppServiceParser(ConfigParserData& data) :
- ElementParser(),
- m_src(DPL::OptionalString::Null),
- m_operation(DPL::OptionalString::Null),
- m_scheme(DPL::OptionalString::Null),
- m_mime(DPL::OptionalString::Null),
- m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW),
- m_data(data)
- {}
-
- private:
- DPL::OptionalString m_src;
- DPL::OptionalString m_operation;
- DPL::OptionalString m_scheme;
- DPL::OptionalString m_mime;
- ConfigParserData::ServiceInfo::Disposition m_disposition;
- ConfigParserData& m_data;
-};
-
class AppControlParser : public ElementParser
{
public:
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})\\.[0-9A-Za-z]{1,52}";
+const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
+
class SplashParser : public ElementParser
{
public:
m_width = attribute.value;
} else if (attribute.name == L"height") {
m_height = attribute.value;
+ } else if (attribute.name == L"fast-open") {
+ m_fastOpen= attribute.value;
}
}
}
m_data.m_pdSrc = m_src;
m_data.m_pdWidth = m_width;
m_data.m_pdHeight = m_height;
+ m_data.m_pdFastOpen = m_fastOpen;
}
explicit PdParser(
DPL::String m_src;
DPL::String m_width;
DPL::String m_height;
+ DPL::String m_fastOpen;
bool m_properNamespace;
ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
bool m_properNamespace;
};
+class AllowNavigationParser : public ElementParser
+{
+ public:
+ AllowNavigationParser(ConfigParserData& data) :
+ ElementParser(),
+ m_data(data),
+ m_properNamespace(false)
+ {}
+
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& /*name*/)
+ {
+ return &IgnoringParser::Create;
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& text)
+ {
+ if (m_properNamespace) {
+ m_origin = text.value;
+ }
+ }
+
+ virtual void Accept(const XmlAttribute& /*attribute*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ if (m_origin.IsNull()) {
+ LogWarning("data is empty");
+ return;
+ }
+
+ char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
+ char* ptr = strtok(data," ");
+ while (ptr != NULL) {
+ std::string origin = ptr;
+ ptr = strtok(NULL," ");
+ if(origin == "*") {
+ ConfigParserData::AllowNavigationInfo info(L"*", L"*");
+ m_data.allowNavigationInfoList.push_back(info);
+ continue;
+ }
+
+ DPL::ScopedPtr<iri_t> iri(iri_parse(origin.c_str()));
+ if (!iri->host || strlen(iri->host) == 0) {
+ // input origin should has schem and host
+ // in case of file scheme path is filled
+ // "http://"
+ LogWarning("input origin isn't verified");
+ continue;
+ }
+ DPL::String scheme = L"*";
+ if (iri->scheme && strlen(iri->scheme) != 0) {
+ scheme = DPL::FromUTF8String(iri->scheme);
+ }
+ ConfigParserData::AllowNavigationInfo info(
+ scheme,
+ DPL::FromUTF8String(iri->host));
+ m_data.allowNavigationInfoList.push_back(info);
+ }
+ }
+
+ private:
+ DPL::OptionalString m_origin;
+ ConfigParserData& m_data;
+ bool m_properNamespace;
+};
+
class CspParser : public ElementParser
{
public:
m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
m_map[L"setting"] =
DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
- // TODO: appservice will be removed
- m_map[L"appservice"] = DPL::MakeDelegate(this,
- &WidgetParser::OnAppServiceElement);
m_map[L"application"] = DPL::MakeDelegate(
this,
&WidgetParser::
&WidgetParser::
OnCspReportOnlyElement);
#endif
+#ifdef ALLOW_NAVIGATION_ENABLED
+ m_map[L"allow-navigation"] =
+ DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
+#endif
m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
}
return ElementParserPtr(new PrivilegeParser(m_data));
}
-ElementParserPtr WidgetParser::OnAppServiceElement()
-{
- return ElementParserPtr(new AppServiceParser(m_data));
-}
-
ElementParserPtr WidgetParser::OnAppControlElement()
{
return ElementParserPtr(new AppControlParser(m_data));
return ElementParserPtr(new CspReportOnlyParser(m_data));
}
+ElementParserPtr WidgetParser::OnAllowNavigationElement()
+{
+ return ElementParserPtr(new AllowNavigationParser(m_data));
+}
+
ElementParserPtr WidgetParser::OnAccountElement()
{
return ElementParserPtr(new AccountParser(m_data));