diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 11:05:25 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 19:21:47 -0700 |
commit | d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3 (patch) | |
tree | d8baf242394faccf5c73ac18367c9a542a73bad7 /src/song.c | |
parent | 5f15ba96cf5fa641d34d4e98ae8e0972fa6fef0c (diff) | |
download | mpd-d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3.tar.gz mpd-d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3.tar.xz mpd-d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/song.c | 52 |
1 files changed, 30 insertions, 22 deletions
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) { |