X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fjobs%2Fwidget_install%2Ftask_widget_config.cpp;h=d7c3640b3bf122767dfb5f662d256a70d0ea44cb;hb=df7b007c93bbec244392ef29d3a244cba9f9a781;hp=54a8f31dc5613856df478a18024ce10ec5c3a0cb;hpb=f80ec377daea002d119da00cc71a08d5d786c3a5;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp index 54a8f31..d7c3640 100644 --- a/src/jobs/widget_install/task_widget_config.cpp +++ b/src/jobs/widget_install/task_widget_config.cpp @@ -44,13 +44,11 @@ #include #include #include -#include - namespace { // anonymous const DPL::String BR = DPL::FromUTF8String("
"); const std::string WIDGET_NOT_COMPATIBLE = "This widget is " - "not compatible with WRT.

"; + "not compatible with WRT.

"; const std::string QUESTION = "Do you want to install it anyway?"; const char *const DEFAULT_LANGUAGE = "default"; @@ -60,11 +58,10 @@ const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml"; const std::string WINDGET_INSTALL_NETWORK_ACCESS = "network access"; } - namespace Jobs { namespace WidgetInstall { void InstallerTaskWidgetPopupData::PopupData::addWidgetInfo( - const DPL::String &info) + const DPL::String &info) { widgetInfo = info; } @@ -73,7 +70,6 @@ TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) : DPL::TaskDecl(this), WidgetInstallPopup(installContext), m_installContext(installContext) - { AddStep(&TaskWidgetConfig::StepProcessConfigurationFile); AddStep(&TaskWidgetConfig::ReadLocaleFolders); @@ -85,7 +81,9 @@ TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) : AddStep(&TaskWidgetConfig::StepCheckMinVersionInfo); if (!GlobalSettings::TestModeEnabled() && !m_installContext.m_quiet) { - AddStep(&TaskWidgetConfig::StepCancelWidgetInstallationAfterVerifyFeatures); + AddStep( + &TaskWidgetConfig:: + StepCancelWidgetInstallationAfterVerifyFeatures); AddStep(&TaskWidgetConfig::StepShowWidgetInfo); AddStep(&TaskWidgetConfig::StepCancelWidgetInstallation); AddStep(&TaskWidgetConfig::StepCancelWidgetInstallationAfterMinVersion); @@ -119,45 +117,50 @@ void TaskWidgetConfig::ReadLocaleFolders() //Adding default locale m_localeFolders.insert(L""); - std::string localePath = m_installContext.locations->getConfigurationDir() + "/locales"; + std::string localePath = + m_installContext.locations->getConfigurationDir() + "/locales"; DIR* localeDir = opendir(localePath.c_str()); if (!localeDir) { LogDebug("No /locales directory in the widget package."); return; } - struct dirent* dirent; + + struct stat statStruct; - do { - errno = 0; - if ((dirent = readdir(localeDir))) { - DPL::String dirName = DPL::FromUTF8String(dirent->d_name); - std::string absoluteDirName = localePath + "/"; - absoluteDirName += dirent->d_name; - - if (stat(absoluteDirName.c_str(), &statStruct) != 0) { - LogError("stat() failed with " << DPL::GetErrnoString()); - continue; - } + struct dirent dirent; + struct dirent *result; + int return_code; + errno = 0; + for (return_code = readdir_r(localeDir, &dirent, &result); + result != NULL && return_code == 0; + return_code = readdir_r(localeDir, &dirent, &result)) + { + DPL::String dirName = DPL::FromUTF8String(dirent.d_name); + std::string absoluteDirName = localePath + "/"; + absoluteDirName += dirent.d_name; - if (S_ISDIR(statStruct.st_mode)) { - //Yes, we ignore current, parent & hidden directories - if (dirName[0] != L'.') { - LogDebug("Adding locale directory \"" << dirName << "\""); - m_localeFolders.insert(dirName); - } + if (stat(absoluteDirName.c_str(), &statStruct) != 0) { + LogError("stat() failed with " << DPL::GetErrnoString()); + continue; + } + + if (S_ISDIR(statStruct.st_mode)) { + //Yes, we ignore current, parent & hidden directories + if (dirName[0] != L'.') { + LogDebug("Adding locale directory \"" << dirName << "\""); + m_localeFolders.insert(dirName); } } } - while (dirent); - if (errno != 0) { - LogError("readdir() failed with " << DPL::GetErrnoString()); + if (return_code != 0 || errno != 0) { + LogError("readdir_r() failed with " << DPL::GetErrnoString()); } if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) { LogError("Failed to close dir: " << localePath << " with error: " - << DPL::GetErrnoString()); + << DPL::GetErrnoString()); } } @@ -175,7 +178,8 @@ void TaskWidgetConfig::ProcessLocalizedStartFiles() ProcessStartFile(S(L"index.svg"), S(L"image/svg+xml")); ProcessStartFile(S(L"index.xhtml"), S(L"application/xhtml+xml")); ProcessStartFile(S(L"index.xht"), S(L"application/xhtml+xml")); - // TODO: (l.wrzosek) we need better check if in current locales widget is valid. + // TODO: (l.wrzosek) we need better check if in current locales widget is + // valid. FOREACH(it, m_installContext.widgetConfig.localizationData.startFiles) { if (it->propertiesForLocales.size() > 0) { return; @@ -186,9 +190,9 @@ void TaskWidgetConfig::ProcessLocalizedStartFiles() } void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, - const DPL::OptionalString& type, - const DPL::OptionalString& encoding, - bool typeForcedInConfig) + const DPL::OptionalString& type, + const DPL::OptionalString& encoding, + bool typeForcedInConfig) { using namespace WrtDB; @@ -204,7 +208,8 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, DPL::String relativePath = pathPrefix + *path; DPL::String absolutePath = DPL::FromUTF8String( - m_installContext.locations->getConfigurationDir()) + L"/" + relativePath; + m_installContext.locations->getConfigurationDir()) + L"/" + + relativePath; // get property data from packaged app if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) { @@ -225,7 +230,7 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, } else { MimeTypeUtils::MimeAttributes attributes = MimeTypeUtils::getMimeAttributes( - startFileProperties.type); + startFileProperties.type); if (attributes.count(L"charset") > 0) { startFileProperties.encoding = attributes[L"charset"]; @@ -250,11 +255,14 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, // set property data for hosted start url // Hosted start url only support TIZEN WebApp if (m_installContext.widgetConfig.webAppType == - APP_TYPE_TIZENWEBAPP) + APP_TYPE_TIZENWEBAPP) { - std::string startPath = DPL::ToUTF8String(startFileData.path); + std::string startPath = DPL::ToUTF8String( + startFileData.path); - if (strstr(startPath.c_str(), "http") == startPath.c_str()) { + if (strstr(startPath.c_str(), + "http") == startPath.c_str()) + { WidgetRegisterInfo::StartFileProperties startFileProperties; if (!!type) { @@ -280,12 +288,12 @@ void TaskWidgetConfig::ProcessBackgroundPageFile() if (!!m_installContext.widgetConfig.configInfo.backgroundPage) { // check whether file exists DPL::String backgroundPagePath = DPL::FromUTF8String( - m_installContext.locations->getConfigurationDir()) + L"/" + + m_installContext.locations->getConfigurationDir()) + L"/" + *m_installContext.widgetConfig.configInfo.backgroundPage; //if no then cancel installation if (!WrtUtilFileExists(DPL::ToUTF8String(backgroundPagePath))) { ThrowMsg(Exceptions::WidgetConfigFileInvalid, - L"Given background page file not found in archive"); + L"Given background page file not found in archive"); } } } @@ -310,7 +318,8 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon) LogInfo("enter"); bool isAnyIconValid = false; //In case a default filename is passed as custom filename in config.xml, we - //need to keep a set of already processed filenames to avoid icon duplication + //need to keep a set of already processed filenames to avoid icon + // duplication //in database. using namespace WrtDB; @@ -331,7 +340,8 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon) DPL::String relativePath = pathPrefix + icon.src; DPL::String absolutePath = DPL::FromUTF8String( - m_installContext.locations->getConfigurationDir()) + L"/" + relativePath; + m_installContext.locations->getConfigurationDir()) + L"/" + + relativePath; if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) { DPL::String type = MimeTypeUtils::identifyFileMimeType(absolutePath); @@ -345,8 +355,7 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon) } } - if(isAnyIconValid) - { + if (isAnyIconValid) { WidgetRegisterInfo::LocalizedIcon localizedIcon(icon, localesAvailableForIcon); m_installContext.widgetConfig.localizationData.icons.push_back( @@ -358,7 +367,8 @@ void TaskWidgetConfig::ProcessWidgetInstalledPath() { LogDebug("ProcessWidgetInstalledPath"); m_installContext.widgetConfig.widgetInstalledPath = - DPL::FromUTF8String(m_installContext.locations->getPackageInstallationDir()); + DPL::FromUTF8String( + m_installContext.locations->getPackageInstallationDir()); } void TaskWidgetConfig::StepCancelWidgetInstallationAfterVerifyFeatures() @@ -389,16 +399,17 @@ void TaskWidgetConfig::StepCancelWidgetInstallationAfterMinVersion() } } -void TaskWidgetConfig::createInstallPopup(PopupType type, const std::string &label) +void TaskWidgetConfig::createInstallPopup(PopupType type, + const std::string &label) { m_installContext.job->Pause(); - if (m_popup) + if (m_popup) { destroyPopup(); + } bool ret = createPopup(); - if (ret) - { - loadPopup( type, label); + if (ret) { + loadPopup(type, label); showPopup(); } } @@ -411,8 +422,8 @@ void TaskWidgetConfig::StepDeletePopupWin() void TaskWidgetConfig::StepShowWidgetInfo() { if (!m_popupData.widgetInfo.empty()) { - std::string label = DPL::ToUTF8String(m_popupData.widgetInfo); - createInstallPopup(PopupType::WIDGET_FEATURE_INFO, label); + std::string label = DPL::ToUTF8String(m_popupData.widgetInfo); + createInstallPopup(PopupType::WIDGET_FEATURE_INFO, label); m_installContext.job->UpdateProgress( InstallerContext::INSTALL_WIDGET_CONFIG2, "Show Widget Info Finished"); @@ -422,25 +433,24 @@ void TaskWidgetConfig::StepShowWidgetInfo() void TaskWidgetConfig::StepCheckMinVersionInfo() { if (!isMinVersionCompatible( - m_installContext.widgetConfig.webAppType.appType, - m_installContext.widgetConfig.minVersion)) { - if(!GlobalSettings::TestModeEnabled() && !m_installContext.m_quiet) - { + m_installContext.widgetConfig.webAppType.appType, + m_installContext.widgetConfig.minVersion)) + { + if (!GlobalSettings::TestModeEnabled() && !m_installContext.m_quiet) { LogDebug("Platform version to low - launching"); std::string label = WIDGET_NOT_COMPATIBLE + QUESTION; createInstallPopup(PopupType::WIDGET_MIN_VERSION, label); - } - else - { - LogError("Platform version lower than required -> cancelling installation"); + } else { + LogError( + "Platform version lower than required -> cancelling installation"); ThrowMsg(Exceptions::NotAllowed, - "Platform version does not meet requirements"); + "Platform version does not meet requirements"); } } m_installContext.job->UpdateProgress( - InstallerContext::INSTALL_WIDGET_CONFIG2, - "Check MinVersion Finished"); + InstallerContext::INSTALL_WIDGET_CONFIG2, + "Check MinVersion Finished"); } void TaskWidgetConfig::StepVerifyFeatures() @@ -464,37 +474,17 @@ void TaskWidgetConfig::StepVerifyFeatures() ThrowMsg( Exceptions::WidgetConfigFileInvalid, "This app type [" << - m_installContext.widgetConfig.webAppType.getApptypeToString() << + m_installContext.widgetConfig.webAppType.getApptypeToString() + << "] cannot be allowed to use [" << DPL::ToUTF8String(it->name) + "] feature"); - } - if (!WrtDB::FeatureDAOReadOnly::isFeatureInstalled( - DPL::ToUTF8String(it->name))) { - LogWarning("Feature not found. Checking if required :[" << - DPL::ToUTF8String(it->name) << "]"); - - if (it->required) { - /** - * WL-3210 The WRT MUST inform the user if a widget cannot be - * installed because one or more required features are not - * supported. - */ - std::ostringstream os; - os << "Widget cannot be installed, required feature is missing:[" - << DPL::ToUTF8String(it->name) << "]"; - if (!GlobalSettings::TestModeEnabled() && !isTizenWebApp()) { - std::string label = os.str(); - createInstallPopup(PopupType::WIDGET_WRONG_FEATURE_INFO, label); - } - ThrowMsg(Exceptions::WidgetConfigFileInvalid, os.str()); - } } else { newList.insert(*it); featureInfo += DPL::ToUTF8String(it->name); featureInfo += DPL::ToUTF8String(BR); } } - if(!data.accessInfoSet.empty()) { + if (!data.accessInfoSet.empty()) { featureInfo += WINDGET_INSTALL_NETWORK_ACCESS; featureInfo += DPL::ToUTF8String(BR); } @@ -544,7 +534,9 @@ bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType, } bool TaskWidgetConfig::parseVersionString(const std::string &version, - long &majorVersion, long &minorVersion, long µVersion) const + long &majorVersion, + long &minorVersion, + long µVersion) const { std::istringstream inputString(version); inputString >> majorVersion; @@ -566,22 +558,28 @@ bool TaskWidgetConfig::parseVersionString(const std::string &version, return true; } -bool TaskWidgetConfig::isMinVersionCompatible(WrtDB::AppType appType, - const DPL::OptionalString &widgetVersion) const +bool TaskWidgetConfig::isMinVersionCompatible( + WrtDB::AppType appType, + const DPL::OptionalString & + widgetVersion) const { - if (widgetVersion.IsNull() || (*widgetVersion).empty()) - { - LogWarning("minVersion attribute is empty. WRT assumes platform " - "supports this widget."); - return true; + if (widgetVersion.IsNull() || (*widgetVersion).empty()) { + if (appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) { + return false; + } else { + LogWarning("minVersion attribute is empty. WRT assumes platform " + "supports this widget."); + return true; + } } //Parse widget version long majorWidget = 0, minorWidget = 0, microWidget = 0; if (!parseVersionString(DPL::ToUTF8String(*widgetVersion), majorWidget, - minorWidget, microWidget)) { + minorWidget, microWidget)) + { LogWarning("Invalid format of widget version string."); - return true; + return false; } //Parse supported version @@ -597,15 +595,16 @@ bool TaskWidgetConfig::isMinVersionCompatible(WrtDB::AppType appType, } if (!parseVersionString(version, - majorSupported, minorSupported, microSupported)) { + majorSupported, minorSupported, microSupported)) + { LogWarning("Invalid format of platform version string."); return true; } if (majorWidget > majorSupported || - (majorWidget == majorSupported && minorWidget > minorSupported) || - (majorWidget == majorSupported && minorWidget == minorSupported - && microWidget > microSupported)) + (majorWidget == majorSupported && minorWidget > minorSupported) || + (majorWidget == majorSupported && minorWidget == minorSupported + && microWidget > microSupported)) { LogInfo("Platform doesn't support this widget."); return false; @@ -617,149 +616,106 @@ bool TaskWidgetConfig::isTizenWebApp() const { bool ret = FALSE; if (m_installContext.widgetConfig.webAppType.appType - == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) + == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) + { ret = TRUE; + } return ret; } -bool TaskWidgetConfig::parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo, - const std::string& _currentPath, int* pErrCode) +bool TaskWidgetConfig::parseConfigurationFileBrowser( + WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath) { ParserRunner parser; Try { parser.Parse(_currentPath, ElementParserPtr(new - RootParser< - WidgetParser>( - configInfo, - DPL::FromUTF32String( - L"widget")))); + RootParser< + WidgetParser>( + configInfo, + DPL::FromUTF32String( + L"widget")))); } Catch(ElementParser::Exception::Base) { LogError("Invalid widget configuration file!"); - *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; return false; } return true; } -bool TaskWidgetConfig::parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo, - const std::string& _currentPath, int* pErrCode) +bool TaskWidgetConfig::parseConfigurationFileWidget( + WrtDB::ConfigParserData& configInfo, + const std::string& _currentPath) { - ParserRunner parser; - - //TODO: rewrite this madness - std::string cfgAbsPath; - DIR* dir = NULL; - struct dirent* ptr = NULL; - - dir = opendir(_currentPath.c_str()); - if (dir == NULL) { - *pErrCode = WRT_ERR_UNKNOWN; + std::string configFilePath; + WrtUtilJoinPaths(configFilePath, _currentPath, WRT_WIDGET_CONFIG_FILE_NAME); + if (!WrtUtilFileExists(configFilePath)) + { + LogError("Archive does not contain configuration file"); return false; } - bool has_config_xml = false; - errno = 0; - while ((ptr = readdir(dir)) != NULL) { //Find configuration file, based on its name - if (ptr->d_type == DT_REG) { - if (!strcmp(ptr->d_name, WRT_WIDGET_CONFIG_FILE_NAME)) { - std::string dName(ptr->d_name); - WrtUtilJoinPaths(cfgAbsPath, _currentPath, dName); - //Parse widget configuration file - LogDebug("Found config: " << cfgAbsPath); + LogDebug("Configuration file: " << configFilePath); - Try - { - parser.Parse(cfgAbsPath, ElementParserPtr(new - RootParser< - WidgetParser>( - configInfo, - DPL - :: - FromUTF32String( - L"widget")))); - } - Catch(ElementParser::Exception::Base) - { - LogError("Invalid widget configuration file!"); - // _rethrown_exception.Dump(); - *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; - if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { - LogError("Failed to close dir: " << _currentPath << " with error: " - << DPL::GetErrnoString()); - } - return false; - } - - has_config_xml = true; - break; - } - } - } - if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { - LogError("Failed to close dir: " << _currentPath << " with error: " - << DPL::GetErrnoString()); + Try + { + ParserRunner parser; + parser.Parse(configFilePath, + ElementParserPtr(new RootParser( + configInfo, + DPL::FromUTF32String(L"widget")))); + return true; } - - //We must have config.xml so leaveing if we doesn't - if (!has_config_xml) { - LogError("Invalid archive"); - *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + Catch (ElementParser::Exception::Base) + { + LogError("Invalid configuration file!"); return false; } - return true; } bool TaskWidgetConfig::locateAndParseConfigurationFile( - const std::string& _currentPath, - WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, - const std::string& baseFolder, - int* pErrCode) + const std::string& _currentPath, + WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + const std::string& baseFolder) { using namespace WrtDB; - if (!pErrCode) { - return false; - } - ConfigParserData& configInfo = pWidgetConfigInfo.configInfo; // check if this installation from browser, or not. size_t pos = _currentPath.rfind("/"); std::ostringstream infoPath; - infoPath << _currentPath.substr(pos+1); + infoPath << _currentPath.substr(pos + 1); if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) { if (_currentPath.empty() || baseFolder.empty()) { - *pErrCode = WRT_ERR_INVALID_ARG; return false; } // in case of general installation using wgt archive - if(!parseConfigurationFileWidget(configInfo, _currentPath, pErrCode)) + if (!parseConfigurationFileWidget(configInfo, _currentPath)) { return false; } } else { // in case of browser installation - if(!parseConfigurationFileBrowser(configInfo, _currentPath, pErrCode)) + if (!parseConfigurationFileBrowser(configInfo, _currentPath)) { return false; } } - if(!fillWidgetConfig(pWidgetConfigInfo, configInfo)) - { - *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE; + if (!fillWidgetConfig(pWidgetConfigInfo, configInfo)) { return false; } return true; } -bool TaskWidgetConfig::fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, - WrtDB::ConfigParserData& configInfo) +bool TaskWidgetConfig::fillWidgetConfig( + WrtDB::WidgetRegisterInfo& pWidgetConfigInfo, + WrtDB::ConfigParserData& configInfo) { if (!!configInfo.widget_id) { if (!pWidgetConfigInfo.guid) { @@ -771,11 +727,19 @@ bool TaskWidgetConfig::fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfig } } } - if (!!configInfo.tizenId) { - if (pWidgetConfigInfo.pkgName != *configInfo.tizenId) { - LogError("Invalid archive - Tizen ID not same error"); - return false; - } + if (!!configInfo.tizenAppId) { + if (DPL::ToUTF8String(pWidgetConfigInfo.tzAppid).compare( + DPL::ToUTF8String(*configInfo.tizenAppId)) < 0) + { + LogError("Invalid archive - Tizen App ID not same error"); + return false; + } + } + if (!!configInfo.tizenPkgId) { + if (pWidgetConfigInfo.tzPkgid != *configInfo.tizenPkgId) { + LogError("Invalid archive - Tizen Pkg ID not same error"); + return false; + } } if (!!configInfo.version) { if (!pWidgetConfigInfo.version) { @@ -795,17 +759,17 @@ bool TaskWidgetConfig::fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfig return true; } -void TaskWidgetConfig::processFile(const std::string& path, - WrtDB::WidgetRegisterInfo &widgetConfiguration) +void TaskWidgetConfig::processFile( + const std::string& path, + WrtDB::WidgetRegisterInfo & + widgetConfiguration) { - int pErrCode; - if (!locateAndParseConfigurationFile(path, widgetConfiguration, - DEFAULT_LANGUAGE, &pErrCode)) { + DEFAULT_LANGUAGE)) + { LogWarning("Widget archive: Failed while parsing config file"); ThrowMsg(Exception::ConfigParseFailed, path); } } - } //namespace WidgetInstall } //namespace Jobs