Fix a bug about access control
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 18 Jun 2019 23:43:38 +0000 (08:43 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 19 Jun 2019 01:13:51 +0000 (10:13 +0900)
The ports should be set after a proxy is connected to a stub.

Change-Id: I54ffc48bb28e1dc2f85c95464120dec98b6271e9
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 18c058c..1ec8db8 100644 (file)
@@ -598,7 +598,7 @@ void FdBroker::OnResultReceived(GObject* source_object,
       res, &err);
   if (reply == nullptr) {
     LOGE("No reply. err(%s)", err ? err->message : "Unknown");
-    watcher->OnPortRejected(broker->watch_appid_);
+    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
     g_error_free(err);
     return;
   }
@@ -606,7 +606,7 @@ void FdBroker::OnResultReceived(GObject* source_object,
   GVariant* reply_body = g_dbus_message_get_body(reply);
   if (reply_body == nullptr) {
     LOGE("g_dbus_message_get_body() is failed");
-    watcher->OnPortRejected(broker->watch_appid_);
+    watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
     g_object_unref(reply);
     return;
   }
index 40a8830..e9603f4 100644 (file)
@@ -48,6 +48,8 @@ class FdBroker {
     virtual void OnPortRejected(const std::string& appid) = 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) = 0;
   };
 
   explicit FdBroker(bool mock = false) : mock_(mock) {}
index 86da798..04deef8 100644 (file)
@@ -100,8 +100,9 @@ void Proxy::OnPortAppeared(const std::string& appid,
   if (listener_ == nullptr)
     return;
 
-  int fds[2] = { 0, };
-  int r = fd_broker_.Send(appid, port_name, &fds);
+  fds_[0] = 0;
+  fds_[1] = 0;
+  int r = fd_broker_.Send(appid, port_name, &fds_);
   if (r <= 0) {
     IEventListener* listener = listener_;
     listener_ = nullptr;
@@ -112,9 +113,7 @@ void Proxy::OnPortAppeared(const std::string& appid,
     return;
   }
 
-  LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]);
-  main_port_.reset(new ProxyPort(this, fds[0], appid, false));
-  delegate_port_.reset(new ProxyPort(this, fds[1], appid));
+  LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds_[0], fds_[1]);
 }
 
 void Proxy::OnPortVanished(const std::string& appid,
@@ -128,9 +127,21 @@ void Proxy::OnPortConnected(const std::string& appid,
   LOGW("[__OnPortConnected__] endpoint(%s), port_name(%s)",
       appid.c_str(), port_name.c_str());
 
+  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());
 }
 
+void Proxy::OnPortDisconnected(const std::string& appid,
+                               const std::string& port_name) {
+  LOGW("[__OnPortDisconnected__] endporint(%s), port_name(%s)",
+      appid.c_str(), port_name.c_str());
+
+  IEventListener* listener = listener_;
+  listener_ = nullptr;
+  listener->OnDisconnected(appid);
+}
+
 int Proxy::Connect(std::string appid, std::string port_name,
                    IEventListener* ev) {
   if (ev == nullptr)
index 76fc462..642be5b 100644 (file)
@@ -87,6 +87,8 @@ class Proxy : public FdBroker::IEventWatcher {
   void OnPortRejected(const std::string& appid) override;
   void OnPortConnected(const std::string& appid,
                        const std::string& port_name) override;
+  void OnPortDisconnected(const std::string& appid,
+                          const std::string& port_name) override;
 
  private:
   std::string port_name_;
@@ -95,6 +97,7 @@ class Proxy : public FdBroker::IEventWatcher {
   IEventListener* listener_ = nullptr;
   FdBroker fd_broker_;
   std::string target_appid_;
+  int fds_[2];
 };
 
 }  // namespace internal