3 * (c) 2005 by Avuton Olrich <avuton@gmail.com>
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "libmpdclient.h"
27 #define DEFAULT_HOST "localhost"
28 #define DEFAULT_PORT "6600"
29 #define MPD_TIMEOUT 60
32 static void parse_password(const char *host
, int *password_len
, int *parsed_len
)
34 /* parse password and host */
35 char *ret
= strstr(host
, "@");
38 if (ret
&& len
== 0) {
42 *parsed_len
+= len
+ 1;
47 void printErrorAndExit(mpd_Connection
* conn
)
50 fprintf(stderr
, "error: %s\n", conn
->errorStr
);
56 static void send_password(char *host
, int password_len
, mpd_Connection
* conn
)
58 host
[password_len
] = '\0';
60 mpd_sendPasswordCommand(conn
, host
);
61 printErrorAndExit(conn
);
62 mpd_finishCommand(conn
);
63 printErrorAndExit(conn
);
66 mpd_Connection
*setup_connection()
76 if ((test
= getenv("MPD_HOST")) && test
) {
82 if ((test
= getenv("MPD_PORT")) && test
) {
88 iport
= strtol(port
, &test
, 10);
90 if (iport
<= 0 || *test
!= '\0') {
91 fprintf(stderr
, "MPD_PORT \"%s\" is not a positive integer\n",
96 parse_password(host
, &password_len
, &parsed_len
);
98 conn
= mpd_newConnection(host
+ parsed_len
, iport
, (float)MPD_TIMEOUT
);
100 printErrorAndExit(conn
);
103 send_password(host
, password_len
, conn
);