Code

mpdclient: implement password for asynchronous connect
authorMax Kellermann <max.kellermann@gmail.com>
Thu, 21 Sep 2017 06:51:19 +0000 (08:51 +0200)
committerMax Kellermann <max.kellermann@gmail.com>
Thu, 21 Sep 2017 06:51:19 +0000 (08:51 +0200)
Closes #5

NEWS
src/mpdclient.c

diff --git a/NEWS b/NEWS
index 157b39dadf390e7f6ede7f383fd893cfafc290f7..43b713c749a9301ca6092e17d9d37ae5ed6d9122 100644 (file)
--- 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)
index ffa1a5d84408e86757b82d2dbde1617dbf07c583..6a81a0bd8ac20bd6cc2708f3438ad194a28ba643 100644 (file)
@@ -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);
 }