client/Client: add interface IClient
This allows detangling dependencies and fixes a linker problem in test/test_translate_song.cxx.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_CLIENT_H
|
||||
#define MPD_CLIENT_H
|
||||
#pragma once
|
||||
|
||||
#include "IClient.hxx"
|
||||
#include "Message.hxx"
|
||||
#include "command/CommandResult.hxx"
|
||||
#include "command/CommandListBuilder.hxx"
|
||||
@@ -32,7 +32,7 @@ class Storage;
|
||||
class BackgroundCommand;
|
||||
|
||||
class Client final
|
||||
: FullyBufferedSocket
|
||||
: public IClient, FullyBufferedSocket
|
||||
{
|
||||
friend struct ClientPerPartitionListHook;
|
||||
friend class ClientList;
|
||||
@@ -223,19 +223,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this client allowed to use the specified local file?
|
||||
*
|
||||
* Note that this function is vulnerable to timing/symlink attacks.
|
||||
* We cannot fix this as long as there are plugins that open a file by
|
||||
* its name, and not by file descriptor / callbacks.
|
||||
*
|
||||
* Throws #std::runtime_error on error.
|
||||
*
|
||||
* @param path_fs the absolute path name in filesystem encoding
|
||||
*/
|
||||
void AllowFile(Path path_fs) const;
|
||||
|
||||
Partition &GetPartition() const noexcept {
|
||||
return *partition;
|
||||
}
|
||||
@@ -251,19 +238,18 @@ public:
|
||||
[[gnu::pure]]
|
||||
PlayerControl &GetPlayerControl() const noexcept;
|
||||
|
||||
/**
|
||||
* Wrapper for Instance::GetDatabase().
|
||||
*/
|
||||
[[gnu::pure]]
|
||||
const Database *GetDatabase() const noexcept;
|
||||
|
||||
/**
|
||||
* Wrapper for Instance::GetDatabaseOrThrow().
|
||||
*/
|
||||
const Database &GetDatabaseOrThrow() const;
|
||||
|
||||
[[gnu::pure]]
|
||||
const Storage *GetStorage() const noexcept;
|
||||
// virtual methods from class IClient
|
||||
void AllowFile(Path path_fs) const override;
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
const Database *GetDatabase() const noexcept override;
|
||||
const Storage *GetStorage() const noexcept override;
|
||||
#endif // ENABLE_DATABASE
|
||||
|
||||
private:
|
||||
CommandResult ProcessCommandList(bool list_ok,
|
||||
@@ -287,5 +273,3 @@ void
|
||||
client_new(EventLoop &loop, Partition &partition,
|
||||
UniqueSocketDescriptor fd, SocketAddress address, int uid,
|
||||
unsigned permission) noexcept;
|
||||
|
||||
#endif
|
||||
|
39
src/client/IClient.hxx
Normal file
39
src/client/IClient.hxx
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
|
||||
class Path;
|
||||
class Database;
|
||||
class Storage;
|
||||
struct Partition;
|
||||
|
||||
/**
|
||||
* An abstract interface for #Client which can be used for unit tests
|
||||
* instead of the full #Client class.
|
||||
*/
|
||||
class IClient {
|
||||
public:
|
||||
/**
|
||||
* Is this client allowed to use the specified local file?
|
||||
*
|
||||
* Note that this function is vulnerable to timing/symlink attacks.
|
||||
* We cannot fix this as long as there are plugins that open a file by
|
||||
* its name, and not by file descriptor / callbacks.
|
||||
*
|
||||
* Throws #std::runtime_error on error.
|
||||
*
|
||||
* @param path_fs the absolute path name in filesystem encoding
|
||||
*/
|
||||
virtual void AllowFile(Path path_fs) const = 0;
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
[[gnu::pure]]
|
||||
virtual const Database *GetDatabase() const noexcept = 0;
|
||||
|
||||
[[gnu::pure]]
|
||||
virtual const Storage *GetStorage() const noexcept = 0;
|
||||
#endif // ENABLE_DATABASE
|
||||
};
|
Reference in New Issue
Block a user