Code

screen_utils: moved screen_auth() to screen_client.c
[ncmpc.git] / src / screen_client.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 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 "screen_client.h"
21 #include "screen_utils.h"
22 #include "mpdclient.h"
24 static gint
25 _screen_auth(struct mpdclient *c, gint recursion)
26 {
27         char *password;
29         mpd_connection_clear_error(c->connection);
30         if (recursion > 2)
31                 return 1;
33         password = screen_read_password(NULL, NULL);
34         if (password == NULL)
35                 return 1;
37         mpd_send_password(c->connection, password);
38         g_free(password);
40         mpd_response_finish(c->connection);
41         mpdclient_update(c);
43         if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
44             mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
45                 return  _screen_auth(c, ++recursion);
46         return 0;
47 }
49 gint
50 screen_auth(struct mpdclient *c)
51 {
52         gint ret = _screen_auth(c, 0);
53         mpdclient_update(c);
54         curs_set(0);
55         return ret;
56 }