|
@@ -4,7 +4,7 @@
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
*/
|
|
|
|
|
|
-#include "ClientConnection.h"
|
|
|
|
|
|
+#include "ConnectionFromClient.h"
|
|
#include <ConfigServer/ConfigClientEndpoint.h>
|
|
#include <ConfigServer/ConfigClientEndpoint.h>
|
|
#include <LibCore/ConfigFile.h>
|
|
#include <LibCore/ConfigFile.h>
|
|
#include <LibCore/FileWatcher.h>
|
|
#include <LibCore/FileWatcher.h>
|
|
@@ -12,7 +12,7 @@
|
|
|
|
|
|
namespace ConfigServer {
|
|
namespace ConfigServer {
|
|
|
|
|
|
-static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
|
|
|
|
|
+static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
|
|
|
|
|
|
struct CachedDomain {
|
|
struct CachedDomain {
|
|
String domain;
|
|
String domain;
|
|
@@ -23,7 +23,7 @@ struct CachedDomain {
|
|
static HashMap<String, NonnullOwnPtr<CachedDomain>> s_cache;
|
|
static HashMap<String, NonnullOwnPtr<CachedDomain>> s_cache;
|
|
static constexpr int s_disk_sync_delay_ms = 5'000;
|
|
static constexpr int s_disk_sync_delay_ms = 5'000;
|
|
|
|
|
|
-static void for_each_monitoring_connection(String const& domain, ClientConnection* excluded_connection, Function<void(ClientConnection&)> callback)
|
|
|
|
|
|
+static void for_each_monitoring_connection(String const& domain, ConnectionFromClient* excluded_connection, Function<void(ConnectionFromClient&)> callback)
|
|
{
|
|
{
|
|
for (auto& it : s_connections) {
|
|
for (auto& it : s_connections) {
|
|
if (it.value->is_monitoring_domain(domain) && (!excluded_connection || it.value != excluded_connection))
|
|
if (it.value->is_monitoring_domain(domain) && (!excluded_connection || it.value != excluded_connection))
|
|
@@ -48,7 +48,7 @@ static Core::ConfigFile& ensure_domain_config(String const& domain)
|
|
for (auto& group : config->groups()) {
|
|
for (auto& group : config->groups()) {
|
|
for (auto& key : config->keys(group)) {
|
|
for (auto& key : config->keys(group)) {
|
|
if (!new_config->has_key(group, key)) {
|
|
if (!new_config->has_key(group, key)) {
|
|
- for_each_monitoring_connection(domain, nullptr, [&domain, &group, &key](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, nullptr, [&domain, &group, &key](ConnectionFromClient& connection) {
|
|
connection.async_notify_removed_key(domain, group, key);
|
|
connection.async_notify_removed_key(domain, group, key);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -60,7 +60,7 @@ static Core::ConfigFile& ensure_domain_config(String const& domain)
|
|
auto old_value = config->read_entry(group, key);
|
|
auto old_value = config->read_entry(group, key);
|
|
auto new_value = new_config->read_entry(group, key);
|
|
auto new_value = new_config->read_entry(group, key);
|
|
if (old_value != new_value) {
|
|
if (old_value != new_value) {
|
|
- for_each_monitoring_connection(domain, nullptr, [&domain, &group, &key, &new_value](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, nullptr, [&domain, &group, &key, &new_value](ConnectionFromClient& connection) {
|
|
connection.async_notify_changed_string_value(domain, group, key, new_value);
|
|
connection.async_notify_changed_string_value(domain, group, key, new_value);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -74,25 +74,25 @@ static Core::ConfigFile& ensure_domain_config(String const& domain)
|
|
return *config;
|
|
return *config;
|
|
}
|
|
}
|
|
|
|
|
|
-ClientConnection::ClientConnection(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id)
|
|
|
|
- : IPC::ClientConnection<ConfigClientEndpoint, ConfigServerEndpoint>(*this, move(client_socket), client_id)
|
|
|
|
|
|
+ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id)
|
|
|
|
+ : IPC::ConnectionFromClient<ConfigClientEndpoint, ConfigServerEndpoint>(*this, move(client_socket), client_id)
|
|
, m_sync_timer(Core::Timer::create_single_shot(s_disk_sync_delay_ms, [this]() { sync_dirty_domains_to_disk(); }))
|
|
, m_sync_timer(Core::Timer::create_single_shot(s_disk_sync_delay_ms, [this]() { sync_dirty_domains_to_disk(); }))
|
|
{
|
|
{
|
|
s_connections.set(client_id, *this);
|
|
s_connections.set(client_id, *this);
|
|
}
|
|
}
|
|
|
|
|
|
-ClientConnection::~ClientConnection()
|
|
|
|
|
|
+ConnectionFromClient::~ConnectionFromClient()
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::die()
|
|
|
|
|
|
+void ConnectionFromClient::die()
|
|
{
|
|
{
|
|
s_connections.remove(client_id());
|
|
s_connections.remove(client_id());
|
|
m_sync_timer->stop();
|
|
m_sync_timer->stop();
|
|
sync_dirty_domains_to_disk();
|
|
sync_dirty_domains_to_disk();
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::pledge_domains(Vector<String> const& domains)
|
|
|
|
|
|
+void ConnectionFromClient::pledge_domains(Vector<String> const& domains)
|
|
{
|
|
{
|
|
if (m_has_pledged) {
|
|
if (m_has_pledged) {
|
|
did_misbehave("Tried to pledge domains twice.");
|
|
did_misbehave("Tried to pledge domains twice.");
|
|
@@ -103,7 +103,7 @@ void ClientConnection::pledge_domains(Vector<String> const& domains)
|
|
m_pledged_domains.set(domain);
|
|
m_pledged_domains.set(domain);
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::monitor_domain(String const& domain)
|
|
|
|
|
|
+void ConnectionFromClient::monitor_domain(String const& domain)
|
|
{
|
|
{
|
|
if (m_has_pledged && !m_pledged_domains.contains(domain)) {
|
|
if (m_has_pledged && !m_pledged_domains.contains(domain)) {
|
|
did_misbehave("Attempt to monitor non-pledged domain");
|
|
did_misbehave("Attempt to monitor non-pledged domain");
|
|
@@ -113,7 +113,7 @@ void ClientConnection::monitor_domain(String const& domain)
|
|
m_monitored_domains.set(domain);
|
|
m_monitored_domains.set(domain);
|
|
}
|
|
}
|
|
|
|
|
|
-bool ClientConnection::validate_access(String const& domain, String const& group, String const& key)
|
|
|
|
|
|
+bool ConnectionFromClient::validate_access(String const& domain, String const& group, String const& key)
|
|
{
|
|
{
|
|
if (!m_has_pledged)
|
|
if (!m_has_pledged)
|
|
return true;
|
|
return true;
|
|
@@ -123,7 +123,7 @@ bool ClientConnection::validate_access(String const& domain, String const& group
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::sync_dirty_domains_to_disk()
|
|
|
|
|
|
+void ConnectionFromClient::sync_dirty_domains_to_disk()
|
|
{
|
|
{
|
|
if (m_dirty_domains.is_empty())
|
|
if (m_dirty_domains.is_empty())
|
|
return;
|
|
return;
|
|
@@ -139,7 +139,7 @@ void ClientConnection::sync_dirty_domains_to_disk()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-Messages::ConfigServer::ListConfigKeysResponse ClientConnection::list_config_keys(String const& domain, String const& group)
|
|
|
|
|
|
+Messages::ConfigServer::ListConfigKeysResponse ConnectionFromClient::list_config_keys(String const& domain, String const& group)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, ""))
|
|
if (!validate_access(domain, group, ""))
|
|
return Vector<String> {};
|
|
return Vector<String> {};
|
|
@@ -147,7 +147,7 @@ Messages::ConfigServer::ListConfigKeysResponse ClientConnection::list_config_key
|
|
return { config.keys(group) };
|
|
return { config.keys(group) };
|
|
}
|
|
}
|
|
|
|
|
|
-Messages::ConfigServer::ListConfigGroupsResponse ClientConnection::list_config_groups(String const& domain)
|
|
|
|
|
|
+Messages::ConfigServer::ListConfigGroupsResponse ConnectionFromClient::list_config_groups(String const& domain)
|
|
{
|
|
{
|
|
if (!validate_access(domain, "", ""))
|
|
if (!validate_access(domain, "", ""))
|
|
return Vector<String> {};
|
|
return Vector<String> {};
|
|
@@ -155,7 +155,7 @@ Messages::ConfigServer::ListConfigGroupsResponse ClientConnection::list_config_g
|
|
return { config.groups() };
|
|
return { config.groups() };
|
|
}
|
|
}
|
|
|
|
|
|
-Messages::ConfigServer::ReadStringValueResponse ClientConnection::read_string_value(String const& domain, String const& group, String const& key)
|
|
|
|
|
|
+Messages::ConfigServer::ReadStringValueResponse ConnectionFromClient::read_string_value(String const& domain, String const& group, String const& key)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return nullptr;
|
|
return nullptr;
|
|
@@ -166,7 +166,7 @@ Messages::ConfigServer::ReadStringValueResponse ClientConnection::read_string_va
|
|
return Optional<String> { config.read_entry(group, key) };
|
|
return Optional<String> { config.read_entry(group, key) };
|
|
}
|
|
}
|
|
|
|
|
|
-Messages::ConfigServer::ReadI32ValueResponse ClientConnection::read_i32_value(String const& domain, String const& group, String const& key)
|
|
|
|
|
|
+Messages::ConfigServer::ReadI32ValueResponse ConnectionFromClient::read_i32_value(String const& domain, String const& group, String const& key)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return nullptr;
|
|
return nullptr;
|
|
@@ -177,7 +177,7 @@ Messages::ConfigServer::ReadI32ValueResponse ClientConnection::read_i32_value(St
|
|
return Optional<i32> { config.read_num_entry(group, key) };
|
|
return Optional<i32> { config.read_num_entry(group, key) };
|
|
}
|
|
}
|
|
|
|
|
|
-Messages::ConfigServer::ReadBoolValueResponse ClientConnection::read_bool_value(String const& domain, String const& group, String const& key)
|
|
|
|
|
|
+Messages::ConfigServer::ReadBoolValueResponse ConnectionFromClient::read_bool_value(String const& domain, String const& group, String const& key)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return nullptr;
|
|
return nullptr;
|
|
@@ -188,7 +188,7 @@ Messages::ConfigServer::ReadBoolValueResponse ClientConnection::read_bool_value(
|
|
return Optional<bool> { config.read_bool_entry(group, key) };
|
|
return Optional<bool> { config.read_bool_entry(group, key) };
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::start_or_restart_sync_timer()
|
|
|
|
|
|
+void ConnectionFromClient::start_or_restart_sync_timer()
|
|
{
|
|
{
|
|
if (m_sync_timer->is_active())
|
|
if (m_sync_timer->is_active())
|
|
m_sync_timer->restart();
|
|
m_sync_timer->restart();
|
|
@@ -196,7 +196,7 @@ void ClientConnection::start_or_restart_sync_timer()
|
|
m_sync_timer->start();
|
|
m_sync_timer->start();
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::write_string_value(String const& domain, String const& group, String const& key, String const& value)
|
|
|
|
|
|
+void ConnectionFromClient::write_string_value(String const& domain, String const& group, String const& key, String const& value)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return;
|
|
return;
|
|
@@ -210,12 +210,12 @@ void ClientConnection::write_string_value(String const& domain, String const& gr
|
|
m_dirty_domains.set(domain);
|
|
m_dirty_domains.set(domain);
|
|
start_or_restart_sync_timer();
|
|
start_or_restart_sync_timer();
|
|
|
|
|
|
- for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ConnectionFromClient& connection) {
|
|
connection.async_notify_changed_string_value(domain, group, key, value);
|
|
connection.async_notify_changed_string_value(domain, group, key, value);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::write_i32_value(String const& domain, String const& group, String const& key, i32 value)
|
|
|
|
|
|
+void ConnectionFromClient::write_i32_value(String const& domain, String const& group, String const& key, i32 value)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return;
|
|
return;
|
|
@@ -229,12 +229,12 @@ void ClientConnection::write_i32_value(String const& domain, String const& group
|
|
m_dirty_domains.set(domain);
|
|
m_dirty_domains.set(domain);
|
|
start_or_restart_sync_timer();
|
|
start_or_restart_sync_timer();
|
|
|
|
|
|
- for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ConnectionFromClient& connection) {
|
|
connection.async_notify_changed_i32_value(domain, group, key, value);
|
|
connection.async_notify_changed_i32_value(domain, group, key, value);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::write_bool_value(String const& domain, String const& group, String const& key, bool value)
|
|
|
|
|
|
+void ConnectionFromClient::write_bool_value(String const& domain, String const& group, String const& key, bool value)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return;
|
|
return;
|
|
@@ -248,12 +248,12 @@ void ClientConnection::write_bool_value(String const& domain, String const& grou
|
|
m_dirty_domains.set(domain);
|
|
m_dirty_domains.set(domain);
|
|
start_or_restart_sync_timer();
|
|
start_or_restart_sync_timer();
|
|
|
|
|
|
- for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, this, [&domain, &group, &key, &value](ConnectionFromClient& connection) {
|
|
connection.async_notify_changed_bool_value(domain, group, key, value);
|
|
connection.async_notify_changed_bool_value(domain, group, key, value);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-void ClientConnection::remove_key(String const& domain, String const& group, String const& key)
|
|
|
|
|
|
+void ConnectionFromClient::remove_key(String const& domain, String const& group, String const& key)
|
|
{
|
|
{
|
|
if (!validate_access(domain, group, key))
|
|
if (!validate_access(domain, group, key))
|
|
return;
|
|
return;
|
|
@@ -266,7 +266,7 @@ void ClientConnection::remove_key(String const& domain, String const& group, Str
|
|
m_dirty_domains.set(domain);
|
|
m_dirty_domains.set(domain);
|
|
start_or_restart_sync_timer();
|
|
start_or_restart_sync_timer();
|
|
|
|
|
|
- for_each_monitoring_connection(domain, this, [&domain, &group, &key](ClientConnection& connection) {
|
|
|
|
|
|
+ for_each_monitoring_connection(domain, this, [&domain, &group, &key](ConnectionFromClient& connection) {
|
|
connection.async_notify_removed_key(domain, group, key);
|
|
connection.async_notify_removed_key(domain, group, key);
|
|
});
|
|
});
|
|
}
|
|
}
|