Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
daf7c3db
Commit
daf7c3db
authored
Jan 02, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapper: allocate the result of map_directory_child_fs(), map_song_fs()
Don't use fixed stack buffers.
parent
72255d58
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
53 deletions
+72
-53
decoder_thread.c
src/decoder_thread.c
+25
-14
mapper.c
src/mapper.c
+12
-11
mapper.h
src/mapper.h
+4
-5
playlist_save.c
src/playlist_save.c
+4
-2
song.c
src/song.c
+9
-7
update.c
src/update.c
+18
-14
No files found.
src/decoder_thread.c
View file @
daf7c3db
...
...
@@ -74,27 +74,14 @@ decoder_file_decode(const struct decoder_plugin *plugin,
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
;
int
ret
;
bool
close_instream
=
true
;
struct
input_stream
input_stream
;
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
))
{
dc
.
state
=
DECODE_STATE_ERROR
;
return
;
...
...
@@ -202,6 +189,30 @@ static void decoder_run(void)
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
)
{
do
{
...
...
src/mapper.c
View file @
daf7c3db
...
...
@@ -108,11 +108,11 @@ map_directory_fs(const struct directory *directory)
return
map_uri_fs
(
dirname
);
}
const
char
*
map_directory_child_fs
(
const
struct
directory
*
directory
,
const
char
*
name
,
char
*
buffer
)
char
*
map_directory_child_fs
(
const
struct
directory
*
directory
,
const
char
*
name
)
{
char
*
parent_fs
;
char
buffer
[
MPD_PATH_MAX
];
char
*
parent_fs
,
*
path
;
/* check for invalid or unauthorized base names */
if
(
*
name
==
0
||
strchr
(
name
,
'/'
)
!=
NULL
||
...
...
@@ -124,21 +124,22 @@ map_directory_child_fs(const struct directory *directory, const char *name,
return
NULL
;
name
=
utf8_to_fs_charset
(
buffer
,
name
);
pfx_dir
(
buffer
,
name
,
strlen
(
name
),
parent_fs
,
strlen
(
parent_fs
));
path
=
g_build_filename
(
parent_fs
,
name
,
NULL
);
g_free
(
parent_fs
);
return
buffer
;
return
path
;
}
c
onst
c
har
*
map_song_fs
(
const
struct
song
*
song
,
char
*
buffer
)
char
*
map_song_fs
(
const
struct
song
*
song
)
{
char
buffer
[
MPD_PATH_MAX
];
assert
(
song_is_file
(
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
return
utf8_to_fs_charset
(
buffer
,
song
->
url
);
return
g_strdup
(
utf8_to_fs_charset
(
buffer
,
song
->
url
)
);
}
const
char
*
...
...
src/mapper.h
View file @
daf7c3db
...
...
@@ -59,9 +59,8 @@ map_directory_fs(const struct directory *directory);
* @param a buffer which is MPD_PATH_MAX bytes long
* @return the path in file system encoding, or NULL if mapping failed
*/
const
char
*
map_directory_child_fs
(
const
struct
directory
*
directory
,
const
char
*
name
,
char
*
buffer
);
char
*
map_directory_child_fs
(
const
struct
directory
*
directory
,
const
char
*
name
);
/**
* 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
* @return the path in file system encoding, or NULL if mapping failed
*/
c
onst
c
har
*
map_song_fs
(
const
struct
song
*
song
,
char
*
buffer
);
char
*
map_song_fs
(
const
struct
song
*
song
);
/**
* Maps a file system path (relative to the music directory or
...
...
src/playlist_save.c
View file @
daf7c3db
...
...
@@ -32,9 +32,11 @@ playlist_print_song(FILE *file, const struct song *song)
char
tmp1
[
MPD_PATH_MAX
],
tmp2
[
MPD_PATH_MAX
];
if
(
playlist_saveAbsolutePaths
&&
song_in_database
(
song
))
{
c
onst
char
*
path
=
map_song_fs
(
song
,
tmp1
);
if
(
path
!=
NULL
)
c
har
*
path
=
map_song_fs
(
song
);
if
(
path
!=
NULL
)
{
fprintf
(
file
,
"%s
\n
"
,
path
);
g_free
(
path
);
}
}
else
{
song_get_url
(
song
,
tmp1
);
utf8_to_fs_charset
(
tmp2
,
tmp1
);
...
...
src/song.c
View file @
daf7c3db
...
...
@@ -104,15 +104,14 @@ song_free(struct song *song)
bool
song_file_update
(
struct
song
*
song
)
{
char
buffer
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
char
*
path_fs
;
const
struct
decoder_plugin
*
plugin
;
unsigned
int
next
=
0
;
struct
stat
st
;
assert
(
song_is_file
(
song
));
path_fs
=
map_song_fs
(
song
,
buffer
);
path_fs
=
map_song_fs
(
song
);
if
(
path_fs
==
NULL
)
return
false
;
...
...
@@ -121,8 +120,10 @@ song_file_update(struct song *song)
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
;
}
song
->
mtime
=
st
.
st_mtime
;
...
...
@@ -130,19 +131,19 @@ song_file_update(struct song *song)
(
plugin
=
hasMusicSuffix
(
path_fs
,
next
++
)))
song
->
tag
=
plugin
->
tag_dup
(
path_fs
);
g_free
(
path_fs
);
return
song
->
tag
!=
NULL
;
}
bool
song_file_update_inarchive
(
struct
song
*
song
)
{
char
buffer
[
MPD_PATH_MAX
];
const
char
*
path_fs
;
char
*
path_fs
;
const
struct
decoder_plugin
*
plugin
;
assert
(
song_is_file
(
song
));
path_fs
=
map_song_fs
(
song
,
buffer
);
path_fs
=
map_song_fs
(
song
);
if
(
path_fs
==
NULL
)
return
false
;
...
...
@@ -154,6 +155,7 @@ song_file_update_inarchive(struct song *song)
//because we dont support tag reading throught
//input streams
plugin
=
hasMusicSuffix
(
path_fs
,
0
);
g_free
(
path_fs
);
if
(
plugin
)
{
song
->
tag
=
tag_new
();
//tag_add_item(tag, TAG_ITEM_TITLE, f->title);
...
...
src/update.c
View file @
daf7c3db
...
...
@@ -163,7 +163,6 @@ delete_name_in(struct directory *parent, const char *name)
}
struct
delete_data
{
char
*
tmp
;
struct
directory
*
dir
;
};
...
...
@@ -172,19 +171,21 @@ static int
delete_song_if_removed
(
struct
song
*
song
,
void
*
_data
)
{
struct
delete_data
*
data
=
_data
;
c
onst
c
har
*
path
;
char
*
path
;
struct
stat
st
;
if
((
path
=
map_song_fs
(
song
,
data
->
tmp
))
==
NULL
||
stat
(
data
->
tmp
,
&
st
)
<
0
||
!
S_ISREG
(
st
.
st_mode
))
{
if
((
path
=
map_song_fs
(
song
))
==
NULL
||
stat
(
path
,
&
st
)
<
0
||
!
S_ISREG
(
st
.
st_mode
))
{
delete_song
(
data
->
dir
,
song
);
modified
=
true
;
}
g_free
(
path
);
return
0
;
}
static
void
removeDeletedFromDirectory
(
char
*
path_max_tmp
,
struct
directory
*
directory
)
removeDeletedFromDirectory
(
struct
directory
*
directory
)
{
int
i
;
struct
dirvec
*
dv
=
&
directory
->
children
;
...
...
@@ -208,7 +209,6 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
}
data
.
dir
=
directory
;
data
.
tmp
=
path_max_tmp
;
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
,
struct
stat
*
st
)
{
char
buffer
[
MPD_PATH_MAX
]
;
const
char
*
path_fs
;
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
)
return
-
1
;
return
stat
(
path_fs
,
st
);
ret
=
stat
(
path_fs
,
st
);
g_free
(
path_fs
);
return
ret
;
}
static
int
...
...
@@ -424,14 +426,16 @@ static bool
skip_symlink
(
const
struct
directory
*
directory
,
const
char
*
utf8_name
)
{
char
buffer
[
MPD_PATH_MAX
];
char
*
path_fs
;
const
char
*
p
;
ssize_t
ret
;
p
=
map_directory_child_fs
(
directory
,
utf8_name
,
buffer
);
if
(
p
==
NULL
)
p
ath_fs
=
map_directory_child_fs
(
directory
,
utf8_name
);
if
(
p
ath_fs
==
NULL
)
return
true
;
ret
=
readlink
(
p
,
buffer
,
sizeof
(
buffer
));
ret
=
readlink
(
path_fs
,
buffer
,
sizeof
(
buffer
));
g_free
(
path_fs
);
if
(
ret
<
0
)
/* don't skip if this is not a symlink */
return
errno
!=
EINVAL
;
...
...
@@ -493,7 +497,7 @@ updateDirectory(struct directory *directory, const struct stat *st)
if
(
!
dir
)
return
false
;
removeDeletedFromDirectory
(
path_max_tmp
,
directory
);
removeDeletedFromDirectory
(
directory
);
while
((
ent
=
readdir
(
dir
)))
{
char
*
utf8
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment