From 0cd7f2e8397e2caf47f3d46ef635358fa0ba194c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Tue, 28 Mar 2017 20:14:53 +0800 Subject: 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. --- source/cbz/mucbz.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'source/cbz/mucbz.c') diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c index a557a9c7..3a19c174 100644 --- a/source/cbz/mucbz.c +++ b/source/cbz/mucbz.c @@ -217,28 +217,29 @@ cbz_open_document_with_stream(fz_context *ctx, fz_stream *file) return &doc->super; } -static int -cbz_recognize(fz_context *ctx, const char *magic) -{ - char *ext = strrchr(magic, '.'); - if ((ext && !fz_strcasecmp(ext, ".cbz")) || !strcmp(magic, "cbz") || - !strcmp(magic, "application/x-cbz")) - return 100; - if ((ext && !fz_strcasecmp(ext, ".zip")) || !strcmp(magic, "zip") || - !strcmp(magic, "application/zip")) - return 100; - if ((ext && !fz_strcasecmp(ext, ".tar")) || !strcmp(magic, "tar") || - !strcmp(magic, "application/x-tar")) - return 100; - if ((ext && !fz_strcasecmp(ext, ".cbt")) || !strcmp(magic, "cbt") || - !strcmp(magic, "application/x-cbt")) - return 100; - return 0; -} +static const char *cbz_extensions[] = +{ + "cbt", + "cbz", + "tar", + "zip", + NULL +}; + +static const char *cbz_mimetypes[] = +{ + "application/x-cbt", + "application/x-cbz", + "application/x-tar", + "application/zip", + NULL +}; fz_document_handler cbz_document_handler = { - cbz_recognize, NULL, - cbz_open_document_with_stream + NULL, + cbz_open_document_with_stream, + cbz_extensions, + cbz_mimetypes }; -- cgit v1.2.3