+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file WidgetConfigurationManager.cpp
- * @author Piotr Fatyga (p.fatyga@samsung.com)
- * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
- * @version 0.1
- * @brief
- */
-#include "WidgetConfigurationManager.h"
-#include <dirent.h>
-#include <dpl/wrt-dao-ro/global_config.h>
-#include "root_parser.h"
-#include "parser_runner.h"
-#include "widget_parser.h"
-#include <wrt_error.h>
-#include <dpl/utils/mime_type_utils.h>
-#include <dpl/localization/w3c_file_localization.h>
-#include <dpl/utils/wrt_utility.h>
-#include <dpl/singleton_impl.h>
-IMPLEMENT_SINGLETON(WidgetConfigurationManager)
-
-//TODO Rewrite this as steps/tasks
-namespace // anonymous
-{
-const char *const DEFAULT_LANGUAGE = "default";
-const size_t MAX_WIDGET_PATH_SIZE = 1024;
-
-//#define WRT_WIDGET_DEFAULT_ICON_WIDTH 80
-//#define WRT_WIDGET_DEFAULT_ICON_HEIGHT 80
-
-//#define WRT_WIDGET_CONFIG_BASE_LOCALE "locales"
-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)
-{
- 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);
-
- ParserRunner parser;
- std::string language = "";
-
- 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);
-
- if (currentPath.empty() || baseFolder.empty()) {
- *pErrCode = WRT_ERR_INVALID_ARG;
- 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;
- }
-
- //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);
-
- //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;
- if (!_WrtUtilStringToLower(baseFolder.c_str(), &tmp_language)) {
- *pErrCode = WRT_ERR_UNKNOWN;
- return false;
- }
-
- if (!tmp_language) {
- *pErrCode = WRT_ERR_UNKNOWN;
- return false;
- }
- language = tmp_language;
- free(tmp_language);
-
- if (!!configInfo.widget_id) {
- if (!pWidgetConfigInfo.guid) {
- pWidgetConfigInfo.guid = configInfo.widget_id;
- } else {
- if (pWidgetConfigInfo.guid != configInfo.widget_id) {
- *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
- LogDebug("Invalid archive");
- return false;
- }
- }
- }
-
- if (!!configInfo.tizenId) {
- if (pWidgetConfigInfo.pkgName != *configInfo.tizenId) {
- *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
- LogDebug("Invalid archive - Tizen ID not same error");
- return false;
- }
- }
-
- if (!!configInfo.version) {
- if (!pWidgetConfigInfo.version) {
- pWidgetConfigInfo.version = configInfo.version;
- } else {
- if (pWidgetConfigInfo.version != configInfo.version) {
- *pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
- LogDebug("Invalid archive");
- return false;
- }
- }
- }
-
- if (!!configInfo.minVersionRequired) {
- pWidgetConfigInfo.minVersion = configInfo.minVersionRequired;
- } else if (!!configInfo.tizenMinVersionRequired) {
- pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired;
- }
-
- return true;
-}
-
-void WidgetConfigurationManager::processFile(
- const std::string& path,
- WrtDB::WidgetRegisterInfo &
- widgetConfiguration)
-{
- int pErrCode;
-
- if (!locateAndParseConfigurationFile(path, widgetConfiguration,
- DEFAULT_LANGUAGE, &pErrCode))
- {
- LogWarning("Widget archive: Failed while parsing config file");
- ThrowMsg(Exception::ProcessFailed, path);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file WidgetConfigurationManager.h
- * @author Piotr Fatyga (p.fatyga@samsung.com)
- * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
- * @version 0.1
- * @brief
- */
-#ifndef _WIDGETCONFIGURATIONMANAGER_H
-#define _WIDGETCONFIGURATIONMANAGER_H
-
-#include <dpl/singleton.h>
-#include <dpl/string.h>
-#include <dpl/optional.h>
-#include <dpl/wrt-dao-ro/config_parser_data.h>
-#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
-#include <list>
-
-class WidgetConfigurationManager
-{
- public:
- class Exception
- {
- public:
- DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
- DECLARE_EXCEPTION_TYPE(Base, ProcessFailed)
- };
-
- /**
- * 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);
-
- private:
- typedef std::list<std::pair<DPL::String, DPL::String> > StringPairList;
-
- bool locateAndParseConfigurationFile(
- const std::string& currentPath,
- WrtDB::WidgetRegisterInfo&
- pWidgetConfigInfo,
- const std::string& baseFolder,
- int* pErrCode);
-};
-
-typedef DPL::Singleton<WidgetConfigurationManager>
-WidgetConfigurationManagerSingleton;
-
-#endif // _WIDGETCONFIGURATIONMANAGER_H