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
This commit is contained in:
@@ -104,28 +104,18 @@ StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisti
|
|||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME - this function is gross */
|
|
||||||
StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
|
StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
|
||||||
{
|
{
|
||||||
StoredPlaylist *sp;
|
StoredPlaylist *sp;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char s[MPD_PATH_MAX];
|
char buffer[MPD_PATH_MAX];
|
||||||
char path_max_tmp[MPD_PATH_MAX];
|
char path_max_tmp[MPD_PATH_MAX];
|
||||||
char path_max_tmp2[MPD_PATH_MAX]; /* TODO: cleanup */
|
const size_t musicDir_len = strlen(musicDir);
|
||||||
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;
|
|
||||||
|
|
||||||
if (!valid_playlist_name(fd, utf8path))
|
if (!valid_playlist_name(fd, utf8path))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
utf8_to_fs_playlist_path(path_max_tmp, utf8path);
|
utf8_to_fs_playlist_path(path_max_tmp, utf8path);
|
||||||
|
|
||||||
while (!(file = fopen(path_max_tmp, "r")) && errno == EINTR);
|
while (!(file = fopen(path_max_tmp, "r")) && errno == EINTR);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
|
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
|
||||||
@@ -137,66 +127,20 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
|
|||||||
if (!sp)
|
if (!sp)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
temp = utf8_to_fs_charset(path_max_tmp2, (char *)utf8path);
|
while (myFgets(buffer, sizeof(buffer), file)) {
|
||||||
parent = parent_path(path_max_tmp3, temp);
|
char *s = buffer;
|
||||||
parentlen = strlen(parent);
|
Song *song;
|
||||||
|
|
||||||
while ((tempInt = fgetc(file)) != EOF) {
|
if (*s == PLAYLIST_COMMENT)
|
||||||
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;
|
continue;
|
||||||
}
|
if (s[musicDir_len] == '/' &&
|
||||||
|
!strncmp(s, musicDir, musicDir_len))
|
||||||
if (!isValidRemoteUtf8Url(temp))
|
memmove(s, s + musicDir_len + 1,
|
||||||
continue;
|
strlen(s + musicDir_len + 1) + 1);
|
||||||
|
if ((song = getSongFromDB(s)))
|
||||||
song = newSong(temp, SONG_TYPE_URL, NULL);
|
|
||||||
if (song) {
|
|
||||||
appendSongToStoredPlaylist(sp, song);
|
appendSongToStoredPlaylist(sp, song);
|
||||||
freeJustSong(song);
|
else if (isValidRemoteUtf8Url(s))
|
||||||
}
|
insertInListWithoutKey(sp->list, xstrdup(s));
|
||||||
}
|
|
||||||
} 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++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
Reference in New Issue
Block a user