Skip to content

Commit 0c05bf8

Browse files
authored
integrate libmagic (#454)
1 parent 0784db6 commit 0c05bf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+547
-165
lines changed

CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ option(ODR_CLI "enable command line interface" ON)
1616
option(ODR_CLANG_TIDY "Run clang-tidy static analysis" OFF)
1717
option(WITH_PDF2HTMLEX "Build with pdf2htmlEX" ON)
1818
option(WITH_WVWARE "Build with wvWare" ON)
19-
option(WITH_CUSTOM_TMPFILE "Build with custom temporary file implementation" OFF)
19+
option(WITH_LIBMAGIC "Build with libmagic" ON)
2020

2121
# TODO defining global compiler flags seems to be bad practice with conan
2222
# TODO consider using conan profiles
@@ -245,15 +245,19 @@ if (WITH_WVWARE)
245245
ODR_WITH_WVWARE
246246
)
247247
endif ()
248-
if (WITH_CUSTOM_TMPFILE)
249-
find_package(tmpfile REQUIRED CONFIG)
248+
if (WITH_LIBMAGIC)
249+
find_package(libmagic REQUIRED)
250+
target_sources(odr
251+
PRIVATE
252+
"src/odr/internal/libmagic/libmagic.cpp"
253+
)
250254
target_link_libraries(odr
251255
PRIVATE
252-
tmpfile::tmpfile
256+
libmagic::libmagic
253257
)
254258
target_compile_definitions(odr
255259
PRIVATE
256-
ODR_WITH_CUSTOM_TMPFILE
260+
ODR_WITH_LIBMAGIC
257261
)
258262
endif ()
259263

conan.lock

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,83 @@
11
{
22
"version": "0.5",
33
"requires": [
4-
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1754336059.551",
5-
"wvware/1.2.9-odr#feeef48fa83e803330bbd3c706718618%1754339134.808372",
6-
"vincentlaucsb-csv-parser/2.3.0#ac67e368e82c9e3da4a663c35e3a1b2f%1754336215.262",
7-
"utfcpp/4.0.4#cd6efc5d62de4e9ee0b5f3abd0df37a9%1754336214.459",
8-
"uchardet/0.0.8#a9026ce72d955751db2dbda62c83c430%1754336213.652",
9-
"pugixml/1.14#c6afdcf73d71858303d8260b0d76ff91%1754336212.85",
10-
"poppler-data/0.4.12-odr#06cdb12e4cab52261a5eb6c7d7dad273%1754339136.6022458",
11-
"poppler/24.08.0-odr#2929132c6c3c67155c6c8f050c923916%1754339139.168313",
4+
"zstd/1.5.7#fde461c0d847a22f16d3066774f61b11%1744114235.235",
5+
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1733936244.862",
6+
"xz_utils/5.4.5#b885d1d79c9d30cff3803f7f551dbe66%1724318972.064",
7+
"wvware/1.2.9-odr#feeef48fa83e803330bbd3c706718618%1754432357.893",
8+
"vincentlaucsb-csv-parser/2.3.0#ac67e368e82c9e3da4a663c35e3a1b2f%1718528275.177",
9+
"util-linux-libuuid/2.39.2#637bd312b6310c18190469fae4e1d480%1748076007.711",
10+
"utfcpp/4.0.4#cd6efc5d62de4e9ee0b5f3abd0df37a9%1722968964.685",
11+
"uchardet/0.0.8#a9026ce72d955751db2dbda62c83c430%1703972855.616",
12+
"pugixml/1.14#c6afdcf73d71858303d8260b0d76ff91%1696206310.014",
13+
"poppler-data/0.4.12-odr#06cdb12e4cab52261a5eb6c7d7dad273%1754427610.1551769",
14+
"poppler/24.08.0-odr#2929132c6c3c67155c6c8f050c923916%1754427612.566178",
1215
"pixman/0.43.4#0dcdf859941e32fcc7bfb73ea1946a7f%1718828937.421",
13-
"pdf2htmlex/0.18.8.rc1-odr-git-eb5d291#01227c46d8bced149c1e2dd031406e57%1754339135.855592",
14-
"pcre2/10.42#9a35f5089feb875ec61a38eca364ce77%1754336050.663",
16+
"pdf2htmlex/0.18.8.rc1-odr-git-eb5d291#01227c46d8bced149c1e2dd031406e57%1754427609.135946",
17+
"pcre2/10.42#9a35f5089feb875ec61a38eca364ce77%1743524593.693",
1518
"openlibm/0.8.3#61d8454cf655e95e0d3d3359bde58ac7%1754339136.456942",
1619
"openjpeg/2.5.2#6f7b733e151d1bbf5ed05cbabb846828%1709653017.024",
17-
"nlohmann_json/3.11.3#45828be26eb619a2e04ca517bb7b828d%1754336206.708",
18-
"miniz/3.0.2#bfbce07c6654293cce27ee24129d2df7%1754336205.867",
20+
"nlohmann_json/3.11.3#45828be26eb619a2e04ca517bb7b828d%1701220705.259",
21+
"miniz/3.0.2#bfbce07c6654293cce27ee24129d2df7%1743673472.805",
1922
"lzo/2.10#5725914235423c771cb1c6b607109b45%1685099992.798",
20-
"libxml2/2.12.7#1c4d20b7ab8b618ce699733723ba4df6%1754336034.974",
21-
"libpng/1.6.48#dd0fc04a42b9a23bce065545a81d4847%1754336033.871",
22-
"libjpeg/9f#8edfe2699565c80c825d0256002504ff%1754336032.766",
23-
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1754336113.172",
24-
"libgsf/1.14.52#9b22c41267004c80ba5cde5d01e23a24%1754339136.153343",
25-
"libgettext/0.22#35d2811b2dd27a98f69e4daa86ca2000%1754336030.102",
26-
"libffi/3.4.8#06926dca35bcf8e321fcc24def952cde%1754336028.993",
27-
"libelf/0.8.13#ba59bbc89757ed62cfd7690a73bf81be%1754336027.877",
23+
"libxml2/2.12.7#1c4d20b7ab8b618ce699733723ba4df6%1721306327.767",
24+
"libselinux/3.6#5a78ff6ae5034eeaac8da723361a8ce4%1748075177.52",
25+
"libpng/1.6.48#dd0fc04a42b9a23bce065545a81d4847%1746141949.748",
26+
"libmagic/5.45#791d5bad38d33272bb120994a198b1ac%1727273086.09",
27+
"libjpeg/9f#8edfe2699565c80c825d0256002504ff%1723665907.087",
28+
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1751451666.321",
29+
"libgsf/1.14.52#9b22c41267004c80ba5cde5d01e23a24%1754427609.682325",
30+
"libgettext/0.22#35d2811b2dd27a98f69e4daa86ca2000%1714393058.647",
31+
"libffi/3.4.8#06926dca35bcf8e321fcc24def952cde%1748531860.405",
32+
"libelf/0.8.13#ba59bbc89757ed62cfd7690a73bf81be%1741781951.327",
2833
"lcms/2.16#fb083506ff40fd950c9e5c39df8bed54%1703969656.459",
29-
"gtest/1.14.0#f8f0757a574a8dd747d16af62d6eb1b7%1754336203.113",
30-
"glib/2.81.0-odr#ddf445d5af468f972978af93c44d26e1%1754339135.261312",
31-
"giflib/5.2.2#3923fc0f7ffec2f0bdbdee9b548f9248%1754336019.711",
32-
"freetype/2.13.2#5d2563803c8558d4ef47271a82c73d20%1754336015.019",
33-
"fontforge/20240423-git#525c82a5e57385c14b647b966e86ea58%1754339139.32232",
34-
"fontconfig/2.15.0-odr#2febbef44ca469204c8ff38cfd21db59%1754339136.30191",
34+
"gtest/1.14.0#f8f0757a574a8dd747d16af62d6eb1b7%1743410807.169",
35+
"glib/2.81.0-odr#ddf445d5af468f972978af93c44d26e1%1754427608.367101",
36+
"giflib/5.2.2#3923fc0f7ffec2f0bdbdee9b548f9248%1731663927.701",
37+
"freetype/2.13.2#5d2563803c8558d4ef47271a82c73d20%1728736671.752",
38+
"fontforge/20240423-git#525c82a5e57385c14b647b966e86ea58%1754432335.33",
39+
"fontconfig/2.15.0-odr#2febbef44ca469204c8ff38cfd21db59%1754427609.845061",
3540
"expat/2.6.3#39b80d3109fbe578fddfe4951f0b1d57%1725469045.298",
36-
"cryptopp/8.9.0#fe3de584c28c0ecc938a1671e3f1bd72%1754336202.171",
37-
"cpp-httplib/0.16.3#7aa89fbb81ffd19539a49fc132502966%1754336201.354",
38-
"cairo/1.18.0-odr#c1d0ad14a91ad6d161e756d54277ac13%1754339136.007648",
39-
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1754336009.237",
40-
"brotli/1.1.0#406ce8f1c997f4ef7852fa01ff85ef9f%1754336007.831",
41+
"cryptopp/8.9.0#fe3de584c28c0ecc938a1671e3f1bd72%1731421245.374",
42+
"cpp-httplib/0.16.3#7aa89fbb81ffd19539a49fc132502966%1748426320.106",
43+
"cairo/1.18.0-odr#c1d0ad14a91ad6d161e756d54277ac13%1754427609.450017",
44+
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1744702067.178",
45+
"brotli/1.1.0#406ce8f1c997f4ef7852fa01ff85ef9f%1743158659.041",
4146
"boost/1.86.0#cd839a2082585255010f9e82eea94c7f%1728027203.247",
42-
"argon2/20190702-odr#965901884bc82ec8a7c0a1305d42c127%1754339135.113191",
43-
"libselinux/3.6#5a78ff6ae5034eeaac8da723361a8ce4%1748075177.52",
44-
"util-linux-libuuid/2.39.2#637bd312b6310c18190469fae4e1d480%1748076007.711"
47+
"argon2/20190702-odr#965901884bc82ec8a7c0a1305d42c127%1754427608.210625"
4548
],
4649
"build_requires": [
47-
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1754336059.551",
48-
"pkgconf/2.2.0#6462942a22803086372db44689ba825f%1754336122.883",
49-
"pkgconf/2.1.0#27f44583701117b571307cf5b5fe5605%1754336055.341",
50-
"pkgconf/2.0.3#f996677e96e61e6552d85e83756c328b%1754336054.459",
51-
"pcre2/10.42#9a35f5089feb875ec61a38eca364ce77%1754336050.663",
52-
"ninja/1.13.0#53ff096207a5599ced46a633271b3cef%1754336120.489",
53-
"meson/1.4.0#2262941cc8fbb0099dd0c196ca2a6c01%1754336038.389",
54-
"meson/1.3.2#26ce8a76a36cc275cdfee1d757bc6561%1754336037.623",
55-
"meson/1.2.2#21b73818ba96d9eea465b310b5bbc993%1754336037.251",
50+
"zstd/1.5.7#fde461c0d847a22f16d3066774f61b11%1744114235.235",
51+
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1733936244.862",
52+
"xz_utils/5.4.5#b885d1d79c9d30cff3803f7f551dbe66%1724318972.064",
53+
"pkgconf/2.2.0#6462942a22803086372db44689ba825f%1713364853.749",
54+
"pkgconf/2.1.0#27f44583701117b571307cf5b5fe5605%1701537936.436",
55+
"pkgconf/2.0.3#f996677e96e61e6552d85e83756c328b%1696606182.229",
56+
"pcre2/10.42#9a35f5089feb875ec61a38eca364ce77%1743524593.693",
57+
"ninja/1.13.0#53ff096207a5599ced46a633271b3cef%1751046277.036",
58+
"msys2/cci.latest#5b73b10144f73cc5bfe0572ed9be39e1%1751977009.857",
59+
"meson/1.4.0#2262941cc8fbb0099dd0c196ca2a6c01%1726730116.631",
60+
"meson/1.3.2#26ce8a76a36cc275cdfee1d757bc6561%1726730118.251",
61+
"meson/1.2.2#21b73818ba96d9eea465b310b5bbc993%1726730120.212",
5662
"meson/1.2.1#f2b0c7763308df8e33172744dace8845%1726730117.905",
57-
"m4/1.4.19#b38ced39a01e31fef5435bc634461fd2%1754336036.417",
58-
"libtool/2.4.7#a182d7ce8d4c346a19dbd4a5d532ef68%1754336116.018",
59-
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1754336113.172",
60-
"libgettext/0.22#35d2811b2dd27a98f69e4daa86ca2000%1754336030.102",
61-
"libffi/3.4.8#06926dca35bcf8e321fcc24def952cde%1754336028.993",
62-
"libelf/0.8.13#ba59bbc89757ed62cfd7690a73bf81be%1754336027.877",
63-
"gtk-doc-stub/cci.20181216#09072d684ce1458596b44a30a747494c%1754336106.527",
63+
"m4/1.4.19#b38ced39a01e31fef5435bc634461fd2%1700758725.451",
64+
"libtool/2.4.7#a182d7ce8d4c346a19dbd4a5d532ef68%1742900203.747",
65+
"libselinux/3.6#5a78ff6ae5034eeaac8da723361a8ce4%1717655459.344",
66+
"libmagic/5.45#791d5bad38d33272bb120994a198b1ac%1727273086.09",
67+
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1751451666.321",
68+
"libgettext/0.22#35d2811b2dd27a98f69e4daa86ca2000%1714393058.647",
69+
"libffi/3.4.8#06926dca35bcf8e321fcc24def952cde%1748531860.405",
70+
"libelf/0.8.13#ba59bbc89757ed62cfd7690a73bf81be%1741781951.327",
71+
"gtk-doc-stub/cci.20181216#09072d684ce1458596b44a30a747494c%1687277608.37",
6472
"gperf/3.1#1d622ad9717e9348ed3685c9994ad0b9%1709324989.76",
65-
"gnu-config/cci.20210814#dc430d754f465e8c74463019672fb97b%1754336027.04",
66-
"glib/2.81.0-odr#ddf445d5af468f972978af93c44d26e1%1754339135.261312",
67-
"gettext/0.22.5#a1f31cc77dee0345699745ef39686dd0%1754336091.687",
68-
"cmake/3.31.8#dd6e07c418afc4b30cb1c21584dccc49%1754336200.956",
69-
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1754336009.237",
70-
"automake/1.16.5#058bda3e21c36c9aa8425daf3c1faf50%1754336006.921",
71-
"autoconf/2.71#f9307992909d7fb3df459340f1932809%1754336006.057",
72-
"libselinux/3.6#5a78ff6ae5034eeaac8da723361a8ce4%1748075177.52",
73-
"flex/2.6.4#e35bc44b3fcbcd661e0af0dc5b5b1ad4%1748075168.656"
73+
"gnu-config/cci.20210814#dc430d754f465e8c74463019672fb97b%1701248168.479",
74+
"glib/2.81.0-odr#ddf445d5af468f972978af93c44d26e1%1754427608.367101",
75+
"gettext/0.22.5#a1f31cc77dee0345699745ef39686dd0%1750252839.982",
76+
"flex/2.6.4#e35bc44b3fcbcd661e0af0dc5b5b1ad4%1674818991.113",
77+
"cmake/3.31.8#dd6e07c418afc4b30cb1c21584dccc49%1750223587.75",
78+
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1744702067.178",
79+
"automake/1.16.5#058bda3e21c36c9aa8425daf3c1faf50%1688481772.751",
80+
"autoconf/2.71#f9307992909d7fb3df459340f1932809%1711983104.648"
7481
],
7582
"python_requires": [],
7683
"config_requires": []

conanfile.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ class OpenDocumentCoreConan(ConanFile):
1919
"fPIC": [True, False],
2020
"with_pdf2htmlEX": [True, False],
2121
"with_wvWare": [True, False],
22+
"with_libmagic": [True, False],
2223
}
2324
default_options = {
2425
"shared": False,
2526
"fPIC": True,
2627
"with_pdf2htmlEX": True,
2728
"with_wvWare": True,
29+
"with_libmagic": True,
2830
}
2931

3032
exports_sources = ["cli/*", "cmake/*", "resources/dist/*", "src/*", "CMakeLists.txt"]
@@ -34,6 +36,7 @@ def config_options(self):
3436
del self.options.fPIC
3537
del self.options.with_pdf2htmlEX
3638
del self.options.with_wvWare
39+
del self.options.with_libmagic
3740

3841
def requirements(self):
3942
self.requires("pugixml/1.14")
@@ -49,6 +52,8 @@ def requirements(self):
4952
self.requires("wvware/1.2.9-odr")
5053
self.requires("cpp-httplib/0.16.3")
5154
self.requires("argon2/20190702-odr")
55+
if self.options.get_safe("with_libmagic", False):
56+
self.requires("libmagic/5.45")
5257

5358
def build_requirements(self):
5459
self.test_requires("gtest/1.14.0")
@@ -67,17 +72,18 @@ def generate(self):
6772
tc.variables["ODR_TEST"] = False
6873
tc.variables["WITH_PDF2HTMLEX"] = self.options.get_safe("with_pdf2htmlEX", False)
6974
tc.variables["WITH_WVWARE"] = self.options.get_safe("with_wvWare", False)
75+
tc.variables["WITH_LIBMAGIC"] = self.options.get_safe("with_libmagic", False)
7076

7177
# Get runenv info, exported by package_info() of dependencies
7278
# We need to obtain PDF2HTMLEX_DATA_DIR, POPPLER_DATA_DIR, FONTCONFIG_PATH and WVDATADIR
7379
runenv_info = Environment()
74-
deps = self.dependencies.host.topological_sort
75-
deps = [dep for dep in reversed(deps.values())]
76-
for dep in deps:
80+
for dep in self.dependencies.host.topological_sort.values():
7781
runenv_info.compose_env(dep.runenv_info)
7882
envvars = runenv_info.vars(self)
79-
for v in ["PDF2HTMLEX_DATA_DIR", "POPPLER_DATA_DIR", "FONTCONFIG_PATH", "WVDATADIR"]:
80-
tc.variables[v] = envvars.get(v)
83+
tc.variables["FONTCONFIG_DATA_PATH"] = envvars.get("FONTCONFIG_PATH")
84+
tc.variables["POPPLER_DATA_PATH"] = envvars.get("POPPLER_DATA_DIR")
85+
tc.variables["PDF2HTMLEX_DATA_PATH"] = envvars.get("PDF2HTMLEX_DATA_DIR")
86+
tc.variables["LIBMAGIC_DATABASE_PATH"] = envvars.get("MAGIC")
8187

8288
tc.generate()
8389

src/odr/file.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <odr/internal/abstract/file.hpp>
88
#include <odr/internal/common/file.hpp>
9+
#include <odr/internal/magic.hpp>
910
#include <odr/internal/open_strategy.hpp>
1011
#include <odr/internal/util/file_util.hpp>
1112
#include <odr/internal/util/stream_util.hpp>
@@ -27,6 +28,12 @@ FileMeta::FileMeta(const FileType type, const bool password_encrypted,
2728
: type{type}, password_encrypted{password_encrypted},
2829
document_meta{document_meta} {}
2930

31+
FileMeta::FileMeta(const FileType type, const std::string_view mimetype,
32+
const bool password_encrypted,
33+
const std::optional<DocumentMeta> document_meta)
34+
: type{type}, mimetype{mimetype}, password_encrypted{password_encrypted},
35+
document_meta{document_meta} {}
36+
3037
File::File() = default;
3138

3239
File::File(std::shared_ptr<internal::abstract::File> impl)
@@ -66,6 +73,12 @@ std::vector<FileType> DecodedFile::list_file_types(const std::string &path,
6673
std::make_shared<internal::DiskFile>(path), logger);
6774
}
6875

76+
std::string_view DecodedFile::mimetype(const std::string &path,
77+
Logger &logger) {
78+
(void)logger;
79+
return internal::magic::mimetype(path);
80+
}
81+
6982
std::vector<DecoderEngine>
7083
DecodedFile::list_decoder_engines(const FileType as) {
7184
return internal::open_strategy::list_decoder_engines(as);

src/odr/file.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <memory>
66
#include <optional>
77
#include <string>
8+
#include <string_view>
89
#include <vector>
910

1011
namespace odr::internal::abstract {
@@ -140,10 +141,14 @@ struct DocumentMeta final {
140141
/// @brief Meta information about a file.
141142
struct FileMeta final {
142143
FileMeta();
144+
[[deprecated]]
143145
FileMeta(FileType type, bool password_encrypted,
144146
std::optional<DocumentMeta> document_meta);
147+
FileMeta(FileType type, std::string_view mimetype, bool password_encrypted,
148+
std::optional<DocumentMeta> document_meta);
145149

146150
FileType type{FileType::unknown};
151+
std::string_view mimetype;
147152
bool password_encrypted{false};
148153
std::optional<DocumentMeta> document_meta;
149154
};
@@ -175,9 +180,12 @@ class File final {
175180
/// @brief Represents a decoded file.
176181
class DecodedFile {
177182
public:
178-
static std::vector<FileType> list_file_types(const std::string &path,
179-
Logger &logger = Logger::null());
180-
static std::vector<DecoderEngine> list_decoder_engines(FileType as);
183+
[[nodiscard]] static std::vector<FileType>
184+
list_file_types(const std::string &path, Logger &logger = Logger::null());
185+
[[nodiscard]] static std::vector<DecoderEngine>
186+
list_decoder_engines(FileType as);
187+
[[nodiscard]] static std::string_view
188+
mimetype(const std::string &path, Logger &logger = Logger::null());
181189

182190
explicit DecodedFile(std::shared_ptr<internal::abstract::DecodedFile> impl);
183191
explicit DecodedFile(const File &file, Logger &logger = Logger::null());

src/odr/global_params.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const std::string &GlobalParams::pdf2htmlex_data_path() {
4141
return instance().m_pdf2htmlex_data_path;
4242
}
4343

44+
const std::string &GlobalParams::libmagic_database_path() {
45+
return instance().m_libmagic_database_path;
46+
}
47+
4448
void GlobalParams::set_odr_core_data_path(const std::string &path) {
4549
instance().m_odr_core_data_path = path;
4650
}
@@ -62,10 +66,16 @@ void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) {
6266
instance().m_pdf2htmlex_data_path = path;
6367
}
6468

69+
void GlobalParams::set_libmagic_database_path(const std::string &path) {
70+
instance().m_libmagic_database_path = path;
71+
}
72+
6573
GlobalParams::GlobalParams()
6674
: m_odr_core_data_path{internal::project_info::odr_data_path()},
6775
m_fontconfig_data_path{internal::project_info::fontconfig_data_path()},
6876
m_poppler_data_path{internal::project_info::poppler_data_path()},
69-
m_pdf2htmlex_data_path{internal::project_info::pdf2htmlex_data_path()} {}
77+
m_pdf2htmlex_data_path{internal::project_info::pdf2htmlex_data_path()},
78+
m_libmagic_database_path{
79+
internal::project_info::libmagic_database_path()} {}
7080

7181
} // namespace odr

src/odr/global_params.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class GlobalParams {
1010
static const std::string &fontconfig_data_path();
1111
static const std::string &poppler_data_path();
1212
static const std::string &pdf2htmlex_data_path();
13+
static const std::string &libmagic_database_path();
1314

1415
static void set_odr_core_data_path(const std::string &path);
1516
static void set_fontconfig_data_path(const std::string &path);
1617
static void set_poppler_data_path(const std::string &path);
1718
static void set_pdf2htmlex_data_path(const std::string &path);
19+
static void set_libmagic_database_path(const std::string &path);
1820

1921
private:
2022
static GlobalParams &instance();
@@ -25,6 +27,7 @@ class GlobalParams {
2527
std::string m_fontconfig_data_path;
2628
std::string m_poppler_data_path;
2729
std::string m_pdf2htmlex_data_path;
30+
std::string m_libmagic_database_path;
2831
};
2932

3033
} // namespace odr

src/odr/internal/abstract/file.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ class DecodedFile {
3434

3535
[[nodiscard]] virtual std::shared_ptr<File> file() const noexcept = 0;
3636

37+
[[nodiscard]] virtual DecoderEngine decoder_engine() const noexcept = 0;
3738
[[nodiscard]] virtual FileType file_type() const noexcept = 0;
3839
[[nodiscard]] virtual FileCategory file_category() const noexcept = 0;
40+
[[nodiscard]] virtual std::string_view mimetype() const noexcept = 0;
3941
[[nodiscard]] virtual FileMeta file_meta() const noexcept = 0;
40-
[[nodiscard]] virtual DecoderEngine decoder_engine() const noexcept = 0;
4142

4243
[[nodiscard]] virtual bool password_encrypted() const noexcept {
4344
return false;
@@ -99,6 +100,9 @@ class PdfFile : public DecodedFile {
99100
[[nodiscard]] FileCategory file_category() const noexcept final {
100101
return FileCategory::document;
101102
}
103+
[[nodiscard]] std::string_view mimetype() const noexcept final {
104+
return "application/pdf";
105+
}
102106
};
103107

104108
} // namespace odr::internal::abstract

0 commit comments

Comments
 (0)