From b802e77b491c184f5a211d3a53059d4286e2004d Mon Sep 17 00:00:00 2001 From: Karol Pawlowski Date: Wed, 15 May 2013 09:48:40 +0200 Subject: [PATCH] Adjust wrt-installer AppWidgetParser to current specification [Issue#] LINUXWRT-322 [Problem] N/A [Cause] N/A [Solution] adjusted to specification http://slp-info.sec.samsung.net/confluence/display/BROWSER/Tizen+Web+Runtime+Core+Specification+2.1#TizenWebRuntimeCoreSpecification21-Web%C2%A0AppWidgetConfigurationExtensions [Verification] Build wrt-installer repository Tests located in test/wrt repository in wrt-webapp-widget-tests subdir shouldn't be installed: app-widget-icon-null.wgt app-widget-content-null.wgt widget-app-box-size-null.wgt app-widget-box-size-invalid.wgt Change-Id: I70460106b2983a360c800b084f41f942a18201c8 --- src/configuration_parser/widget_parser.cpp | 191 +++++++++++++++++++++++++++-- 1 file changed, 180 insertions(+), 11 deletions(-) diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index 56127be..9a7610e 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -43,6 +43,9 @@ #include #include #include +#include +#include +#include using namespace WrtDB; @@ -1278,6 +1281,8 @@ class ApplicationParser : public ElementParser m_properNamespace(false) {} + static const char* const REGEXP_ID; + private: void VerifyIdAndPackage() { @@ -1341,7 +1346,6 @@ class ApplicationParser : public ElementParser } static const char* const REGEXP_PACKAGE; - static const char* const REGEXP_ID; static const char* const REGEXP_VERSION; ConfigParserData& m_data; @@ -1606,6 +1610,10 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if (m_label.empty()) { + ThrowMsg(Exception::ParseError, + "box-label element cannot be empty - ignoring"); + } m_data.m_label = m_label; } @@ -1652,6 +1660,10 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if (m_icon.empty()) { + ThrowMsg(Exception::ParseError, + "src attribute of box-icon element is mandatory - ignoring"); + } m_data.m_icon = m_icon; } @@ -1704,6 +1716,11 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if(m_size.empty()) { + ThrowMsg(Exception::ParseError, + "size is mandatory - ignoring"); + } + std::pair boxSize; boxSize.first = m_size; boxSize.second = m_preview; @@ -1741,8 +1758,6 @@ class AppWidgetParser : public ElementParser 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; } } } @@ -1761,10 +1776,45 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if (m_src.empty()) { + ThrowMsg(Exception::ParseError, + "src attribute of pd element is mandatory - ignoring"); + } + + if (m_width.empty()) { + ThrowMsg(Exception::ParseError, + "width attribute of pd element is mandatory - ignoring"); + } + + if (m_height.empty()) { + ThrowMsg(Exception::ParseError, + "height attribute of pd element is mandatory - ignoring"); + } + + if (ConvertToInt(m_width).IsNull()) { + ThrowMsg(Exception::ParseError, + "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width); + } + + + DPL::OptionalInt height = ConvertToInt(m_height); + + if (height.IsNull()) { + ThrowMsg(Exception::ParseError, + "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height); + } + + if (*height < 1) { + m_height = L"1"; + LogDebug("height attribute of pd element shouldn't be less than 1. Changed to 1 from " << *height); + } else if (*height > 380){ + m_height = L"380"; + LogDebug("height attribute of pd element shouldn't be greater than 380. Changed to 380 from " << *height); + } + 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( @@ -1775,10 +1825,26 @@ class AppWidgetParser : public ElementParser {} private: + DPL::OptionalInt ConvertToInt(const DPL::String& intAsString) + { + char * endptr; + std::string tempStr = DPL::ToUTF8String(intAsString); + const char * intAsString_c = tempStr.c_str(); + errno = 0; + long int intAsString_i = strtol(intAsString_c, &endptr, 10); + + if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN)) + || intAsString_i > INT_MAX || intAsString_i < INT_MIN + || *endptr != '\0') { + return DPL::OptionalInt::Null; + } + + return static_cast(intAsString_i); + } + DPL::String m_src; DPL::String m_width; DPL::String m_height; - DPL::String m_fastOpen; bool m_properNamespace; ConfigParserData::LiveboxInfo::BoxContentInfo& m_data; @@ -1832,6 +1898,38 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if (m_box.m_boxSrc.empty()) { + ThrowMsg(Exception::ParseError, + "src attribute of box-content element is mandatory - ignoring"); + } + + if (!m_box.m_boxMouseEvent.empty() && + CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent)) + { + ThrowMsg(Exception::ParseError, + "mouse-event attribute of box-content element should be true or false - ignoring"); + } + + if (!m_box.m_boxTouchEffect.empty() && + CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect)) + { + ThrowMsg(Exception::ParseError, + "touch-effect attribute of box-content element should be true or false - ignoring"); + } + + if (m_box.m_boxMouseEvent.empty()) { + m_box.m_boxMouseEvent = L"false"; + } + + if (m_box.m_boxTouchEffect.empty()) { + m_box.m_boxTouchEffect = L"true"; + } + + if (m_box.m_boxSize.empty()) { + ThrowMsg(Exception::ParseError, + "box-size element of box-content element not found - ignoring"); + } + m_data.m_boxInfo = m_box; } @@ -1852,7 +1950,6 @@ class AppWidgetParser : public ElementParser } private: - DPL::String m_src; bool m_properNamespace; ConfigParserData::LiveboxInfo& m_data; ConfigParserData::LiveboxInfo::BoxContentInfo m_box; @@ -1883,8 +1980,6 @@ class AppWidgetParser : public ElementParser m_autoLaunch = attribute.value; } else if (attribute.name == L"update-period") { m_updatePeriod = attribute.value; - } else if (attribute.name == L"type") { - m_type = attribute.value; } } } @@ -1903,11 +1998,74 @@ class AppWidgetParser : public ElementParser virtual void Verify() { + if (m_liveboxId.empty()) { + ThrowMsg(Exception::ParseError, + "app-widget element must have id attribute"); + } + else + { + pcrecpp::RE re(REGEXP_ID_STRING.c_str()); + if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId))) + { + ThrowMsg(Exception::ParseError, + "invalid format of app-widget id attribute"); + } + } + + if (m_primary.empty()) + { + ThrowMsg(Exception::ParseError, + "app-widget element must have primary attribute"); + } else if (CheckIfNotTrueNorFalse(m_primary)) + { + ThrowMsg(Exception::ParseError, + "auto-launch attribute of app-widget element should be true or false - ignoring"); + } + + if (!m_autoLaunch.empty() && + CheckIfNotTrueNorFalse(m_autoLaunch)) + { + ThrowMsg(Exception::ParseError, + "auto-launch attribute of app-widget element should be true or false - ignoring"); + } + + if (!m_updatePeriod.empty()) + { + char * endptr; + std::string tempStr = DPL::ToUTF8String(m_updatePeriod); + const char * up_cstr = tempStr.c_str(); + + errno = 0; + double update_period = strtod(up_cstr, &endptr); + + if ((errno == ERANGE && (update_period == -HUGE_VAL || update_period == HUGE_VAL)) + || *endptr != '\0') { + ThrowMsg(Exception::ParseError, + "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod); + } else if (update_period < 60.0) { + LogDebug("update-period attribute of app-widget element shouldn't be less than 60.0 - changed to 60 from value: " << m_updatePeriod); + m_updatePeriod = L"60.0"; + } + } + + if (m_autoLaunch.empty()) { + m_autoLaunch = L"false"; + } + + if(m_livebox.m_label.empty()) { + ThrowMsg(Exception::ParseError, + "box-label element of app-widget element not found - ignoring"); + } + + if(!m_boxContentFound) { + ThrowMsg(Exception::ParseError, + "box-content element of app-widget element not found - ignoring"); + } + m_livebox.m_liveboxId = m_liveboxId; m_livebox.m_primary = m_primary; m_livebox.m_autoLaunch = m_autoLaunch; m_livebox.m_updatePeriod = m_updatePeriod; - m_livebox.m_type = m_type; m_data.m_livebox.push_back(m_livebox); } @@ -1915,13 +2073,15 @@ class AppWidgetParser : public ElementParser explicit AppWidgetParser(ConfigParserData& data) : ElementParser(), m_data(data), - m_properNamespace(false) + m_properNamespace(false), + m_boxContentFound(false) { m_livebox = ConfigParserData::LiveboxInfo(); } ElementParserPtr OnBoxLabelElement() { + return ElementParserPtr(new BoxLabelParser(m_livebox)); } @@ -1932,20 +2092,29 @@ class AppWidgetParser : public ElementParser ElementParserPtr OnBoxContentElement() { + m_boxContentFound = true; return ElementParserPtr(new BoxContentParser(m_livebox)); } private: + static std::string REGEXP_ID_STRING; ConfigParserData& m_data; ConfigParserData::LiveboxInfo m_livebox; DPL::String m_liveboxId; DPL::String m_primary; DPL::String m_autoLaunch; DPL::String m_updatePeriod; - DPL::String m_type; bool m_properNamespace; + bool m_boxContentFound; + + static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck) + { + return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0; + } }; +std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+"; + class AllowNavigationParser : public ElementParser { public: -- 2.7.4