Fix allowed appid plugin parser 96/243096/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 3 Sep 2020 05:30:02 +0000 (14:30 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 3 Sep 2020 22:25:37 +0000 (07:25 +0900)
This patch supports "|" delimiter to split the value string.

+----------------------------------------------------------+
| e.g. org.tizen.hello & org.tizen.tizen                   |
| <metadata key="http://tizen.org/metadata/allowedappid"   |
|           value="org.tizen.hello|org.tizen.tizen"/>      |
+----------------------------------------------------------+

Change-Id: I9cfd2f7fcbc55d59650891e87d7206dc5f1193ef
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
parser/metadata/allowed-appid/plugin_manager.cc
parser/metadata/allowed-appid/plugin_manager.hh

index d6de6c8..896d615 100644 (file)
@@ -33,6 +33,20 @@ PluginManager& PluginManager::GetInst() {
   return inst;
 }
 
+std::vector<std::string> PluginManager::Split(const std::string& str,
+    const std::string& delim) {
+  std::string string(str);
+  std::vector<std::string> 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<AppEventArgs>& args) {
   auto* db = dynamic_cast<AppSvcDB*>(GetDB());
   if (db == nullptr) {
@@ -41,10 +55,12 @@ bool PluginManager::StepInstall(const std::unique_ptr<AppEventArgs>& 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;
index 8238ed7..bdc41c2 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef ALIAS_APPID_PLUGIN_MANAGER_HH_
 #define ALIAS_APPID_PLUGIN_MANAGER_HH_
 
+#include <vector>
+
 #include "common/metadata_plugin.hh"
 
 namespace plugin {
@@ -33,6 +35,9 @@ class PluginManager : public MetadataPlugin {
   bool StepUninstall(const std::unique_ptr<AppEventArgs>& args) override;
   bool StepUpgrade(const std::unique_ptr<AppEventArgs>& args) override;
 
+ private:
+  std::vector<std::string> Split(const std::string& str,
+      const std::string& delim);
 };
 
 }  // namespace plugin