aboutsummaryrefslogtreecommitdiffstats
path: root/src/storedPlaylist.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2007-12-28 02:56:25 +0000
committerEric Wong <normalperson@yhbt.net>2007-12-28 02:56:25 +0000
commitb79f6b882a70526ec2e9fc231e0baeebdfef1e52 (patch)
tree719912135d059476070834c3c62ae940955e9e20 /src/storedPlaylist.c
parent0d26248a0d8cb2e5cf6be5a438a18b16793bbb63 (diff)
downloadmpd-b79f6b882a70526ec2e9fc231e0baeebdfef1e52.tar.gz
mpd-b79f6b882a70526ec2e9fc231e0baeebdfef1e52.tar.xz
mpd-b79f6b882a70526ec2e9fc231e0baeebdfef1e52.zip
Merge branches/ew r7104
thread-safety work in preparation for rewrite to use pthreads Expect no regressions against trunk (r7078), possibly minor performance improvements in update (due to fewer heap allocations), but increased stack usage. Applied the following patches: * maxpath_str for reentrancy (temporary fix, reverted) * path: start working on thread-safe variants of these methods * Re-entrancy work on path/character-set conversions * directory.c: exploreDirectory() use reentrant functions here * directory/update: more use of reentrant functions + cleanups * string_toupper: a strdup-less version of strDupToUpper * get_song_url: a static-variable-free version of getSongUrl() * Use reentrant/thread-safe get_song_url everywhere * replace rmp2amp with the reentrant version, rmp2amp_r * Get rid of the non-reentrant/non-thread-safe rpp2app, too. * buffer2array: assert strdup() returns a usable value in unit tests * replace utf8ToFsCharset and fsCharsetToUtf8 with thread-safe variants * fix storing playlists w/o absolute paths * parent_path(), a reentrant version of parentPath() * parentPath => parent_path for reentrancy and thread-safety * allow "make test" to automatically run embedded unit tests * remove convStrDup() and maxpath_str() * use MPD_PATH_MAX everywhere instead of MAXPATHLEN * path: get rid of appendSlash, pfx_path and just use pfx_dir * get_song_url: fix the ability to play songs in the top-level music_directory git-svn-id: https://svn.musicpd.org/mpd/trunk@7106 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/storedPlaylist.c')
-rw-r--r--src/storedPlaylist.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c
index 322cb1b5b..a166064ab 100644
--- a/src/storedPlaylist.c
+++ b/src/storedPlaylist.c
@@ -34,6 +34,7 @@ static char *utf8pathToFsPathInStoredPlaylist(const char *utf8path, int fd)
char *file;
char *rfile;
char *actualFile;
+ static char path_max_tmp[MPD_PATH_MAX]; /* should be MT-safe */
if (strstr(utf8path, "/")) {
commandError(fd, ACK_ERROR_ARG, "playlist name \"%s\" is "
@@ -42,8 +43,7 @@ static char *utf8pathToFsPathInStoredPlaylist(const char *utf8path, int fd)
return NULL;
}
- file = utf8ToFsCharset((char *)utf8path);
-
+ file = utf8_to_fs_charset(path_max_tmp, (char *)utf8path);
rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
@@ -51,7 +51,7 @@ static char *utf8pathToFsPathInStoredPlaylist(const char *utf8path, int fd)
strcat(rfile, ".");
strcat(rfile, PLAYLIST_FILE_SUFFIX);
- actualFile = rpp2app(rfile);
+ actualFile = rpp2app_r(path_max_tmp, rfile);
free(rfile);
@@ -100,7 +100,10 @@ static ListNode *nodeOfStoredPlaylist(StoredPlaylist *sp, int index)
static void appendSongToStoredPlaylist(StoredPlaylist *sp, Song *song)
{
- insertInListWithoutKey(sp->list, xstrdup(getSongUrl(song)));
+ char path_max_tmp[MPD_PATH_MAX];
+
+ get_song_url(path_max_tmp, song);
+ insertInListWithoutKey(sp->list, xstrdup(path_max_tmp));
}
StoredPlaylist *newStoredPlaylist(const char *utf8name, int fd, int ignoreExisting)
@@ -138,10 +141,13 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
char *filename;
StoredPlaylist *sp;
FILE *file;
- char s[MAXPATHLEN + 1];
+ char s[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 = utf8ToFsCharset((char *)utf8path);
- char *parent = parentPath(temp);
+ char *temp = utf8_to_fs_charset(path_max_tmp2, (char *)utf8path);
+ char *parent = parent_path(path_max_tmp3, temp);
int parentlen = strlen(parent);
int tempInt;
int commentCharFound = 0;
@@ -169,15 +175,18 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
s[slength] = '\0';
if (s[0] == PLAYLIST_COMMENT)
commentCharFound = 1;
- if (strncmp(s, musicDir, strlen(musicDir)) == 0) {
- strcpy(s, &(s[strlen(musicDir)]));
+ if (!strncmp(s, musicDir, strlen(musicDir)) &&
+ s[strlen(musicDir)] == '/') {
+ memmove(s, &(s[strlen(musicDir) + 1]),
+ strlen(&(s[strlen(musicDir) + 1])) + 1);
+ printf("s: <%s>\n", s);
} else if (parentlen) {
temp = xstrdup(s);
- memset(s, 0, MAXPATHLEN + 1);
+ memset(s, 0, MPD_PATH_MAX);
strcpy(s, parent);
- strncat(s, "/", MAXPATHLEN - parentlen);
- strncat(s, temp, MAXPATHLEN - parentlen - 1);
- if (strlen(s) >= MAXPATHLEN) {
+ 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);
@@ -189,7 +198,7 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
free(temp);
}
slength = 0;
- temp = fsCharsetToUtf8(s);
+ temp = fs_charset_to_utf8(path_max_tmp, s);
if (temp && !commentCharFound) {
song = getSongFromDB(temp);
if (song) {
@@ -206,7 +215,7 @@ StoredPlaylist *loadStoredPlaylist(const char *utf8path, int fd)
freeJustSong(song);
}
}
- } else if (slength == MAXPATHLEN) {
+ } else if (slength == (MPD_PATH_MAX - 1)) {
s[slength] = '\0';
commandError(sp->fd, ACK_ERROR_PLAYLIST_LOAD,
"line \"%s\" in playlist \"%s\" "
@@ -401,11 +410,11 @@ static int writeStoredPlaylistToPath(StoredPlaylist *sp, const char *fspath)
node = sp->list->firstNode;
while (node != NULL) {
- s = (char *)node->data;
- if (isValidRemoteUtf8Url(s) || !playlist_saveAbsolutePaths)
- s = utf8ToFsCharset(s);
- else
- s = rmp2amp(utf8ToFsCharset(s));
+ char path_max_tmp[MPD_PATH_MAX];
+
+ s = utf8_to_fs_charset(path_max_tmp, (char *)node->data);
+ if (playlist_saveAbsolutePaths && !isValidRemoteUtf8Url(s))
+ s = rmp2amp_r(path_max_tmp, s);
fprintf(file, "%s\n", s);
node = node->nextNode;
}
@@ -424,6 +433,8 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
char *filename;
FILE *file;
char *s;
+ char path_max_tmp[MPD_PATH_MAX];
+ char path_max_tmp2[MPD_PATH_MAX];
filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd);
if (!filename)
@@ -436,10 +447,10 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
return -1;
}
+ s = utf8_to_fs_charset(path_max_tmp2, get_song_url(path_max_tmp, song));
+
if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE)
- s = rmp2amp(utf8ToFsCharset(getSongUrl(song)));
- else
- s = utf8ToFsCharset(getSongUrl(song));
+ s = rmp2amp_r(path_max_tmp, s);
fprintf(file, "%s\n", s);