diff options
author | Max Kellermann <max@duempel.org> | 2009-01-18 16:56:07 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-18 16:56:07 +0100 |
commit | 1f0dfb4407344996bbe874525413275b79da12b3 (patch) | |
tree | 6da8c04bf1e3c6143927d3a69eecb3532f88939f /src/mapper.c | |
parent | 9933144de7389b12b2a75cfb4320baecefa952af (diff) | |
download | mpd-1f0dfb4407344996bbe874525413275b79da12b3.tar.gz mpd-1f0dfb4407344996bbe874525413275b79da12b3.tar.xz mpd-1f0dfb4407344996bbe874525413275b79da12b3.zip |
mapper: make the music_directory optional
Without a music_directory, MPD is an excellent streaming client.
Diffstat (limited to '')
-rw-r--r-- | src/mapper.c | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/src/mapper.c b/src/mapper.c index 2c3e50ab0..a47507bb1 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -41,6 +41,24 @@ static size_t music_dir_length; static char *playlist_dir; static void +mapper_set_music_dir(const char *path, int line) +{ + int ret; + struct stat st; + + music_dir = g_strdup(path); + music_dir_length = strlen(music_dir); + + ret = stat(music_dir, &st); + if (ret < 0) + g_warning("failed to stat music directory \"%s\" (config line %i): %s\n", + music_dir, line, g_strerror(errno)); + else if (!S_ISDIR(st.st_mode)) + g_warning("music directory is not a directory: \"%s\" (config line %i)\n", + music_dir, line); +} + +static void mapper_set_playlist_dir(const char *path, int line) { int ret; @@ -59,34 +77,19 @@ mapper_set_playlist_dir(const char *path, int line) void mapper_init(void) { - struct config_param *music_dir_param = - parseConfigFilePath(CONF_MUSIC_DIR, false); struct config_param *param; - int ret; - struct stat st; - if (music_dir_param != NULL) { - music_dir = g_strdup(music_dir_param->value); - } else { + param = parseConfigFilePath(CONF_MUSIC_DIR, false); + if (param != NULL) + mapper_set_music_dir(param->value, param->line); #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 14) - music_dir = g_strdup(g_get_user_special_dir(G_USER_DIRECTORY_MUSIC)); - if (music_dir == NULL) - /* GLib failed to determine the XDG music - directory - abort */ -#endif - g_error("config parameter \"%s\" not found\n", CONF_MUSIC_DIR); + else { + const char *path = + g_get_user_special_dir(G_USER_DIRECTORY_MUSIC); + if (path != NULL) + mapper_set_music_dir(path, -1); } - - music_dir_length = strlen(music_dir); - - ret = stat(music_dir, &st); - if (ret < 0) - g_warning("failed to stat music directory \"%s\" (config line %i): %s\n", - music_dir_param->value, music_dir_param->line, - strerror(errno)); - else if (!S_ISDIR(st.st_mode)) - g_warning("music directory is not a directory: \"%s\" (config line %i)\n", - music_dir_param->value, music_dir_param->line); +#endif param = parseConfigFilePath(CONF_PLAYLIST_DIR, false); if (param != NULL) @@ -99,6 +102,12 @@ void mapper_finish(void) g_free(playlist_dir); } +bool +mapper_has_music_directory(void) +{ + return music_dir != NULL; +} + char * map_uri_fs(const char *uri) { @@ -107,6 +116,9 @@ map_uri_fs(const char *uri) assert(uri != NULL); assert(*uri != '/'); + if (music_dir == NULL) + return NULL; + uri_fs = utf8_to_fs_charset(uri); if (uri_fs == NULL) return NULL; @@ -120,6 +132,8 @@ map_uri_fs(const char *uri) char * map_directory_fs(const struct directory *directory) { + assert(music_dir != NULL); + if (directory_is_root(directory)) return g_strdup(music_dir); @@ -131,6 +145,8 @@ map_directory_child_fs(const struct directory *directory, const char *name) { char *name_fs, *parent_fs, *path; + assert(music_dir != NULL); + /* check for invalid or unauthorized base names */ if (*name == 0 || strchr(name, '/') != NULL || strcmp(name, ".") == 0 || strcmp(name, "..") == 0) @@ -167,7 +183,8 @@ map_song_fs(const struct song *song) char * map_fs_to_utf8(const char *path_fs) { - if (strncmp(path_fs, music_dir, music_dir_length) == 0 && + if (music_dir != NULL && + strncmp(path_fs, music_dir, music_dir_length) == 0 && path_fs[music_dir_length] == '/') /* remove musicDir prefix */ path_fs += music_dir_length + 1; |