Skip to content

Commit

Permalink
Using dynamical channel id for UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Chapyshev committed Aug 29, 2023
1 parent e226331 commit 6816025
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 35 deletions.
6 changes: 6 additions & 0 deletions source/base/ipc/ipc_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ bool IpcChannel::connect(std::u16string_view channel_id)
{
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

if (channel_id.empty())
{
LOG(LS_ERROR) << "Empty channel id";
return false;
}

#if defined(OS_WIN)
const DWORD flags = SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION | FILE_FLAG_OVERLAPPED;
channel_name_ = channelName(channel_id);
Expand Down
4 changes: 2 additions & 2 deletions source/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ list(APPEND SOURCE_HOST_CORE
desktop_session_proxy.cc
desktop_session_proxy.h
host_export.h
host_ipc_storage.cc
host_ipc_storage.h
host_key_storage.cc
host_key_storage.h
input_injector.h
Expand All @@ -71,8 +73,6 @@ list(APPEND SOURCE_HOST_CORE
user_session_agent.h
user_session_agent_proxy.cc
user_session_agent_proxy.h
user_session_constants.cc
user_session_constants.h
user_session_manager.cc
user_session_manager.h
user_session_window.h
Expand Down
46 changes: 46 additions & 0 deletions source/host/host_ipc_storage.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Aspia Project
// Copyright (C) 2016-2023 Dmitry Chapyshev <dmitry@aspia.ru>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include "host/host_ipc_storage.h"

namespace host {

//--------------------------------------------------------------------------------------------------
HostIpcStorage::HostIpcStorage()
: impl_(base::JsonSettings::Scope::SYSTEM, "aspia", "host_ipc")
{
// Nothing
}

//--------------------------------------------------------------------------------------------------
HostIpcStorage::~HostIpcStorage() = default;

//--------------------------------------------------------------------------------------------------
std::u16string HostIpcStorage::channelIdForUI() const
{
return impl_.get<std::u16string>("ui_channel_id");
}

//--------------------------------------------------------------------------------------------------
void HostIpcStorage::setChannelIdForUI(const std::u16string& channel_id)
{
impl_.set<std::u16string>("ui_channel_id", channel_id);
impl_.flush();
}

} // namespace host
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef HOST_USER_SESSION_CONSTANTS_H
#define HOST_USER_SESSION_CONSTANTS_H
#ifndef HOST_HOST_IPC_STORAGE_H
#define HOST_HOST_IPC_STORAGE_H

#include "base/macros_magic.h"
#include "base/settings/json_settings.h"

namespace host {

extern const char16_t kIpcChannelIdForUI[];
class HostIpcStorage
{
public:
HostIpcStorage();
~HostIpcStorage();

std::u16string channelIdForUI() const;
void setChannelIdForUI(const std::u16string& channel_id);

private:
base::JsonSettings impl_;

DISALLOW_COPY_AND_ASSIGN(HostIpcStorage);
};

} // namespace host

#endif // HOST_USER_SESSION_CONSTANTS_H
#endif // HOST_HOST_IPC_STORAGE_H
4 changes: 2 additions & 2 deletions source/host/user_session_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "host/user_session_agent.h"

#include "base/logging.h"
#include "host/user_session_constants.h"
#include "host/host_ipc_storage.h".h"
#include "host/user_session_window_proxy.h"
namespace host {
Expand Down Expand Up @@ -54,7 +54,7 @@ void UserSessionAgent::start()
ipc_channel_ = std::make_unique<base::IpcChannel>();
ipc_channel_->setListener(this);
if (ipc_channel_->connect(kIpcChannelIdForUI))
if (ipc_channel_->connect(HostIpcStorage().channelIdForUI()))
{
LOG(LS_INFO) << "IPC channel connected";
Expand Down
25 changes: 0 additions & 25 deletions source/host/user_session_constants.cc

This file was deleted.

8 changes: 6 additions & 2 deletions source/host/user_session_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "host/client_session.h"
#include "host/host_ipc_storage.h"
#include "host/user_session.h"
#include "host/user_session_constants.h"

#if defined(OS_WIN)
#include "base/win/scoped_object.h"
Expand Down Expand Up @@ -222,8 +222,12 @@ bool UserSessionManager::start(Delegate* delegate)

ipc_server_ = std::make_unique<base::IpcServer>();

std::u16string ipc_channel_for_ui = base::IpcServer::createUniqueId();
HostIpcStorage ipc_storage;
ipc_storage.setChannelIdForUI(ipc_channel_for_ui);

// Start the server which will accept incoming connections from UI processes in user sessions.
if (!ipc_server_->start(kIpcChannelIdForUI, this))
if (!ipc_server_->start(ipc_channel_for_ui, this))
{
LOG(LS_WARNING) << "Failed to start IPC server for UI";
return false;
Expand Down

0 comments on commit 6816025

Please sign in to comment.