Merge "Implement tizen privilege for w3c API"
[framework/web/wrt-installer.git] / src / configuration_parser / WidgetConfigurationManager.cpp
index 1373329..6044a5f 100644 (file)
@@ -47,10 +47,10 @@ const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
 }
 
 bool WidgetConfigurationManager::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,
+    int* pErrCode)
 {
     using namespace WrtDB;
 
@@ -58,81 +58,115 @@ bool WidgetConfigurationManager::locateAndParseConfigurationFile(
         return false;
     }
 
-    //TODO: use DPL::String in the caller to this function too.
-    DPL::String currentPath = DPL::FromUTF8String(_currentPath);
+    ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
 
-    if (currentPath.empty() || baseFolder.empty()) {
-        *pErrCode = WRT_ERR_INVALID_ARG;
-        return false;
-    }
+    // check if this installation from browser, or not.
+    size_t pos = _currentPath.rfind("/");
+    std::ostringstream infoPath;
+    infoPath << _currentPath.substr(pos + 1);
 
-    //TODO: rewrite this madness
-    char cfgAbsPath[MAX_WIDGET_PATH_SIZE + 1] = { 0 };
-    DIR* dir = NULL;
-    struct dirent* ptr = NULL;
+    ParserRunner parser;
     std::string language = "";
 
-    dir = opendir(_currentPath.c_str());
-    if (dir == NULL) {
-        *pErrCode = WRT_ERR_UNKNOWN;
-        return false;
-    }
+    if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
+        // in case of general installation using wgt archive
+        //TODO: use DPL::String in the caller to this function too.
+        DPL::String currentPath = DPL::FromUTF8String(_currentPath);
 
-    ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
+        if (currentPath.empty() || baseFolder.empty()) {
+            *pErrCode = WRT_ERR_INVALID_ARG;
+            return false;
+        }
 
-    //TODO why don't we use fopen here
-    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)) {
-                _WrtUtilSetAbsolutePath(cfgAbsPath,
-                                        _currentPath.c_str(), ptr->d_name);
-                //Parse widget configuration file
-                LogDebug("Found config: " << cfgAbsPath);
-                ParserRunner parser;
-
-                Try
-                {
-                    parser.Parse(cfgAbsPath, ElementParserPtr(new
-                                                              RootParser<
-                                                                  WidgetParser>(
-                                                                  configInfo,
-                                                                  DPL
-                                                                      ::
-                                                                      FromUTF32String(
-                                                                      L"widget"))));
-                }
-                Catch(ElementParser::Exception::Base)
-                {
-                    LogDebug("Invalid widget configuration file!");
-                    //                    _rethrown_exception.Dump();
-                    *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
-                    closedir(dir);
-                    return false;
-                }
+        //TODO: rewrite this madness
+        char cfgAbsPath[MAX_WIDGET_PATH_SIZE + 1] = { 0 };
+        DIR* dir = NULL;
+        struct dirent* ptr = NULL;
+
+        dir = opendir(_currentPath.c_str());
+        if (dir == NULL) {
+            *pErrCode = WRT_ERR_UNKNOWN;
+            return false;
+        }
 
-                //
-                //                WidgetConfigurationParser & parser = WidgetConfigurationParserSingleton::Instance();
-                //                if (!parser.parseConfigurationFile(cfgAbsPath, configInfo, baseFolder.c_str(), pWidgetConfigInfo.signature_type)) {
-                //                    LogDebug("Invalid widget configuration file!");
-                //                    *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
-                //                    closedir(dir);
-                //                    return false;
-                //                }
-
-                has_config_xml = true;
-                break;
+        //TODO why don't we use fopen here
+        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)) {
+                    _WrtUtilSetAbsolutePath(cfgAbsPath,
+                                            _currentPath.c_str(), ptr->d_name);
+                    //Parse widget configuration file
+                    LogDebug("Found config: " << cfgAbsPath);
+
+                    Try
+                    {
+                        parser.Parse(cfgAbsPath, ElementParserPtr(new
+                                                                  RootParser<
+                                                                      WidgetParser>(
+                                                                      configInfo,
+                                                                      DPL
+                                                                          ::
+                                                                          FromUTF32String(
+                                                                          L"widget"))));
+                    }
+                    Catch(ElementParser::Exception::Base)
+                    {
+                        LogDebug("Invalid widget configuration file!");
+                        //                    _rethrown_exception.Dump();
+                        *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+                        closedir(dir);
+                        return false;
+                    }
+
+                    //
+                    //                WidgetConfigurationParser & parser =
+                    // WidgetConfigurationParserSingleton::Instance();
+                    //                if
+                    // (!parser.parseConfigurationFile(cfgAbsPath, configInfo,
+                    // baseFolder.c_str(), pWidgetConfigInfo.signature_type)) {
+                    //                    LogDebug("Invalid widget configuration
+                    // file!");
+                    //                    *pErrCode =
+                    // WRT_WM_ERR_INVALID_ARCHIVE;
+                    //                    closedir(dir);
+                    //                    return false;
+                    //                }
+
+                    has_config_xml = true;
+                    break;
+                }
             }
         }
-    }
-    closedir(dir);
+        closedir(dir);
 
-    //We must have config.xml so leaveing if we doesn't
-    if (!has_config_xml) {
-        LogDebug("Invalid archive");
-        *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
-        return false;
+        //We must have config.xml so leaveing if we doesn't
+        if (!has_config_xml) {
+            LogDebug("Invalid archive");
+            *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+            return false;
+        }
+    } else {
+        // in case of browser installation
+        Try
+        {
+            parser.Parse(_currentPath, ElementParserPtr(new
+                                                        RootParser<
+                                                            WidgetParser>(
+                                                            configInfo,
+                                                            DPL::
+                                                                FromUTF32String(
+                                                                L"widget"))));
+        }
+        Catch(ElementParser::Exception::Base)
+        {
+            LogDebug("Invalid widget configuration file!");
+            //                    _rethrown_exception.Dump();
+            *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+            return false;
+        }
     }
 
     char *tmp_language;
@@ -161,14 +195,10 @@ bool WidgetConfigurationManager::locateAndParseConfigurationFile(
     }
 
     if (!!configInfo.tizenId) {
-        if (!pWidgetConfigInfo.pkgname) {
-            pWidgetConfigInfo.pkgname = configInfo.tizenId;
-        } else {
-            if (pWidgetConfigInfo.pkgname != configInfo.tizenId) {
-                *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
-                LogDebug("Invalid archive - Tizen ID not same error");
-                return false;
-            }
+        if (pWidgetConfigInfo.pkgName != *configInfo.tizenId) {
+            *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
+            LogDebug("Invalid archive - Tizen ID not same error");
+            return false;
         }
     }
 
@@ -193,13 +223,16 @@ bool WidgetConfigurationManager::locateAndParseConfigurationFile(
     return true;
 }
 
-void WidgetConfigurationManager::processFile(const std::string& path,
-        WrtDB::WidgetRegisterInfo &widgetConfiguration)
+void WidgetConfigurationManager::processFile(
+    const std::string& path,
+    WrtDB::WidgetRegisterInfo &
+    widgetConfiguration)
 {
     int pErrCode;
 
     if (!locateAndParseConfigurationFile(path, widgetConfiguration,
-                                         DEFAULT_LANGUAGE, &pErrCode)) {
+                                         DEFAULT_LANGUAGE, &pErrCode))
+    {
         LogWarning("Widget archive: Failed while parsing config file");
         ThrowMsg(Exception::ProcessFailed, path);
     }