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
5e4be9e4
Commit
5e4be9e4
authored
Oct 08, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
song: replaced all song constructors
Provide separate constructors for creating a remote song, a local song, and one for loading data from a song file. This way, we can add more assertions.
parent
4a510a26
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
28 deletions
+49
-28
playlist.c
src/playlist.c
+2
-2
song.c
src/song.c
+32
-21
song.h
src/song.h
+12
-2
song_save.c
src/song_save.c
+2
-2
update.c
src/update.c
+1
-1
No files found.
src/playlist.c
View file @
5e4be9e4
...
...
@@ -561,7 +561,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id)
if
((
song
=
getSongFromDB
(
url
)))
{
}
else
if
(
!
(
isValidRemoteUtf8Url
(
url
)
&&
(
song
=
newSong
(
url
,
NULL
))))
{
(
song
=
song_remote_new
(
url
))))
{
return
PLAYLIST_RESULT_NO_SUCH_SONG
;
}
...
...
@@ -581,7 +581,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
if
(
!
isValidRemoteUtf8Url
(
url
))
return
ACK_ERROR_NO_EXIST
;
song
=
newSong
(
url
,
NULL
);
song
=
song_remote_new
(
url
);
if
(
song
)
{
int
ret
=
appendSongToStoredPlaylistByPath
(
utf8file
,
song
);
freeJustSong
(
song
);
...
...
src/song.c
View file @
5e4be9e4
...
...
@@ -26,7 +26,7 @@
#include "decoder_list.h"
#include "decoder_api.h"
struct
song
*
st
atic
st
ruct
song
*
song_alloc
(
const
char
*
url
,
struct
directory
*
parent
)
{
size_t
urllen
;
...
...
@@ -45,34 +45,45 @@ song_alloc(const char *url, struct directory *parent)
}
struct
song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
)
song_remote_new
(
const
char
*
url
)
{
return
song_alloc
(
url
,
NULL
);
}
struct
song
*
song_file_new
(
const
char
*
path
,
struct
directory
*
parent
)
{
assert
(
parent
!=
NULL
);
return
song_alloc
(
path
,
parent
);
}
struct
song
*
song_file_load
(
const
char
*
path
,
struct
directory
*
parent
)
{
struct
song
*
song
;
assert
(
*
url
);
struct
decoder_plugin
*
plugin
;
unsigned
int
next
=
0
;
char
path_max_tmp
[
MPD_PATH_MAX
],
*
abs_path
;
assert
(
parent
!=
NULL
);
if
(
strchr
(
url
,
'\n'
))
{
DEBUG
(
"newSong: '%s' is not a valid uri
\n
"
,
url
);
if
(
strchr
(
path
,
'\n'
))
{
DEBUG
(
"newSong: '%s' is not a valid uri
\n
"
,
path
);
return
NULL
;
}
song
=
song_
alloc
(
url
,
parentDir
);
song
=
song_
file_new
(
path
,
parent
);
if
(
song_is_file
(
song
))
{
struct
decoder_plugin
*
plugin
;
unsigned
int
next
=
0
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
*
abs_path
=
rmp2amp_r
(
path_max_tmp
,
get_song_url
(
path_max_tmp
,
song
));
abs_path
=
rmp2amp_r
(
path_max_tmp
,
get_song_url
(
path_max_tmp
,
song
));
while
(
song
->
tag
==
NULL
&&
(
plugin
=
isMusic
(
abs_path
,
&
(
song
->
mtime
),
next
++
)))
{
song
->
tag
=
plugin
->
tag_dup
(
abs_path
);
}
while
(
!
song
->
tag
&&
(
plugin
=
isMusic
(
abs_path
,
&
(
song
->
mtime
),
next
++
)))
{
song
->
tag
=
plugin
->
tag_dup
(
abs_path
);
}
if
(
!
song
->
tag
||
song
->
tag
->
time
<
0
)
{
freeJustSong
(
song
);
song
=
NULL
;
}
if
(
song
->
tag
==
NULL
||
song
->
tag
->
time
<
0
)
{
freeJustSong
(
song
);
return
NULL
;
}
return
song
;
...
...
src/song.h
View file @
5e4be9e4
...
...
@@ -36,11 +36,21 @@ struct song {
char
url
[
sizeof
(
int
)];
};
/** allocate a new song with a remote URL */
struct
song
*
song_
alloc
(
const
char
*
url
,
struct
directory
*
parent
);
song_
remote_new
(
const
char
*
url
);
/** allocate a new song with a local file name */
struct
song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
);
song_file_new
(
const
char
*
path
,
struct
directory
*
parent
);
/**
* allocate a new song structure with a local file name and attempt to
* load its metadata. If all decoder plugin fail to read its meta
* data, NULL is returned.
*/
struct
song
*
song_file_load
(
const
char
*
path
,
struct
directory
*
parent
);
void
freeJustSong
(
struct
song
*
);
...
...
src/song_save.c
View file @
5e4be9e4
...
...
@@ -113,8 +113,8 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
if
(
song
)
insertSongIntoList
(
sv
,
song
);
song
=
song_
alloc
(
buffer
+
strlen
(
SONG_KEY
),
parentDir
);
song
=
song_
file_new
(
buffer
+
strlen
(
SONG_KEY
),
parentDir
);
}
else
if
(
*
buffer
==
0
)
{
/* ignore empty lines (starting with '\0') */
}
else
if
(
song
==
NULL
)
{
...
...
src/update.c
View file @
5e4be9e4
...
...
@@ -201,7 +201,7 @@ addToDirectory(struct directory *directory, const char *name)
struct
song
*
song
;
const
char
*
shortname
=
mpd_basename
(
name
);
if
(
!
(
song
=
newSong
(
shortname
,
directory
)))
if
(
!
(
song
=
song_file_load
(
shortname
,
directory
)))
return
-
1
;
songvec_add
(
&
directory
->
songs
,
song
);
LOG
(
"added %s
\n
"
,
name
);
...
...
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