Support alias appid 54/238254/4
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Jul 2020 04:09:23 +0000 (13:09 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Sun, 12 Jul 2020 23:34:45 +0000 (08:34 +0900)
Before sending the request to connect to stub, proxy checks the real
appid using appid. If aul_svc_get_appid_by_alias_appid() returns
AUL_SVC_RET_OK, proxy uses it.

Change-Id: I8b379d0cf08f0779c5d9800c41d1e745dd9848f3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/fdbroker-internal.cc
src/fdbroker-internal.h
src/proxy-internal.cc
src/proxy-internal.h

index e137819..5fc79e6 100644 (file)
@@ -135,7 +135,7 @@ int FdBroker::DBusMock::AddListener(const std::string& port,
 int FdBroker::DBusMock::Watch(FdBroker::IEventWatcher* watcher,
                               const std::string& target_appid,
                               const std::string& port_name) {
-  watcher->OnPortAppeared(target_appid, port_name);
+  watcher->OnPortAppeared();
   return 0;
 }
 // LCOV_EXCL_STOP
@@ -300,7 +300,7 @@ int FdBroker::Send(const std::string& target_appid,
 
     (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER);
     (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER);
-    watcher_->OnPortConnected(watch_appid_, watch_port_name_);
+    watcher_->OnPortConnected();
     return (*fds)[0];
     // LCOV_EXCL_STOP
   }
@@ -758,8 +758,7 @@ void FdBroker::OnNameAppeared(GDBusConnection *connection,
   if (aul_app_get_appid_bypid(pid, owner_appid, sizeof(owner_appid)) < 0) {
     // LCOV_EXCL_START
     LOGE("aul_app_get_appid_bypid failed %d", pid);
-    broker->watcher_->OnPortRejected(owner_appid,
-        RPC_PORT_ERROR_IO_ERROR);
+    broker->watcher_->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
     return;
     // LCOV_EXCL_STOP
   }
@@ -767,14 +766,12 @@ void FdBroker::OnNameAppeared(GDBusConnection *connection,
   if (broker->watch_appid_ != owner_appid) {
     // LCOV_EXCL_START
     LOGE("invalid appid %s", owner_appid);
-    broker->watcher_->OnPortRejected(owner_appid,
-        RPC_PORT_ERROR_IO_ERROR);
+    broker->watcher_->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
     return;
     // LCOV_EXCL_STOP
   }
 
-  broker->watcher_->OnPortAppeared(broker->watch_appid_,
-      broker->watch_port_name_);
+  broker->watcher_->OnPortAppeared();
 }
 
 void FdBroker::OnNameVanished(GDBusConnection *connection,
@@ -793,8 +790,7 @@ void FdBroker::OnNameVanished(GDBusConnection *connection,
     return;
   }
 
-  broker->watcher_->OnPortVanished(broker->watch_appid_,
-      broker->watch_port_name_);
+  broker->watcher_->OnPortVanished();
 }
 
 int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid,
@@ -911,8 +907,7 @@ void FdBroker::OnResultReceived(GObject* source_object,
 
   if (err) {
     // LCOV_EXCL_START
-    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_,
-        true);
+    watcher->OnPortDisconnected(true);
     g_error_free(err);
     if (broker->cancellable_) {
       LOGW("Cancel the send request");
@@ -933,7 +928,7 @@ void FdBroker::OnResultReceived(GObject* source_object,
   if (reply_body == nullptr) {
     // LCOV_EXCL_START
     LOGE("g_dbus_message_get_body() is failed");
-    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
+    watcher->OnPortDisconnected();
     g_object_unref(reply);
     return;
     // LCOV_EXCL_STOP
@@ -944,12 +939,11 @@ void FdBroker::OnResultReceived(GObject* source_object,
   g_object_unref(reply);
   if (ret != 0) {
     LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str());
-    watcher->OnPortRejected(broker->watch_appid_,
-        RPC_PORT_ERROR_PERMISSION_DENIED);
+    watcher->OnPortRejected(RPC_PORT_ERROR_PERMISSION_DENIED);
     return;
   }
 
-  watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_);
+  watcher->OnPortConnected();
   LOGD("[Reply : %d]", ret);
 }
 
@@ -971,7 +965,7 @@ gboolean FdBroker::OnDbusNameTimeout(gpointer user_data) {
   broker->conn_data_ = nullptr;
   broker->Cancel();
   auto* watcher = broker->watcher_;
-  watcher->OnPortRejected(broker->watch_appid_, RPC_PORT_ERROR_IO_ERROR);
+  watcher->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
 
   return G_SOURCE_REMOVE;
 }
index 5086218..21ce847 100644 (file)
@@ -44,17 +44,11 @@ class FdBroker : public std::enable_shared_from_this<FdBroker> {
 
   class IEventWatcher {
    public:
-    virtual void OnPortAppeared(const std::string& appid,
-                                const std::string& port_name) = 0;
-    virtual void OnPortVanished(const std::string& appid,
-                                const std::string& port_name) = 0;
-    virtual void OnPortRejected(const std::string& appid,
-                                int error) = 0;
-    virtual void OnPortConnected(const std::string& appid,
-                                 const std::string& port_name) = 0;
-    virtual void OnPortDisconnected(const std::string& appid,
-                                    const std::string& port_name,
-                                    bool cancel = false) = 0;
+    virtual void OnPortAppeared() = 0;
+    virtual void OnPortVanished() = 0;
+    virtual void OnPortRejected(int error) = 0;
+    virtual void OnPortConnected() = 0;
+    virtual void OnPortDisconnected(bool cancel = false) = 0;
   };
 
   explicit FdBroker(bool mock = false);
index f3e8b40..217e974 100644 (file)
 #define _GNU_SOURCE
 #endif
 
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <aul_svc.h>
 #include <dlog.h>
+#include <sys/socket.h>
+#include <sys/types.h>
 
 #include "debug-port-internal.hh"
 #include "log-private.hh"
@@ -96,33 +97,33 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond,
   return TRUE;
 }
 
-void Proxy::OnPortRejected(const std::string& appid, int error) {
+void Proxy::OnPortRejected(int error) {
+  _W("[__OnPortRejected__] endpoint(%s), error(%d)",
+      target_appid_.c_str(), error);
   if (listener_ == nullptr)
     return;
 
   IEventListener* listener = listener_;
   listener_ = nullptr;
-  listener->OnRejected(appid, error);
+  listener->OnRejected(target_appid_, error);
 }
 
-void Proxy::OnPortAppeared(const std::string& appid,
-                           const std::string& port_name) {
-  _D("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str());
-
+void Proxy::OnPortAppeared() {
+  _D("endpoint(%s), port_name(%s)", target_appid_.c_str(), port_name_.c_str());
   if (listener_ == nullptr)
     return;
 
   fds_[0] = 0;
   fds_[1] = 0;
-  int r = fd_broker_->Send(appid, port_name, &fds_);
+  int r = fd_broker_->Send(real_appid_, port_name_, &fds_);
   if (r <= 0) {
     // LCOV_EXCL_START
     IEventListener* listener = listener_;
     listener_ = nullptr;
     if (r == -EILLEGALACCESS)
-      listener->OnRejected(appid, RPC_PORT_ERROR_PERMISSION_DENIED);
+      listener->OnRejected(target_appid_, RPC_PORT_ERROR_PERMISSION_DENIED);
     else
-      listener->OnDisconnected(appid);
+      listener->OnDisconnected(target_appid_);
     return;
     // LCOV_EXCL_STOP
   }
@@ -130,32 +131,29 @@ void Proxy::OnPortAppeared(const std::string& appid,
   _W("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds_[0], fds_[1]);
 }
 
-void Proxy::OnPortVanished(const std::string& appid,
-                           const std::string& port_name) {
+void Proxy::OnPortVanished() {
   _W("[__OnPortVanished__] endpoint(%s), port_name(%s)",
-      appid.c_str(), port_name.c_str());
+      target_appid_.c_str(), port_name_.c_str());
 }
 
-void Proxy::OnPortConnected(const std::string& appid,
-                            const std::string& port_name) {
+void Proxy::OnPortConnected() {
   _W("[__OnPortConnected__] endpoint(%s), port_name(%s)",
-      appid.c_str(), port_name.c_str());
+      target_appid_.c_str(), port_name_.c_str());
   if (!listener_) {
     _W("listener is null");  // LCOV_EXCL_LINE
     return;  // LCOV_EXCL_LINE
   }
 
-  main_port_.reset(new ProxyPort(this, fds_[0], appid, false));
-  delegate_port_.reset(new ProxyPort(this, fds_[1], appid));
-  listener_->OnConnected(appid, main_port_.get());
-  DebugPort::GetInst().AddSession(port_name, appid, fds_[0], fds_[1]);
+  main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
+  delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_));
+  listener_->OnConnected(target_appid_, main_port_.get());
+  DebugPort::GetInst().AddSession(port_name_, target_appid_, fds_[0], fds_[1]);
 }
 
 // LCOV_EXCL_START
-void Proxy::OnPortDisconnected(const std::string& appid,
-                               const std::string& port_name, bool cancel) {
+void Proxy::OnPortDisconnected(bool cancel) {
   _W("[__OnPortDisconnected__] endporint(%s), port_name(%s)",
-      appid.c_str(), port_name.c_str());
+      target_appid_.c_str(), port_name_.c_str());
 
   if (cancel) {
     close(fds_[0]);
@@ -169,7 +167,7 @@ void Proxy::OnPortDisconnected(const std::string& appid,
 
   IEventListener* listener = listener_;
   listener_ = nullptr;
-  listener->OnDisconnected(appid);
+  listener->OnDisconnected(target_appid_);
   DebugPort::GetInst().RemoveSession(fds_[0]);
 }
 // LCOV_EXCL_STOP
@@ -187,8 +185,9 @@ int Proxy::Connect(std::string appid, std::string port_name,
   listener_ = ev;
   target_appid_ = std::move(appid);
   port_name_ = std::move(port_name);
+  SetRealAppId(target_appid_);
 
-  int r = fd_broker_->Watch(this, target_appid_, port_name_);
+  int r = fd_broker_->Watch(this, real_appid_, port_name_);
   if (r < 0) {
     // LCOV_EXCL_START
     listener_ = nullptr;
@@ -216,8 +215,9 @@ int Proxy::ConnectSync(std::string appid, std::string port_name,
   listener_ = ev;
   target_appid_ = std::move(appid);
   port_name_ = std::move(port_name);
+  SetRealAppId(target_appid_);
 
-  int ret = fd_broker_->Prepare(target_appid_, port_name_);
+  int ret = fd_broker_->Prepare(real_appid_, port_name_);
   if (ret < 0) {
     listener_ = nullptr;
     if (ret == -EILLEGALACCESS)
@@ -228,7 +228,7 @@ int Proxy::ConnectSync(std::string appid, std::string port_name,
 
   fds_[0] = 0;
   fds_[1] = 0;
-  ret = fd_broker_->SendSync(target_appid_, port_name_, &fds_);
+  ret = fd_broker_->SendSync(real_appid_, port_name_, &fds_);
   if (ret <= 0) {
     listener_ = nullptr;
     if (ret == -EILLEGALACCESS)
@@ -240,12 +240,28 @@ int Proxy::ConnectSync(std::string appid, std::string port_name,
   main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
   delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_));
   listener_->OnConnected(target_appid_, main_port_.get());
-  DebugPort::GetInst().AddSession(port_name, appid, fds_[0], fds_[1]);
+  DebugPort::GetInst().AddSession(port_name, target_appid_, fds_[0], fds_[1]);
 
   return RPC_PORT_ERROR_NONE;
 }
 // LCOV_EXCL_STOP
 
+void Proxy::SetRealAppId(const std::string& alias_appid) {
+  if (!real_appid_.empty())
+    return;
+
+  char* appid = nullptr;
+  int ret = aul_svc_get_appid_by_alias_appid(alias_appid.c_str(), &appid);
+  if (ret != AUL_SVC_RET_OK) {
+    real_appid_ = alias_appid;
+    return;
+  }
+
+  std::unique_ptr<char, decltype(std::free)*> appid_ptr(appid, std::free);
+  real_appid_ = std::string(appid);
+  _W("alias_appid(%s), real_appid(%s)", alias_appid.c_str(), appid);
+}
+
 Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id,
     bool receive) : Port(fd, id), parent_(parent) {
   Watch(receive);
index dfb666f..389ad29 100644 (file)
@@ -82,17 +82,12 @@ class Proxy : public FdBroker::IEventWatcher {
   static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
                                  gpointer data);
   static gboolean DbusNameTimeout(gpointer user_data);
-  void OnPortAppeared(const std::string& appid,
-                      const std::string& port_name) override;
-  void OnPortVanished(const std::string& appid,
-                      const std::string& port_name) override;
-  void OnPortRejected(const std::string& appid,
-                      int error) override;
-  void OnPortConnected(const std::string& appid,
-                       const std::string& port_name) override;
-  void OnPortDisconnected(const std::string& appid,
-                          const std::string& port_name,
-                          bool cancel = false) override;
+  void OnPortAppeared() override;
+  void OnPortVanished() override;
+  void OnPortRejected(int error) override;
+  void OnPortConnected() override;
+  void OnPortDisconnected(bool cancel = false) override;
+  void SetRealAppId(const std::string& alias_appid);
 
  private:
   std::string port_name_;
@@ -101,6 +96,7 @@ class Proxy : public FdBroker::IEventWatcher {
   IEventListener* listener_ = nullptr;
   std::shared_ptr<FdBroker> fd_broker_;
   std::string target_appid_;
+  std::string real_appid_;
   int fds_[2];
   guint conn_timer_ = 0;
 };