Code

release v0.29
[ncmpc.git] / src / callbacks.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
20 #include "callbacks.h"
21 #include "screen_utils.h"
22 #include "screen_status.h"
23 #include "mpdclient.h"
25 static bool
26 _mpdclient_auth_callback(struct mpdclient *c, gint recursion)
27 {
28         struct mpd_connection *connection = mpdclient_get_connection(c);
29         if (connection == NULL)
30                 return false;
32         mpd_connection_clear_error(connection);
33         if (recursion > 2)
34                 return false;
36         char *password = screen_read_password(NULL);
37         if (password == NULL)
38                 return false;
40         mpd_send_password(connection, password);
41         g_free(password);
43         mpd_response_finish(connection);
44         mpdclient_update(c);
46         if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
47             mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
48                 return _mpdclient_auth_callback(c, ++recursion);
50         return true;
51 }
53 bool
54 mpdclient_auth_callback(struct mpdclient *c)
55 {
56         return _mpdclient_auth_callback(c, 0);
57 }
59 void
60 mpdclient_error_callback(const char *message)
61 {
62         screen_status_message(message);
63         screen_bell();
64         doupdate();
65 }