summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-04-03 20:03:17 +0200
committerMax Kellermann <max@musicpd.org>2019-04-03 20:04:59 +0200
commit380f73c1129d75dab75bd22c6aededa7e9c3716c (patch)
tree75eb102da31dde4f964dce994d2e8b82eccfccc1 /src/client
parent9f79d034b34e4253a5768e499d24011a6427c09b (diff)
client/Process: convert functions to Client methods
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.hxx8
-rw-r--r--src/client/ClientInternal.hxx4
-rw-r--r--src/client/ClientProcess.cxx68
-rw-r--r--src/client/ClientRead.cxx2
4 files changed, 41 insertions, 41 deletions
diff --git a/src/client/Client.hxx b/src/client/Client.hxx
index 66be0ead8..f6677b145 100644
--- a/src/client/Client.hxx
+++ b/src/client/Client.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2018 The Music Player Daemon Project
+ * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@
#define MPD_CLIENT_H
#include "ClientMessage.hxx"
+#include "command/CommandResult.hxx"
#include "command/CommandListBuilder.hxx"
#include "tag/Mask.hxx"
#include "event/FullyBufferedSocket.hxx"
@@ -226,6 +227,11 @@ public:
const Storage *GetStorage() const noexcept;
private:
+ CommandResult ProcessCommandList(bool list_ok,
+ std::list<std::string> &&list) noexcept;
+
+ CommandResult ProcessLine(char *line) noexcept;
+
/* virtual methods from class BufferedSocket */
InputResult OnSocketInput(void *data, size_t length) noexcept override;
void OnSocketError(std::exception_ptr ep) noexcept override;
diff --git a/src/client/ClientInternal.hxx b/src/client/ClientInternal.hxx
index 37b5925f2..f9555e0cf 100644
--- a/src/client/ClientInternal.hxx
+++ b/src/client/ClientInternal.hxx
@@ -21,7 +21,6 @@
#define MPD_CLIENT_INTERNAL_HXX
#include "Client.hxx"
-#include "command/CommandResult.hxx"
#include <chrono>
@@ -34,7 +33,4 @@ extern std::chrono::steady_clock::duration client_timeout;
extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;
-CommandResult
-client_process_line(Client &client, char *line) noexcept;
-
#endif
diff --git a/src/client/ClientProcess.cxx b/src/client/ClientProcess.cxx
index eeb72d35a..3926bee71 100644
--- a/src/client/ClientProcess.cxx
+++ b/src/client/ClientProcess.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2018 The Music Player Daemon Project
+ * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,38 +28,38 @@
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define CLIENT_LIST_MODE_END "command_list_end"
-static CommandResult
-client_process_command_list(Client &client, bool list_ok,
- std::list<std::string> &&list) noexcept
+inline CommandResult
+Client::ProcessCommandList(bool list_ok,
+ std::list<std::string> &&list) noexcept
{
CommandResult ret = CommandResult::OK;
- unsigned num = 0;
+ unsigned n = 0;
for (auto &&i : list) {
char *cmd = &*i.begin();
FormatDebug(client_domain, "process command \"%s\"", cmd);
- ret = command_process(client, num++, cmd);
+ ret = command_process(*this, n++, cmd);
FormatDebug(client_domain, "command returned %i", int(ret));
- if (ret != CommandResult::OK || client.IsExpired())
+ if (ret != CommandResult::OK || IsExpired())
break;
else if (list_ok)
- client.Write("list_OK\n");
+ Write("list_OK\n");
}
return ret;
}
CommandResult
-client_process_line(Client &client, char *line) noexcept
+Client::ProcessLine(char *line) noexcept
{
CommandResult ret;
if (StringIsEqual(line, "noidle")) {
- if (client.idle_waiting) {
+ if (idle_waiting) {
/* send empty idle response and leave idle mode */
- client.idle_waiting = false;
- command_success(client);
+ idle_waiting = false;
+ command_success(*this);
}
/* do nothing if the client wasn't idling: the client
@@ -67,44 +67,43 @@ client_process_line(Client &client, char *line) noexcept
client_idle_notify(), which he can now evaluate */
return CommandResult::OK;
- } else if (client.idle_waiting) {
+ } else if (idle_waiting) {
/* during idle mode, clients must not send anything
except "noidle" */
FormatWarning(client_domain,
"[%u] command \"%s\" during idle",
- client.num, line);
+ num, line);
return CommandResult::CLOSE;
}
- if (client.cmd_list.IsActive()) {
+ if (cmd_list.IsActive()) {
if (StringIsEqual(line, CLIENT_LIST_MODE_END)) {
FormatDebug(client_domain,
"[%u] process command list",
- client.num);
+ num);
- auto &&cmd_list = client.cmd_list.Commit();
+ auto &&list = cmd_list.Commit();
- ret = client_process_command_list(client,
- client.cmd_list.IsOKMode(),
- std::move(cmd_list));
+ ret = ProcessCommandList(cmd_list.IsOKMode(),
+ std::move(list));
FormatDebug(client_domain,
"[%u] process command "
- "list returned %i", client.num, int(ret));
+ "list returned %i", num, int(ret));
if (ret == CommandResult::CLOSE ||
- client.IsExpired())
+ IsExpired())
return CommandResult::CLOSE;
if (ret == CommandResult::OK)
- command_success(client);
+ command_success(*this);
- client.cmd_list.Reset();
+ cmd_list.Reset();
} else {
- if (!client.cmd_list.Add(line)) {
+ if (!cmd_list.Add(line)) {
FormatWarning(client_domain,
"[%u] command list size "
"is larger than the max (%lu)",
- client.num,
+ num,
(unsigned long)client_max_command_list_size);
return CommandResult::CLOSE;
}
@@ -113,10 +112,10 @@ client_process_line(Client &client, char *line) noexcept
}
} else {
if (StringIsEqual(line, CLIENT_LIST_MODE_BEGIN)) {
- client.cmd_list.Begin(false);
+ cmd_list.Begin(false);
ret = CommandResult::OK;
} else if (StringIsEqual(line, CLIENT_LIST_OK_MODE_BEGIN)) {
- client.cmd_list.Begin(true);
+ cmd_list.Begin(true);
ret = CommandResult::OK;
} else if (IsUpperAlphaASCII(*line)) {
/* no valid MPD command begins with an upper
@@ -124,23 +123,22 @@ client_process_line(Client &client, char *line) noexcept
HTTP request */
FormatWarning(client_domain,
"[%u] malformed command \"%s\"",
- client.num, line);
+ num, line);
ret = CommandResult::CLOSE;
} else {
FormatDebug(client_domain,
"[%u] process command \"%s\"",
- client.num, line);
- ret = command_process(client, 0, line);
+ num, line);
+ ret = command_process(*this, 0, line);
FormatDebug(client_domain,
"[%u] command returned %i",
- client.num, int(ret));
+ num, int(ret));
- if (ret == CommandResult::CLOSE ||
- client.IsExpired())
+ if (ret == CommandResult::CLOSE || IsExpired())
return CommandResult::CLOSE;
if (ret == CommandResult::OK)
- command_success(client);
+ command_success(*this);
}
}
diff --git a/src/client/ClientRead.cxx b/src/client/ClientRead.cxx
index 5a0fb2d81..1c69b2830 100644
--- a/src/client/ClientRead.cxx
+++ b/src/client/ClientRead.cxx
@@ -43,7 +43,7 @@ Client::OnSocketInput(void *data, size_t length) noexcept
/* terminate the string at the end of the line */
*end = 0;
- CommandResult result = client_process_line(*this, p);
+ CommandResult result = ProcessLine(p);
switch (result) {
case CommandResult::OK:
case CommandResult::IDLE: