From d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:05:25 +0200 Subject: song: replaced all song constructors Provide separate constructors for creating a remote song, a local song, and one for loading data from a song file. This way, we can add more assertions. --- src/song.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index be84bfa4b..cf9994086 100644 --- a/src/song.c +++ b/src/song.c @@ -46,34 +46,41 @@ static struct mpd_song * song_alloc(const char *url, struct directory *parent) return song; } -struct mpd_song *newSong(const char *url, struct directory *parentDir) +struct mpd_song * song_remote_new(const char *url) +{ + return song_alloc(url, NULL); +} + +struct mpd_song * song_file_new(const char *path, struct directory *parent) +{ + assert(parent != NULL); + + return song_alloc(path, parent); +} + +struct mpd_song * song_file_load(const char *path, struct directory *parent) { struct mpd_song *song; - assert(*url); + unsigned int next = 0; + InputPlugin *plugin; + char path_max_tmp[MPD_PATH_MAX]; + char *abs_path; - if (strchr(url, '\n')) { - DEBUG("newSong: '%s' is not a valid uri\n", url); + if (strchr(path, '\n')) { + DEBUG("song_file_load: '%s' is not a valid uri\n", path); return NULL; } - song = song_alloc(url, parentDir); - - if (song_is_file(song)) { - InputPlugin *plugin; - unsigned int next = 0; - char path_max_tmp[MPD_PATH_MAX]; - char *abs_path = rmp2amp_r(path_max_tmp, - get_song_url(path_max_tmp, song)); + song = song_file_new(path, parent); + abs_path = rmp2amp_r(path_max_tmp, get_song_url(path_max_tmp, song)); - while (!song->tag && (plugin = isMusic(abs_path, - &(song->mtime), - next++))) { - song->tag = plugin->tagDupFunc(abs_path); - } - if (!song->tag || song->tag->time < 0) { - freeJustSong(song); - song = NULL; - } + while (!song->tag && + (plugin = isMusic(abs_path, &song->mtime, next++))) { + song->tag = plugin->tagDupFunc(abs_path); + } + if (!song->tag || song->tag->time < 0) { + freeJustSong(song); + return NULL; } return song; @@ -172,7 +179,8 @@ void readSongInfoIntoList(FILE * fp, struct directory * parentDir) if (!prefixcmp(buffer, SONG_KEY)) { if (song) insertSongIntoList(sv, song); - song = song_alloc(buffer + strlen(SONG_KEY), parentDir); + song = song_file_new(buffer + strlen(SONG_KEY), + parentDir); } else if (*buffer == 0) { /* ignore empty lines (starting with '\0') */ } else if (song == NULL) { -- cgit v1.2.3