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
f5c0b0d3
Commit
f5c0b0d3
authored
Jan 29, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ArchiveFile: convert to a class
parent
ba51045d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
66 additions
and
85 deletions
+66
-85
Makefile.am
Makefile.am
+1
-1
ArchiveFile.hxx
src/ArchiveFile.hxx
+8
-11
ArchivePlugin.cxx
src/ArchivePlugin.cxx
+15
-21
ArchivePlugin.hxx
src/ArchivePlugin.hxx
+9
-9
UpdateArchive.cxx
src/UpdateArchive.cxx
+1
-2
Bzip2ArchivePlugin.cxx
src/archive/Bzip2ArchivePlugin.cxx
+10
-13
Iso9660ArchivePlugin.cxx
src/archive/Iso9660ArchivePlugin.cxx
+9
-13
ZzipArchivePlugin.cxx
src/archive/ZzipArchivePlugin.cxx
+9
-12
ArchiveInputPlugin.cxx
src/input/ArchiveInputPlugin.cxx
+1
-2
visit_archive.cxx
test/visit_archive.cxx
+3
-1
No files found.
Makefile.am
View file @
f5c0b0d3
...
...
@@ -399,7 +399,7 @@ libarchive_a_SOURCES = \
src/ArchiveList.cxx src/ArchiveList.hxx
\
src/ArchivePlugin.cxx src/ArchivePlugin.hxx
\
src/ArchiveVisitor.hxx
\
src/Archive
Internal
.hxx
\
src/Archive
File
.hxx
\
src/input/ArchiveInputPlugin.cxx src/input/ArchiveInputPlugin.hxx
libarchive_a_CPPFLAGS
=
$(AM_CPPFLAGS)
\
$(BZ2_CFLAGS)
\
...
...
src/Archive
Internal
.hxx
→
src/Archive
File
.hxx
View file @
f5c0b0d3
...
...
@@ -17,18 +17,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ARCHIVE_
INTERNAL
_HXX
#define MPD_ARCHIVE_
INTERNAL
_HXX
#ifndef MPD_ARCHIVE_
FILE
_HXX
#define MPD_ARCHIVE_
FILE
_HXX
struct
archive_f
ile
{
const
struct
archive_plugin
*
plugin
;
}
;
class
ArchiveF
ile
{
public
:
const
struct
archive_plugin
&
plugin
;
static
inline
void
archive_file_init
(
struct
archive_file
*
archive_file
,
const
struct
archive_plugin
*
plugin
)
{
archive_file
->
plugin
=
plugin
;
}
ArchiveFile
(
const
struct
archive_plugin
&
_plugin
)
:
plugin
(
_plugin
)
{}
};
#endif
src/ArchivePlugin.cxx
View file @
f5c0b0d3
...
...
@@ -18,28 +18,25 @@
*/
#include "ArchivePlugin.hxx"
#include "Archive
Internal
.hxx"
#include "Archive
File
.hxx"
#include <assert.h>
struct
archive_f
ile
*
ArchiveF
ile
*
archive_file_open
(
const
struct
archive_plugin
*
plugin
,
const
char
*
path
,
GError
**
error_r
)
{
struct
archive_file
*
file
;
assert
(
plugin
!=
NULL
);
assert
(
plugin
->
open
!=
NULL
);
assert
(
path
!=
NULL
);
assert
(
error_r
==
NULL
||
*
error_r
==
NULL
);
file
=
plugin
->
open
(
path
,
error_r
);
ArchiveFile
*
file
=
plugin
->
open
(
path
,
error_r
);
if
(
file
!=
NULL
)
{
assert
(
file
->
plugin
!=
NULL
);
assert
(
file
->
plugin
->
close
!=
NULL
);
assert
(
file
->
plugin
->
visit
!=
nullptr
);
assert
(
file
->
plugin
->
open_stream
!=
NULL
);
assert
(
file
->
plugin
.
close
!=
NULL
);
assert
(
file
->
plugin
.
visit
!=
nullptr
);
assert
(
file
->
plugin
.
open_stream
!=
NULL
);
assert
(
error_r
==
NULL
||
*
error_r
==
NULL
);
}
else
{
assert
(
error_r
==
NULL
||
*
error_r
!=
NULL
);
...
...
@@ -49,34 +46,31 @@ archive_file_open(const struct archive_plugin *plugin, const char *path,
}
void
archive_file_close
(
struct
archive_f
ile
*
file
)
archive_file_close
(
ArchiveF
ile
*
file
)
{
assert
(
file
!=
NULL
);
assert
(
file
->
plugin
!=
NULL
);
assert
(
file
->
plugin
->
close
!=
NULL
);
assert
(
file
->
plugin
.
close
!=
NULL
);
file
->
plugin
->
close
(
file
);
file
->
plugin
.
close
(
file
);
}
void
archive_file_visit
(
archive_f
ile
*
file
,
ArchiveVisitor
&
visitor
)
archive_file_visit
(
ArchiveF
ile
*
file
,
ArchiveVisitor
&
visitor
)
{
assert
(
file
!=
NULL
);
assert
(
file
->
plugin
!=
NULL
);
assert
(
file
->
plugin
->
visit
!=
nullptr
);
assert
(
file
->
plugin
.
visit
!=
nullptr
);
file
->
plugin
->
visit
(
file
,
visitor
);
file
->
plugin
.
visit
(
file
,
visitor
);
}
struct
input_stream
*
archive_file_open_stream
(
struct
archive_f
ile
*
file
,
const
char
*
path
,
archive_file_open_stream
(
ArchiveF
ile
*
file
,
const
char
*
path
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
)
{
assert
(
file
!=
NULL
);
assert
(
file
->
plugin
!=
NULL
);
assert
(
file
->
plugin
->
open_stream
!=
NULL
);
assert
(
file
->
plugin
.
open_stream
!=
NULL
);
return
file
->
plugin
->
open_stream
(
file
,
path
,
mutex
,
cond
,
return
file
->
plugin
.
open_stream
(
file
,
path
,
mutex
,
cond
,
error_r
);
}
src/ArchivePlugin.hxx
View file @
f5c0b0d3
...
...
@@ -25,7 +25,7 @@
#include "gerror.h"
struct
input_stream
;
struct
archive_f
ile
;
class
ArchiveF
ile
;
class
ArchiveVisitor
;
struct
archive_plugin
{
...
...
@@ -49,12 +49,12 @@ struct archive_plugin {
* returns pointer to handle used is all operations with this archive
* or NULL when opening fails
*/
struct
archive_f
ile
*
(
*
open
)(
const
char
*
path_fs
,
GError
**
error_r
);
ArchiveF
ile
*
(
*
open
)(
const
char
*
path_fs
,
GError
**
error_r
);
/**
* Visit all entries inside this archive.
*/
void
(
*
visit
)(
archive_f
ile
*
af
,
ArchiveVisitor
&
visitor
);
void
(
*
visit
)(
ArchiveF
ile
*
af
,
ArchiveVisitor
&
visitor
);
/**
* Opens an input_stream of a file within the archive.
...
...
@@ -63,7 +63,7 @@ struct archive_plugin {
* @param error_r location to store the error occurring, or
* NULL to ignore errors
*/
struct
input_stream
*
(
*
open_stream
)(
struct
archive_f
ile
*
af
,
struct
input_stream
*
(
*
open_stream
)(
ArchiveF
ile
*
af
,
const
char
*
path
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
);
...
...
@@ -71,7 +71,7 @@ struct archive_plugin {
/**
* closes archive file.
*/
void
(
*
close
)(
struct
archive_f
ile
*
);
void
(
*
close
)(
ArchiveF
ile
*
);
/**
* suffixes handled by this plugin.
...
...
@@ -80,18 +80,18 @@ struct archive_plugin {
const
char
*
const
*
suffixes
;
};
struct
archive_f
ile
*
ArchiveF
ile
*
archive_file_open
(
const
struct
archive_plugin
*
plugin
,
const
char
*
path
,
GError
**
error_r
);
void
archive_file_close
(
struct
archive_f
ile
*
file
);
archive_file_close
(
ArchiveF
ile
*
file
);
void
archive_file_visit
(
archive_f
ile
*
file
,
ArchiveVisitor
&
visitor
);
archive_file_visit
(
ArchiveF
ile
*
file
,
ArchiveVisitor
&
visitor
);
struct
input_stream
*
archive_file_open_stream
(
struct
archive_f
ile
*
file
,
const
char
*
path
,
archive_file_open_stream
(
ArchiveF
ile
*
file
,
const
char
*
path
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
);
...
...
src/UpdateArchive.cxx
View file @
f5c0b0d3
...
...
@@ -101,8 +101,7 @@ update_archive_file2(Directory *parent, const char *name,
/* open archive */
GError
*
error
=
NULL
;
struct
archive_file
*
file
=
archive_file_open
(
plugin
,
path_fs
.
c_str
(),
&
error
);
ArchiveFile
*
file
=
archive_file_open
(
plugin
,
path_fs
.
c_str
(),
&
error
);
if
(
file
==
NULL
)
{
g_warning
(
"%s"
,
error
->
message
);
g_error_free
(
error
);
...
...
src/archive/Bzip2ArchivePlugin.cxx
View file @
f5c0b0d3
...
...
@@ -23,8 +23,8 @@
#include "config.h"
#include "Bzip2ArchivePlugin.hxx"
#include "ArchiveInternal.hxx"
#include "ArchivePlugin.hxx"
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "InputInternal.hxx"
#include "InputStream.hxx"
...
...
@@ -42,17 +42,14 @@
#define BZ2_bzDecompress bzDecompress
#endif
struct
Bzip2ArchiveFile
{
struct
archive_file
base
;
class
Bzip2ArchiveFile
:
public
ArchiveFile
{
public
:
RefCount
ref
;
char
*
name
;
struct
input_stream
*
istream
;
Bzip2ArchiveFile
()
{
archive_file_init
(
&
base
,
&
bz2_archive_plugin
);
}
Bzip2ArchiveFile
()
:
ArchiveFile
(
bz2_archive_plugin
)
{}
void
Unref
()
{
if
(
!
ref
.
Decrement
())
...
...
@@ -123,7 +120,7 @@ Bzip2InputStream::Close()
/* archive open && listing routine */
static
struct
archive_f
ile
*
static
ArchiveF
ile
*
bz2_open
(
const
char
*
pathname
,
GError
**
error_r
)
{
Bzip2ArchiveFile
*
context
=
new
Bzip2ArchiveFile
();
...
...
@@ -147,11 +144,11 @@ bz2_open(const char *pathname, GError **error_r)
context
->
name
[
len
-
4
]
=
0
;
//remove .bz2 suffix
}
return
&
context
->
base
;
return
context
;
}
static
void
bz2_visit
(
archive_f
ile
*
file
,
ArchiveVisitor
&
visitor
)
bz2_visit
(
ArchiveF
ile
*
file
,
ArchiveVisitor
&
visitor
)
{
Bzip2ArchiveFile
*
context
=
(
Bzip2ArchiveFile
*
)
file
;
...
...
@@ -159,7 +156,7 @@ bz2_visit(archive_file *file, ArchiveVisitor &visitor)
}
static
void
bz2_close
(
struct
archive_f
ile
*
file
)
bz2_close
(
ArchiveF
ile
*
file
)
{
Bzip2ArchiveFile
*
context
=
(
Bzip2ArchiveFile
*
)
file
;
...
...
@@ -178,11 +175,11 @@ Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri,
Bzip2InputStream
::~
Bzip2InputStream
()
{
bz2_close
(
&
archive
->
base
);
archive
->
Unref
(
);
}
static
struct
input_stream
*
bz2_open_stream
(
struct
archive_f
ile
*
file
,
const
char
*
path
,
bz2_open_stream
(
ArchiveF
ile
*
file
,
const
char
*
path
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
)
{
...
...
src/archive/Iso9660ArchivePlugin.cxx
View file @
f5c0b0d3
...
...
@@ -23,8 +23,8 @@
#include "config.h"
#include "Iso9660ArchivePlugin.hxx"
#include "ArchiveInternal.hxx"
#include "ArchivePlugin.hxx"
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "InputInternal.hxx"
#include "InputStream.hxx"
...
...
@@ -41,17 +41,14 @@
#define CEILING(x, y) ((x+(y-1))/y)
struct
Iso9660ArchiveFile
{
struct
archive_file
base
;
class
Iso9660ArchiveFile
:
public
ArchiveFile
{
public
:
RefCount
ref
;
iso9660_t
*
iso
;
Iso9660ArchiveFile
(
iso9660_t
*
_iso
)
:
iso
(
_iso
)
{
archive_file_init
(
&
base
,
&
iso9660_archive_plugin
);
}
:
ArchiveFile
(
iso9660_archive_plugin
),
iso
(
_iso
)
{}
~
Iso9660ArchiveFile
()
{
iso9660_close
(
iso
);
...
...
@@ -107,7 +104,7 @@ Iso9660ArchiveFile::Visit(const char *psz_path, ArchiveVisitor &visitor)
_cdio_list_free
(
entlist
,
true
);
}
static
struct
archive_f
ile
*
static
ArchiveF
ile
*
iso9660_archive_open
(
const
char
*
pathname
,
GError
**
error_r
)
{
/* open archive */
...
...
@@ -118,12 +115,11 @@ iso9660_archive_open(const char *pathname, GError **error_r)
return
NULL
;
}
Iso9660ArchiveFile
*
archive
=
new
Iso9660ArchiveFile
(
iso
);
return
&
archive
->
base
;
return
new
Iso9660ArchiveFile
(
iso
);
}
static
void
iso9660_archive_visit
(
archive_f
ile
*
file
,
ArchiveVisitor
&
visitor
)
iso9660_archive_visit
(
ArchiveF
ile
*
file
,
ArchiveVisitor
&
visitor
)
{
Iso9660ArchiveFile
*
context
=
(
Iso9660ArchiveFile
*
)
file
;
...
...
@@ -132,7 +128,7 @@ iso9660_archive_visit(archive_file *file, ArchiveVisitor &visitor)
}
static
void
iso9660_archive_close
(
struct
archive_f
ile
*
file
)
iso9660_archive_close
(
ArchiveF
ile
*
file
)
{
Iso9660ArchiveFile
*
context
=
(
Iso9660ArchiveFile
*
)
file
;
...
...
@@ -170,7 +166,7 @@ struct Iso9660InputStream {
};
static
struct
input_stream
*
iso9660_archive_open_stream
(
struct
archive_f
ile
*
file
,
const
char
*
pathname
,
iso9660_archive_open_stream
(
ArchiveF
ile
*
file
,
const
char
*
pathname
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
)
{
...
...
src/archive/ZzipArchivePlugin.cxx
View file @
f5c0b0d3
...
...
@@ -23,8 +23,8 @@
#include "config.h"
#include "ZzipArchivePlugin.hxx"
#include "ArchiveInternal.hxx"
#include "ArchivePlugin.hxx"
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "InputInternal.hxx"
#include "InputStream.hxx"
...
...
@@ -35,16 +35,13 @@
#include <glib.h>
#include <string.h>
struct
ZzipArchiveFile
{
struct
archive_file
base
;
class
ZzipArchiveFile
:
public
ArchiveFile
{
public
:
RefCount
ref
;
ZZIP_DIR
*
dir
;
ZzipArchiveFile
()
{
archive_file_init
(
&
base
,
&
zzip_archive_plugin
);
}
ZzipArchiveFile
()
:
ArchiveFile
(
zzip_archive_plugin
)
{}
void
Unref
()
{
if
(
!
ref
.
Decrement
())
...
...
@@ -69,7 +66,7 @@ zzip_quark(void)
/* archive open && listing routine */
static
struct
archive_f
ile
*
static
ArchiveF
ile
*
zzip_archive_open
(
const
char
*
pathname
,
GError
**
error_r
)
{
ZzipArchiveFile
*
context
=
new
ZzipArchiveFile
();
...
...
@@ -82,7 +79,7 @@ zzip_archive_open(const char *pathname, GError **error_r)
return
NULL
;
}
return
&
context
->
base
;
return
context
;
}
inline
void
...
...
@@ -98,7 +95,7 @@ ZzipArchiveFile::Visit(ArchiveVisitor &visitor)
}
static
void
zzip_archive_visit
(
archive_f
ile
*
file
,
ArchiveVisitor
&
visitor
)
zzip_archive_visit
(
ArchiveF
ile
*
file
,
ArchiveVisitor
&
visitor
)
{
ZzipArchiveFile
*
context
=
(
ZzipArchiveFile
*
)
file
;
...
...
@@ -106,7 +103,7 @@ zzip_archive_visit(archive_file *file, ArchiveVisitor &visitor)
}
static
void
zzip_archive_close
(
struct
archive_f
ile
*
file
)
zzip_archive_close
(
ArchiveF
ile
*
file
)
{
ZzipArchiveFile
*
context
=
(
ZzipArchiveFile
*
)
file
;
...
...
@@ -145,7 +142,7 @@ struct ZzipInputStream {
};
static
struct
input_stream
*
zzip_archive_open_stream
(
struct
archive_f
ile
*
file
,
zzip_archive_open_stream
(
ArchiveF
ile
*
file
,
const
char
*
pathname
,
Mutex
&
mutex
,
Cond
&
cond
,
GError
**
error_r
)
...
...
src/input/ArchiveInputPlugin.cxx
View file @
f5c0b0d3
...
...
@@ -40,7 +40,6 @@ input_archive_open(const char *pathname,
GError
**
error_r
)
{
const
struct
archive_plugin
*
arplug
;
struct
archive_file
*
file
;
char
*
archive
,
*
filename
,
*
suffix
,
*
pname
;
struct
input_stream
*
is
;
...
...
@@ -63,7 +62,7 @@ input_archive_open(const char *pathname,
return
NULL
;
}
file
=
archive_file_open
(
arplug
,
archive
,
error_r
);
auto
file
=
archive_file_open
(
arplug
,
archive
,
error_r
);
if
(
file
==
NULL
)
{
g_free
(
pname
);
return
NULL
;
...
...
test/visit_archive.cxx
View file @
f5c0b0d3
...
...
@@ -25,6 +25,7 @@
#include "InputInit.hxx"
#include "ArchiveList.hxx"
#include "ArchivePlugin.hxx"
#include "ArchiveFile.hxx"
#include "ArchiveVisitor.hxx"
#include "fs/Path.hxx"
...
...
@@ -97,10 +98,11 @@ main(int argc, char **argv)
int
result
=
EXIT_SUCCESS
;
archive_f
ile
*
file
=
archive_file_open
(
plugin
,
path
.
c_str
(),
&
error
);
ArchiveF
ile
*
file
=
archive_file_open
(
plugin
,
path
.
c_str
(),
&
error
);
if
(
file
!=
nullptr
)
{
MyArchiveVisitor
visitor
;
archive_file_visit
(
file
,
visitor
);
archive_file_close
(
file
);
}
else
{
fprintf
(
stderr
,
"%s
\n
"
,
error
->
message
);
g_error_free
(
error
);
...
...
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