Commit abc16b91 authored by Max Kellermann's avatar Max Kellermann

{Message,Neighbor}Commands: use Client::partition instead of Main.hxx

parent 2de7cd32
......@@ -32,6 +32,7 @@
#include "Permission.hxx"
#include "tag/TagType.h"
#include "protocol/Result.hxx"
#include "Partition.hxx"
#include "client/Client.hxx"
#include "util/Tokenizer.hxx"
#include "util/Error.hxx"
......@@ -184,7 +185,8 @@ static const struct command commands[] = {
static const unsigned num_commands = sizeof(commands) / sizeof(commands[0]);
static bool
command_available(gcc_unused const struct command *cmd)
command_available(gcc_unused const Partition &partition,
gcc_unused const struct command *cmd)
{
#ifdef ENABLE_SQLITE
if (strcmp(cmd->cmd, "sticker") == 0)
......@@ -193,7 +195,7 @@ command_available(gcc_unused const struct command *cmd)
#ifdef ENABLE_NEIGHBOR_PLUGINS
if (strcmp(cmd->cmd, "listneighbors") == 0)
return neighbor_commands_available();
return neighbor_commands_available(partition.instance);
#endif
return true;
......@@ -211,7 +213,7 @@ handle_commands(Client &client,
cmd = &commands[i];
if (cmd->permission == (permission & cmd->permission) &&
command_available(cmd))
command_available(client.partition, cmd))
client_printf(client, "command: %s\n", cmd->cmd);
}
......
......@@ -22,7 +22,7 @@
#include "client/Client.hxx"
#include "client/ClientList.hxx"
#include "Instance.hxx"
#include "Main.hxx"
#include "Partition.hxx"
#include "protocol/Result.hxx"
#include <set>
......@@ -81,7 +81,7 @@ handle_channels(Client &client,
assert(argc == 1);
std::set<std::string> channels;
for (const auto &c : *instance->client_list)
for (const auto &c : *client.partition.instance.client_list)
channels.insert(c->subscriptions.begin(),
c->subscriptions.end());
......@@ -122,7 +122,7 @@ handle_send_message(Client &client,
bool sent = false;
const ClientMessage msg(argv[1], argv[2]);
for (const auto &c : *instance->client_list)
for (const auto &c : *client.partition.instance.client_list)
if (c->PushMessage(msg))
sent = true;
......
......@@ -21,7 +21,7 @@
#include "NeighborCommands.hxx"
#include "client/Client.hxx"
#include "Instance.hxx"
#include "Main.hxx"
#include "Partition.hxx"
#include "protocol/Result.hxx"
#include "neighbor/Glue.hxx"
#include "neighbor/Info.hxx"
......@@ -32,23 +32,24 @@
#include <assert.h>
bool
neighbor_commands_available()
neighbor_commands_available(const Instance &instance)
{
return instance->neighbors != nullptr;
return instance.neighbors != nullptr;
}
CommandResult
handle_listneighbors(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
if (instance->neighbors == nullptr) {
const NeighborGlue *const neighbors =
client.partition.instance.neighbors;
if (neighbors == nullptr) {
command_error(client, ACK_ERROR_UNKNOWN,
"No neighbor plugin configured");
return CommandResult::ERROR;
}
const auto neighbors = instance->neighbors->GetList();
for (const auto &i : neighbors)
for (const auto &i : neighbors->GetList())
client_printf(client,
"neighbor: %s\n"
"name: %s\n",
......
......@@ -23,11 +23,12 @@
#include "CommandResult.hxx"
#include "Compiler.h"
struct Instance;
class Client;
gcc_pure
bool
neighbor_commands_available();
neighbor_commands_available(const Instance &instance);
CommandResult
handle_listneighbors(Client &client, int argc, char *argv[]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment