Fix a bug about getting appid list
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 27 Apr 2021 10:21:07 +0000 (19:21 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 28 Apr 2021 01:00:39 +0000 (10:00 +0900)
This patch is for backward compatibility.
To create the resolve info properly, if the mime is not an empty string
and uri has a slash, the uri should be the empty string
in the GetMime() method of ResolveInfo::Manager class.
To get the appid list properly, the GetAppID() method is added.

Change-Id: I356e5e3423df470dbe414ae32cc5d2d79e3246c7
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_app_control.cc
src/lib/app_control/app_control_resolver.hh
src/lib/app_control/resolve_info.cc
src/lib/app_control/resolver.hh
src/lib/app_control/scheme_host_resolver.cc
src/lib/app_control/scheme_host_resolver.hh
src/lib/app_control/scheme_resolver.cc
src/lib/app_control/scheme_resolver.hh
src/lib/app_control/uri_resolver.cc
src/lib/app_control/uri_resolver.hh

index 4eeeeb0c497ca2883bb8848a3f583d093076574e..a1cb3752a952fa1d0c7fa47e9b493dc653136368 100644 (file)
@@ -183,7 +183,7 @@ static int __dispatch_app_get_appid_list(request_h req) {
   }
 
   int ret;
-  auto result = AppControlResolver::GetInst().Resolve(target_uid, info);
+  auto result = AppControlResolver::GetInst().GetAppList(target_uid, info);
   if (result.size() == 0)
     ret = -ENOENT;
   else
index a93547c244c2e0f7b0b4a9b1038e81b29bfe1ee4..c6314d5edc581501d1094f0647e417002ccb1530 100644 (file)
@@ -55,6 +55,10 @@ class AppControlResolver {
     return resolver_->Resolve(uid, info);
   }
 
+  std::vector<std::string> GetAppList(uid_t uid, const ResolveInfo& info) {
+    return resolver_->GetAppList(uid, info);
+  }
+
  private:
   void Init() {
     resolver_ = std::shared_ptr<Resolver>(
index d445351516da89427bc60fbf6c2ca14b368798d4..d611e72124107da0f51d1e3dd96c57f963bbe403 100644 (file)
@@ -108,6 +108,8 @@ void ResolveInfo::Manager::GetMime(std::string& uri, std::string& mime) {
     if (mime.empty()) {
       need_check = true;
       index = 0;
+    } else {
+      uri = "";
     }
   } else if (uri.compare(0, 8, "file:///") == 0) {
     if (mime.empty()) {
@@ -207,6 +209,8 @@ ResolveInfo ResolveInfo::Manager::Create(const tizen_base::Bundle& b) {
   if (ret != 0)
     THROW(ret);
 
+  SECURE_LOGD("uri_r_info(%s), scheme(%s), host(%s)",
+      uri_r_info.c_str(), scheme.c_str(), host.c_str());
   builder.SetUriRInfo(uri_r_info);
   builder.SetScheme(scheme);
   builder.SetHost(host);
index 9399c2518a96225b72cf637883544295e4d5e328..4883a0a6db777051287734732bab33da8d35507a 100644 (file)
@@ -34,6 +34,8 @@ class Resolver {
       std::shared_ptr<Resolver> resolver) = 0;
   virtual std::vector<std::string> Resolve(uid_t uid,
       const ResolveInfo& info) = 0;
+  virtual std::vector<std::string> GetAppList(uid_t uid,
+      const ResolveInfo& info) = 0;
 
   static std::string GetAppControl(const std::string& operation,
       const std::string& uri, const std::string& mime);
index 61257e9f3526d92057b508ceea6a3716ed5bb0d0..812506e816581e98ab95f759b35fe86798271288 100644 (file)
@@ -42,7 +42,8 @@ std::vector<std::string> SchemeHostResolver::Resolve(uid_t uid,
 
  auto app_control_infos = GetAppControlInfos(info.GetOperation(),
      info.GetUriRInfo(), info.GetMime(), info.GetMType(), info.GetSType());
-  auto app_list = GetAppList(uid, "", app_control_infos, false, false);
+  auto app_list = Resolver::GetAppList(uid, "", app_control_infos, false,
+      false);
   if (app_list.size() == 0) {
     if (next_resolver_.get() != nullptr)
       return next_resolver_->Resolve(uid, info);
@@ -57,8 +58,8 @@ std::vector<std::string> SchemeHostResolver::Resolve(uid_t uid,
           info.GetMime(), info.GetMType(), info.GetSType()));
   }
 
-  app_list = GetAppList(uid, info.GetCategory(), app_control_infos, true,
-      false);
+  app_list = Resolver::GetAppList(uid, info.GetCategory(), app_control_infos,
+      true, false);
   if (app_list.size() > 0) {
     std::vector<std::string> result {
         std::make_move_iterator(std::begin(app_list)),
@@ -74,4 +75,12 @@ std::vector<std::string> SchemeHostResolver::Resolve(uid_t uid,
   return {};
 }
 
+std::vector<std::string> SchemeHostResolver::GetAppList(uid_t uid,
+    const ResolveInfo& info) {
+  if (next_resolver_.get() != nullptr)
+    return next_resolver_->GetAppList(uid, info);
+
+  return {};
+}
+
 }  // namespace amd
index 3221f972ab2e302993d960d785dbf4be06cc400d..9fe520be221d7ee75b0281d21271b79443f71e73 100644 (file)
@@ -23,9 +23,11 @@ namespace amd {
 
 class SchemeHostResolver : public Resolver {
  public:
-   virtual std::shared_ptr<Resolver> SetNext(
+   std::shared_ptr<Resolver> SetNext(
        std::shared_ptr<Resolver> resolver) override;
-   virtual std::vector<std::string> Resolve(uid_t uid,
+   std::vector<std::string> Resolve(uid_t uid,
+       const ResolveInfo& info) override;
+   std::vector<std::string> GetAppList(uid_t uid,
        const ResolveInfo& info) override;
 
  private:
index f3cdbdb8c11d00a27b106d5517ea71508c5f0989..2957028700ad0369add0efc8c8536e04e12591f2 100644 (file)
@@ -49,8 +49,8 @@ std::vector<std::string> SchemeResolver::Resolve(uid_t uid,
           info.GetMime(), info.GetMType(), info.GetSType()));
   }
 
-  auto app_list = GetAppList(uid, info.GetCategory(), app_control_infos, true,
-      false);
+  auto app_list = Resolver::GetAppList(uid, info.GetCategory(),
+      app_control_infos, true, false);
   if (app_list.size() > 0) {
     std::vector<std::string> result {
         std::make_move_iterator(std::begin(app_list)),
@@ -69,4 +69,12 @@ std::vector<std::string> SchemeResolver::Resolve(uid_t uid,
   return {};
 }
 
+std::vector<std::string> SchemeResolver::GetAppList(uid_t uid,
+    const ResolveInfo& info) {
+  if (next_resolver_.get() != nullptr)
+    return next_resolver_->GetAppList(uid, info);
+
+  return {};
+}
+
 }  // namespace amd
index 34351bd977eef606b21666dcdae3c13fb9db0e2c..91275a97dbc4b2a812a82976ea10988460303ba4 100644 (file)
@@ -23,9 +23,11 @@ namespace amd {
 
 class SchemeResolver : public Resolver {
  public:
-   virtual std::shared_ptr<Resolver> SetNext(
+   std::shared_ptr<Resolver> SetNext(
        std::shared_ptr<Resolver> resolver) override;
-   virtual std::vector<std::string> Resolve(uid_t uid,
+   std::vector<std::string> Resolve(uid_t uid,
+       const ResolveInfo& info) override;
+   std::vector<std::string> GetAppList(uid_t uid,
        const ResolveInfo& info) override;
 
  private:
index fcdd6a8a4562781e6cb9d4b53153765c5a535043..f00705e55b595f876605ef16aa07117a60338ac3 100644 (file)
@@ -42,7 +42,7 @@ std::vector<std::string> UriResolver::Resolve(uid_t uid,
 
   auto app_control_infos = GetAppControlInfos(info.GetOperation(),
       info.GetUri(), info.GetMime(), info.GetMType(), info.GetSType());
-  auto app_list = GetAppList(uid, "", app_control_infos, false, true);
+  auto app_list = Resolver::GetAppList(uid, "", app_control_infos, false, true);
   if (app_list.size() == 0) {
     if (next_resolver_.get() != nullptr)
       return next_resolver_->Resolve(uid, info);
@@ -64,8 +64,8 @@ std::vector<std::string> UriResolver::Resolve(uid_t uid,
           info.GetMime(), info.GetMType(), info.GetSType()));
   }
 
-  app_list = GetAppList(uid, info.GetCategory(), app_control_infos, true,
-      false);
+  app_list = Resolver::GetAppList(uid, info.GetCategory(), app_control_infos,
+      true, false);
   if (app_list.size() > 0) {
     std::vector<std::string> result {
         std::make_move_iterator(std::begin(app_list)),
@@ -84,4 +84,43 @@ std::vector<std::string> UriResolver::Resolve(uid_t uid,
   return {};
 }
 
+std::vector<std::string> UriResolver::GetAppList(uid_t uid,
+    const ResolveInfo& info) {
+  auto app_control_infos = GetAppControlInfos(info.GetOperation(),
+      info.GetUri(), info.GetMime(), info.GetMType(), info.GetSType());
+
+  if (!info.GetUriRInfo().empty()) {
+    app_control_infos.merge(GetAppControlInfos(info.GetOperation(),
+        info.GetUriRInfo(), info.GetMime(), info.GetMType(), info.GetSType()));
+  }
+
+  app_control_infos.merge(GetAppControlInfos(info.GetOperation(),
+        info.GetScheme(), info.GetMime(), info.GetMType(), info.GetSType()));
+  app_control_infos.merge(GetAppControlInfos(info.GetOperation(), "*",
+        info.GetMime(), info.GetMType(), info.GetSType()));
+  if (info.GetScheme() == "file" && info.GetMime() != "NULL") {
+    app_control_infos.merge(GetAppControlInfos(info.GetOperation(), "NULL",
+          info.GetMime(), info.GetMType(), info.GetSType()));
+  }
+
+  auto app_list = Resolver::GetAppList(uid, info.GetCategory(),
+      app_control_infos, true, true);
+  if (app_list.size() > 0) {
+    std::vector<std::string> result {
+        std::make_move_iterator(std::begin(app_list)),
+        std::make_move_iterator(std::end(app_list))
+    };
+
+    if (result.size() > 1)
+      const_cast<ResolveInfo&>(info).SetUriRInfo(info.GetUri());
+
+    return result;
+  }
+
+  if (next_resolver_.get() != nullptr)
+    return next_resolver_->GetAppList(uid, info);
+
+  return {};
+}
+
 }  // namespace amd
index 7d8d3522cae57aca2c04534f286bded3876a1aea..d35a00f14930d7c4c31ed5ffb598a371033f4a8b 100644 (file)
@@ -23,9 +23,11 @@ namespace amd {
 
 class UriResolver : public Resolver {
  public:
-  virtual std::shared_ptr<Resolver> SetNext(
+  std::shared_ptr<Resolver> SetNext(
       std::shared_ptr<Resolver> resolver) override;
-  virtual std::vector<std::string> Resolve(uid_t uid,
+  std::vector<std::string> Resolve(uid_t uid,
+      const ResolveInfo& info) override;
+  std::vector<std::string> GetAppList(uid_t uid,
       const ResolveInfo& info) override;
 
  private: