aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-01-01 10:09:26 +0000
committerEric Wong <normalperson@yhbt.net>2008-01-01 10:09:26 +0000
commit390ed29740c4aa5caf41d659bf392b20aec4788f (patch)
treeff2bf3754333af3d3d61493c174bbc6d9fc9defc
parent24c58132ec23d199bb7e0d9e67f5ad6af27089e8 (diff)
downloadmpd-390ed29740c4aa5caf41d659bf392b20aec4788f.tar.gz
mpd-390ed29740c4aa5caf41d659bf392b20aec4788f.tar.xz
mpd-390ed29740c4aa5caf41d659bf392b20aec4788f.zip
storedPlaylist: cleanup load function
* stop supporting unused parentlen block, I have no idea how it was ever usable, but playlists don't work in subdirectories... * myFgets is far easier to use than fgetc loops. * Since we're using myFgets, we'll just skip lines that are too long, rather than error out and bitch and moan about things... git-svn-id: https://svn.musicpd.org/mpd/trunk@7118 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/storedPlaylist.c88
1 files changed, 16 insertions, 72 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c
index 68122b5b4..17b3fceaf 100644
--- a/src/storedPlaylist.c
+++ b/src/storedPlaylist.c
@@ -104,28 +104,18 @@ StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisti
return sp;
}
-/* FIXME - this function is gross */
StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
{
StoredPlaylist *sp;
FILE *file;
- char s[MPD_PATH_MAX];
+ char buffer[MPD_PATH_MAX];
char path_max_tmp[MPD_PATH_MAX];
- char path_max_tmp2[MPD_PATH_MAX]; /* TODO: cleanup */
- char path_max_tmp3[MPD_PATH_MAX]; /* TODO: cleanup */
- int slength = 0;
- char *temp;
- char *parent;
- int parentlen;
- int tempInt;
- int commentCharFound = 0;
- Song *song;
+ const size_t musicDir_len = strlen(musicDir);
if (!valid_playlist_name(fd, utf8path))
return NULL;
utf8_to_fs_playlist_path(path_max_tmp, utf8path);
-
while (!(file = fopen(path_max_tmp, "r")) && errno == EINTR);
if (file == NULL) {
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
@@ -137,66 +127,20 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
if (!sp)
goto out;
- temp = utf8_to_fs_charset(path_max_tmp2, (char *)utf8path);
- parent = parent_path(path_max_tmp3, temp);
- parentlen = strlen(parent);
-
- while ((tempInt = fgetc(file)) != EOF) {
- s[slength] = tempInt;
- if (s[slength] == '\n' || s[slength] == '\0') {
- commentCharFound = 0;
- s[slength] = '\0';
- if (s[0] == PLAYLIST_COMMENT)
- commentCharFound = 1;
- if (!strncmp(s, musicDir, strlen(musicDir)) &&
- s[strlen(musicDir)] == '/') {
- memmove(s, &(s[strlen(musicDir) + 1]),
- strlen(&(s[strlen(musicDir) + 1])) + 1);
- } else if (parentlen) {
- temp = xstrdup(s);
- strcpy(s, parent);
- strncat(s, "/", MPD_PATH_MAX - parentlen);
- strncat(s, temp, MPD_PATH_MAX - parentlen - 1);
- if (strlen(s) >= MPD_PATH_MAX) {
- commandError(sp->fd,
- ACK_ERROR_PLAYLIST_LOAD,
- "\"%s\" is too long", temp);
- free(temp);
- freeStoredPlaylist(sp);
- sp = NULL;
- goto out;
- }
- free(temp);
- }
- slength = 0;
- temp = fs_charset_to_utf8(path_max_tmp, s);
- if (temp && !commentCharFound) {
- song = getSongFromDB(temp);
- if (song) {
- appendSongToStoredPlaylist(sp, song);
- continue;
- }
-
- if (!isValidRemoteUtf8Url(temp))
- continue;
-
- song = newSong(temp, SONG_TYPE_URL, NULL);
- if (song) {
- appendSongToStoredPlaylist(sp, song);
- freeJustSong(song);
- }
- }
- } else if (slength == (MPD_PATH_MAX - 1)) {
- s[slength] = '\0';
- commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD,
- "line \"%s\" in playlist \"%s\" "
- "is too long", s, utf8path);
- freeStoredPlaylist(sp);
- sp = NULL;
- goto out;
- } else if (s[slength] != '\r') {
- slength++;
- }
+ while (myFgets(buffer, sizeof(buffer), file)) {
+ char *s = buffer;
+ Song *song;
+
+ if (*s == PLAYLIST_COMMENT)
+ continue;
+ if (s[musicDir_len] == '/' &&
+ !strncmp(s, musicDir, musicDir_len))
+ memmove(s, s + musicDir_len + 1,
+ strlen(s + musicDir_len + 1) + 1);
+ if ((song = getSongFromDB(s)))
+ appendSongToStoredPlaylist(sp, song);
+ else if (isValidRemoteUtf8Url(s))
+ insertInListWithoutKey(sp->list, xstrdup(s));
}
out: