summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-03-28 20:14:53 +0800
committerTor Andersson <tor.andersson@artifex.com>2017-04-13 14:13:31 +0200
commit0cd7f2e8397e2caf47f3d46ef635358fa0ba194c (patch)
tree74dd47522cbcd34873121bed2520834613ae9957 /source/html
parent48be72fb64202cb52d5ebe3a4c931aa925276b6d (diff)
downloadmupdf-0cd7f2e8397e2caf47f3d46ef635358fa0ba194c.tar.xz
Move extension/mimetype detection to common function.
A document handler normally only exposes a list of extensions and mimetypes. Only formats that use some kind of extra detection mechnism need to supply a recognize() callback, such as xps that can handle .xps-files unpacked into a directory.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/epub-doc.c22
-rw-r--r--source/html/html-doc.c38
2 files changed, 36 insertions, 24 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index 44903d99..c43ef8b1 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -519,20 +519,28 @@ epub_open_document(fz_context *ctx, const char *filename)
static int
epub_recognize(fz_context *doc, const char *magic)
{
- char *ext = strrchr(magic, '.');
- if (ext)
- if (!fz_strcasecmp(ext, ".epub"))
- return 100;
if (strstr(magic, "META-INF/container.xml") || strstr(magic, "META-INF\\container.xml"))
return 200;
- if (!strcmp(magic, "application/epub+zip"))
- return 100;
return 0;
}
+static const char *epub_extensions[] =
+{
+ "epub",
+ NULL
+};
+
+static const char *epub_mimetypes[] =
+{
+ "application/epub+zip",
+ NULL
+};
+
fz_document_handler epub_document_handler =
{
epub_recognize,
epub_open_document,
- epub_open_document_with_stream
+ epub_open_document_with_stream,
+ epub_extensions,
+ epub_mimetypes
};
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index ba765350..1cf3dca5 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -197,26 +197,30 @@ htdoc_open_document(fz_context *ctx, const char *filename)
return (fz_document*)doc;
}
-static int
-htdoc_recognize(fz_context *doc, const char *magic)
-{
- char *ext = strrchr(magic, '.');
+static const char *htdoc_extensions[] =
+{
+ "fb2",
+ "htm",
+ "html",
+ "xhtml",
+ "xml",
+ NULL
+};
- if (ext)
- {
- if (!fz_strcasecmp(ext, ".xml") || !fz_strcasecmp(ext, ".xhtml") ||
- !fz_strcasecmp(ext, ".html") || !fz_strcasecmp(ext, ".htm") ||
- !fz_strcasecmp(ext, ".fb2"))
- return 100;
- }
- if (!strcmp(magic, "application/html+xml") || !strcmp(magic, "application/xml") || !strcmp(magic, "text/xml"))
- return 100;
- return 0;
-}
+static const char *htdoc_mimetypes[] =
+{
+ "application/html+xml",
+ "application/x-fictionbook",
+ "application/xml",
+ "text/xml",
+ NULL
+};
fz_document_handler html_document_handler =
{
- htdoc_recognize,
+ NULL,
htdoc_open_document,
- htdoc_open_document_with_stream
+ htdoc_open_document_with_stream,
+ htdoc_extensions,
+ htdoc_mimetypes
};