mapper: allocate the result of map_directory_child_fs(), map_song_fs()
Don't use fixed stack buffers.
This commit is contained in:
parent
72255d580e
commit
daf7c3db5a
@ -74,27 +74,14 @@ decoder_file_decode(const struct decoder_plugin *plugin,
|
|||||||
return dc.state != DECODE_STATE_START;
|
return dc.state != DECODE_STATE_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decoder_run(void)
|
static void decoder_run_song(const struct song *song, const char *uri)
|
||||||
{
|
{
|
||||||
struct song *song = dc.next_song;
|
|
||||||
char buffer[MPD_PATH_MAX];
|
|
||||||
const char *uri;
|
|
||||||
struct decoder decoder;
|
struct decoder decoder;
|
||||||
int ret;
|
int ret;
|
||||||
bool close_instream = true;
|
bool close_instream = true;
|
||||||
struct input_stream input_stream;
|
struct input_stream input_stream;
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
|
|
||||||
if (song_is_file(song))
|
|
||||||
uri = map_song_fs(song, buffer);
|
|
||||||
else
|
|
||||||
uri = song_get_url(song, buffer);
|
|
||||||
if (uri == NULL) {
|
|
||||||
dc.state = DECODE_STATE_ERROR;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.current_song = dc.next_song; /* NEED LOCK */
|
|
||||||
if (!input_stream_open(&input_stream, uri)) {
|
if (!input_stream_open(&input_stream, uri)) {
|
||||||
dc.state = DECODE_STATE_ERROR;
|
dc.state = DECODE_STATE_ERROR;
|
||||||
return;
|
return;
|
||||||
@ -202,6 +189,30 @@ static void decoder_run(void)
|
|||||||
dc.state = ret ? DECODE_STATE_STOP : DECODE_STATE_ERROR;
|
dc.state = ret ? DECODE_STATE_STOP : DECODE_STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void decoder_run(void)
|
||||||
|
{
|
||||||
|
struct song *song = dc.next_song;
|
||||||
|
char *uri;
|
||||||
|
|
||||||
|
if (song_is_file(song))
|
||||||
|
uri = map_song_fs(song);
|
||||||
|
else {
|
||||||
|
char buffer[MPD_PATH_MAX];
|
||||||
|
|
||||||
|
uri = g_strdup(song_get_url(song, buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uri == NULL) {
|
||||||
|
dc.state = DECODE_STATE_ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.current_song = dc.next_song; /* NEED LOCK */
|
||||||
|
decoder_run_song(song, uri);
|
||||||
|
g_free(uri);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static gpointer decoder_task(G_GNUC_UNUSED gpointer arg)
|
static gpointer decoder_task(G_GNUC_UNUSED gpointer arg)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
|
23
src/mapper.c
23
src/mapper.c
@ -108,11 +108,11 @@ map_directory_fs(const struct directory *directory)
|
|||||||
return map_uri_fs(dirname);
|
return map_uri_fs(dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
char *
|
||||||
map_directory_child_fs(const struct directory *directory, const char *name,
|
map_directory_child_fs(const struct directory *directory, const char *name)
|
||||||
char *buffer)
|
|
||||||
{
|
{
|
||||||
char *parent_fs;
|
char buffer[MPD_PATH_MAX];
|
||||||
|
char *parent_fs, *path;
|
||||||
|
|
||||||
/* check for invalid or unauthorized base names */
|
/* check for invalid or unauthorized base names */
|
||||||
if (*name == 0 || strchr(name, '/') != NULL ||
|
if (*name == 0 || strchr(name, '/') != NULL ||
|
||||||
@ -124,21 +124,22 @@ map_directory_child_fs(const struct directory *directory, const char *name,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
name = utf8_to_fs_charset(buffer, name);
|
name = utf8_to_fs_charset(buffer, name);
|
||||||
pfx_dir(buffer, name, strlen(name),
|
path = g_build_filename(parent_fs, name, NULL);
|
||||||
parent_fs, strlen(parent_fs));
|
|
||||||
g_free(parent_fs);
|
g_free(parent_fs);
|
||||||
return buffer;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
char *
|
||||||
map_song_fs(const struct song *song, char *buffer)
|
map_song_fs(const struct song *song)
|
||||||
{
|
{
|
||||||
|
char buffer[MPD_PATH_MAX];
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
if (song_in_database(song))
|
if (song_in_database(song))
|
||||||
return map_directory_child_fs(song->parent, song->url, buffer);
|
return map_directory_child_fs(song->parent, song->url);
|
||||||
else
|
else
|
||||||
return utf8_to_fs_charset(buffer, song->url);
|
return g_strdup(utf8_to_fs_charset(buffer, song->url));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -59,9 +59,8 @@ map_directory_fs(const struct directory *directory);
|
|||||||
* @param a buffer which is MPD_PATH_MAX bytes long
|
* @param a buffer which is MPD_PATH_MAX bytes long
|
||||||
* @return the path in file system encoding, or NULL if mapping failed
|
* @return the path in file system encoding, or NULL if mapping failed
|
||||||
*/
|
*/
|
||||||
const char *
|
char *
|
||||||
map_directory_child_fs(const struct directory *directory, const char *name,
|
map_directory_child_fs(const struct directory *directory, const char *name);
|
||||||
char *buffer);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the file system path of a song. This must not be a
|
* Determines the file system path of a song. This must not be a
|
||||||
@ -71,8 +70,8 @@ map_directory_child_fs(const struct directory *directory, const char *name,
|
|||||||
* @param a buffer which is MPD_PATH_MAX bytes long
|
* @param a buffer which is MPD_PATH_MAX bytes long
|
||||||
* @return the path in file system encoding, or NULL if mapping failed
|
* @return the path in file system encoding, or NULL if mapping failed
|
||||||
*/
|
*/
|
||||||
const char *
|
char *
|
||||||
map_song_fs(const struct song *song, char *buffer);
|
map_song_fs(const struct song *song);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps a file system path (relative to the music directory or
|
* Maps a file system path (relative to the music directory or
|
||||||
|
@ -32,9 +32,11 @@ playlist_print_song(FILE *file, const struct song *song)
|
|||||||
char tmp1[MPD_PATH_MAX], tmp2[MPD_PATH_MAX];
|
char tmp1[MPD_PATH_MAX], tmp2[MPD_PATH_MAX];
|
||||||
|
|
||||||
if (playlist_saveAbsolutePaths && song_in_database(song)) {
|
if (playlist_saveAbsolutePaths && song_in_database(song)) {
|
||||||
const char *path = map_song_fs(song, tmp1);
|
char *path = map_song_fs(song);
|
||||||
if (path != NULL)
|
if (path != NULL) {
|
||||||
fprintf(file, "%s\n", path);
|
fprintf(file, "%s\n", path);
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
song_get_url(song, tmp1);
|
song_get_url(song, tmp1);
|
||||||
utf8_to_fs_charset(tmp2, tmp1);
|
utf8_to_fs_charset(tmp2, tmp1);
|
||||||
|
16
src/song.c
16
src/song.c
@ -104,15 +104,14 @@ song_free(struct song *song)
|
|||||||
bool
|
bool
|
||||||
song_file_update(struct song *song)
|
song_file_update(struct song *song)
|
||||||
{
|
{
|
||||||
char buffer[MPD_PATH_MAX];
|
char *path_fs;
|
||||||
const char *path_fs;
|
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
unsigned int next = 0;
|
unsigned int next = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
path_fs = map_song_fs(song, buffer);
|
path_fs = map_song_fs(song);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -121,8 +120,10 @@ song_file_update(struct song *song)
|
|||||||
song->tag = NULL;
|
song->tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode))
|
if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) {
|
||||||
|
g_free(path_fs);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
song->mtime = st.st_mtime;
|
song->mtime = st.st_mtime;
|
||||||
|
|
||||||
@ -130,19 +131,19 @@ song_file_update(struct song *song)
|
|||||||
(plugin = hasMusicSuffix(path_fs, next++)))
|
(plugin = hasMusicSuffix(path_fs, next++)))
|
||||||
song->tag = plugin->tag_dup(path_fs);
|
song->tag = plugin->tag_dup(path_fs);
|
||||||
|
|
||||||
|
g_free(path_fs);
|
||||||
return song->tag != NULL;
|
return song->tag != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
song_file_update_inarchive(struct song *song)
|
song_file_update_inarchive(struct song *song)
|
||||||
{
|
{
|
||||||
char buffer[MPD_PATH_MAX];
|
char *path_fs;
|
||||||
const char *path_fs;
|
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
|
|
||||||
assert(song_is_file(song));
|
assert(song_is_file(song));
|
||||||
|
|
||||||
path_fs = map_song_fs(song, buffer);
|
path_fs = map_song_fs(song);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -154,6 +155,7 @@ song_file_update_inarchive(struct song *song)
|
|||||||
//because we dont support tag reading throught
|
//because we dont support tag reading throught
|
||||||
//input streams
|
//input streams
|
||||||
plugin = hasMusicSuffix(path_fs, 0);
|
plugin = hasMusicSuffix(path_fs, 0);
|
||||||
|
g_free(path_fs);
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
song->tag = tag_new();
|
song->tag = tag_new();
|
||||||
//tag_add_item(tag, TAG_ITEM_TITLE, f->title);
|
//tag_add_item(tag, TAG_ITEM_TITLE, f->title);
|
||||||
|
32
src/update.c
32
src/update.c
@ -163,7 +163,6 @@ delete_name_in(struct directory *parent, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct delete_data {
|
struct delete_data {
|
||||||
char *tmp;
|
|
||||||
struct directory *dir;
|
struct directory *dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,19 +171,21 @@ static int
|
|||||||
delete_song_if_removed(struct song *song, void *_data)
|
delete_song_if_removed(struct song *song, void *_data)
|
||||||
{
|
{
|
||||||
struct delete_data *data = _data;
|
struct delete_data *data = _data;
|
||||||
const char *path;
|
char *path;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if ((path = map_song_fs(song, data->tmp)) == NULL ||
|
if ((path = map_song_fs(song)) == NULL ||
|
||||||
stat(data->tmp, &st) < 0 || !S_ISREG(st.st_mode)) {
|
stat(path, &st) < 0 || !S_ISREG(st.st_mode)) {
|
||||||
delete_song(data->dir, song);
|
delete_song(data->dir, song);
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
|
removeDeletedFromDirectory(struct directory *directory)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct dirvec *dv = &directory->children;
|
struct dirvec *dv = &directory->children;
|
||||||
@ -208,7 +209,6 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.dir = directory;
|
data.dir = directory;
|
||||||
data.tmp = path_max_tmp;
|
|
||||||
songvec_for_each(&directory->songs, delete_song_if_removed, &data);
|
songvec_for_each(&directory->songs, delete_song_if_removed, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,14 +230,16 @@ static int
|
|||||||
stat_directory_child(const struct directory *parent, const char *name,
|
stat_directory_child(const struct directory *parent, const char *name,
|
||||||
struct stat *st)
|
struct stat *st)
|
||||||
{
|
{
|
||||||
char buffer[MPD_PATH_MAX];
|
char *path_fs;
|
||||||
const char *path_fs;
|
int ret;
|
||||||
|
|
||||||
path_fs = map_directory_child_fs(parent, name, buffer);
|
path_fs = map_directory_child_fs(parent, name);
|
||||||
if (path_fs == NULL)
|
if (path_fs == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return stat(path_fs, st);
|
ret = stat(path_fs, st);
|
||||||
|
g_free(path_fs);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -424,14 +426,16 @@ static bool
|
|||||||
skip_symlink(const struct directory *directory, const char *utf8_name)
|
skip_symlink(const struct directory *directory, const char *utf8_name)
|
||||||
{
|
{
|
||||||
char buffer[MPD_PATH_MAX];
|
char buffer[MPD_PATH_MAX];
|
||||||
|
char *path_fs;
|
||||||
const char *p;
|
const char *p;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
p = map_directory_child_fs(directory, utf8_name, buffer);
|
path_fs = map_directory_child_fs(directory, utf8_name);
|
||||||
if (p == NULL)
|
if (path_fs == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ret = readlink(p, buffer, sizeof(buffer));
|
ret = readlink(path_fs, buffer, sizeof(buffer));
|
||||||
|
g_free(path_fs);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
/* don't skip if this is not a symlink */
|
/* don't skip if this is not a symlink */
|
||||||
return errno != EINVAL;
|
return errno != EINVAL;
|
||||||
@ -493,7 +497,7 @@ updateDirectory(struct directory *directory, const struct stat *st)
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
removeDeletedFromDirectory(path_max_tmp, directory);
|
removeDeletedFromDirectory(directory);
|
||||||
|
|
||||||
while ((ent = readdir(dir))) {
|
while ((ent = readdir(dir))) {
|
||||||
char *utf8;
|
char *utf8;
|
||||||
|
Loading…
Reference in New Issue
Block a user