From 8b9f626d0eb7afea54cba00d7a374c4f3c562400 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 3 Sep 2020 14:30:02 +0900 Subject: [PATCH] Fix allowed appid plugin parser This patch supports "|" delimiter to split the value string. +----------------------------------------------------------+ | e.g. org.tizen.hello & org.tizen.tizen | | | +----------------------------------------------------------+ Change-Id: I9cfd2f7fcbc55d59650891e87d7206dc5f1193ef Signed-off-by: Hwankyu Jhun --- parser/metadata/allowed-appid/plugin_manager.cc | 24 ++++++++++++++++++++---- parser/metadata/allowed-appid/plugin_manager.hh | 5 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/parser/metadata/allowed-appid/plugin_manager.cc b/parser/metadata/allowed-appid/plugin_manager.cc index d6de6c8..896d615 100644 --- a/parser/metadata/allowed-appid/plugin_manager.cc +++ b/parser/metadata/allowed-appid/plugin_manager.cc @@ -33,6 +33,20 @@ PluginManager& PluginManager::GetInst() { return inst; } +std::vector PluginManager::Split(const std::string& str, + const std::string& delim) { + std::string string(str); + std::vector result; + std::size_t pos; + while ((pos = string.find(delim)) != std::string::npos) { + std::string token = string.substr(0, pos); + result.push_back(token); + string.erase(0, pos + delim.length()); + } + result.push_back(string); + return result; +} + bool PluginManager::StepInstall(const std::unique_ptr& args) { auto* db = dynamic_cast(GetDB()); if (db == nullptr) { @@ -41,10 +55,12 @@ bool PluginManager::StepInstall(const std::unique_ptr& args) { } for (auto& metadata : args->GetMetadataList()) { - try { - db->Insert(args->GetAppId(), metadata->GetValue()); - } catch (Exception& e) { - return false; + for (auto& app_id : Split(metadata->GetValue(), "|")) { + try { + db->Insert(args->GetAppId(), app_id); + } catch (Exception& e) { + return false; + } } } return true; diff --git a/parser/metadata/allowed-appid/plugin_manager.hh b/parser/metadata/allowed-appid/plugin_manager.hh index 8238ed7..bdc41c2 100644 --- a/parser/metadata/allowed-appid/plugin_manager.hh +++ b/parser/metadata/allowed-appid/plugin_manager.hh @@ -17,6 +17,8 @@ #ifndef ALIAS_APPID_PLUGIN_MANAGER_HH_ #define ALIAS_APPID_PLUGIN_MANAGER_HH_ +#include + #include "common/metadata_plugin.hh" namespace plugin { @@ -33,6 +35,9 @@ class PluginManager : public MetadataPlugin { bool StepUninstall(const std::unique_ptr& args) override; bool StepUpgrade(const std::unique_ptr& args) override; + private: + std::vector Split(const std::string& str, + const std::string& delim); }; } // namespace plugin -- 2.7.4