{Message,Neighbor}Commands: use Client::partition instead of Main.hxx
This commit is contained in:
parent
2de7cd32ea
commit
abc16b919d
@ -32,6 +32,7 @@
|
|||||||
#include "Permission.hxx"
|
#include "Permission.hxx"
|
||||||
#include "tag/TagType.h"
|
#include "tag/TagType.h"
|
||||||
#include "protocol/Result.hxx"
|
#include "protocol/Result.hxx"
|
||||||
|
#include "Partition.hxx"
|
||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "util/Tokenizer.hxx"
|
#include "util/Tokenizer.hxx"
|
||||||
#include "util/Error.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 const unsigned num_commands = sizeof(commands) / sizeof(commands[0]);
|
||||||
|
|
||||||
static bool
|
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
|
#ifdef ENABLE_SQLITE
|
||||||
if (strcmp(cmd->cmd, "sticker") == 0)
|
if (strcmp(cmd->cmd, "sticker") == 0)
|
||||||
@ -193,7 +195,7 @@ command_available(gcc_unused const struct command *cmd)
|
|||||||
|
|
||||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||||
if (strcmp(cmd->cmd, "listneighbors") == 0)
|
if (strcmp(cmd->cmd, "listneighbors") == 0)
|
||||||
return neighbor_commands_available();
|
return neighbor_commands_available(partition.instance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -211,7 +213,7 @@ handle_commands(Client &client,
|
|||||||
cmd = &commands[i];
|
cmd = &commands[i];
|
||||||
|
|
||||||
if (cmd->permission == (permission & cmd->permission) &&
|
if (cmd->permission == (permission & cmd->permission) &&
|
||||||
command_available(cmd))
|
command_available(client.partition, cmd))
|
||||||
client_printf(client, "command: %s\n", cmd->cmd);
|
client_printf(client, "command: %s\n", cmd->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "client/ClientList.hxx"
|
#include "client/ClientList.hxx"
|
||||||
#include "Instance.hxx"
|
#include "Instance.hxx"
|
||||||
#include "Main.hxx"
|
#include "Partition.hxx"
|
||||||
#include "protocol/Result.hxx"
|
#include "protocol/Result.hxx"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -81,7 +81,7 @@ handle_channels(Client &client,
|
|||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
std::set<std::string> channels;
|
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(),
|
channels.insert(c->subscriptions.begin(),
|
||||||
c->subscriptions.end());
|
c->subscriptions.end());
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ handle_send_message(Client &client,
|
|||||||
|
|
||||||
bool sent = false;
|
bool sent = false;
|
||||||
const ClientMessage msg(argv[1], argv[2]);
|
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))
|
if (c->PushMessage(msg))
|
||||||
sent = true;
|
sent = true;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "NeighborCommands.hxx"
|
#include "NeighborCommands.hxx"
|
||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "Instance.hxx"
|
#include "Instance.hxx"
|
||||||
#include "Main.hxx"
|
#include "Partition.hxx"
|
||||||
#include "protocol/Result.hxx"
|
#include "protocol/Result.hxx"
|
||||||
#include "neighbor/Glue.hxx"
|
#include "neighbor/Glue.hxx"
|
||||||
#include "neighbor/Info.hxx"
|
#include "neighbor/Info.hxx"
|
||||||
@ -32,23 +32,24 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
bool
|
bool
|
||||||
neighbor_commands_available()
|
neighbor_commands_available(const Instance &instance)
|
||||||
{
|
{
|
||||||
return instance->neighbors != nullptr;
|
return instance.neighbors != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_listneighbors(Client &client,
|
handle_listneighbors(Client &client,
|
||||||
gcc_unused int argc, gcc_unused char *argv[])
|
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,
|
command_error(client, ACK_ERROR_UNKNOWN,
|
||||||
"No neighbor plugin configured");
|
"No neighbor plugin configured");
|
||||||
return CommandResult::ERROR;
|
return CommandResult::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto neighbors = instance->neighbors->GetList();
|
for (const auto &i : neighbors->GetList())
|
||||||
for (const auto &i : neighbors)
|
|
||||||
client_printf(client,
|
client_printf(client,
|
||||||
"neighbor: %s\n"
|
"neighbor: %s\n"
|
||||||
"name: %s\n",
|
"name: %s\n",
|
||||||
|
@ -23,11 +23,12 @@
|
|||||||
#include "CommandResult.hxx"
|
#include "CommandResult.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
struct Instance;
|
||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool
|
bool
|
||||||
neighbor_commands_available();
|
neighbor_commands_available(const Instance &instance);
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_listneighbors(Client &client, int argc, char *argv[]);
|
handle_listneighbors(Client &client, int argc, char *argv[]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user