2nd config.xml parsing removal
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 4 Sep 2013 12:14:00 +0000 (14:14 +0200)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Thu, 3 Oct 2013 08:47:00 +0000 (17:47 +0900)
[Issue#]   LINUXWRT-820
[Problem]  Config.xml parsed twice
[Cause]    N/A
[Solution] TaskProcessConfig fixture.

[Verification] Install, update. uninstall widgets attached in:
               http://cam.sprc.samsung.pl/browse/LINUXWRT-820

Change-Id: I3a3923b4bbd6d81feeecd1e4ac1f21f93e3f26df

src/jobs/widget_install/task_configuration.cpp
src/jobs/widget_install/task_configuration.h
src/jobs/widget_install/task_process_config.cpp
src/jobs/widget_install/task_process_config.h

index 052af02..c0ec745 100644 (file)
@@ -94,7 +94,8 @@ namespace WidgetInstall {
 
 TaskConfiguration::TaskConfiguration(InstallerContext& context) :
     DPL::TaskDecl<TaskConfiguration>(this),
-    m_context(context)
+    m_context(context),
+    m_widgetConfig(m_context.widgetConfig.configInfo)
 {
     AddStep(&TaskConfiguration::StartStep);
 
@@ -186,7 +187,7 @@ void TaskConfiguration::SetupTempDirStep()
 
 void TaskConfiguration::ParseXMLConfigStep()
 {
-    m_widgetConfig = getWidgetDataFromXML( //TODO: make one parsing of config.xml
+    parseWidgetXMLConfig(
             m_context.requestedPath, m_tempDir,
             m_context.widgetConfig.packagingType,
             m_context.mode.command == InstallMode::Command::REINSTALL);
@@ -475,7 +476,7 @@ bool TaskConfiguration::checkWidgetUpdate(
     return false;
 }
 
-ConfigParserData TaskConfiguration::getWidgetDataFromXML(
+void TaskConfiguration::parseWidgetXMLConfig(
     const std::string &widgetSource,
     const std::string &tempPath,
     WrtDB::PackagingType pkgType,
@@ -483,13 +484,12 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
 {
     // Parse config
     ParserRunner parser;
-    ConfigParserData configInfo;
     Try
     {
         if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
             parser.Parse(widgetSource,
                          ElementParserPtr(
-                             new RootParser<WidgetParser>(configInfo,
+                             new RootParser<WidgetParser>(m_widgetConfig,
                                                           DPL::FromUTF32String(
                                                               L"widget"))));
         } else {
@@ -525,7 +525,7 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
 #endif
             parser.Parse(configFile,
                     ElementParserPtr(
-                        new RootParser<WidgetParser>(configInfo,
+                        new RootParser<WidgetParser>(m_widgetConfig,
                             DPL::
                             FromUTF32String(
                                 L"widget"))));
@@ -545,8 +545,6 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
         _E("Failed to find config.xml");
         ThrowMsg(Exceptions::MissingConfig, "Parser exeption");
     }
-
-    return configInfo;
 }
 
 WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
index 3a50ca7..44b02be 100644 (file)
@@ -41,11 +41,11 @@ class TaskConfiguration : public DPL::TaskDecl<TaskConfiguration>
 {
     InstallerContext& m_context;
     std::string m_tempDir;
-    WrtDB::ConfigParserData m_widgetConfig; //TODO: temporary result of config.xml parsing
+    WrtDB::ConfigParserData &m_widgetConfig;
 
     WidgetUpdateInfo m_widgetUpdateInfo;
 
-    static WrtDB::ConfigParserData getWidgetDataFromXML(
+    void parseWidgetXMLConfig(
         const std::string &widgetSource,
         const std::string &tempPath,
         WrtDB::PackagingType pkgType,
index 3e41d24..57958eb 100755 (executable)
@@ -20,8 +20,6 @@
  * @brief   Implementation file for installer task widget config
  */
 
-#include <map>
-#include <sstream>
 #include <string>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <dpl/wrt-dao-ro/config_parser_data.h>
 #include <dpl/wrt-dao-rw/feature_dao.h>
 
-#include <libiriwrapper.h>
-#include <parser_runner.h>
-#include <root_parser.h>
-
 #include <widget_install/job_widget_install.h>
 #include <widget_install/task_process_config.h>
 #include <widget_install/widget_install_context.h>
 
 namespace { // anonymous
 const DPL::String BR = DPL::FromUTF8String("<br>");
-const std::string WIDGET_NOT_COMPATIBLE = "This widget is "
-                                          "not compatible with WRT.<br><br>";
-
-const char *const DEFAULT_LANGUAGE = "default";
-
-const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
-
 const std::string WINDGET_INSTALL_NETWORK_ACCESS = "network access";
-
-const char WRT_WIDGETS_XML_SCHEMA[] = "/usr/etc/wrt-installer/widgets.xsd";
 }
 
 namespace Jobs {
@@ -75,7 +60,7 @@ TaskProcessConfig::TaskProcessConfig(InstallerContext& installContext) :
 {
     AddStep(&TaskProcessConfig::StartStep);
     AddStep(&TaskProcessConfig::ReadLocaleFolders);
-    AddStep(&TaskProcessConfig::StepProcessConfigurationFile);
+    AddStep(&TaskProcessConfig::StepFillWidgetConfig);
     AddStep(&TaskProcessConfig::ProcessLocalizedStartFiles);
     AddStep(&TaskProcessConfig::ProcessBackgroundPageFile);
     AddStep(&TaskProcessConfig::ProcessLocalizedIcons);
@@ -88,23 +73,14 @@ TaskProcessConfig::TaskProcessConfig(InstallerContext& installContext) :
     AddStep(&TaskProcessConfig::EndStep);
 }
 
-void TaskProcessConfig::StepProcessConfigurationFile()
+void TaskProcessConfig::StepFillWidgetConfig()
 {
-    Try
+    if (!fillWidgetConfig(m_installContext.widgetConfig,
+                         m_installContext.widgetConfig.configInfo))
     {
-        std::string path = m_installContext.locations->getConfigurationDir();
-        _D("path: %s", path.c_str());
-        processFile(path, m_installContext.widgetConfig);
+        _E("Widget configuration is illformed");
+        ThrowMsg(Exception::ConfigParseFailed, "Widget configuration is illformed");
     }
-    Catch(Exception::ConfigParseFailed)
-    {
-        _E("Parsing failed.");
-        ReThrow(Exceptions::WidgetConfigFileInvalid);
-    }
-
-    m_installContext.job->UpdateProgress(
-        InstallerContext::INSTALL_WIDGET_CONFIG1,
-        "Parse elements of configuration file and save them");
 }
 
 void TaskProcessConfig::ReadLocaleFolders()
@@ -155,6 +131,8 @@ void TaskProcessConfig::ReadLocaleFolders()
     if (-1 == closedir(localeDir)) {
         _E("Failed to close dir: %s with error: %s", localePath.c_str(), DPL::GetErrnoString().c_str());
     }
+
+    m_installContext.job->UpdateProgress(InstallerContext::INSTALL_WIDGET_CONFIG1, "Read locale folders");
 }
 
 void TaskProcessConfig::ProcessLocalizedStartFiles()
@@ -656,140 +634,19 @@ bool TaskProcessConfig::isMinVersionCompatible(
 
 bool TaskProcessConfig::isTizenWebApp() const
 {
-    bool ret = FALSE;
-    if (m_installContext.widgetConfig.webAppType.appType
-        == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
-    {
-        ret = TRUE;
-    }
-
-    return ret;
-}
-
-bool TaskProcessConfig::parseConfigurationFileBrowser(
-    WrtDB::ConfigParserData& configInfo,
-    const std::string& _currentPath)
-{
-    ParserRunner parser;
-    Try
-    {
-        parser.Parse(_currentPath, ElementParserPtr(new
-                                                    RootParser<
-                                                        WidgetParser>(
-                                                        configInfo,
-                                                        DPL::FromUTF32String(
-                                                            L"widget"))));
-    }
-    Catch(ElementParser::Exception::Base)
-    {
-        _E("Invalid widget configuration file!");
-        return false;
-    }
-    return true;
-}
-
-bool TaskProcessConfig::parseConfigurationFileWidget(
-    WrtDB::ConfigParserData& configInfo,
-    const std::string& _currentPath)
-{
-    std::string configFilePath;
-    WrtUtilJoinPaths(configFilePath, _currentPath, WRT_WIDGET_CONFIG_FILE_NAME);
-    if (!WrtUtilFileExists(configFilePath))
-    {
-        _E("Archive does not contain configuration file");
-        return false;
-    }
-
-    _D("Configuration file: %s", configFilePath.c_str());
-
-    Try
+    if (m_installContext.widgetConfig.webAppType.appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
     {
-        ParserRunner parser;
-#ifdef SCHEMA_VALIDATION_ENABLED
-        if(!parser.Validate(configFilePath, WRT_WIDGETS_XML_SCHEMA))
-        {
-            _E("Invalid configuration file - schema validation failed");
-            return false;
-        }
-#endif
-        parser.Parse(configFilePath,
-                     ElementParserPtr(new RootParser<WidgetParser>(
-                                          configInfo,
-                                          DPL::FromUTF32String(L"widget"))));
         return true;
     }
-    Catch (ElementParser::Exception::Base)
-    {
-        _E("Invalid configuration file!");
-        return false;
-    }
-}
-
-bool TaskProcessConfig::locateAndParseConfigurationFile(
-    const std::string& _currentPath,
-    WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
-    const std::string& baseFolder)
-{
-    using namespace WrtDB;
-
-    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);
-
-    if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
-        if (_currentPath.empty() || baseFolder.empty()) {
-            return false;
-        }
-        // in case of general installation using wgt archive
-        if (!parseConfigurationFileWidget(configInfo, _currentPath))
-        {
-            return false;
-        }
-    } else {
-        // in case of browser installation
-        if (!parseConfigurationFileBrowser(configInfo, _currentPath))
-        {
-            return false;
-        }
-    }
-    if (!fillWidgetConfig(pWidgetConfigInfo, configInfo)) {
-        return false;
-    }
-    return true;
+    return false;
 }
 
 bool TaskProcessConfig::fillWidgetConfig(
     WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
     WrtDB::ConfigParserData& configInfo)
 {
-    if (!!configInfo.widget_id) {
-        if (!pWidgetConfigInfo.guid) {
-            pWidgetConfigInfo.guid = configInfo.widget_id;
-            _D("W3C Widget GUID : %ls", (*pWidgetConfigInfo.guid).c_str());
-        } else {
-            if (pWidgetConfigInfo.guid != configInfo.widget_id) {
-                _E("Invalid archive");
-                return false;
-            }
-        }
-    }
-    if (!!configInfo.tizenAppId) {
-        if (DPL::ToUTF8String(pWidgetConfigInfo.tzAppid).compare(
-                DPL::ToUTF8String(*configInfo.tizenAppId)) < 0)
-        {
-            _E("Invalid archive - Tizen App ID not same error");
-            return false;
-        }
-    }
-    if (!!configInfo.tizenPkgId) {
-        if (pWidgetConfigInfo.tzPkgid != *configInfo.tizenPkgId) {
-            _E("Invalid archive - Tizen Pkg ID not same error");
-            return false;
-        }
-    }
+    pWidgetConfigInfo.guid = configInfo.widget_id;
+
     if (!!configInfo.version) {
         if (!pWidgetConfigInfo.version) {
             pWidgetConfigInfo.version = configInfo.version;
@@ -808,19 +665,6 @@ bool TaskProcessConfig::fillWidgetConfig(
     return true;
 }
 
-void TaskProcessConfig::processFile(
-    const std::string& path,
-    WrtDB::WidgetRegisterInfo &
-    widgetConfiguration)
-{
-    if (!locateAndParseConfigurationFile(path, widgetConfiguration,
-                                         DEFAULT_LANGUAGE))
-    {
-        _W("Widget archive: Failed while parsing config file");
-        ThrowMsg(Exception::ConfigParseFailed, path);
-    }
-}
-
 void TaskProcessConfig::StartStep()
 {
     _D("--------- <TaskProcessConfig> : START ----------");
index f9cbc57..8d844d6 100755 (executable)
@@ -57,7 +57,7 @@ class TaskProcessConfig :
     WrtDB::LocaleSet m_localeFolders;
     std::set<DPL::String> m_processedIconSet;
 
-    void StepProcessConfigurationFile();
+    void StepFillWidgetConfig();
     void ReadLocaleFolders();
     void ProcessLocalizedStartFiles();
     void ProcessStartFile(
@@ -95,25 +95,7 @@ class TaskProcessConfig :
     bool isTizenWebApp() const;
     bool parseVersionString(const std::string &version, long &majorVersion,
                             long &minorVersion, long &microVersion) const;
-    /**
-     * This method is used to process the config.xml of widget, get
-     * the corresponding configuration to pWidgetConfigInfo
-     *
-     * @param[in] path Specified the widget archive file path (absolute path).
-     * @return         Configuration information of  widget
-     */
-    void processFile(const std::string& path,
-                     WrtDB::WidgetRegisterInfo &wConfig);
 
-    bool locateAndParseConfigurationFile(
-        const std::string& currentPath,
-        WrtDB::WidgetRegisterInfo&
-        pWidgetConfigInfo,
-        const std::string& baseFolder);
-    bool parseConfigurationFileBrowser(WrtDB::ConfigParserData& configInfo,
-                                       const std::string& _currentPath);
-    bool parseConfigurationFileWidget(WrtDB::ConfigParserData& configInfo,
-                                      const std::string& _currentPath);
     bool fillWidgetConfig(WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
                           WrtDB::ConfigParserData& configInfo);