From c2d5ce0ca213e2d25df17e080b07a3d91d330972 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Sat, 19 Oct 2013 19:39:40 +0200
Subject: [PATCH] Client: move trivial functions into the Client class

---
 src/AllCommands.cxx   |  6 +++---
 src/Client.cxx        | 18 ----------------
 src/Client.hxx        | 49 +++++++++++++++++++++----------------------
 src/ClientFile.cxx    |  2 +-
 src/OtherCommands.cxx |  6 +++---
 5 files changed, 31 insertions(+), 50 deletions(-)

diff --git a/src/AllCommands.cxx b/src/AllCommands.cxx
index 73dd7d218..95edb0f19 100644
--- a/src/AllCommands.cxx
+++ b/src/AllCommands.cxx
@@ -182,7 +182,7 @@ static enum command_return
 handle_commands(Client &client,
 		gcc_unused int argc, gcc_unused char *argv[])
 {
-	const unsigned permission = client_get_permission(client);
+	const unsigned permission = client.GetPermission();
 	const struct command *cmd;
 
 	for (unsigned i = 0; i < num_commands; ++i) {
@@ -200,7 +200,7 @@ static enum command_return
 handle_not_commands(Client &client,
 		    gcc_unused int argc, gcc_unused char *argv[])
 {
-	const unsigned permission = client_get_permission(client);
+	const unsigned permission = client.GetPermission();
 	const struct command *cmd;
 
 	for (unsigned i = 0; i < num_commands; ++i) {
@@ -364,7 +364,7 @@ command_process(Client &client, unsigned num, char *line)
 
 	/* look up and invoke the command handler */
 
-	cmd = command_checked_lookup(client, client_get_permission(client),
+	cmd = command_checked_lookup(client, client.GetPermission(),
 				     argc, argv);
 	if (cmd)
 		ret = cmd->handler(client, argc, argv);
diff --git a/src/Client.cxx b/src/Client.cxx
index b60061a60..928747897 100644
--- a/src/Client.cxx
+++ b/src/Client.cxx
@@ -22,21 +22,3 @@
 #include "util/Domain.hxx"
 
 const Domain client_domain("client");
-
-int
-client_get_uid(const Client &client)
-{
-	return client.uid;
-}
-
-unsigned
-client_get_permission(const Client &client)
-{
-	return client.permission;
-}
-
-void
-client_set_permission(Client &client, unsigned permission)
-{
-	client.permission = permission;
-}
diff --git a/src/Client.hxx b/src/Client.hxx
index 3a2fda282..13a4a14e7 100644
--- a/src/Client.hxx
+++ b/src/Client.hxx
@@ -101,6 +101,30 @@ public:
 
 	using FullyBufferedSocket::Write;
 
+	/**
+	 * returns the uid of the client process, or a negative value
+	 * if the uid is unknown
+	 */
+	int GetUID() const {
+		return uid;
+	}
+
+	/**
+	 * Is this client running on the same machine, connected with
+	 * a local (UNIX domain) socket?
+	 */
+	bool IsLocal() const {
+		return uid > 0;
+	}
+
+	unsigned GetPermission() const {
+		return permission;
+	}
+
+	void SetPermission(unsigned _permission) {
+		permission = _permission;
+	}
+
 	/**
 	 * Send "idle" response to this client.
 	 */
@@ -124,31 +148,6 @@ void
 client_new(EventLoop &loop, Partition &partition,
 	   int fd, const struct sockaddr *sa, size_t sa_length, int uid);
 
-/**
- * returns the uid of the client process, or a negative value if the
- * uid is unknown
- */
-gcc_pure
-int
-client_get_uid(const Client &client);
-
-/**
- * Is this client running on the same machine, connected with a local
- * (UNIX domain) socket?
- */
-gcc_pure
-static inline bool
-client_is_local(const Client &client)
-{
-	return client_get_uid(client) > 0;
-}
-
-gcc_pure
-unsigned
-client_get_permission(const Client &client);
-
-void client_set_permission(Client &client, unsigned permission);
-
 /**
  * Write a C string to the client.
  */
diff --git a/src/ClientFile.cxx b/src/ClientFile.cxx
index 6d9fa474e..382b76083 100644
--- a/src/ClientFile.cxx
+++ b/src/ClientFile.cxx
@@ -41,7 +41,7 @@ client_allow_file(const Client &client, Path path_fs, Error &error)
 	error.Set(ack_domain, ACK_ERROR_PERMISSION, "Access denied");
 	return false;
 #else
-	const int uid = client_get_uid(client);
+	const int uid = client.GetUID();
 	if (uid >= 0 && (uid_t)uid == geteuid())
 		/* always allow access if user runs his own MPD
 		   instance */
diff --git a/src/OtherCommands.cxx b/src/OtherCommands.cxx
index 038a6448b..3e1e6fdd4 100644
--- a/src/OtherCommands.cxx
+++ b/src/OtherCommands.cxx
@@ -67,7 +67,7 @@ enum command_return
 handle_urlhandlers(Client &client,
 		   gcc_unused int argc, gcc_unused char *argv[])
 {
-	if (client_is_local(client))
+	if (client.IsLocal())
 		client_puts(client, "handler: file://\n");
 	print_supported_uri_schemes(client);
 	return COMMAND_RETURN_OK;
@@ -262,7 +262,7 @@ handle_password(Client &client, gcc_unused int argc, char *argv[])
 		return COMMAND_RETURN_ERROR;
 	}
 
-	client_set_permission(client, permission);
+	client.SetPermission(permission);
 
 	return COMMAND_RETURN_OK;
 }
@@ -271,7 +271,7 @@ enum command_return
 handle_config(Client &client,
 	      gcc_unused int argc, gcc_unused char *argv[])
 {
-	if (!client_is_local(client)) {
+	if (!client.IsLocal()) {
 		command_error(client, ACK_ERROR_PERMISSION,
 			      "Command only permitted to local clients");
 		return COMMAND_RETURN_ERROR;