From: Max Kellermann Date: Thu, 21 Sep 2017 06:51:19 +0000 (+0200) Subject: mpdclient: implement password for asynchronous connect X-Git-Tag: v0.28~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8204fc68202f5fc858cd7246b6b2cb5104d980e4;p=ncmpc.git mpdclient: implement password for asynchronous connect Closes #5 --- 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); }