Support MPD_HOST and MPD_PORT env variables

This commit is contained in:
Lucas Verney 2016-04-06 00:52:14 +02:00
parent 72324c5fb8
commit 1c188bcb6d
4 changed files with 17 additions and 11 deletions

View File

@ -46,10 +46,10 @@ struct gengetopt_args_info
char * mpd_root_arg; /**< @brief MPD library base path.. */
char * mpd_root_orig; /**< @brief MPD library base path. original value given at command line. */
const char *mpd_root_help; /**< @brief MPD library base path. help description. */
char * host_arg; /**< @brief MPD host. (default='localhost'). */
char * host_arg; /**< @brief MPD host. (default=''). */
char * host_orig; /**< @brief MPD host. original value given at command line. */
const char *host_help; /**< @brief MPD host. help description. */
int port_arg; /**< @brief MPD port. (default='6600'). */
int port_arg; /**< @brief MPD port. (default='0'). */
char * port_orig; /**< @brief MPD port. original value given at command line. */
const char *port_help; /**< @brief MPD port. help description. */

View File

@ -5,5 +5,5 @@ purpose "Binding MPD and Bliss."
option "rescan" r "Rescan the whole MPD database." flag off
option "update" u "Trigger an update." flag off
option "mpd_root" - "MPD library base path." string
option "host" - "MPD host." string default="localhost" optional
option "port" - "MPD port." int default="6600" optional
option "host" - "MPD host." string default="" optional
option "port" - "MPD port." int default="0" optional

View File

@ -39,8 +39,8 @@ const char *gengetopt_args_info_help[] = {
" -r, --rescan Rescan the whole MPD database. (default=off)",
" -u, --update Trigger an update. (default=off)",
" --mpd_root=STRING MPD library base path.",
" --host=STRING MPD host. (default=`localhost')",
" --port=INT MPD port. (default=`6600')",
" --host=STRING MPD host. (default=`')",
" --port=INT MPD port. (default=`0')",
0
};
@ -85,9 +85,9 @@ void clear_args (struct gengetopt_args_info *args_info)
args_info->update_flag = 0;
args_info->mpd_root_arg = NULL;
args_info->mpd_root_orig = NULL;
args_info->host_arg = gengetopt_strdup ("localhost");
args_info->host_arg = gengetopt_strdup ("");
args_info->host_orig = NULL;
args_info->port_arg = 6600;
args_info->port_arg = 0;
args_info->port_orig = NULL;
}
@ -587,7 +587,7 @@ cmdline_parser_internal (
if (update_arg( (void *)&(args_info->host_arg),
&(args_info->host_orig), &(args_info->host_given),
&(local_args_info.host_given), optarg, 0, "localhost", ARG_STRING,
&(local_args_info.host_given), optarg, 0, "", ARG_STRING,
check_ambiguity, override, 0, 0,
"host", '-',
additional_error))
@ -601,7 +601,7 @@ cmdline_parser_internal (
if (update_arg( (void *)&(args_info->port_arg),
&(args_info->port_orig), &(args_info->port_given),
&(local_args_info.port_given), optarg, 0, "6600", ARG_INT,
&(local_args_info.port_given), optarg, 0, "0", ARG_INT,
check_ambiguity, override, 0, 0,
"port", '-',
additional_error))

View File

@ -13,6 +13,8 @@
#include "cmdline.h"
// TODO: Handle deletions from db
// TODO: Respect MPD_HOST / PORT
// TODO: Support MPD servers with passwords
#define DEFAULT_STRING_LENGTH 255
@ -230,8 +232,12 @@ int main(int argc, char** argv) {
}
// Create MPD connection
char *mpd_host = NULL;
if (strlen(args_info.host_arg) > 0) {
mpd_host = args_info.host_arg;
}
conn = mpd_connection_new(
args_info.host_arg,
mpd_host,
args_info.port_arg,
30000);
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {