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
cc5443c3
Commit
cc5443c3
authored
Feb 22, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag/ApeLoader: use class InputStream instead of FILE*
Prepare for APE tag support on userspace NFS/SMB/CIFS mounts.
parent
8a86460b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
14 deletions
+67
-14
Makefile.am
Makefile.am
+6
-1
ApeLoader.cxx
src/tag/ApeLoader.cxx
+24
-13
ApeLoader.hxx
src/tag/ApeLoader.hxx
+10
-0
ApeTag.cxx
src/tag/ApeTag.cxx
+17
-0
ApeTag.hxx
src/tag/ApeTag.hxx
+10
-0
No files found.
Makefile.am
View file @
cc5443c3
...
...
@@ -1882,10 +1882,15 @@ test_read_tags_SOURCES = test/read_tags.cxx \
test_ReadApeTags_LDADD
=
\
$(TAG_LIBS)
\
$(INPUT_LIBS)
\
$(ARCHIVE_LIBS)
\
$(FS_LIBS)
\
$(ICU_LDADD)
\
libsystem.a
\
libutil.a
test_ReadApeTags_SOURCES
=
test
/ReadApeTags.cxx
test_ReadApeTags_SOURCES
=
\
src/Log.cxx src/LogBackend.cxx
\
test
/ReadApeTags.cxx
if
ENABLE_ID3TAG
test_dump_rva2_LDADD
=
\
...
...
src/tag/ApeLoader.cxx
View file @
cc5443c3
...
...
@@ -20,12 +20,16 @@
#include "config.h"
#include "ApeLoader.hxx"
#include "system/ByteOrder.hxx"
#include "fs/FileSystem.hxx"
#include "fs/Path.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "input/InputStream.hxx"
#include "input/LocalOpen.hxx"
#include "util/StringView.hxx"
#include "util/Error.hxx"
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
struct
ape_footer
{
...
...
@@ -37,13 +41,18 @@ struct ape_footer {
unsigned
char
reserved
[
8
];
};
static
bool
ape_scan_internal
(
FILE
*
fp
,
ApeTagCallback
callback
)
bool
tag_ape_scan
(
InputStream
&
is
,
ApeTagCallback
callback
)
{
const
ScopeLock
protect
(
is
.
mutex
);
if
(
!
is
.
KnownSize
()
||
!
is
.
CheapSeeking
())
return
false
;
/* determine if file has an apeV2 tag */
struct
ape_footer
footer
;
if
(
fseek
(
fp
,
-
(
long
)
sizeof
(
footer
),
SEEK_END
)
||
fread
(
&
footer
,
1
,
sizeof
(
footer
),
fp
)
!=
sizeof
(
footer
)
||
if
(
!
is
.
Seek
(
is
.
GetSize
()
-
sizeof
(
footer
),
IgnoreError
()
)
||
!
is
.
ReadFull
(
&
footer
,
sizeof
(
footer
),
IgnoreError
()
)
||
memcmp
(
footer
.
id
,
"APETAGEX"
,
sizeof
(
footer
.
id
))
!=
0
||
FromLE32
(
footer
.
version
)
!=
2000
)
return
false
;
...
...
@@ -53,7 +62,7 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
if
(
remaining
<=
sizeof
(
footer
)
+
10
||
/* refuse to load more than one megabyte of tag data */
remaining
>
1024
*
1024
||
fseek
(
fp
,
-
(
long
)
remaining
,
SEEK_END
))
!
is
.
Seek
(
is
.
GetSize
()
-
remaining
,
IgnoreError
()
))
return
false
;
/* read tag into buffer */
...
...
@@ -61,7 +70,7 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
assert
(
remaining
>
10
);
char
*
buffer
=
new
char
[
remaining
];
if
(
fread
(
buffer
,
1
,
remaining
,
fp
)
!=
remaining
)
{
if
(
!
is
.
ReadFull
(
buffer
,
remaining
,
IgnoreError
())
)
{
delete
[]
buffer
;
return
false
;
}
...
...
@@ -104,11 +113,13 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
bool
tag_ape_scan
(
Path
path_fs
,
ApeTagCallback
callback
)
{
FILE
*
fp
=
FOpen
(
path_fs
,
PATH_LITERAL
(
"rb"
));
if
(
fp
==
nullptr
)
Mutex
mutex
;
Cond
cond
;
std
::
unique_ptr
<
InputStream
>
is
(
OpenLocalInputStream
(
path_fs
,
mutex
,
cond
,
IgnoreError
()));
if
(
!
is
)
return
false
;
bool
success
=
ape_scan_internal
(
fp
,
callback
);
fclose
(
fp
);
return
success
;
return
tag_ape_scan
(
*
is
,
callback
);
}
src/tag/ApeLoader.hxx
View file @
cc5443c3
...
...
@@ -28,6 +28,7 @@
struct
StringView
;
class
Path
;
class
InputStream
;
typedef
std
::
function
<
bool
(
unsigned
long
flags
,
const
char
*
key
,
StringView
value
)
>
ApeTagCallback
;
...
...
@@ -35,6 +36,15 @@ typedef std::function<bool(unsigned long flags, const char *key,
/**
* Scans the APE tag values from a file.
*
* @return false if the file could not be opened or if no APE tag is
* present
*/
bool
tag_ape_scan
(
InputStream
&
is
,
ApeTagCallback
callback
);
/**
* Scans the APE tag values from a file.
*
* @param path_fs the path of the file in filesystem encoding
* @return false if the file could not be opened or if no APE tag is
* present
...
...
src/tag/ApeTag.cxx
View file @
cc5443c3
...
...
@@ -106,6 +106,23 @@ tag_ape_import_item(unsigned long flags,
}
bool
tag_ape_scan2
(
InputStream
&
is
,
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
{
bool
recognized
=
false
;
auto
callback
=
[
handler
,
handler_ctx
,
&
recognized
]
(
unsigned
long
flags
,
const
char
*
key
,
StringView
value
)
{
recognized
|=
tag_ape_import_item
(
flags
,
key
,
value
,
handler
,
handler_ctx
);
return
true
;
};
return
tag_ape_scan
(
is
,
callback
)
&&
recognized
;
}
bool
tag_ape_scan2
(
Path
path_fs
,
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
{
...
...
src/tag/ApeTag.hxx
View file @
cc5443c3
...
...
@@ -23,11 +23,21 @@
#include "TagTable.hxx"
class
Path
;
class
InputStream
;
struct
tag_handler
;
extern
const
struct
tag_table
ape_tags
[];
/**
* Scan the APE tags of a stream.
*
* @param path_fs the path of the file in filesystem encoding
*/
bool
tag_ape_scan2
(
InputStream
&
is
,
const
tag_handler
*
handler
,
void
*
handler_ctx
);
/**
* Scan the APE tags of a file.
*
* @param path_fs the path of the file in filesystem encoding
...
...
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