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"
24 #include "charset.h"
26 static bool
27 _mpdclient_auth_callback(struct mpdclient *c, gint recursion)
28 {
29 struct mpd_connection *connection = mpdclient_get_connection(c);
30 if (connection == NULL)
31 return false;
33 mpd_connection_clear_error(connection);
34 if (recursion > 2)
35 return false;
37 char *password = screen_read_password(NULL);
38 if (password == NULL)
39 return false;
41 mpd_send_password(connection, password);
42 g_free(password);
44 mpd_response_finish(connection);
45 mpdclient_update(c);
47 if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
48 mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
49 return _mpdclient_auth_callback(c, ++recursion);
51 return true;
52 }
54 bool
55 mpdclient_auth_callback(struct mpdclient *c)
56 {
57 return _mpdclient_auth_callback(c, 0);
58 }
60 void
61 mpdclient_error_callback(const char *message_utf8)
62 {
63 char *message_locale = utf8_to_locale(message_utf8);
64 screen_status_printf("%s", message_locale);
65 g_free(message_locale);
67 screen_bell();
68 doupdate();
69 }