aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-08 11:05:25 +0200
committerMax Kellermann <max@duempel.org>2008-10-08 11:05:25 +0200
commit5e4be9e495677a6728e3161e39a05a081a5bff9a (patch)
treecbcf94a5d1c9236e5fff17f21cbd9e3f0557a574 /src/song.c
parent4a510a26744a78696f0c69713bf3b05881175fef (diff)
downloadmpd-5e4be9e495677a6728e3161e39a05a081a5bff9a.tar.gz
mpd-5e4be9e495677a6728e3161e39a05a081a5bff9a.tar.xz
mpd-5e4be9e495677a6728e3161e39a05a081a5bff9a.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.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/song.c b/src/song.c
index 3219e7c48..f96f90c8a 100644
--- a/src/song.c
+++ b/src/song.c
@@ -26,7 +26,7 @@
#include "decoder_list.h"
#include "decoder_api.h"
-struct song *
+static struct song *
song_alloc(const char *url, struct directory *parent)
{
size_t urllen;
@@ -45,34 +45,45 @@ song_alloc(const char *url, struct directory *parent)
}
struct song *
-newSong(const char *url, struct directory *parentDir)
+song_remote_new(const char *url)
+{
+ return song_alloc(url, NULL);
+}
+
+struct song *
+song_file_new(const char *path, struct directory *parent)
+{
+ assert(parent != NULL);
+
+ return song_alloc(path, parent);
+}
+
+struct song *
+song_file_load(const char *path, struct directory *parent)
{
struct song *song;
- assert(*url);
+ struct decoder_plugin *plugin;
+ unsigned int next = 0;
+ char path_max_tmp[MPD_PATH_MAX], *abs_path;
+
+ assert(parent != NULL);
- if (strchr(url, '\n')) {
- DEBUG("newSong: '%s' is not a valid uri\n", url);
+ if (strchr(path, '\n')) {
+ DEBUG("newSong: '%s' is not a valid uri\n", path);
return NULL;
}
- song = song_alloc(url, parentDir);
+ song = song_file_new(path, parent);
- if (song_is_file(song)) {
- struct decoder_plugin *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));
+ abs_path = rmp2amp_r(path_max_tmp, get_song_url(path_max_tmp, song));
+ while (song->tag == NULL &&
+ (plugin = isMusic(abs_path, &(song->mtime), next++))) {
+ song->tag = plugin->tag_dup(abs_path);
+ }
- while (!song->tag && (plugin = isMusic(abs_path,
- &(song->mtime),
- next++))) {
- song->tag = plugin->tag_dup(abs_path);
- }
- if (!song->tag || song->tag->time < 0) {
- freeJustSong(song);
- song = NULL;
- }
+ if (song->tag == NULL || song->tag->time < 0) {
+ freeJustSong(song);
+ return NULL;
}
return song;