From 8204fc68202f5fc858cd7246b6b2cb5104d980e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 21 Sep 2017 08:51:19 +0200 Subject: [PATCH] mpdclient: implement password for asynchronous connect Closes #5 --- NEWS | 1 + src/mpdclient.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/NEWS b/NEWS index 157b39d..43b713c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ncmpc 0.28 - not yet released * fix crash on lyrics screen * fix memory leak * hide the MPD password from the queue screen title +* implement password for asynchronous connect * build with Meson instead of autotools ncmpc 0.27 - (2017-03-25) diff --git a/src/mpdclient.c b/src/mpdclient.c index ffa1a5d..6a81a0b 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -355,6 +355,17 @@ static void mpdclient_aconnect_start(struct mpdclient *c, const struct mpd_settings *settings); +static const struct mpd_settings * +mpdclient_get_settings(const struct mpdclient *c) +{ +#ifndef WIN32 + if (c->connecting2) + return c->settings2; +#endif + + return c->settings; +} + static void mpdclient_connect_success(struct mpd_connection *connection, void *ctx) { @@ -362,6 +373,15 @@ mpdclient_connect_success(struct mpd_connection *connection, void *ctx) assert(c->async_connect != NULL); c->async_connect = NULL; + const char *password = + mpd_settings_get_password(mpdclient_get_settings(c)); + if (password != NULL && !mpd_run_password(connection, password)) { + mpdclient_error_callback(mpd_connection_get_error_message(connection)); + mpd_connection_free(connection); + mpdclient_failed_callback(); + return; + } + mpdclient_connected(c, connection); } -- 2.30.2