aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/MessageCommands.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/MessageCommands.cxx')
-rw-r--r--src/command/MessageCommands.cxx66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/command/MessageCommands.cxx b/src/command/MessageCommands.cxx
index a86bdf30c..28f97a52f 100644
--- a/src/command/MessageCommands.cxx
+++ b/src/command/MessageCommands.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,11 +19,13 @@
#include "config.h"
#include "MessageCommands.hxx"
+#include "Request.hxx"
#include "client/Client.hxx"
#include "client/ClientList.hxx"
+#include "client/Response.hxx"
#include "Instance.hxx"
#include "Partition.hxx"
-#include "protocol/Result.hxx"
+#include "util/ConstBuffer.hxx"
#include <set>
#include <string>
@@ -31,27 +33,25 @@
#include <assert.h>
CommandResult
-handle_subscribe(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_subscribe(Client &client, Request args, Response &r)
{
- assert(argc == 2);
+ assert(args.size == 1);
+ const char *const channel_name = args[0];
- switch (client.Subscribe(argv[1])) {
+ switch (client.Subscribe(channel_name)) {
case Client::SubscribeResult::OK:
return CommandResult::OK;
case Client::SubscribeResult::INVALID:
- command_error(client, ACK_ERROR_ARG,
- "invalid channel name");
+ r.Error(ACK_ERROR_ARG, "invalid channel name");
return CommandResult::ERROR;
case Client::SubscribeResult::ALREADY:
- command_error(client, ACK_ERROR_EXIST,
- "already subscribed to this channel");
+ r.Error(ACK_ERROR_EXIST, "already subscribed to this channel");
return CommandResult::ERROR;
case Client::SubscribeResult::FULL:
- command_error(client, ACK_ERROR_EXIST,
- "subscription list is full");
+ r.Error(ACK_ERROR_EXIST, "subscription list is full");
return CommandResult::ERROR;
}
@@ -61,24 +61,23 @@ handle_subscribe(Client &client, gcc_unused unsigned argc, char *argv[])
}
CommandResult
-handle_unsubscribe(Client &client, gcc_unused unsigned argc, char *argv[])
+handle_unsubscribe(Client &client, Request args, Response &r)
{
- assert(argc == 2);
+ assert(args.size == 1);
+ const char *const channel_name = args[0];
- if (client.Unsubscribe(argv[1]))
+ if (client.Unsubscribe(channel_name))
return CommandResult::OK;
else {
- command_error(client, ACK_ERROR_NO_EXIST,
- "not subscribed to this channel");
+ r.Error(ACK_ERROR_NO_EXIST, "not subscribed to this channel");
return CommandResult::ERROR;
}
}
CommandResult
-handle_channels(Client &client,
- gcc_unused unsigned argc, gcc_unused char *argv[])
+handle_channels(Client &client, gcc_unused Request args, Response &r)
{
- assert(argc == 1);
+ assert(args.IsEmpty());
std::set<std::string> channels;
for (const auto &c : *client.partition.instance.client_list)
@@ -86,22 +85,22 @@ handle_channels(Client &client,
c.subscriptions.end());
for (const auto &channel : channels)
- client_printf(client, "channel: %s\n", channel.c_str());
+ r.Format("channel: %s\n", channel.c_str());
return CommandResult::OK;
}
CommandResult
handle_read_messages(Client &client,
- gcc_unused unsigned argc, gcc_unused char *argv[])
+ gcc_unused Request args, Response &r)
{
- assert(argc == 1);
+ assert(args.IsEmpty());
while (!client.messages.empty()) {
const ClientMessage &msg = client.messages.front();
- client_printf(client, "channel: %s\nmessage: %s\n",
- msg.GetChannel(), msg.GetMessage());
+ r.Format("channel: %s\nmessage: %s\n",
+ msg.GetChannel(), msg.GetMessage());
client.messages.pop_front();
}
@@ -109,19 +108,20 @@ handle_read_messages(Client &client,
}
CommandResult
-handle_send_message(Client &client,
- gcc_unused unsigned argc, gcc_unused char *argv[])
+handle_send_message(Client &client, Request args, Response &r)
{
- assert(argc == 3);
+ assert(args.size == 2);
- if (!client_message_valid_channel_name(argv[1])) {
- command_error(client, ACK_ERROR_ARG,
- "invalid channel name");
+ const char *const channel_name = args[0];
+ const char *const message_text = args[1];
+
+ if (!client_message_valid_channel_name(channel_name)) {
+ r.Error(ACK_ERROR_ARG, "invalid channel name");
return CommandResult::ERROR;
}
bool sent = false;
- const ClientMessage msg(argv[1], argv[2]);
+ const ClientMessage msg(channel_name, message_text);
for (auto &c : *client.partition.instance.client_list)
if (c.PushMessage(msg))
sent = true;
@@ -129,8 +129,8 @@ handle_send_message(Client &client,
if (sent)
return CommandResult::OK;
else {
- command_error(client, ACK_ERROR_NO_EXIST,
- "nobody is subscribed to this channel");
+ r.Error(ACK_ERROR_NO_EXIST,
+ "nobody is subscribed to this channel");
return CommandResult::ERROR;
}
}