db/proxy: add "password" setting

Closes #283
This commit is contained in:
Max Kellermann 2018-05-28 19:58:38 +02:00
parent 04f928e2b0
commit a8b9e5b9b9
3 changed files with 17 additions and 0 deletions

2
NEWS
View File

@ -1,4 +1,6 @@
ver 0.20.21 (not yet released)
* database
- proxy: add "password" setting
ver 0.20.20 (2018/05/22)
* protocol

View File

@ -2114,6 +2114,15 @@ run</programlisting>
<application>MPD</application> instance.
</entry>
</row>
<row>
<entry>
<varname>password</varname>
</entry>
<entry>
The password used to log in to the "master"
<application>MPD</application> instance.
</entry>
</row>
<row>
<entry>
<varname>keepalive</varname>

View File

@ -82,6 +82,7 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
DatabaseListener &listener;
const std::string host;
const std::string password;
const unsigned port;
const bool keepalive;
@ -359,6 +360,7 @@ ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
SocketMonitor(_loop), IdleMonitor(_loop),
listener(_listener),
host(block.GetBlockValue("host", "")),
password(block.GetBlockValue("password", "")),
port(block.GetBlockValue("port", 0u)),
keepalive(block.GetBlockValue("keepalive", false))
{
@ -402,6 +404,10 @@ ProxyDatabase::Connect()
try {
CheckError(connection);
if (!password.empty() &&
!mpd_run_password(connection, password.c_str()))
ThrowError(connection);
} catch (...) {
mpd_connection_free(connection);
connection = nullptr;