2008-12-27 19:03:33 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2008-12-27 19:03:33 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-12-27 19:03:33 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2008-12-27 19:03:33 +01:00
|
|
|
#include "cmdline.h"
|
|
|
|
#include "path.h"
|
2009-02-19 08:35:20 +01:00
|
|
|
#include "log.h"
|
2008-12-27 19:03:33 +01:00
|
|
|
#include "conf.h"
|
|
|
|
#include "decoder_list.h"
|
2009-11-07 15:46:45 +01:00
|
|
|
#include "decoder_plugin.h"
|
2009-03-18 19:11:48 +01:00
|
|
|
#include "output_list.h"
|
2012-06-12 22:29:04 +02:00
|
|
|
#include "output_plugin.h"
|
2012-06-12 22:24:42 +02:00
|
|
|
#include "input_registry.h"
|
|
|
|
#include "input_plugin.h"
|
2012-06-12 19:59:03 +02:00
|
|
|
#include "playlist_list.h"
|
|
|
|
#include "playlist_plugin.h"
|
2009-03-03 17:01:42 +01:00
|
|
|
#include "ls.h"
|
2010-09-25 15:00:43 +02:00
|
|
|
#include "mpd_error.h"
|
2012-06-03 09:00:11 +02:00
|
|
|
#include "glib_compat.h"
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2009-11-17 20:39:26 +01:00
|
|
|
#ifdef ENABLE_ENCODER
|
|
|
|
#include "encoder_list.h"
|
2012-06-12 22:29:04 +02:00
|
|
|
#include "encoder_plugin.h"
|
2009-11-17 20:39:26 +01:00
|
|
|
#endif
|
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
#include "archive_list.h"
|
2012-06-12 22:29:04 +02:00
|
|
|
#include "archive_plugin.h"
|
2008-12-27 19:03:33 +01:00
|
|
|
#endif
|
|
|
|
|
2008-12-27 19:36:03 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
#include <stdio.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <stdlib.h>
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2010-05-20 15:53:07 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#define CONFIG_FILE_LOCATION "\\mpd\\mpd.conf"
|
|
|
|
#else /* G_OS_WIN32 */
|
2009-01-14 14:27:17 +01:00
|
|
|
#define USER_CONFIG_FILE_LOCATION1 ".mpdconf"
|
|
|
|
#define USER_CONFIG_FILE_LOCATION2 ".mpd/mpd.conf"
|
2010-05-20 15:53:07 +02:00
|
|
|
#endif
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2009-09-24 21:40:05 +02:00
|
|
|
static GQuark
|
|
|
|
cmdline_quark(void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string("cmdline");
|
|
|
|
}
|
|
|
|
|
2009-01-01 18:26:59 +01:00
|
|
|
G_GNUC_NORETURN
|
2008-12-27 19:03:33 +01:00
|
|
|
static void version(void)
|
|
|
|
{
|
|
|
|
puts(PACKAGE " (MPD: Music Player Daemon) " VERSION " \n"
|
|
|
|
"\n"
|
|
|
|
"Copyright (C) 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n"
|
2012-06-12 19:55:30 +02:00
|
|
|
"Copyright (C) 2008-2012 Max Kellermann <max@duempel.org>\n"
|
2008-12-27 19:03:33 +01:00
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
|
|
|
"warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
|
|
|
|
"\n"
|
2012-06-12 22:29:04 +02:00
|
|
|
"Decoders plugins:");
|
|
|
|
|
|
|
|
decoder_plugins_for_each(plugin) {
|
|
|
|
printf(" [%s]", plugin->name);
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2012-06-12 22:29:04 +02:00
|
|
|
const char *const*suffixes = plugin->suffixes;
|
|
|
|
if (suffixes != NULL)
|
|
|
|
for (; *suffixes != NULL; ++suffixes)
|
|
|
|
printf(" %s", *suffixes);
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2012-06-12 22:29:04 +02:00
|
|
|
puts("");
|
|
|
|
}
|
2008-12-30 14:08:59 +01:00
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
puts("\n"
|
2012-06-12 22:29:04 +02:00
|
|
|
"Output plugins:");
|
|
|
|
audio_output_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
puts("");
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2009-11-17 20:39:26 +01:00
|
|
|
#ifdef ENABLE_ENCODER
|
|
|
|
puts("\n"
|
2012-06-12 22:29:04 +02:00
|
|
|
"Encoder plugins:");
|
|
|
|
encoder_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
puts("");
|
2009-11-17 20:39:26 +01:00
|
|
|
#endif
|
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
puts("\n"
|
2012-06-12 22:29:04 +02:00
|
|
|
"Archive plugins:");
|
|
|
|
archive_plugins_for_each(plugin) {
|
|
|
|
printf(" [%s]", plugin->name);
|
|
|
|
|
|
|
|
const char *const*suffixes = plugin->suffixes;
|
|
|
|
if (suffixes != NULL)
|
|
|
|
for (; *suffixes != NULL; ++suffixes)
|
|
|
|
printf(" %s", *suffixes);
|
|
|
|
|
|
|
|
puts("");
|
|
|
|
}
|
2008-12-27 19:03:33 +01:00
|
|
|
#endif
|
2009-01-01 18:26:59 +01:00
|
|
|
|
2009-03-03 17:01:42 +01:00
|
|
|
puts("\n"
|
2012-06-12 22:24:42 +02:00
|
|
|
"Input plugins:");
|
|
|
|
input_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
|
|
|
|
puts("\n\n"
|
2012-06-12 19:59:03 +02:00
|
|
|
"Playlist plugins:");
|
|
|
|
playlist_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
|
|
|
|
puts("\n\n"
|
2012-06-12 22:29:04 +02:00
|
|
|
"Protocols:");
|
2009-03-03 17:01:42 +01:00
|
|
|
print_supported_uri_schemes_to_fp(stdout);
|
|
|
|
|
2009-01-01 18:26:59 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2008-12-27 19:03:33 +01:00
|
|
|
}
|
|
|
|
|
2008-12-27 19:36:03 +01:00
|
|
|
static const char *summary =
|
|
|
|
"Music Player Daemon - a daemon for playing music.";
|
|
|
|
|
2009-09-24 21:40:05 +02:00
|
|
|
bool
|
|
|
|
parse_cmdline(int argc, char **argv, struct options *options,
|
|
|
|
GError **error_r)
|
2008-12-27 19:03:33 +01:00
|
|
|
{
|
2008-12-27 19:36:03 +01:00
|
|
|
GError *error = NULL;
|
|
|
|
GOptionContext *context;
|
|
|
|
bool ret;
|
|
|
|
static gboolean option_version,
|
2009-09-20 23:31:35 +02:00
|
|
|
option_no_daemon,
|
2009-02-26 00:30:52 +01:00
|
|
|
option_no_config;
|
2008-12-27 19:36:03 +01:00
|
|
|
const GOptionEntry entries[] = {
|
2009-02-26 00:34:57 +01:00
|
|
|
{ "kill", 0, 0, G_OPTION_ARG_NONE, &options->kill,
|
|
|
|
"kill the currently running mpd session", NULL },
|
|
|
|
{ "no-config", 0, 0, G_OPTION_ARG_NONE, &option_no_config,
|
|
|
|
"don't read from config", NULL },
|
2008-12-27 19:36:03 +01:00
|
|
|
{ "no-daemon", 0, 0, G_OPTION_ARG_NONE, &option_no_daemon,
|
|
|
|
"don't detach from console", NULL },
|
2009-07-22 13:40:19 +02:00
|
|
|
{ "stdout", 0, 0, G_OPTION_ARG_NONE, &options->log_stderr,
|
2009-07-15 18:27:32 +02:00
|
|
|
NULL, NULL },
|
2009-07-22 13:40:19 +02:00
|
|
|
{ "stderr", 0, 0, G_OPTION_ARG_NONE, &options->log_stderr,
|
2008-12-28 19:48:52 +01:00
|
|
|
"print messages to stderr", NULL },
|
2008-12-27 19:36:03 +01:00
|
|
|
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &options->verbose,
|
|
|
|
"verbose logging", NULL },
|
2009-02-26 00:34:57 +01:00
|
|
|
{ "version", 'V', 0, G_OPTION_ARG_NONE, &option_version,
|
|
|
|
"print version number", NULL },
|
2008-12-27 19:36:03 +01:00
|
|
|
{ .long_name = NULL }
|
|
|
|
};
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2008-12-27 19:35:30 +01:00
|
|
|
options->kill = false;
|
|
|
|
options->daemon = true;
|
2009-07-22 13:40:19 +02:00
|
|
|
options->log_stderr = false;
|
2008-12-27 19:35:30 +01:00
|
|
|
options->verbose = false;
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2008-12-27 19:36:03 +01:00
|
|
|
context = g_option_context_new("[path/to/mpd.conf]");
|
|
|
|
g_option_context_add_main_entries(context, entries, NULL);
|
|
|
|
|
|
|
|
g_option_context_set_summary(context, summary);
|
|
|
|
|
|
|
|
ret = g_option_context_parse(context, &argc, &argv, &error);
|
|
|
|
g_option_context_free(context);
|
|
|
|
|
2010-09-25 15:00:43 +02:00
|
|
|
if (!ret)
|
|
|
|
MPD_ERROR("option parsing failed: %s\n", error->message);
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2008-12-27 19:36:03 +01:00
|
|
|
if (option_version)
|
|
|
|
version();
|
|
|
|
|
2009-02-19 08:35:20 +01:00
|
|
|
/* initialize the logging library, so the configuration file
|
|
|
|
parser can use it already */
|
|
|
|
log_early_init(options->verbose);
|
|
|
|
|
2008-12-27 19:36:03 +01:00
|
|
|
options->daemon = !option_no_daemon;
|
|
|
|
|
2009-02-26 00:30:52 +01:00
|
|
|
if (option_no_config) {
|
|
|
|
g_debug("Ignoring config, using daemon defaults\n");
|
2009-09-24 21:40:05 +02:00
|
|
|
return true;
|
2009-02-26 00:30:52 +01:00
|
|
|
} else if (argc <= 1) {
|
2008-12-27 19:36:03 +01:00
|
|
|
/* default configuration file path */
|
2009-01-14 14:27:17 +01:00
|
|
|
char *path1;
|
|
|
|
|
2010-05-20 15:53:07 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
path1 = g_build_filename(g_get_user_config_dir(),
|
|
|
|
CONFIG_FILE_LOCATION, NULL);
|
|
|
|
if (g_file_test(path1, G_FILE_TEST_IS_REGULAR))
|
|
|
|
ret = config_read_file(path1, error_r);
|
|
|
|
else {
|
|
|
|
int i = 0;
|
|
|
|
char *system_path = NULL;
|
|
|
|
const char * const *system_config_dirs;
|
|
|
|
|
|
|
|
system_config_dirs = g_get_system_config_dirs();
|
|
|
|
|
|
|
|
while(system_config_dirs[i] != NULL) {
|
|
|
|
system_path = g_build_filename(system_config_dirs[i],
|
|
|
|
CONFIG_FILE_LOCATION,
|
|
|
|
NULL);
|
|
|
|
if(g_file_test(system_path,
|
|
|
|
G_FILE_TEST_IS_REGULAR)) {
|
|
|
|
ret = config_read_file(system_path,error_r);
|
2012-10-17 19:47:21 +02:00
|
|
|
g_free(system_path);
|
2010-05-20 15:53:07 +02:00
|
|
|
break;
|
2012-10-17 19:47:21 +02:00
|
|
|
} else
|
|
|
|
g_free(system_path);
|
|
|
|
++i;
|
2010-05-20 15:53:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* G_OS_WIN32 */
|
|
|
|
char *path2;
|
2009-01-14 14:27:17 +01:00
|
|
|
path1 = g_build_filename(g_get_home_dir(),
|
|
|
|
USER_CONFIG_FILE_LOCATION1, NULL);
|
|
|
|
path2 = g_build_filename(g_get_home_dir(),
|
|
|
|
USER_CONFIG_FILE_LOCATION2, NULL);
|
|
|
|
if (g_file_test(path1, G_FILE_TEST_IS_REGULAR))
|
2009-09-24 21:40:07 +02:00
|
|
|
ret = config_read_file(path1, error_r);
|
2009-01-14 14:27:17 +01:00
|
|
|
else if (g_file_test(path2, G_FILE_TEST_IS_REGULAR))
|
2009-09-24 21:40:07 +02:00
|
|
|
ret = config_read_file(path2, error_r);
|
2008-12-27 19:46:43 +01:00
|
|
|
else if (g_file_test(SYSTEM_CONFIG_FILE_LOCATION,
|
|
|
|
G_FILE_TEST_IS_REGULAR))
|
2009-09-24 21:40:07 +02:00
|
|
|
ret = config_read_file(SYSTEM_CONFIG_FILE_LOCATION,
|
|
|
|
error_r);
|
2010-05-20 15:53:07 +02:00
|
|
|
#endif
|
|
|
|
|
2009-01-14 14:27:17 +01:00
|
|
|
g_free(path1);
|
2010-05-20 15:53:07 +02:00
|
|
|
#ifndef G_OS_WIN32
|
2009-01-14 14:27:17 +01:00
|
|
|
g_free(path2);
|
2010-05-20 15:53:07 +02:00
|
|
|
#endif
|
2009-09-24 21:40:05 +02:00
|
|
|
|
2009-09-24 21:40:07 +02:00
|
|
|
return ret;
|
2008-12-27 19:36:03 +01:00
|
|
|
} else if (argc == 2) {
|
|
|
|
/* specified configuration file */
|
2009-09-24 21:40:07 +02:00
|
|
|
return config_read_file(argv[1], error_r);
|
2009-09-24 21:40:05 +02:00
|
|
|
} else {
|
|
|
|
g_set_error(error_r, cmdline_quark(), 0,
|
|
|
|
"too many arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-27 19:03:33 +01:00
|
|
|
}
|