release v0.26
[ncmpc.git] / src / callbacks.c
blob90eb40923001281ba7eb3a1d9936b8eb175f335d
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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.
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.
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)
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;
53 bool
54 mpdclient_auth_callback(struct mpdclient *c)
56 return _mpdclient_auth_callback(c, 0);
59 void
60 mpdclient_error_callback(const char *message)
62 screen_status_message(message);
63 screen_bell();
64 doupdate();