aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/client/Client.cxx2
-rw-r--r--src/client/Client.hxx17
-rw-r--r--src/client/ClientEvent.cxx5
-rw-r--r--src/client/ClientExpire.cxx2
-rw-r--r--src/client/ClientFile.cxx13
-rw-r--r--src/client/ClientGlobal.cxx8
-rw-r--r--src/client/ClientIdle.cxx2
-rw-r--r--src/client/ClientInternal.hxx2
-rw-r--r--src/client/ClientList.cxx7
-rw-r--r--src/client/ClientList.hxx2
-rw-r--r--src/client/ClientMessage.cxx2
-rw-r--r--src/client/ClientMessage.hxx6
-rw-r--r--src/client/ClientNew.cxx11
-rw-r--r--src/client/ClientProcess.cxx13
-rw-r--r--src/client/ClientRead.cxx2
-rw-r--r--src/client/ClientSubscribe.cxx2
-rw-r--r--src/client/ClientWrite.cxx20
-rw-r--r--src/client/Response.cxx76
-rw-r--r--src/client/Response.hxx65
19 files changed, 191 insertions, 66 deletions
diff --git a/src/client/Client.cxx b/src/client/Client.cxx
index 01ead4645..d5d153a46 100644
--- a/src/client/Client.cxx
+++ b/src/client/Client.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
diff --git a/src/client/Client.hxx b/src/client/Client.hxx
index c0a940ded..38127b124 100644
--- a/src/client/Client.hxx
+++ b/src/client/Client.hxx
@@ -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
@@ -36,7 +36,7 @@
#include <stddef.h>
#include <stdarg.h>
-struct sockaddr;
+class SocketAddress;
class EventLoop;
class Path;
struct Partition;
@@ -51,12 +51,6 @@ public:
struct playlist &playlist;
struct PlayerControl &player_control;
- struct Disposer {
- void operator()(Client *client) const {
- delete client;
- }
- };
-
unsigned permission;
/** the uid of the client process, or -1 if unknown */
@@ -112,7 +106,7 @@ public:
void Close();
void SetExpired();
- using FullyBufferedSocket::Write;
+ bool Write(const void *data, size_t length);
/**
* returns the uid of the client process, or a negative value
@@ -200,11 +194,12 @@ private:
virtual void OnTimeout() override;
};
-void client_manager_init(void);
+void
+client_manager_init();
void
client_new(EventLoop &loop, Partition &partition,
- int fd, const sockaddr *sa, size_t sa_length, int uid);
+ int fd, SocketAddress address, int uid);
/**
* Write a C string to the client.
diff --git a/src/client/ClientEvent.cxx b/src/client/ClientEvent.cxx
index fd9f24b0d..0d330e975 100644
--- a/src/client/ClientEvent.cxx
+++ b/src/client/ClientEvent.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
@@ -18,8 +18,7 @@
*/
#include "config.h"
-#include "ClientInternal.hxx"
-#include "util/Error.hxx"
+#include "Client.hxx"
#include "Log.hxx"
void
diff --git a/src/client/ClientExpire.cxx b/src/client/ClientExpire.cxx
index 5891756b6..70527312d 100644
--- a/src/client/ClientExpire.cxx
+++ b/src/client/ClientExpire.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
diff --git a/src/client/ClientFile.cxx b/src/client/ClientFile.cxx
index 3ea8034d2..37979c1f9 100644
--- a/src/client/ClientFile.cxx
+++ b/src/client/ClientFile.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
@@ -21,10 +21,9 @@
#include "Client.hxx"
#include "protocol/Ack.hxx"
#include "fs/Path.hxx"
-#include "fs/FileSystem.hxx"
+#include "fs/FileInfo.hxx"
#include "util/Error.hxx"
-#include <sys/stat.h>
#include <unistd.h>
bool
@@ -47,13 +46,11 @@ Client::AllowFile(Path path_fs, Error &error) const
return false;
}
- struct stat st;
- if (!StatFile(path_fs, st)) {
- error.SetErrno();
+ FileInfo fi;
+ if (!GetFileInfo(path_fs, fi, error))
return false;
- }
- if (st.st_uid != (uid_t)uid && (st.st_mode & 0444) != 0444) {
+ if (fi.GetUid() != (uid_t)uid && (fi.GetMode() & 0444) != 0444) {
/* client is not owner */
error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
return false;
diff --git a/src/client/ClientGlobal.cxx b/src/client/ClientGlobal.cxx
index 8d90721e9..078fd0981 100644
--- a/src/client/ClientGlobal.cxx
+++ b/src/client/ClientGlobal.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
@@ -31,15 +31,15 @@ size_t client_max_output_buffer_size;
void client_manager_init(void)
{
- client_timeout = config_get_positive(CONF_CONN_TIMEOUT,
+ client_timeout = config_get_positive(ConfigOption::CONN_TIMEOUT,
CLIENT_TIMEOUT_DEFAULT);
client_max_command_list_size =
- config_get_positive(CONF_MAX_COMMAND_LIST_SIZE,
+ config_get_positive(ConfigOption::MAX_COMMAND_LIST_SIZE,
CLIENT_MAX_COMMAND_LIST_DEFAULT / 1024)
* 1024;
client_max_output_buffer_size =
- config_get_positive(CONF_MAX_OUTPUT_BUFFER_SIZE,
+ config_get_positive(ConfigOption::MAX_OUTPUT_BUFFER_SIZE,
CLIENT_MAX_OUTPUT_BUFFER_SIZE_DEFAULT / 1024)
* 1024;
}
diff --git a/src/client/ClientIdle.cxx b/src/client/ClientIdle.cxx
index 0b4fa5751..b43647b6c 100644
--- a/src/client/ClientIdle.cxx
+++ b/src/client/ClientIdle.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
diff --git a/src/client/ClientInternal.hxx b/src/client/ClientInternal.hxx
index a819d64b8..66bdfbb0f 100644
--- a/src/client/ClientInternal.hxx
+++ b/src/client/ClientInternal.hxx
@@ -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
diff --git a/src/client/ClientList.cxx b/src/client/ClientList.cxx
index a1f286928..375e99090 100644
--- a/src/client/ClientList.cxx
+++ b/src/client/ClientList.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
@@ -20,8 +20,7 @@
#include "config.h"
#include "ClientList.hxx"
#include "ClientInternal.hxx"
-
-#include <algorithm>
+#include "util/DeleteDisposer.hxx"
#include <assert.h>
@@ -36,7 +35,7 @@ ClientList::Remove(Client &client)
void
ClientList::CloseAll()
{
- list.clear_and_dispose(Client::Disposer());
+ list.clear_and_dispose(DeleteDisposer());
}
void
diff --git a/src/client/ClientList.hxx b/src/client/ClientList.hxx
index 7d20a8737..68292097c 100644
--- a/src/client/ClientList.hxx
+++ b/src/client/ClientList.hxx
@@ -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
diff --git a/src/client/ClientMessage.cxx b/src/client/ClientMessage.cxx
index be6d2f007..84838219e 100644
--- a/src/client/ClientMessage.cxx
+++ b/src/client/ClientMessage.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
diff --git a/src/client/ClientMessage.hxx b/src/client/ClientMessage.hxx
index bc6a4cd41..13804e715 100644
--- a/src/client/ClientMessage.hxx
+++ b/src/client/ClientMessage.hxx
@@ -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
@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_CLIENT_MESSAGE_H
-#define MPD_CLIENT_MESSAGE_H
+#ifndef MPD_CLIENT_MESSAGE_HXX
+#define MPD_CLIENT_MESSAGE_HXX
#include "Compiler.h"
diff --git a/src/client/ClientNew.cxx b/src/client/ClientNew.cxx
index a080e9ec6..90c81f2c6 100644
--- a/src/client/ClientNew.cxx
+++ b/src/client/ClientNew.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
@@ -23,7 +23,8 @@
#include "Partition.hxx"
#include "Instance.hxx"
#include "system/fd_util.h"
-#include "system/Resolver.hxx"
+#include "net/SocketAddress.hxx"
+#include "net/ToString.hxx"
#include "Permission.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
@@ -58,15 +59,15 @@ Client::Client(EventLoop &_loop, Partition &_partition,
void
client_new(EventLoop &loop, Partition &partition,
- int fd, const struct sockaddr *sa, size_t sa_length, int uid)
+ int fd, SocketAddress address, int uid)
{
static unsigned int next_client_num;
- const auto remote = sockaddr_to_string(sa, sa_length);
+ const auto remote = ToString(address);
assert(fd >= 0);
#ifdef HAVE_LIBWRAP
- if (sa->sa_family != AF_UNIX) {
+ if (address.GetFamily() != AF_UNIX) {
// TODO: shall we obtain the program name from argv[0]?
const char *progname = "mpd";
diff --git a/src/client/ClientProcess.cxx b/src/client/ClientProcess.cxx
index 0b6953371..1502e0d96 100644
--- a/src/client/ClientProcess.cxx
+++ b/src/client/ClientProcess.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
@@ -22,8 +22,7 @@
#include "protocol/Result.hxx"
#include "command/AllCommands.hxx"
#include "Log.hxx"
-
-#include <string.h>
+#include "util/StringAPI.hxx"
#define CLIENT_LIST_MODE_BEGIN "command_list_begin"
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
@@ -56,7 +55,7 @@ client_process_line(Client &client, char *line)
{
CommandResult ret;
- if (strcmp(line, "noidle") == 0) {
+ if (StringIsEqual(line, "noidle")) {
if (client.idle_waiting) {
/* send empty idle response and leave idle mode */
client.idle_waiting = false;
@@ -78,7 +77,7 @@ client_process_line(Client &client, char *line)
}
if (client.cmd_list.IsActive()) {
- if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
+ if (StringIsEqual(line, CLIENT_LIST_MODE_END)) {
FormatDebug(client_domain,
"[%u] process command list",
client.num);
@@ -113,10 +112,10 @@ client_process_line(Client &client, char *line)
ret = CommandResult::OK;
}
} else {
- if (strcmp(line, CLIENT_LIST_MODE_BEGIN) == 0) {
+ if (StringIsEqual(line, CLIENT_LIST_MODE_BEGIN)) {
client.cmd_list.Begin(false);
ret = CommandResult::OK;
- } else if (strcmp(line, CLIENT_LIST_OK_MODE_BEGIN) == 0) {
+ } else if (StringIsEqual(line, CLIENT_LIST_OK_MODE_BEGIN)) {
client.cmd_list.Begin(true);
ret = CommandResult::OK;
} else {
diff --git a/src/client/ClientRead.cxx b/src/client/ClientRead.cxx
index 9cfb1271f..7a1e937ed 100644
--- a/src/client/ClientRead.cxx
+++ b/src/client/ClientRead.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
diff --git a/src/client/ClientSubscribe.cxx b/src/client/ClientSubscribe.cxx
index 8ea2e363b..ebc4848f5 100644
--- a/src/client/ClientSubscribe.cxx
+++ b/src/client/ClientSubscribe.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
diff --git a/src/client/ClientWrite.cxx b/src/client/ClientWrite.cxx
index b5d172a8d..f30f2f8b3 100644
--- a/src/client/ClientWrite.cxx
+++ b/src/client/ClientWrite.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
@@ -18,35 +18,29 @@
*/
#include "config.h"
-#include "ClientInternal.hxx"
+#include "Client.hxx"
#include "util/FormatString.hxx"
#include <string.h>
-/**
- * Write a block of data to the client.
- */
-static void
-client_write(Client &client, const char *data, size_t length)
+bool
+Client::Write(const void *data, size_t length)
{
/* if the client is going to be closed, do nothing */
- if (client.IsExpired() || length == 0)
- return;
-
- client.Write(data, length);
+ return !IsExpired() && FullyBufferedSocket::Write(data, length);
}
void
client_puts(Client &client, const char *s)
{
- client_write(client, s, strlen(s));
+ client.Write(s, strlen(s));
}
void
client_vprintf(Client &client, const char *fmt, va_list args)
{
char *p = FormatNewV(fmt, args);
- client_write(client, p, strlen(p));
+ client.Write(p, strlen(p));
delete[] p;
}
diff --git a/src/client/Response.cxx b/src/client/Response.cxx
new file mode 100644
index 000000000..d443e66a5
--- /dev/null
+++ b/src/client/Response.cxx
@@ -0,0 +1,76 @@
+/*
+ * 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
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "Response.hxx"
+#include "Client.hxx"
+#include "util/FormatString.hxx"
+
+#include <string.h>
+
+bool
+Response::Write(const void *data, size_t length)
+{
+ return client.Write(data, length);
+}
+
+bool
+Response::Write(const char *data)
+{
+ return Write(data, strlen(data));
+}
+
+bool
+Response::FormatV(const char *fmt, va_list args)
+{
+ char *p = FormatNewV(fmt, args);
+ bool success = Write(p);
+ delete[] p;
+ return success;
+}
+
+bool
+Response::Format(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ bool success = FormatV(fmt, args);
+ va_end(args);
+ return success;
+}
+
+void
+Response::Error(enum ack code, const char *msg)
+{
+ FormatError(code, "%s", msg);
+}
+
+void
+Response::FormatError(enum ack code, const char *fmt, ...)
+{
+ Format("ACK [%i@%u] {%s} ",
+ (int)code, list_index, command);
+
+ va_list args;
+ va_start(args, fmt);
+ FormatV(fmt, args);
+ va_end(args);
+
+ Write("\n");
+}
diff --git a/src/client/Response.hxx b/src/client/Response.hxx
new file mode 100644
index 000000000..5841e7f61
--- /dev/null
+++ b/src/client/Response.hxx
@@ -0,0 +1,65 @@
+/*
+ * 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
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_RESPONSE_HXX
+#define MPD_RESPONSE_HXX
+
+#include "check.h"
+#include "protocol/Ack.hxx"
+
+#include <stddef.h>
+#include <stdarg.h>
+
+class Client;
+
+class Response {
+ Client &client;
+
+ /**
+ * This command's index in the command list. Used to generate
+ * error messages.
+ */
+ const unsigned list_index;
+
+ /**
+ * This command's name. Used to generate error messages.
+ */
+ const char *command;
+
+public:
+ Response(Client &_client, unsigned _list_index)
+ :client(_client), list_index(_list_index), command("") {}
+
+ Response(const Response &) = delete;
+ Response &operator=(const Response &) = delete;
+
+ void SetCommand(const char *_command) {
+ command = _command;
+ }
+
+ bool Write(const void *data, size_t length);
+ bool Write(const char *data);
+ bool FormatV(const char *fmt, va_list args);
+ bool Format(const char *fmt, ...);
+
+ void Error(enum ack code, const char *msg);
+ void FormatError(enum ack code, const char *fmt, ...);
+};
+
+#endif